ESPHome
2026.3.0
Loading...
Searching...
No Matches
esphome
components
light
light_color_values.cpp
Go to the documentation of this file.
1
#include "
light_color_values.h
"
2
3
namespace
esphome::light
{
4
5
// Lightweight lerp: a + t * (b - a).
6
// Avoids std::lerp's NaN/infinity handling which Clang doesn't optimize out,
7
// adding ~200 bytes per call. Safe because all values are finite floats.
8
static
float
__attribute__
((noinline)) lerp_fast(
float
a,
float
b
,
float
t
) {
return
a +
t
* (
b
- a); }
9
10
LightColorValues
LightColorValues::lerp
(
const
LightColorValues
&start,
const
LightColorValues
&
end
,
float
completion) {
11
// Directly interpolate the raw values to avoid getter/setter overhead.
12
// This is safe because:
13
// - All LightColorValues except color_temperature_ have their values clamped when set via the setters
14
// - lerp_fast output stays in range when inputs are in range and 0 <= completion <= 1
15
// - Therefore the output doesn't need clamping, so we can skip the setters
16
LightColorValues
v;
17
v.
color_mode_
=
end
.color_mode_;
18
v.
state_
= lerp_fast(start.
state_
,
end
.state_, completion);
19
v.
brightness_
= lerp_fast(start.
brightness_
,
end
.brightness_, completion);
20
v.
color_brightness_
= lerp_fast(start.
color_brightness_
,
end
.color_brightness_, completion);
21
v.
red_
= lerp_fast(start.
red_
,
end
.red_, completion);
22
v.
green_
= lerp_fast(start.
green_
,
end
.green_, completion);
23
v.
blue_
= lerp_fast(start.
blue_
,
end
.blue_, completion);
24
v.
white_
= lerp_fast(start.
white_
,
end
.white_, completion);
25
v.
color_temperature_
= lerp_fast(start.
color_temperature_
,
end
.color_temperature_, completion);
26
v.
cold_white_
= lerp_fast(start.
cold_white_
,
end
.cold_white_, completion);
27
v.
warm_white_
= lerp_fast(start.
warm_white_
,
end
.warm_white_, completion);
28
return
v;
29
}
30
31
}
// namespace esphome::light
esphome::light::LightColorValues
This class represents the color state for a light object.
Definition
light_color_values.h:44
esphome::light::LightColorValues::red_
float red_
Definition
light_color_values.h:282
esphome::light::LightColorValues::state_
float state_
ON / OFF, float for transition.
Definition
light_color_values.h:279
esphome::light::LightColorValues::blue_
float blue_
Definition
light_color_values.h:284
esphome::light::LightColorValues::lerp
static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion)
Linearly interpolate between the values in start to the values in end.
Definition
light_color_values.cpp:10
esphome::light::LightColorValues::brightness_
float brightness_
Definition
light_color_values.h:280
esphome::light::LightColorValues::color_temperature_
float color_temperature_
Color Temperature in Mired.
Definition
light_color_values.h:286
esphome::light::LightColorValues::color_mode_
ColorMode color_mode_
Definition
light_color_values.h:289
esphome::light::LightColorValues::cold_white_
float cold_white_
Definition
light_color_values.h:287
esphome::light::LightColorValues::warm_white_
float warm_white_
Definition
light_color_values.h:288
esphome::light::LightColorValues::white_
float white_
Definition
light_color_values.h:285
esphome::light::LightColorValues::green_
float green_
Definition
light_color_values.h:283
esphome::light::LightColorValues::color_brightness_
float color_brightness_
Definition
light_color_values.h:281
__attribute__
struct @65::@66 __attribute__
light_color_values.h
esphome::light
Definition
addressable_light.cpp:4
esphome::light::t
static float float float t
Definition
light_color_values.cpp:8
esphome::light::b
static float float b
Definition
light_color_values.cpp:8
end
uint8_t end[39]
Definition
sun_gtil2.cpp:17
Generated by
1.12.0