ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
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
8namespace esphome::display {
9
10static const char *const TAG = "display";
11
13 RAMAllocator<uint8_t> allocator;
14 this->buffer_ = allocator.allocate(buffer_length);
15 if (this->buffer_ == nullptr) {
16 ESP_LOGE(TAG, "Could not allocate buffer for display!");
17 return;
18 }
19 this->clear();
20}
21
23 switch (this->rotation_) {
26 return this->get_height_internal();
29 default:
30 return this->get_width_internal();
31 }
32}
33
35 switch (this->rotation_) {
38 return this->get_height_internal();
41 default:
42 return this->get_width_internal();
43 }
44}
45
46void HOT DisplayBuffer::draw_pixel_at(int x, int y, Color color) {
47 if (!this->get_clipping().inside(x, y))
48 return; // NOLINT
49
50 switch (this->rotation_) {
52 break;
54 std::swap(x, y);
55 x = this->get_width_internal() - x - 1;
56 break;
58 x = this->get_width_internal() - x - 1;
59 y = this->get_height_internal() - y - 1;
60 break;
62 std::swap(x, y);
63 y = this->get_height_internal() - y - 1;
64 break;
65 }
66 this->draw_absolute_pixel_internal(x, y, color);
67 App.feed_wdt();
68}
69
70} // namespace esphome::display
void feed_wdt()
Feed the task watchdog.
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:2053
T * allocate(size_t n)
Definition helpers.h:2080
int get_width() override
Get the width of the image in pixels with rotation applied.
void init_internal_(uint32_t buffer_length)
virtual void draw_absolute_pixel_internal(int x, int y, Color color)=0
int get_height() override
Get the height of the image in pixels with rotation applied.
void draw_pixel_at(int x, int y, Color color) override
Set a single pixel at the specified coordinates to the given color.
virtual void clear()
Clear the entire screen by filling it with OFF pixels.
Definition display.cpp:15
virtual int get_width_internal()=0
virtual int get_height_internal()=0
Rect get_clipping() const
Get the current the clipping rectangle.
Definition display.cpp:766
DisplayRotation rotation_
Definition display.h:789
@ DISPLAY_ROTATION_0_DEGREES
Definition display.h:134
@ DISPLAY_ROTATION_270_DEGREES
Definition display.h:137
@ DISPLAY_ROTATION_180_DEGREES
Definition display.h:136
@ DISPLAY_ROTATION_90_DEGREES
Definition display.h:135
Application App
Global storage of Application pointer - only one Application can exist.
static void uint32_t
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6