1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-26 20:11:50 +01:00

avr: use a own header to define constants

We will soon share them with python

Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
Ralf Ramsauer 2019-06-14 20:43:53 +02:00
parent b5154faecd
commit 6725555af6
2 changed files with 25 additions and 7 deletions

View File

@ -18,6 +18,8 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <util/delay.h> #include <util/delay.h>
#include "protocol.h"
#define RED 0x1 #define RED 0x1
#define GREEN 0x2 #define GREEN 0x2
#define YELLOW 0x4 #define YELLOW 0x4
@ -107,17 +109,17 @@ static void update_state(unsigned char new_state, enum state_source source)
case RED: case RED:
set_bolzen(true); set_bolzen(true);
set_schnapper(false); set_schnapper(false);
ret = 'r'; ret = AVR_STATE_SWITCH_RED;
break; break;
case YELLOW: case YELLOW:
set_bolzen(false); set_bolzen(false);
set_schnapper(false); set_schnapper(false);
ret = 'y'; ret = AVR_STATE_SWITCH_YELLOW;
break; break;
case GREEN: case GREEN:
set_bolzen(false); set_bolzen(false);
set_schnapper(true); set_schnapper(true);
ret = 'g'; ret = AVR_STATE_SWITCH_GREEN;
break; break;
} }
@ -126,7 +128,7 @@ static void update_state(unsigned char new_state, enum state_source source)
uart_putc(toupper(ret)); uart_putc(toupper(ret));
break; break;
case EMERGENCY: case EMERGENCY:
uart_putc('E'); uart_putc(AVR_EMERGENCY);
break; break;
case TIMEOUT: case TIMEOUT:
uart_putc(ret); uart_putc(ret);
@ -142,13 +144,13 @@ ISR(USART_RX_vect)
unsigned char c = UDR; unsigned char c = UDR;
switch (c) { switch (c) {
case 'r': case AVR_STATE_SWITCH_RED:
update_state(RED, COMM); update_state(RED, COMM);
break; break;
case 'y': case AVR_STATE_SWITCH_YELLOW:
update_state(YELLOW, COMM); update_state(YELLOW, COMM);
break; break;
case 'g': case AVR_STATE_SWITCH_GREEN:
update_state(GREEN, COMM); update_state(GREEN, COMM);
break; break;
} }

16
avr-code/protocol.h Normal file
View File

@ -0,0 +1,16 @@
/*
* doorlock-avr, AVR code of Binary Kitchen's doorlock
*
* Copyright (c) Binary Kitchen, 2019
*
* Authors:
* Ralf Ramsauer <ralf@binary-kitchen.de>
*
* 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'