ESPHome  2024.10.2
display_buffer.cpp
Go to the documentation of this file.
1 #include "display_buffer.h"
2 
3 #include <utility>
4 
6 #include "esphome/core/log.h"
7 
8 namespace esphome {
9 namespace display {
10 
11 static const char *const TAG = "display";
12 
13 void DisplayBuffer::init_internal_(uint32_t buffer_length) {
15  this->buffer_ = allocator.allocate(buffer_length);
16  if (this->buffer_ == nullptr) {
17  ESP_LOGE(TAG, "Could not allocate buffer for display!");
18  return;
19  }
20  this->clear();
21 }
22 
24  switch (this->rotation_) {
27  return this->get_height_internal();
30  default:
31  return this->get_width_internal();
32  }
33 }
34 
36  switch (this->rotation_) {
39  return this->get_height_internal();
42  default:
43  return this->get_width_internal();
44  }
45 }
46 
47 void HOT DisplayBuffer::draw_pixel_at(int x, int y, Color color) {
48  if (!this->get_clipping().inside(x, y))
49  return; // NOLINT
50 
51  switch (this->rotation_) {
53  break;
55  std::swap(x, y);
56  x = this->get_width_internal() - x - 1;
57  break;
59  x = this->get_width_internal() - x - 1;
60  y = this->get_height_internal() - y - 1;
61  break;
63  std::swap(x, y);
64  y = this->get_height_internal() - y - 1;
65  break;
66  }
67  this->draw_absolute_pixel_internal(x, y, color);
68  App.feed_wdt();
69 }
70 
71 } // namespace display
72 } // namespace esphome
virtual void draw_absolute_pixel_internal(int x, int y, Color color)=0
int get_width() override
Get the width of the image in pixels with rotation applied.
uint16_t x
Definition: tt21100.cpp:17
Rect get_clipping() const
Get the current the clipping rectangle.
Definition: display.cpp:567
uint16_t y
Definition: tt21100.cpp:18
void init_internal_(uint32_t buffer_length)
virtual int get_height_internal()=0
int get_height() override
Get the height of the image in pixels with rotation applied.
virtual int get_width_internal()=0
void clear()
Clear the entire screen by filling it with OFF pixels.
Definition: display.cpp:16
Application App
Global storage of Application pointer - only one Application can exist.
void swap(optional< T > &x, optional< T > &y)
Definition: optional.h:209
DisplayRotation rotation_
Definition: display.h:659
void draw_pixel_at(int x, int y, Color color) override
Set a single pixel at the specified coordinates to the given color.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7