-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_matrixled_display.h
75 lines (62 loc) · 2.1 KB
/
my_matrixled_display.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "esphome.h"
using namespace esphome;
// returns the new bytepos
uint16_t get_next_char(const char *text, display::Font *font, uint16_t byte_pos,
char *buf, uint16_t buf_len) {
assert(buf_len > 0);
if (text[byte_pos] == '\0') // finished, start over!
byte_pos = 0;
int glyph_length;
int glyph_n = font->match_next_glyph(text + byte_pos, &glyph_length);
int i = 0;
if (glyph_n >= 0) { // valid glyph, save it to buf
while ((i < glyph_length) && (i < (buf_len - 1))) { // copy
buf[i] = text[byte_pos + i];
i++;
}
byte_pos += glyph_length;
} else
byte_pos += 1; // invalid glyph, advance one byte
buf[i++] = 0; // terminate string
return byte_pos;
}
class MatrixLedDisplay : public display::DisplayBuffer {
public:
void set_addr_light(light::AddressableLight *lights) {
this->lights = lights;
}
void set_fg_color(const light::ESPColor &fg_color) {
this->fg_color = fg_color;
}
void set_bg_color(const light::ESPColor &bg_color) {
this->bg_color = bg_color;
}
void set_width(const uint8_t width) { this->width = width; }
void set_height(const uint8_t height) { this->height = height; }
protected:
void draw_absolute_pixel_internal(int x, int y, int color) override {
if (x >= this->get_width_internal() || x < 0 ||
y >= this->get_height_internal() || y < 0)
return;
uint16_t pos = x + y * this->get_width_internal();
if (pos >= (*(this->lights)).size()) {
ESP_LOGD("MatrixLedDisplay",
"Size mismatch of AddressableLight and Matrix, could not get "
"light %i",
pos);
return;
}
if (color) {
(*(this->lights))[pos] = this->fg_color;
} else {
(*(this->lights))[pos] = this->bg_color;
}
}
int get_height_internal() override { return this->height; }
int get_width_internal() override { return this->width; }
uint8_t width{8};
uint8_t height{8};
light::AddressableLight *lights;
light::ESPColor fg_color = light::ESPColor(0xff, 0xff, 0xff);
light::ESPColor bg_color = light::ESPColor(0x00, 0x00, 0x00);
};