ESPHome
2025.5.0
Loading...
Searching...
No Matches
esphome
components
addressable_light
addressable_light_display.cpp
Go to the documentation of this file.
1
#include "
addressable_light_display.h
"
2
#include "
esphome/core/log.h
"
3
4
namespace
esphome
{
5
namespace
addressable_light {
6
7
static
const
char
*
const
TAG =
"addressable_light.display"
;
8
9
int
AddressableLightDisplay::get_width_internal
() {
return
this->
width_
; }
10
int
AddressableLightDisplay::get_height_internal
() {
return
this->
height_
; }
11
12
void
AddressableLightDisplay::setup
() {
13
this->
addressable_light_buffer_
.resize(this->
width_
* this->
height_
, {0, 0, 0, 0});
14
}
15
16
void
AddressableLightDisplay::update
() {
17
if
(!this->
enabled_
)
18
return
;
19
20
this->
do_update_
();
21
this->
display
();
22
}
23
24
void
AddressableLightDisplay::display
() {
25
bool
dirty =
false
;
26
uint8_t old_r, old_g, old_b, old_w;
27
Color
*c;
28
29
for
(uint32_t offset = 0; offset < this->
addressable_light_buffer_
.size(); offset++) {
30
c = &(this->
addressable_light_buffer_
[offset]);
31
32
light::ESPColorView
pixel = (*this->
light_
)[offset];
33
34
// Track the original values for the pixel view. If it has changed updating, then
35
// we trigger a redraw. Avoiding redraws == avoiding flicker!
36
old_r = pixel.
get_red
();
37
old_g = pixel.
get_green
();
38
old_b = pixel.
get_blue
();
39
old_w = pixel.
get_white
();
40
41
pixel.
set_rgbw
(c->
r
, c->
g
, c->
b
, c->
w
);
42
43
// If the actual value of the pixel changed, then schedule a redraw.
44
if
(pixel.
get_red
() != old_r || pixel.
get_green
() != old_g || pixel.
get_blue
() != old_b ||
45
pixel.
get_white
() != old_w) {
46
dirty =
true
;
47
}
48
}
49
50
if
(dirty) {
51
this->
light_
->
schedule_show
();
52
}
53
}
54
55
void
HOT
AddressableLightDisplay::draw_absolute_pixel_internal
(
int
x
,
int
y
,
Color
color) {
56
if
(
x
>= this->
get_width_internal
() ||
x < 0 || y >
= this->
get_height_internal
() || y < 0)
57
return
;
58
59
if
(this->
pixel_mapper_f_
.
has_value
()) {
60
// Params are passed by reference, so they may be modified in call.
61
this->
addressable_light_buffer_
[(*this->
pixel_mapper_f_
)(x,
y
)] = color;
62
}
else
{
63
this->
addressable_light_buffer_
[y * this->
get_width_internal
() +
x
] = color;
64
}
65
}
66
}
// namespace addressable_light
67
}
// namespace esphome
addressable_light_display.h
esphome::addressable_light::AddressableLightDisplay::display
void display()
Definition
addressable_light_display.cpp:24
esphome::addressable_light::AddressableLightDisplay::width_
int32_t width_
Definition
addressable_light_display.h:56
esphome::addressable_light::AddressableLightDisplay::get_width_internal
int get_width_internal() override
Definition
addressable_light_display.cpp:9
esphome::addressable_light::AddressableLightDisplay::update
void update() override
Definition
addressable_light_display.cpp:16
esphome::addressable_light::AddressableLightDisplay::enabled_
bool enabled_
Definition
addressable_light_display.h:55
esphome::addressable_light::AddressableLightDisplay::addressable_light_buffer_
std::vector< Color > addressable_light_buffer_
Definition
addressable_light_display.h:58
esphome::addressable_light::AddressableLightDisplay::pixel_mapper_f_
optional< std::function< int(int, int)> > pixel_mapper_f_
Definition
addressable_light_display.h:60
esphome::addressable_light::AddressableLightDisplay::light_
light::AddressableLight * light_
Definition
addressable_light_display.h:54
esphome::addressable_light::AddressableLightDisplay::get_height_internal
int get_height_internal() override
Definition
addressable_light_display.cpp:10
esphome::addressable_light::AddressableLightDisplay::setup
void setup() override
Definition
addressable_light_display.cpp:12
esphome::addressable_light::AddressableLightDisplay::draw_absolute_pixel_internal
void draw_absolute_pixel_internal(int x, int y, Color color) override
Definition
addressable_light_display.cpp:55
esphome::addressable_light::AddressableLightDisplay::height_
int32_t height_
Definition
addressable_light_display.h:57
esphome::display::Display::do_update_
void do_update_()
Definition
display.cpp:649
esphome::light::AddressableLight::schedule_show
void schedule_show()
Definition
addressable_light.h:76
esphome::light::ESPColorSettable::set_rgbw
void set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white)
Definition
esp_color_view.h:32
esphome::light::ESPColorView
Definition
esp_color_view.h:38
esphome::light::ESPColorView::get_white
uint8_t get_white() const
Definition
esp_color_view.h:81
esphome::light::ESPColorView::get_green
uint8_t get_green() const
Definition
esp_color_view.h:77
esphome::light::ESPColorView::get_blue
uint8_t get_blue() const
Definition
esp_color_view.h:79
esphome::light::ESPColorView::get_red
uint8_t get_red() const
Definition
esp_color_view.h:75
esphome::optional::has_value
bool has_value() const
Definition
optional.h:87
log.h
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
esphome::Color
Definition
color.h:10
esphome::Color::w
uint8_t w
Definition
color.h:26
esphome::Color::g
uint8_t g
Definition
color.h:18
esphome::Color::b
uint8_t b
Definition
color.h:22
esphome::Color::r
uint8_t r
Definition
color.h:14
x
uint16_t x
Definition
tt21100.cpp:5
y
uint16_t y
Definition
tt21100.cpp:6
Generated by
1.12.0