-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.py
executable file
·46 lines (35 loc) · 1.16 KB
/
code.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
import menu.elevator_floors
import touchscreen
from time import monotonic, sleep
import elevator
TIMEOUT_MINUTES = 5
print("Initializing elevator...")
lift = elevator.Elevator()
print("Drawing menu...")
menu.elevator_floors.drawMenu()
menu.elevator_floors.drawCurrentFloor(1)
print("Starting run loop...")
timeoutAfter = 0
def goToFloor(floor: int) -> None:
print("going to floor %s..." % floor)
menu.elevator_floors.drawCurrentFloor(floor)
lift.goToFloor(floor)
while True:
sleep(.1)
p = touchscreen.ts.touch_point
if p:
print("x %s y %s z %s" % p)
floor = menu.elevator_floors.whichFloor(p[0], p[1])
if (floor > 0):
goToFloor(floor)
if (lift.isBraked()):
# Update timeout to be 5 min after last touch (even if not touched on button)
timeoutAfter = monotonic() + (60*TIMEOUT_MINUTES)
else:
timeoutAfter = 0
if (timeoutAfter > 0 and monotonic() > timeoutAfter):
# go to floor 1 to save energy on motor brake
print("Timeout reached of %s minutes, going to floor 1" %
TIMEOUT_MINUTES)
goToFloor(1)
timeoutAfter = 0