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