10 inline static uint8_t to_uint8_scale(
float x) {
return static_cast<uint8_t
>(roundf(x * 255.0f)); }
62 float blue,
float white,
float color_temperature,
float cold_white,
float warm_white) {
114 if (max_value == 0.0f) {
138 void as_rgb(
float *red,
float *green,
float *blue,
float gamma = 0,
bool color_interlock =
false)
const {
145 *red = *green = *blue = 0;
150 void as_rgbw(
float *red,
float *green,
float *blue,
float *white,
float gamma = 0,
151 bool color_interlock =
false)
const {
152 this->
as_rgb(red, green, blue, gamma);
161 void as_rgbww(
float *red,
float *green,
float *blue,
float *cold_white,
float *warm_white,
float gamma = 0,
162 bool constant_brightness =
false)
const {
163 this->
as_rgb(red, green, blue, gamma);
164 this->
as_cwww(cold_white, warm_white, gamma, constant_brightness);
168 void as_rgbct(
float color_temperature_cw,
float color_temperature_ww,
float *red,
float *green,
float *blue,
169 float *color_temperature,
float *white_brightness,
float gamma = 0)
const {
170 this->
as_rgb(red, green, blue, gamma);
171 this->
as_ct(color_temperature_cw, color_temperature_ww, color_temperature, white_brightness, gamma);
175 void as_cwww(
float *cold_white,
float *warm_white,
float gamma = 0,
bool constant_brightness =
false)
const {
180 if (!constant_brightness) {
181 *cold_white = white_level * cw_level;
182 *warm_white = white_level * ww_level;
189 const float sum = cw_level > 0 || ww_level > 0 ? cw_level + ww_level : 1;
190 *cold_white = white_level * std::max(cw_level, ww_level) * cw_level / sum;
191 *warm_white = white_level * std::max(cw_level, ww_level) * ww_level / sum;
194 *cold_white = *warm_white = 0;
199 void as_ct(
float color_temperature_cw,
float color_temperature_ww,
float *color_temperature,
float *white_brightness,
200 float gamma = 0)
const {
204 (this->
color_temperature_ - color_temperature_cw) / (color_temperature_ww - color_temperature_cw);
207 *white_brightness = 0;
278 if (color_temperature <= 0) {
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
float get_warm_white() const
Get the warm white property of these light color values. In range 0.0 to 1.0.
bool is_on() const
Get the binary true/false state of these light color values.
float color_temperature_
Color Temperature in Mired.
void set_warm_white(float warm_white)
Set the warm white property of these light color values. In range 0.0 to 1.0.
void as_cwww(float *cold_white, float *warm_white, float gamma=0, bool constant_brightness=false) const
Convert these light color values to an CWWW representation with the given parameters.
void set_state(bool state)
Set the state of these light color values as a binary true/false.
float get_cold_white() const
Get the cold white property of these light color values. In range 0.0 to 1.0.
void set_green(float green)
Set the green property of these light color values. In range 0.0 to 1.0.
void as_rgbct(float color_temperature_cw, float color_temperature_ww, float *red, float *green, float *blue, float *color_temperature, float *white_brightness, float gamma=0) const
Convert these light color values to an RGB+CT+BR representation with the given parameters.
void set_state(float state)
Set the state of these light color values. In range from 0.0 (off) to 1.0 (on)
float get_red() const
Get the red property of these light color values. In range 0.0 to 1.0.
LightColorValues(ColorMode color_mode, float state, float brightness, float color_brightness, float red, float green, float blue, float white, float color_temperature, float cold_white, float warm_white)
float lerp(float completion, float start, float end)
Linearly interpolate between start and end by completion (between 0 and 1).
Color temperature can be controlled.
float get_color_temperature_kelvin() const
Get the color temperature property of these light color values in kelvin.
LightColorValues()
Construct the LightColorValues with all attributes enabled, but state set to off. ...
void set_color_mode(ColorMode color_mode)
Set the color mode of these light color values.
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
bool operator==(const LightColorValues &rhs) const
Compare this LightColorValues to rhs, return true if and only if all attributes match.
void set_red(float red)
Set the red property of these light color values. In range 0.0 to 1.0.
float get_blue() const
Get the blue property of these light color values. In range 0.0 to 1.0.
float gamma_correct(float value, float gamma)
Applies gamma correction of gamma to value.
This class represents the color state for a light object.
Brightness of cold and warm white output can be controlled.
float get_white() const
Get the white property of these light color values. In range 0.0 to 1.0.
float state_
ON / OFF, float for transition.
float get_color_temperature() const
Get the color temperature property of these light color values in mired.
Brightness of white channel can be controlled separately from other channels.
float get_state() const
Get the state of these light color values. In range from 0.0 (off) to 1.0 (on)
ColorMode get_color_mode() const
Get the color mode of these light color values.
void set_white(float white)
Set the white property of these light color values. In range 0.0 to 1.0.
No color mode configured (cannot be a supported mode, only active when light is off).
void set_color_brightness(float brightness)
Set the color brightness property of these light color values. In range 0.0 to 1.0.
void as_rgbww(float *red, float *green, float *blue, float *cold_white, float *warm_white, float gamma=0, bool constant_brightness=false) const
Convert these light color values to an RGBWW representation with the given parameters.
void as_ct(float color_temperature_cw, float color_temperature_ww, float *color_temperature, float *white_brightness, float gamma=0) const
Convert these light color values to a CT+BR representation with the given parameters.
void normalize_color()
Normalize the color (RGB/W) component.
void set_color_temperature(float color_temperature)
Set the color temperature property of these light color values in mired.
void set_brightness(float brightness)
Set the brightness property of these light color values. In range 0.0 to 1.0.
void set_blue(float blue)
Set the blue property of these light color values. In range 0.0 to 1.0.
void as_binary(bool *binary) const
Convert these light color values to a binary representation and write them to binary.
void set_cold_white(float cold_white)
Set the cold white property of these light color values. In range 0.0 to 1.0.
void set_color_temperature_kelvin(float color_temperature)
Set the color temperature property of these light color values in kelvin.
Implementation of SPI Controller mode.
Color can be controlled using RGB format (includes a brightness control for the color).
float get_color_brightness() const
Get the color brightness property of these light color values. In range 0.0 to 1.0.
void as_rgbw(float *red, float *green, float *blue, float *white, float gamma=0, bool color_interlock=false) const
Convert these light color values to an RGBW representation and write them to red, green...
bool operator!=(const LightColorValues &rhs) const
void as_rgb(float *red, float *green, float *blue, float gamma=0, bool color_interlock=false) const
Convert these light color values to an RGB representation and write them to red, green, blue.
void as_brightness(float *brightness, float gamma=0) const
Convert these light color values to a brightness-only representation and write them to brightness...
static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion)
Linearly interpolate between the values in start to the values in end.
float get_green() const
Get the green property of these light color values. In range 0.0 to 1.0.
float get_brightness() const
Get the brightness property of these light color values. In range 0.0 to 1.0.