Compare commits

..

2 commits

Author SHA1 Message Date
e2d30d7050 Fix indents and switch syntax
Fix indentions in `spi_byte()` and add missing space after `switch`
keywords.
2021-09-11 00:21:01 +02:00
6eb515e2d4 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.
2021-09-11 00:19:59 +02:00

View file

@ -107,7 +107,7 @@ uint8_t spi_byte(uint8_t data) {
SPDR = data; SPDR = data;
while(!(SPSR & (1 << SPIF))); while(!(SPSR & (1 << SPIF)));
return SPDR; return SPDR;
} }
void lcd_write(uint8_t data) { void lcd_write(uint8_t data) {
SPI_PORT &= ~(1 << SPI_SS); SPI_PORT &= ~(1 << SPI_SS);
@ -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);
@ -200,7 +256,7 @@ static void lcd_home(void) {
bool ch3_selected = false; bool ch3_selected = false;
bool setup_selected = false; bool setup_selected = false;
switch(home_state) { switch (home_state) {
case ch1: case ch1:
ch1_selected = true; ch1_selected = true;
break; break;
@ -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++) {
@ -367,7 +425,7 @@ static void lcd_setup(void) {
} }
static void change_state(enum state new_state) { static void change_state(enum state new_state) {
switch(new_state) { switch (new_state) {
case home: case home:
lcd_home(); lcd_home();
current_state = home; current_state = home;
@ -442,7 +500,7 @@ static void update_state(enum input event) {
ISR(PCINT0_vect) { ISR(PCINT0_vect) {
cli(); cli();
switch(enc) { switch (enc) {
case 0: case 0:
if (ENC_A && !ENC_B) if (ENC_A && !ENC_B)
enc = 1; enc = 1;