Variable thresholds
This commit is contained in:
parent
e48f0f6338
commit
b2d7c5a4cc
14
door.py
14
door.py
|
@ -2,6 +2,10 @@
|
||||||
import os, serial, socket, subprocess, select, datetime, sys
|
import os, serial, socket, subprocess, select, datetime, sys
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
OPEN_THRESHOLD = 35
|
||||||
|
CLOSED_THRESHOLD = 60
|
||||||
|
CLOSED_WANT = 135
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--serial_port", default="/dev/serial/by-id/usb-Imaginaerraum.de_DoorControl_43363220195053573A002C0-if01")
|
parser.add_argument("--serial_port", default="/dev/serial/by-id/usb-Imaginaerraum.de_DoorControl_43363220195053573A002C0-if01")
|
||||||
parser.add_argument("--nfc_fifo", default="/tmp/nfc_fifo")
|
parser.add_argument("--nfc_fifo", default="/tmp/nfc_fifo")
|
||||||
|
@ -120,10 +124,10 @@ def poll_door_state():
|
||||||
data = int(data[1])
|
data = int(data[1])
|
||||||
state_pos = data
|
state_pos = data
|
||||||
changed = False
|
changed = False
|
||||||
if data < 80 and state != OPEN:
|
if data < OPEN_THRESHOLD and state != OPEN:
|
||||||
state = OPEN
|
state = OPEN
|
||||||
changed = True
|
changed = True
|
||||||
elif data > 100 and state != CLOSE:
|
elif data > CLOSED_THRESHOLD and state != CLOSE:
|
||||||
state = CLOSE
|
state = CLOSE
|
||||||
changed = True
|
changed = True
|
||||||
return state
|
return state
|
||||||
|
@ -154,6 +158,12 @@ def handle_door_state():
|
||||||
if action == IDLE:
|
if action == IDLE:
|
||||||
if state != old_state:
|
if state != old_state:
|
||||||
log("Door changed unexpectedly:", state_names[state])
|
log("Door changed unexpectedly:", state_names[state])
|
||||||
|
start_time = datetime.datetime.now()
|
||||||
|
if start_time and (datetime.datetime.now() - start_time).total_seconds() >= config.state_timeout:
|
||||||
|
start_time = None
|
||||||
|
if state_pos >= CLOSED_THRESHOLD and state_pos < CLOSED_WANT:
|
||||||
|
log("Closing door a bit more")
|
||||||
|
serial_port.write(target_state_cmd[CLOSE])
|
||||||
return
|
return
|
||||||
|
|
||||||
# Target state, next action, timeout action
|
# Target state, next action, timeout action
|
||||||
|
|
Loading…
Reference in New Issue
Block a user