Dot Matrix: Replace std::map to avoid excessive init heap usage.

pull/733/head
Phil Howard 2023-03-27 13:32:54 +01:00
rodzic 140fe913ae
commit cc5a2bdb6f
2 zmienionych plików z 11 dodań i 5 usunięć

Wyświetl plik

@ -8,10 +8,11 @@ namespace pimoroni {
static const uint8_t DOT_CHAR_WIDTH = 5;
struct DotChar {
uint16_t code;
uint8_t data[DOT_CHAR_WIDTH];
};
static const std::map<uint16_t, DotChar> dotfont = {
static const DotChar dotfont[] = {
{32, {0x00, 0x00, 0x00, 0x00, 0x00}}, // (space)
{33, {0x00, 0x00, 0x5f, 0x00, 0x00}}, // !
{34, {0x00, 0x07, 0x00, 0x07, 0x00}}, // "

Wyświetl plik

@ -64,13 +64,18 @@ namespace pimoroni {
}
void LTP305::set_character(uint8_t x, uint16_t ch) {
std::map<uint16_t, DotChar>::const_iterator it = dotfont.find(ch);
uint8_t *data = nullptr;
for(auto c : dotfont) {
if(c.code == ch) {
data = &c.data[0];
break;
}
}
if(it != dotfont.end()) {
DotChar dchar = it->second;
if(data) {
for(uint8_t cx = 0; cx < DOT_CHAR_WIDTH; cx++) {
for(uint8_t cy = 0; cy < HEIGHT; cy++) {
uint8_t c = dchar.data[cx] & (0b1 << cy);
uint8_t c = data[cx] & (0b1 << cy);
set_pixel(x + cx, cy, c);
}
}