/
door_controller.py
56 lines (44 loc) · 1.31 KB
/
door_controller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
import logging
import time
from motor_controller import MotorController
from switch_simulator import SwitchSimulator
from configuration import DoorStatus
from configuration import Config
from switch_controller import SwitchController
from time import sleep
class DoorController:
#status == True when open
def __init__(self):
pass
@staticmethod
def get_status():
return SwitchController.get_status()
state = DoorController.get_switch_state()
if state:
return DoorStatus.Closed
else:
return DoorStatus.Open
return state
@staticmethod
def get_switch_state():
try:
f = open('/var/local/executioner/switch', 'r')
status = f.read().strip()
return status == "1"
except IOError as e:
logging.error('I/O error while reading switch: {}.'.format(e))
return False
@staticmethod
def set_status(newStatus):
#switch = SwitchSimulator(newStatus)
#switch.start()
if newStatus == DoorStatus.Closed:
MotorController.energize_down()
currentTime = time.time()
while DoorController.get_status() == DoorStatus.Open and time.time() < currentTime + Config.MaxDownDuration:
sleep(0.01)
else:
MotorController.energize_up()
sleep(Config.MaxUpDuration)
MotorController.halt()