ESPHome 2025.5.0
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 {
9namespace display {
10
11static const char *const TAG = "display";
12
13void 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
47void 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
void feed_wdt(uint32_t time=0)
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:683
T * allocate(size_t n)
Definition helpers.h:703
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.
void clear()
Clear the entire screen by filling it with OFF pixels.
Definition display.cpp:16
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:714
DisplayRotation rotation_
Definition display.h:680
@ DISPLAY_ROTATION_0_DEGREES
Definition display.h:135
@ DISPLAY_ROTATION_270_DEGREES
Definition display.h:138
@ DISPLAY_ROTATION_180_DEGREES
Definition display.h:137
@ DISPLAY_ROTATION_90_DEGREES
Definition display.h:136
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
Application App
Global storage of Application pointer - only one Application can exist.
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6