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;
126 void as_rgb(
float *red,
float *green,
float *blue,
float gamma = 0,
bool color_interlock =
false)
const {
133 *red = *green = *blue = 0;
138 void as_rgbw(
float *red,
float *green,
float *blue,
float *white,
float gamma = 0,
139 bool color_interlock =
false)
const {
140 this->
as_rgb(red, green, blue, gamma);
149 void as_rgbww(
float *red,
float *green,
float *blue,
float *cold_white,
float *warm_white,
float gamma = 0,
150 bool constant_brightness =
false)
const {
151 this->
as_rgb(red, green, blue, gamma);
152 this->
as_cwww(cold_white, warm_white, gamma, constant_brightness);
156 void as_rgbct(
float color_temperature_cw,
float color_temperature_ww,
float *red,
float *green,
float *blue,
157 float *color_temperature,
float *white_brightness,
float gamma = 0)
const {
158 this->
as_rgb(red, green, blue, gamma);
159 this->
as_ct(color_temperature_cw, color_temperature_ww, color_temperature, white_brightness, gamma);
163 void as_cwww(
float *cold_white,
float *warm_white,
float gamma = 0,
bool constant_brightness =
false)
const {
168 if (!constant_brightness) {
169 *cold_white = white_level * cw_level;
170 *warm_white = white_level * ww_level;
177 const float sum = cw_level > 0 || ww_level > 0 ? cw_level + ww_level : 1;
178 *cold_white = white_level * std::max(cw_level, ww_level) * cw_level / sum;
179 *warm_white = white_level * std::max(cw_level, ww_level) * ww_level / sum;
182 *cold_white = *warm_white = 0;
187 void as_ct(
float color_temperature_cw,
float color_temperature_ww,
float *color_temperature,
float *white_brightness,
188 float gamma = 0)
const {
192 (this->
color_temperature_ - color_temperature_cw) / (color_temperature_ww - color_temperature_cw);
195 *white_brightness = 0;
266 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.
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.
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.
float get_color_temperature() const
Get the color temperature property of these light color values in mired.
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,...
bool operator!=(const LightColorValues &rhs) const
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 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_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.
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_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,...
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.
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.
float get_color_brightness() const
Get the color brightness property of these light color values. In range 0.0 to 1.0.
void as_brightness(float *brightness, float gamma=0) const
Convert these light color values to a brightness-only representation and write them to brightness.
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.
float get_color_temperature_kelvin() const
Get the color temperature property of these light color values in kelvin.
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.
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.
float gamma_correct(float value, float gamma)
Applies gamma correction of gamma to value.