From 6725555af6cbe8113e1c6f83853247dd1602f1e3 Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Fri, 14 Jun 2019 20:43:53 +0200 Subject: [PATCH] avr: use a own header to define constants We will soon share them with python Signed-off-by: Ralf Ramsauer --- avr-code/main.c | 16 +++++++++------- avr-code/protocol.h | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 avr-code/protocol.h diff --git a/avr-code/main.c b/avr-code/main.c index 663bfb8..49dbbe9 100644 --- a/avr-code/main.c +++ b/avr-code/main.c @@ -18,6 +18,8 @@ #include #include +#include "protocol.h" + #define RED 0x1 #define GREEN 0x2 #define YELLOW 0x4 @@ -107,17 +109,17 @@ static void update_state(unsigned char new_state, enum state_source source) case RED: set_bolzen(true); set_schnapper(false); - ret = 'r'; + ret = AVR_STATE_SWITCH_RED; break; case YELLOW: set_bolzen(false); set_schnapper(false); - ret = 'y'; + ret = AVR_STATE_SWITCH_YELLOW; break; case GREEN: set_bolzen(false); set_schnapper(true); - ret = 'g'; + ret = AVR_STATE_SWITCH_GREEN; break; } @@ -126,7 +128,7 @@ static void update_state(unsigned char new_state, enum state_source source) uart_putc(toupper(ret)); break; case EMERGENCY: - uart_putc('E'); + uart_putc(AVR_EMERGENCY); break; case TIMEOUT: uart_putc(ret); @@ -142,13 +144,13 @@ ISR(USART_RX_vect) unsigned char c = UDR; switch (c) { - case 'r': + case AVR_STATE_SWITCH_RED: update_state(RED, COMM); break; - case 'y': + case AVR_STATE_SWITCH_YELLOW: update_state(YELLOW, COMM); break; - case 'g': + case AVR_STATE_SWITCH_GREEN: update_state(GREEN, COMM); break; } diff --git a/avr-code/protocol.h b/avr-code/protocol.h new file mode 100644 index 0000000..380e745 --- /dev/null +++ b/avr-code/protocol.h @@ -0,0 +1,16 @@ +/* + * doorlock-avr, AVR code of Binary Kitchen's doorlock + * + * Copyright (c) Binary Kitchen, 2019 + * + * Authors: + * Ralf Ramsauer + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#define AVR_STATE_SWITCH_RED 'r' +#define AVR_STATE_SWITCH_YELLOW 'y' +#define AVR_STATE_SWITCH_GREEN 'g' +#define AVR_EMERGENCY 'E'