mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 10:24:26 +01:00
doorlockd, avr: Don't respond on commands
No need to read back the AVR. Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
parent
95c35e7c06
commit
9f3062340c
@ -123,22 +123,23 @@ static void update_state(unsigned char new_state, enum state_source source)
|
|||||||
|
|
||||||
switch (source) {
|
switch (source) {
|
||||||
case BUTTON:
|
case BUTTON:
|
||||||
ret = toupper(ret);
|
uart_putc(toupper(ret));
|
||||||
break;
|
break;
|
||||||
case EMERGENCY:
|
case EMERGENCY:
|
||||||
ret = 'E';
|
uart_putc('E');
|
||||||
break;
|
break;
|
||||||
|
case TIMEOUT:
|
||||||
|
uart_putc(ret);
|
||||||
|
break;
|
||||||
|
case COMM:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uart_putc(ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(USART_RX_vect)
|
ISR(USART_RX_vect)
|
||||||
{
|
{
|
||||||
unsigned char c = UDR;
|
unsigned char c = UDR;
|
||||||
bool respond = true;
|
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'r':
|
case 'r':
|
||||||
@ -150,13 +151,7 @@ ISR(USART_RX_vect)
|
|||||||
case 'g':
|
case 'g':
|
||||||
update_state(GREEN, COMM);
|
update_state(GREEN, COMM);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
respond = false;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (respond)
|
|
||||||
uart_putc(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(TIMER1_OVF_vect)
|
ISR(TIMER1_OVF_vect)
|
||||||
|
74
doorlockd
74
doorlockd
@ -248,56 +248,50 @@ class DoorHandler:
|
|||||||
self.serial = Serial(device, baudrate=9600, bytesize=8, parity='N',
|
self.serial = Serial(device, baudrate=9600, bytesize=8, parity='N',
|
||||||
stopbits=1, timeout=0)
|
stopbits=1, timeout=0)
|
||||||
self.thread = Thread(target=self.thread_worker)
|
self.thread = Thread(target=self.thread_worker)
|
||||||
|
log.debug('Spawning RS232 Thread')
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
def handle_input(self, recv, expect=None):
|
|
||||||
if recv == DoorHandler.BUTTON_CLOSE:
|
|
||||||
playsound(wave_lock_button)
|
|
||||||
if self.state.is_open():
|
|
||||||
run_lock()
|
|
||||||
self.state = DoorState.Closed
|
|
||||||
logic.emit_status(LogicResponse.ButtonLock)
|
|
||||||
elif recv == DoorHandler.BUTTON_OPEN:
|
|
||||||
playsound(wave_unlock_button)
|
|
||||||
self.state = DoorState.Open
|
|
||||||
logic.emit_status(LogicResponse.ButtonUnlock)
|
|
||||||
elif recv == DoorHandler.BUTTON_PRESENT:
|
|
||||||
# playsound...
|
|
||||||
self.state = DoorState.Present
|
|
||||||
logic.emit_status(LogicResponse.ButtonPresent)
|
|
||||||
elif recv == DoorHandler.CMD_EMERGENCY_SWITCH:
|
|
||||||
playsound(wave_emergency)
|
|
||||||
logic.emit_status(LogicResponse.EmergencyUnlock)
|
|
||||||
|
|
||||||
if expect is None:
|
|
||||||
return True
|
|
||||||
return recv == expect
|
|
||||||
|
|
||||||
def send_command(self, cmd):
|
|
||||||
self.serial.write(cmd)
|
|
||||||
self.serial.flush()
|
|
||||||
sleep(0.1)
|
|
||||||
char = self.serial.read(1)
|
|
||||||
if not self.handle_input(char, cmd):
|
|
||||||
log.warning('Sent serial command, got wrong response')
|
|
||||||
|
|
||||||
def thread_worker(self):
|
def thread_worker(self):
|
||||||
while True:
|
while True:
|
||||||
sleep(0.4)
|
sleep(0.4)
|
||||||
while True:
|
while True:
|
||||||
char = self.serial.read(1)
|
rx = self.serial.read(1)
|
||||||
if len(char) == 0:
|
if len(rx) == 0:
|
||||||
break
|
break
|
||||||
self.handle_input(char)
|
if rx == DoorHandler.BUTTON_CLOSE:
|
||||||
|
self.close()
|
||||||
|
log.info('Closed due to Button press')
|
||||||
|
logic.emit_status(LogicResponse.ButtonLock)
|
||||||
|
elif rx == DoorHandler.BUTTON_OPEN:
|
||||||
|
self.open()
|
||||||
|
log.info('Opened due to Button press')
|
||||||
|
logic.emit_status(LogicResponse.ButtonUnlock)
|
||||||
|
elif rx == DoorHandler.BUTTON_PRESENT:
|
||||||
|
self.present()
|
||||||
|
log.info('Present due to Button press')
|
||||||
|
logic.emit_status(LogicResponse.ButtonPresent)
|
||||||
|
elif rx == DoorHandler.CMD_EMERGENCY_SWITCH:
|
||||||
|
log.warning('Emergency unlock')
|
||||||
|
logic.emit_status(LogicResponse.EmergencyUnlock)
|
||||||
|
else:
|
||||||
|
log.error('Received unknown message "%s" from AVR' % rx)
|
||||||
|
|
||||||
if self.do_close:
|
if self.do_close:
|
||||||
self.send_command(DoorHandler.CMD_CLOSE)
|
tx = DoorHandler.CMD_CLOSE
|
||||||
self.do_close = False
|
self.do_close = False
|
||||||
elif self.state.is_open():
|
if self.state == DoorState.Present:
|
||||||
if self.state == DoorState.Present:
|
tx = DoorHandler.CMD_PRESENT
|
||||||
self.send_command(DoorHandler.CMD_PRESENT)
|
elif self.state == DoorState.Open:
|
||||||
else:
|
tx = DoorHandler.CMD_OPEN
|
||||||
self.send_command(DoorHandler.CMD_OPEN)
|
else:
|
||||||
|
tx = None
|
||||||
|
|
||||||
|
if not tx:
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.serial.write(tx)
|
||||||
|
self.serial.flush()
|
||||||
|
sleep(0.1)
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
if self.state == DoorState.Open:
|
if self.state == DoorState.Open:
|
||||||
|
Loading…
Reference in New Issue
Block a user