25 constexpr ChannelColors(uint8_t r_offset, uint8_t g_offset, uint8_t b_offset)
27 constexpr ChannelColors(uint8_t r_offset, uint8_t g_offset, uint8_t b_offset, uint8_t w_offset)
28 :
r(r_offset),
g(g_offset),
b(b_offset),
w(w_offset) {}
40 inline bool has_white()
const {
return (this->
w & 0x80) == 0; }
44 inline Color get(
const uint8_t *color_data, int32_t index)
const ESPHOME_ALWAYS_INLINE {
45 if (this->
w == NO_WHITE)
46 return Color(color_data[index * 3 + this->
r], color_data[index * 3 + this->
g], color_data[index * 3 + this->
b]);
47 return Color(color_data[index * 4 + this->
r], color_data[index * 4 + this->
g], color_data[index * 4 + this->
b],
48 this->
has_white() ? color_data[index * 4 + this->
w] : 0);
51 uint8_t
get_channel(
const uint8_t *color_data, int32_t index, uint8_t channel)
const {
52 const uint8_t offset = this->
raw[channel];
53 return (offset & 0x80) == 0 ? color_data[index * this->
bytes_per_led() + offset] : 0;
56 void set(uint8_t *color_data, int32_t index,
Color color)
const {
57 if (this->
w == NO_WHITE) {
58 color_data[index * 3 + this->
r] = color.
red;
59 color_data[index * 3 + this->
g] = color.
green;
60 color_data[index * 3 + this->
b] = color.
blue;
62 color_data[index * 4 + this->
r] = color.
red;
63 color_data[index * 4 + this->
g] = color.
green;
64 color_data[index * 4 + this->
b] = color.
blue;
66 color_data[index * 4 + this->
w] = color.
white;
70 void set_channel(uint8_t *color_data, int32_t index, uint8_t channel, uint8_t
value)
const {
71 const uint8_t offset = this->
raw[channel];
72 if ((offset & 0x80) == 0)
104static_assert(offsetof(ChannelColors,
raw) == COLOR_CHANNEL_R);
105static_assert(offsetof(ChannelColors, r) == COLOR_CHANNEL_R);
106static_assert(offsetof(ChannelColors, g) == COLOR_CHANNEL_G);
107static_assert(offsetof(ChannelColors,
b) == COLOR_CHANNEL_B);
108static_assert(offsetof(ChannelColors, w) == COLOR_CHANNEL_W);
This class is used to represent the capabilities of a light.
void set_supported_color_modes(ColorModeMask supported_color_modes)
@ RGB_WHITE
RGB color output and a separate white output.
@ WHITE
White output only (use only if the light also has another color mode such as RGB).
Which byte of an addressable LED's data carries each colour.
constexpr ChannelColors(uint8_t r_offset, uint8_t g_offset, uint8_t b_offset)
void set_channel(uint8_t *color_data, int32_t index, uint8_t channel, uint8_t value) const
size_t bytes_per_led() const
static constexpr uint8_t NO_WHITE
Value of w for an RGB LED strip that uses 3 bytes per led.
const char * to_string(char *buf) const
Write the order back out as text, e.g.
constexpr ChannelColors(uint8_t r_offset, uint8_t g_offset, uint8_t b_offset, uint8_t w_offset)
constexpr ChannelColors()
Color get(const uint8_t *color_data, int32_t index) const ESPHOME_ALWAYS_INLINE
void set(uint8_t *color_data, int32_t index, Color color) const
LightTraits traits() const
Colour modes of a strip with this channel order.
uint8_t get_channel(const uint8_t *color_data, int32_t index, uint8_t channel) const
static constexpr uint8_t RESERVED_WHITE
Value of w for an RGB LED strip that uses 4 bytes per led where the 4th byte is reserved.