Iterable setup settings with encoder

To make setup settings configurable make it possible to select them
first. Therefore the `setup_state` enum is created to keep track of
the currently selected setting state.
This commit is contained in:
finga 2021-09-11 11:13:15 +02:00
parent e2d30d7050
commit 0acd0bd98b

View file

@ -93,6 +93,7 @@ enum input {cw, ccw, click, hold};
static volatile enum state {home, ch1, ch2, ch3, setup} current_state = home; static volatile enum state {home, ch1, ch2, ch3, setup} current_state = home;
static volatile enum state home_state = ch1; static volatile enum state home_state = ch1;
static volatile enum setup_state {contrast, backlight, back} setup_state = contrast;
static volatile uint8_t enc = 0; static volatile uint8_t enc = 0;
@ -329,6 +330,22 @@ static void lcd_home(void) {
static void lcd_setup(void) { static void lcd_setup(void) {
lcd_fill(0x00); lcd_fill(0x00);
bool contrast_selected = false;
bool backlight_selected = false;
bool back_selected = false;
switch (setup_state) {
case contrast:
contrast_selected = true;
break;
case backlight:
backlight_selected = true;
break;
default: // back
back_selected = true;
break;
}
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
SPI_PORT &= ~(1 << LCD_CD); SPI_PORT &= ~(1 << LCD_CD);
lcd_write(0x00); lcd_write(0x00);
@ -374,7 +391,8 @@ static void lcd_setup(void) {
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(11, false); lcd_write_kerning(11, false);
lcd_write_integer_page(123, 1, i, false); lcd_write_integer_page(123, 1, i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
} }
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
@ -404,23 +422,26 @@ static void lcd_setup(void) {
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(7, false); lcd_write_kerning(7, false);
lcd_write_integer_page(123, 3, i, false); lcd_write_integer_page(123, 3, i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
} }
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
SPI_PORT &= ~(1 << LCD_CD); SPI_PORT &= ~(1 << LCD_CD);
lcd_write(0x03); lcd_write(0x01);
lcd_write(0x12); lcd_write(0x12);
lcd_write(0xB6 + i); lcd_write(0xB6 + i);
SPI_PORT |= (1 << LCD_CD); SPI_PORT |= (1 << LCD_CD);
lcd_write_symbol_page(&sym_b, i, false); lcd_write_kerning(2, back_selected);
lcd_write_kerning(2, false); lcd_write_symbol_page(&sym_b, i, back_selected);
lcd_write_symbol_page(&sym_a, i, false); lcd_write_kerning(2, back_selected);
lcd_write_kerning(2, false); lcd_write_symbol_page(&sym_a, i, back_selected);
lcd_write_symbol_page(&sym_c, i, false); lcd_write_kerning(2, back_selected);
lcd_write_kerning(2, false); lcd_write_symbol_page(&sym_c, i, back_selected);
lcd_write_symbol_page(&sym_k, i, false); lcd_write_kerning(2, back_selected);
lcd_write_symbol_page(&sym_k, i, back_selected);
lcd_write_kerning(2, back_selected);
} }
} }
@ -437,6 +458,7 @@ static void change_state(enum state new_state) {
case ch3: case ch3:
break; break;
case setup: case setup:
setup_state = contrast;
lcd_setup(); lcd_setup();
current_state = setup; current_state = setup;
break; break;
@ -468,10 +490,27 @@ static void update_home(enum input event) {
static void update_setup(enum input event) { static void update_setup(enum input event) {
switch (event) { switch (event) {
case cw: case cw:
setup_state++;
if (setup_state > back)
setup_state = contrast;
lcd_setup();
break; break;
case ccw: case ccw:
setup_state--;
if (setup_state > back)
setup_state = back;
lcd_setup();
break; break;
case click: case click:
switch (setup_state) {
case contrast:
break;
case backlight:
break;
case back:
change_state(home);
break;
}
break; break;
case hold: case hold:
change_state(home); change_state(home);