Editable setup settings

In order to be able to change the setup settings two new setup states
are introduced `change_contrast` and `change_backlight`. All
procedures that handle the setup states are adapted to handle those
new states correct. To keep track of their values the global variables
`value_contrast` and `value_backlight` are introduced.
This commit is contained in:
finga 2021-09-11 15:36:02 +02:00
parent 0acd0bd98b
commit acf4bc5754

View file

@ -93,10 +93,13 @@ 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 enum setup_state {contrast, backlight, back, change_contrast, change_backlight} setup_state = contrast;
static volatile uint8_t enc = 0; static volatile uint8_t enc = 0;
static volatile uint8_t value_contrast;
static volatile uint8_t value_backlight;
void spi_init(void) { void spi_init(void) {
SPI_DDR |= (1 << SPI_SCK) | (1 << SPI_MOSI) | (1 << SPI_SS); SPI_DDR |= (1 << SPI_SCK) | (1 << SPI_MOSI) | (1 << SPI_SS);
SPI_PORT |= (1 << SPI_SS); SPI_PORT |= (1 << SPI_SS);
@ -333,6 +336,8 @@ static void lcd_setup(void) {
bool contrast_selected = false; bool contrast_selected = false;
bool backlight_selected = false; bool backlight_selected = false;
bool back_selected = false; bool back_selected = false;
bool change_contrast_selected = false;
bool change_backlight_selected = false;
switch (setup_state) { switch (setup_state) {
case contrast: case contrast:
@ -341,9 +346,15 @@ static void lcd_setup(void) {
case backlight: case backlight:
backlight_selected = true; backlight_selected = true;
break; break;
default: // back case back:
back_selected = true; back_selected = true;
break; break;
case change_contrast:
change_contrast_selected = true;
break;
case change_backlight:
change_backlight_selected = true;
break;
} }
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
@ -368,31 +379,33 @@ static void lcd_setup(void) {
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(0x02); lcd_write(0x00);
lcd_write(0x10); lcd_write(0x10);
lcd_write(0xB2 + i); lcd_write(0xB2 + i);
SPI_PORT |= (1 << LCD_CD); SPI_PORT |= (1 << LCD_CD);
lcd_write_symbol_page(&sym_c, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_o, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_n, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_t, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_r, 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_s, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_t, i, false);
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, contrast_selected);
lcd_write_kerning(2, contrast_selected); lcd_write_kerning(2, contrast_selected);
lcd_write_symbol_page(&sym_c, i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
lcd_write_symbol_page(&sym_o, i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
lcd_write_symbol_page(&sym_n, i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
lcd_write_symbol_page(&sym_t, i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
lcd_write_symbol_page(&sym_r, i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
lcd_write_symbol_page(&sym_a, i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
lcd_write_symbol_page(&sym_s, i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
lcd_write_symbol_page(&sym_t, i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
lcd_write_symbol_page(&sym_colon, i, contrast_selected);
lcd_write_kerning(2, contrast_selected);
lcd_write_kerning(9, false);
lcd_write_integer_page(value_contrast, 3, i, change_contrast_selected);
lcd_write_kerning(2, change_contrast_selected);
} }
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
@ -402,28 +415,29 @@ static void lcd_setup(void) {
lcd_write(0xB4 + i); lcd_write(0xB4 + i);
SPI_PORT |= (1 << LCD_CD); SPI_PORT |= (1 << LCD_CD);
lcd_write_symbol_page(&sym_b, i, false); lcd_write_symbol_page(&sym_b, i, backlight_selected);
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, false);
lcd_write_symbol_page(&sym_l, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_i, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_g, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_h, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_t, i, false);
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, backlight_selected);
lcd_write_kerning(2, backlight_selected); lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_a, i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_c, i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_k, i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_l, i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_i, i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_g, i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_h, i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_t, i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_colon, i, backlight_selected);
lcd_write_kerning(2, backlight_selected);
lcd_write_kerning(5, false);
lcd_write_integer_page(value_backlight, 3, i, change_backlight_selected);
lcd_write_kerning(2, change_backlight_selected);
} }
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
@ -490,31 +504,81 @@ 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:
switch (setup_state) {
case contrast:
case backlight:
case back:
setup_state++; setup_state++;
if (setup_state > back) if (setup_state > back)
setup_state = contrast; setup_state = contrast;
break;
case change_contrast:
value_contrast++;
break;
case change_backlight:
value_backlight++;
break;
}
lcd_setup(); lcd_setup();
break; break;
case ccw: case ccw:
switch (setup_state) {
case contrast:
case backlight:
case back:
setup_state--; setup_state--;
if (setup_state > back) if (setup_state > back)
setup_state = back; setup_state = back;
break;
case change_contrast:
value_contrast--;
break;
case change_backlight:
value_backlight--;
break;
}
lcd_setup(); lcd_setup();
break; break;
case click: case click:
switch (setup_state) { switch (setup_state) {
case contrast: case contrast:
setup_state = change_contrast;
lcd_setup();
break; break;
case backlight: case backlight:
setup_state = change_backlight;
lcd_setup();
break; break;
case back: case back:
change_state(home); change_state(home);
break; break;
case change_contrast:
setup_state = contrast;
lcd_setup();
break;
case change_backlight:
setup_state = backlight;
lcd_setup();
break;
} }
break; break;
case hold: case hold:
switch (setup_state) {
case contrast:
case backlight:
case back:
change_state(home); change_state(home);
break; break;
case change_contrast:
setup_state = contrast;
lcd_setup();
break;
case change_backlight:
setup_state = backlight;
lcd_setup();
break;
}
break;
} }
} }