12#ifndef M5_UNIT_COLOR_UNIT_TCS3472X_DATA_HPP
13#define M5_UNIT_COLOR_UNIT_TCS3472X_DATA_HPP
67 std::array<uint8_t, 8>
raw{};
72 inline uint16_t
R16()
const
74 return (
static_cast<uint16_t
>(
raw[3]) << 8) |
raw[2];
77 inline uint16_t
G16()
const
79 return (
static_cast<uint16_t
>(
raw[5]) << 8) |
raw[4];
82 inline uint16_t
B16()
const
84 return (
static_cast<uint16_t
>(
raw[7]) << 8) |
raw[6];
87 inline uint16_t
C16()
const
89 return (
static_cast<uint16_t
>(
raw[1]) << 8) |
raw[0];
94 return std::max(std::min(
R16() -
IR(),
static_cast<int32_t
>(0xFFFF)),
static_cast<int32_t
>(0x0000));
99 return std::max(std::min(
G16() -
IR(),
static_cast<int32_t
>(0xFFFF)),
static_cast<int32_t
>(0x0000));
104 return std::max(std::min(
B16() -
IR(),
static_cast<int32_t
>(0xFFFF)),
static_cast<int32_t
>(0x0000));
109 return std::max(std::min(
C16() -
IR(),
static_cast<int32_t
>(0xFFFF)),
static_cast<int32_t
>(0x0000));
116 inline uint8_t
R8()
const
121 inline uint8_t
G8()
const
126 inline uint8_t
B8()
const
175 inline int32_t
IR(
const bool usingCache =
true)
const
177 if (!usingCache || !_cacheValid) {
178 _cache =
static_cast<int32_t
>((
static_cast<int32_t
>(
R16()) +
static_cast<int32_t
>(
G16()) +
179 static_cast<int32_t
>(
B16()) -
static_cast<int32_t
>(
C16())) *
194 return std::max(std::min(
static_cast<int>(c ? (
static_cast<float>(v) / c) * 255.f : 0), 0xFF), 0x00);
206 inline static constexpr uint8_t
color332(
const uint8_t r,
const uint8_t g,
const uint8_t b)
208 return ((((r >> 5) << 3) + (g >> 5)) << 2) + (b >> 6);
217 inline static constexpr uint16_t
color565(
const uint8_t r,
const uint8_t g,
const uint8_t b)
219 return (r >> 3) << 11 | (g >> 2) << 5 | b >> 3;
228 inline static constexpr uint32_t
color888(
const uint8_t r,
const uint8_t g,
const uint8_t b)
230 return r << 16 | g << 8 | b;
239 inline static constexpr uint16_t
swap565(
const uint8_t r,
const uint8_t g,
const uint8_t b)
241 return (((r >> 3) << 3) + (g >> 5)) | (((g >> 2) << 5) | (b >> 3)) << 8;
250 inline static constexpr uint32_t
swap888(
const uint8_t r,
const uint8_t g,
const uint8_t b)
252 return b << 16 | g << 8 | r;
257 mutable int32_t _cache{};
258 mutable bool _cacheValid{};
Top level namespace of M5Stack.
Measurement data group.
Definition unit_TCS3472x_data.hpp:66
uint16_t RGBnoIR565() const
Gets the value in RGB565 format without IR component.
Definition unit_TCS3472x_data.hpp:157
uint8_t G8() const
Gets the green value (0-255)
Definition unit_TCS3472x_data.hpp:121
std::array< uint8_t, 8 > raw
Raw data ClCh/RlRh/GlGh/BlBh.
Definition unit_TCS3472x_data.hpp:67
static constexpr uint8_t color332(const uint8_t r, const uint8_t g, const uint8_t b)
Converts 8-bit RGB channels to RGB332 format.
Definition unit_TCS3472x_data.hpp:206
static uint8_t raw_to_uint8(const int32_t v, const int32_t c)
Raw to uint8_t.
Definition unit_TCS3472x_data.hpp:192
static constexpr uint16_t swap565(const uint8_t r, const uint8_t g, const uint8_t b)
Converts 8-bit RGB channels to byte-swapped RGB565 format.
Definition unit_TCS3472x_data.hpp:239
uint32_t RGBnoIR888() const
Gets the value in RGB888 format without IR component.
Definition unit_TCS3472x_data.hpp:162
uint16_t RnoIR16() const
Gets the raw red value without IR component.
Definition unit_TCS3472x_data.hpp:92
uint16_t RGB565() const
Gets the value in RGB565 format.
Definition unit_TCS3472x_data.hpp:147
static constexpr uint32_t swap888(const uint8_t r, const uint8_t g, const uint8_t b)
Converts 8-bit RGB channels to byte-swapped RGB888 format.
Definition unit_TCS3472x_data.hpp:250
uint16_t G16() const
Gets the raw green value.
Definition unit_TCS3472x_data.hpp:77
uint16_t R16() const
Gets the raw red value.
Definition unit_TCS3472x_data.hpp:72
uint16_t B16() const
Gets the raw blue value.
Definition unit_TCS3472x_data.hpp:82
uint8_t BnoIR8() const
Gets the blue value without IR component (0-255)
Definition unit_TCS3472x_data.hpp:141
uint8_t GnoIR8() const
Gets the green value without IR component (0-255)
Definition unit_TCS3472x_data.hpp:136
int32_t IR(const bool usingCache=true) const
Gets the IR component.
Definition unit_TCS3472x_data.hpp:175
uint16_t BnoIR16() const
Gets the raw blue value without IR component.
Definition unit_TCS3472x_data.hpp:102
uint16_t CnoIR16() const
Gets the raw clear value without IR component.
Definition unit_TCS3472x_data.hpp:107
uint16_t GnoIR16() const
Gets the raw green value without IR component.
Definition unit_TCS3472x_data.hpp:97
uint32_t RGB888() const
Gets the value in RGB888 format.
Definition unit_TCS3472x_data.hpp:152
uint8_t R8() const
Gets the red value (0-255)
Definition unit_TCS3472x_data.hpp:116
static constexpr uint32_t color888(const uint8_t r, const uint8_t g, const uint8_t b)
Converts 8-bit RGB channels to RGB888 format.
Definition unit_TCS3472x_data.hpp:228
uint8_t RnoIR8() const
Gets the red value without IR component (0-255)
Definition unit_TCS3472x_data.hpp:131
static constexpr uint16_t color565(const uint8_t r, const uint8_t g, const uint8_t b)
Converts 8-bit RGB channels to RGB565 format.
Definition unit_TCS3472x_data.hpp:217
uint16_t C16() const
Gets the raw clear value.
Definition unit_TCS3472x_data.hpp:87
uint8_t B8() const
Gets the blue value (0-255)
Definition unit_TCS3472x_data.hpp:126
Gain
RGBC Gain Control.
Definition unit_TCS3472x_data.hpp:55
Persistence
Interrupt persistence.
Definition unit_TCS3472x_data.hpp:32
@ Cycle35
35 clear channel value outside of threshold range
@ Cycle15
15 clear channel value outside of threshold range
@ Cycle45
45 clear channel value outside of threshold range
@ Cycle40
40 clear channel value outside of threshold range
@ Cycle3
3 clear channel value outside of threshold range
@ Cycle55
55 clear channel value outside of threshold range
@ Cycle5
5 clear channel value outside of threshold range
@ Cycle10
10 clear channel value outside of threshold range
@ Cycle30
30 clear channel value outside of threshold range
@ Cycle1
1 clear channel value outside of threshold range
@ Cycle2
2 clear channel value outside of threshold range
@ Cycle25
25 clear channel value outside of threshold range
@ Cycle50
50 clear channel value outside of threshold range
@ Cycle60
60 clear channel value outside of threshold range
@ Cycle20
20 clear channel value outside of threshold range
@ Every
Every RGBC cycle generates an interrupt.