10inline 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;
138 void as_rgb(
float *red,
float *green,
float *blue,
float gamma = 0,
bool color_interlock =
false)
const {
…}
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);
150 void as_rgbw(
float *red,
float *green,
float *blue,
float *white,
float gamma = 0, {
…}
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);
161 void as_rgbww(
float *red,
float *green,
float *blue,
float *cold_white,
float *warm_white,
float gamma = 0, {
…}
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);
168 void as_rgbct(
float color_temperature_cw,
float color_temperature_ww,
float *red,
float *green,
float *blue, {
…}
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;
175 void as_cwww(
float *cold_white,
float *warm_white,
float gamma = 0,
bool constant_brightness =
false)
const {
…}
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;
199 void as_ct(
float color_temperature_cw,
float color_temperature_ww,
float *color_temperature,
float *white_brightness, {
…}
278 if (color_temperature <= 0) {
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.
static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion)
Linearly interpolate between the values in start to the values in end.
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.
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.
Providing packet encoding functions for exchanging data with a remote host.
float gamma_correct(float value, float gamma)
Applies gamma correction of gamma to value.
float lerp(float completion, float start, float end)
Linearly interpolate between start and end by completion (between 0 and 1).
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)