diff --git a/firmware/src/main.c b/firmware/src/main.c index 93515ff..b7ac373 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -60,10 +60,10 @@ static const struct symbol sym_setup = { 19, { 0xF8, 0x98, 0xB8, 0x00, 0xF8, 0x9 enum input {cw, ccw, click, hold}; -static enum state {home} current_state = home; -static enum home_state {ch1, ch2, ch3, setup} current_home_state = ch1; +static volatile enum state {home, ch1, ch2, ch3, setup} current_state = home; +static volatile enum state home_state = ch1; -static uint8_t enc = 0; +static volatile uint8_t enc = 0; void spi_init(void) { SPI_DDR |= (1 << SPI_SCK) | (1 << SPI_MOSI) | (1 << SPI_SS); @@ -169,7 +169,7 @@ static void lcd_home(void) { bool ch3_selected = false; bool setup_selected = false; - switch(current_home_state) { + switch(home_state) { case ch1: ch1_selected = true; break; @@ -239,21 +239,39 @@ static void lcd_home(void) { } } +static void change_state(enum state new_state) { + switch(new_state) { + case home: + lcd_home(); + current_state = home; + break; + case ch1: + break; + case ch2: + break; + case ch3: + break; + case setup: + break; + } +} + static void update_home(enum input event) { switch (event) { case cw: - current_home_state++; - if (current_home_state > setup) - current_home_state = ch1; + home_state++; + if (home_state > setup) + home_state = ch1; lcd_home(); break; case ccw: - current_home_state--; - if (current_home_state > setup) - current_home_state = setup; + home_state--; + if (home_state > setup) + home_state = setup; lcd_home(); break; case click: + change_state(home_state); break; case hold: break; @@ -265,14 +283,13 @@ static void update_state(enum input event) { case home: update_home(event); break; - } -} - -static void change_state(enum state new_state) { - switch(new_state) { - case home: - lcd_home(); - current_state = home; + case ch1: + break; + case ch2: + break; + case ch3: + break; + case setup: break; } }