ESPHome  2024.10.2
addressable_light_display.cpp
Go to the documentation of this file.
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 
11 
13  this->addressable_light_buffer_.resize(this->width_ * this->height_, {0, 0, 0, 0});
14 }
15 
17  if (!this->enabled_)
18  return;
19 
20  this->do_update_();
21  this->display();
22 }
23 
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 
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
optional< std::function< int(int, int)> > pixel_mapper_f_
uint16_t x
Definition: tt21100.cpp:17
bool has_value() const
Definition: optional.h:87
uint8_t g
Definition: color.h:18
uint16_t y
Definition: tt21100.cpp:18
void set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white)
uint8_t w
Definition: color.h:26
uint8_t b
Definition: color.h:22
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
uint8_t r
Definition: color.h:14
void draw_absolute_pixel_internal(int x, int y, Color color) override