kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Dot Matrix: Replace std::map to avoid excessive init heap usage.
rodzic
140fe913ae
commit
cc5a2bdb6f
|
|
@ -8,10 +8,11 @@ namespace pimoroni {
|
||||||
static const uint8_t DOT_CHAR_WIDTH = 5;
|
static const uint8_t DOT_CHAR_WIDTH = 5;
|
||||||
|
|
||||||
struct DotChar {
|
struct DotChar {
|
||||||
|
uint16_t code;
|
||||||
uint8_t data[DOT_CHAR_WIDTH];
|
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)
|
{32, {0x00, 0x00, 0x00, 0x00, 0x00}}, // (space)
|
||||||
{33, {0x00, 0x00, 0x5f, 0x00, 0x00}}, // !
|
{33, {0x00, 0x00, 0x5f, 0x00, 0x00}}, // !
|
||||||
{34, {0x00, 0x07, 0x00, 0x07, 0x00}}, // "
|
{34, {0x00, 0x07, 0x00, 0x07, 0x00}}, // "
|
||||||
|
|
|
||||||
|
|
@ -64,13 +64,18 @@ namespace pimoroni {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LTP305::set_character(uint8_t x, uint16_t ch) {
|
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()) {
|
if(data) {
|
||||||
DotChar dchar = it->second;
|
|
||||||
for(uint8_t cx = 0; cx < DOT_CHAR_WIDTH; cx++) {
|
for(uint8_t cx = 0; cx < DOT_CHAR_WIDTH; cx++) {
|
||||||
for(uint8_t cy = 0; cy < HEIGHT; cy++) {
|
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);
|
set_pixel(x + cx, cy, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue