Display digits and integers

Display digits and integers, for the later displaying leading zeroes
is supported via parameter. Demo integers are displayed in the setup
screen.
This commit is contained in:
finga 2021-09-11 00:10:46 +02:00
parent 19c0f141a4
commit 6eb515e2d4

View file

@ -165,6 +165,62 @@ static void lcd_write_symbol_page(const struct symbol* sym,
lcd_write(sym->symbol[page * sym->length + i]); lcd_write(sym->symbol[page * sym->length + i]);
} }
static void lcd_write_digit_page(uint8_t digit, uint8_t page,
bool invert) {
switch (digit) {
case 0:
lcd_write_symbol_page(&sym_0, page, invert);
break;
case 1:
lcd_write_symbol_page(&sym_1, page, invert);
break;
case 2:
lcd_write_symbol_page(&sym_2, page, invert);
break;
case 3:
lcd_write_symbol_page(&sym_3, page, invert);
break;
case 4:
lcd_write_symbol_page(&sym_4, page, invert);
break;
case 5:
lcd_write_symbol_page(&sym_5, page, invert);
break;
case 6:
lcd_write_symbol_page(&sym_6, page, invert);
break;
case 7:
lcd_write_symbol_page(&sym_7, page, invert);
break;
case 8:
lcd_write_symbol_page(&sym_8, page, invert);
break;
case 9:
lcd_write_symbol_page(&sym_9, page, invert);
break;
}
}
static void lcd_write_integer_page(uint8_t integer, uint8_t digits,
uint8_t page, bool invert) {
if (digits != 0 || integer != 0) {
uint8_t input_digits = 0;
uint16_t comperator = 1;
for (; comperator <= integer; comperator *= 10, input_digits++);
for (int8_t i = digits - input_digits; i > 0; i--) {
lcd_write_kerning(2, invert);
lcd_write_digit_page(0, page, invert);
}
for (; comperator >= 10; comperator /= 10) {
lcd_write_kerning(2, invert);
lcd_write_digit_page((integer % comperator) / (comperator / 10),
page, invert);
}
}
}
void lcd_splash(void) { void lcd_splash(void) {
lcd_fill(0x00); lcd_fill(0x00);
@ -317,7 +373,8 @@ static void lcd_setup(void) {
lcd_write_symbol_page(&sym_t, i, false); lcd_write_symbol_page(&sym_t, i, false);
lcd_write_kerning(2, false); lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_colon, i, false); lcd_write_symbol_page(&sym_colon, i, false);
lcd_write_kerning(13, false); lcd_write_kerning(11, false);
lcd_write_integer_page(123, 1, i, false);
} }
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
@ -346,7 +403,8 @@ static void lcd_setup(void) {
lcd_write_symbol_page(&sym_t, i, false); lcd_write_symbol_page(&sym_t, i, false);
lcd_write_kerning(2, false); lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_colon, i, false); lcd_write_symbol_page(&sym_colon, i, false);
lcd_write_kerning(9, false); lcd_write_kerning(7, false);
lcd_write_integer_page(123, 3, i, false);
} }
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {