Refactor the lcd_print_custom() method
This commit is contained in:
parent
90222747f2
commit
7e0ab44d09
|
|
@ -835,24 +835,27 @@ const CustomCharacter Font[] PROGMEM = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void lcd_print_custom(uint8_t c) {
|
static void lcd_print_custom(uint8_t c) {
|
||||||
if (lcd_custom_index >= 8) { //ran out of custom characters. Use the alternate character.
|
uint8_t charToSend;
|
||||||
lcd_send(pgm_read_byte(&Font[c - 0x80].alternate), HIGH);
|
|
||||||
lcd_ddram_address++; // no need for preventing ddram overflow
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if we already have the character in the lcd memory
|
// check if we already have the character in the lcd memory
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
if (lcd_custom_characters[i] == c) {
|
if (lcd_custom_characters[i] == c) {
|
||||||
lcd_send(i, HIGH);
|
// send the found custom character id
|
||||||
lcd_ddram_address++; // no need for preventing ddram overflow
|
charToSend = i;
|
||||||
return;
|
goto sendChar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// character not in memory. Add it
|
|
||||||
lcd_createChar_P(lcd_custom_index, Font[c - 0x80].data);
|
// character not in memory.
|
||||||
lcd_custom_characters[lcd_custom_index] = c;
|
if (lcd_custom_index >= 8) { //ran out of custom characters. Use the alternate character.
|
||||||
lcd_send(lcd_custom_index, HIGH);
|
charToSend = pgm_read_byte(&Font[c - 0x80].alternate);
|
||||||
|
}
|
||||||
|
else { //create a new custom character and send it
|
||||||
|
lcd_createChar_P(lcd_custom_index, Font[c - 0x80].data);
|
||||||
|
lcd_custom_characters[lcd_custom_index] = c;
|
||||||
|
charToSend = lcd_custom_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendChar:
|
||||||
|
lcd_send(charToSend, HIGH);
|
||||||
lcd_ddram_address++; // no need for preventing ddram overflow
|
lcd_ddram_address++; // no need for preventing ddram overflow
|
||||||
lcd_custom_index++;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue