ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
addressable_light_display.cpp
Go to the documentation of this file.
2#include "esphome/core/log.h"
3
5
6ESPHOME_LOG_TAG(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 Color *c;
26
27 for (uint32_t offset = 0; offset < this->addressable_light_buffer_.size(); offset++) {
28 c = &(this->addressable_light_buffer_[offset]);
29
30 light::ESPColorView pixel = (*this->light_)[offset];
31
32 // Track the original values for the pixel view. If it has changed updating, then
33 // we trigger a redraw. Avoiding redraws == avoiding flicker!
34 const Color old_raw_color = pixel.get_raw();
35 pixel.set(Color{c->r, c->g, c->b, c->w});
36
37 // If the actual value of the pixel changed, then schedule a redraw.
38 if (pixel.get_raw() != old_raw_color) {
39 dirty = true;
40 }
41 }
42
43 if (dirty) {
44 this->light_->schedule_show();
45 }
46}
47
49 if (x >= this->get_width_internal() || x < 0 || y >= this->get_height_internal() || y < 0)
50 return;
51
52 if (this->pixel_mapper_f_.has_value()) {
53 // Params are passed by reference, so they may be modified in call.
54 int index = (*this->pixel_mapper_f_)(x, y);
55 if (index < 0 || static_cast<size_t>(index) >= this->addressable_light_buffer_.size())
56 return;
57 this->addressable_light_buffer_[index] = color;
58 } else {
59 this->addressable_light_buffer_[y * this->get_width_internal() + x] = color;
60 }
61}
62} // 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
Gets or sets the color or effect data at a specific index within an color accessor.
void set(Color color) override
ESPHOME_LOG_TAG(TAG, "addressable_light.display")
static void uint32_t
uint8_t w
Definition color.h:48
uint8_t g
Definition color.h:40
uint8_t b
Definition color.h:44
uint8_t r
Definition color.h:36
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6