From 5fd19def7723c58eff0a15b8b641b02e27dfc7ba Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Mon, 3 Sep 2018 23:04:58 +0000 Subject: [PATCH] avr: support emergency unlock Signed-off-by: Ralf Ramsauer --- avr-code/main.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/avr-code/main.c b/avr-code/main.c index b3eb8a2..e9525da 100644 --- a/avr-code/main.c +++ b/avr-code/main.c @@ -35,6 +35,7 @@ enum state_source { BUTTON, COMM, TIMEOUT, + EMERGENCY, }; static inline void set_schnapper(bool state) @@ -120,8 +121,16 @@ static void update_state(unsigned char new_state, enum state_source source) break; } - if (source == BUTTON) + switch (source) { + case BUTTON: ret = toupper(ret); + break; + case EMERGENCY: + ret = 'E'; + break; + default: + break; + } uart_putc(ret); } @@ -207,13 +216,17 @@ int main(void) sei(); for (;;) { - i = get_keys(); - if (i & GREEN) - update_state(GREEN, BUTTON); - else if (i & YELLOW) - update_state(YELLOW, BUTTON); - else if (i & RED) - update_state(RED, BUTTON); + if (is_emergency()) { + update_state(GREEN, EMERGENCY); + } else { + i = get_keys(); + if (i & GREEN) + update_state(GREEN, BUTTON); + else if (i & YELLOW) + update_state(YELLOW, BUTTON); + else if (i & RED) + update_state(RED, BUTTON); + } set_leds(); } }