9inline static uint8_t to_uint8_scale(
float x) {
return static_cast<uint8_t
>(roundf(
x * 255.0f)); }
61 float blue,
float white,
float color_temperature,
float cold_white,
float warm_white) {
102 if (max_value == 0.0f) {
107 this->
red_ /= max_value;
108 this->
green_ /= max_value;
109 this->
blue_ /= max_value;
121 void as_rgb(
float *red,
float *green,
float *blue)
const {
124 *red = brightness * this->
red_;
125 *green = brightness * this->
green_;
126 *blue = brightness * this->
blue_;
128 *red = *green = *blue = 0;
133 void as_rgbw(
float *red,
float *green,
float *blue,
float *white)
const {
134 this->
as_rgb(red, green, blue);
143 void as_rgbww(
float *red,
float *green,
float *blue,
float *cold_white,
float *warm_white,
144 bool constant_brightness =
false)
const {
145 this->
as_rgb(red, green, blue);
146 this->
as_cwww(cold_white, warm_white, constant_brightness);
150 void as_rgbct(
float color_temperature_cw,
float color_temperature_ww,
float *red,
float *green,
float *blue,
151 float *color_temperature,
float *white_brightness)
const {
152 this->
as_rgb(red, green, blue);
153 this->
as_ct(color_temperature_cw, color_temperature_ww, color_temperature, white_brightness);
157 void as_cwww(
float *cold_white,
float *warm_white,
bool constant_brightness =
false)
const {
162 if (!constant_brightness) {
163 *cold_white = white_level * cw_level;
164 *warm_white = white_level * ww_level;
171 const float sum = cw_level > 0 || ww_level > 0 ? cw_level + ww_level : 1;
172 *cold_white = white_level * std::max(cw_level, ww_level) * cw_level / sum;
173 *warm_white = white_level * std::max(cw_level, ww_level) * ww_level / sum;
176 *cold_white = *warm_white = 0;
181 void as_ct(
float color_temperature_cw,
float color_temperature_ww,
float *color_temperature,
182 float *white_brightness)
const {
186 (this->
color_temperature_ - color_temperature_cw) / (color_temperature_ww - color_temperature_cw);
189 *white_brightness = 0;
260 if (color_temperature <= 0) {
This class represents a requested change in a light state.
This class represents the color state for a light object.
float get_state() const
Get the state of these light color values. In range from 0.0 (off) to 1.0 (on)
void set_color_mode(ColorMode color_mode)
Set the color mode of these light color values.
float get_brightness() const
Get the brightness 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 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.
void as_rgbww(float *red, float *green, float *blue, float *cold_white, float *warm_white, bool constant_brightness=false) const
Convert these light color values to an RGBWW representation with the given parameters.
float get_color_temperature() const
Get the color temperature property of these light color values in mired.
bool operator!=(const LightColorValues &rhs) const
void as_cwww(float *cold_white, float *warm_white, 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.
void set_brightness(float brightness)
Set the brightness property of these light color values. In range 0.0 to 1.0.
float get_cold_white() const
Get the cold white property of these light color values. In range 0.0 to 1.0.
void as_rgbw(float *red, float *green, float *blue, float *white) const
Convert these light color values to an RGBW representation and write them to red, green,...
void set_blue(float blue)
Set the blue property of these light color values. In range 0.0 to 1.0.
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_brightness(float brightness)
Set the color brightness 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.
bool operator==(const LightColorValues &rhs) const
Compare this LightColorValues to rhs, return true if and only if all attributes match.
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_rgb(float *red, float *green, float *blue) const
Convert these light color values to an RGB representation and write them to red, green,...
bool is_on() const
Get the binary true/false state of these light color values.
float get_green() const
Get the green property of these light color values. In range 0.0 to 1.0.
void set_state(float state)
Set the state of these light color values. In range from 0.0 (off) to 1.0 (on)
void set_color_temperature(float color_temperature)
Set the color temperature property of these light color values in mired.
float get_warm_white() const
Get the warm white property of these light color values. In range 0.0 to 1.0.
LightColorValues()
Construct the LightColorValues with all attributes enabled, but state set to off.
static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion)
Linearly interpolate between the values in start to the values in end.
void as_binary(bool *binary) const
Convert these light color values to a binary representation and write them to binary.
float color_temperature_
Color Temperature in Mired.
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)
void as_ct(float color_temperature_cw, float color_temperature_ww, float *color_temperature, float *white_brightness) const
Convert these light color values to a CT+BR representation with the given parameters.
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.
void as_rgbct(float color_temperature_cw, float color_temperature_ww, float *red, float *green, float *blue, float *color_temperature, float *white_brightness) const
Convert these light color values to an RGB+CT+BR representation with the given parameters.
float get_red() const
Get the red 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 set_red(float red)
Set the red property of these light color values. In range 0.0 to 1.0.
void normalize_color()
Normalize the color (RGB/W) component.
void as_brightness(float *brightness) const
Convert these light color values to a brightness-only representation and write them to brightness.
float get_color_brightness() const
Get the color brightness property of these light color values. In range 0.0 to 1.0.
float get_color_temperature_kelvin() const
Get the color temperature property of these light color values in kelvin.
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
@ UNKNOWN
No color mode configured (cannot be a supported mode, only active when light is off).
@ RGB
Color can be controlled using RGB format (includes a brightness control for the color).
@ COLOR_TEMPERATURE
Color temperature can be controlled.
@ WHITE
Brightness of white channel can be controlled separately from other channels.
@ COLD_WARM_WHITE
Brightness of cold and warm white output can be controlled.