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:
parent
e2d30d7050
commit
0acd0bd98b
1 changed files with 49 additions and 10 deletions
|
@ -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_state = ch1;
|
||||
static volatile enum setup_state {contrast, backlight, back} setup_state = contrast;
|
||||
|
||||
static volatile uint8_t enc = 0;
|
||||
|
||||
|
@ -329,6 +330,22 @@ static void lcd_home(void) {
|
|||
static void lcd_setup(void) {
|
||||
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++) {
|
||||
SPI_PORT &= ~(1 << LCD_CD);
|
||||
lcd_write(0x00);
|
||||
|
@ -374,7 +391,8 @@ static void lcd_setup(void) {
|
|||
lcd_write_kerning(2, false);
|
||||
lcd_write_symbol_page(&sym_colon, i, 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++) {
|
||||
|
@ -404,23 +422,26 @@ static void lcd_setup(void) {
|
|||
lcd_write_kerning(2, false);
|
||||
lcd_write_symbol_page(&sym_colon, i, 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++) {
|
||||
SPI_PORT &= ~(1 << LCD_CD);
|
||||
lcd_write(0x03);
|
||||
lcd_write(0x01);
|
||||
lcd_write(0x12);
|
||||
lcd_write(0xB6 + i);
|
||||
SPI_PORT |= (1 << LCD_CD);
|
||||
|
||||
lcd_write_symbol_page(&sym_b, i, false);
|
||||
lcd_write_kerning(2, false);
|
||||
lcd_write_symbol_page(&sym_a, i, false);
|
||||
lcd_write_kerning(2, false);
|
||||
lcd_write_symbol_page(&sym_c, i, false);
|
||||
lcd_write_kerning(2, false);
|
||||
lcd_write_symbol_page(&sym_k, i, false);
|
||||
lcd_write_kerning(2, back_selected);
|
||||
lcd_write_symbol_page(&sym_b, i, back_selected);
|
||||
lcd_write_kerning(2, back_selected);
|
||||
lcd_write_symbol_page(&sym_a, i, back_selected);
|
||||
lcd_write_kerning(2, back_selected);
|
||||
lcd_write_symbol_page(&sym_c, i, back_selected);
|
||||
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:
|
||||
break;
|
||||
case setup:
|
||||
setup_state = contrast;
|
||||
lcd_setup();
|
||||
current_state = setup;
|
||||
break;
|
||||
|
@ -468,10 +490,27 @@ static void update_home(enum input event) {
|
|||
static void update_setup(enum input event) {
|
||||
switch (event) {
|
||||
case cw:
|
||||
setup_state++;
|
||||
if (setup_state > back)
|
||||
setup_state = contrast;
|
||||
lcd_setup();
|
||||
break;
|
||||
case ccw:
|
||||
setup_state--;
|
||||
if (setup_state > back)
|
||||
setup_state = back;
|
||||
lcd_setup();
|
||||
break;
|
||||
case click:
|
||||
switch (setup_state) {
|
||||
case contrast:
|
||||
break;
|
||||
case backlight:
|
||||
break;
|
||||
case back:
|
||||
change_state(home);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case hold:
|
||||
change_state(home);
|
||||
|
|
Loading…
Reference in a new issue