-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu
executable file
·83 lines (66 loc) · 2.15 KB
/
menu
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
import inspect
import time
import pyfirmata
from programs import load_print_shop, load_print_master
from print import print_latest
def main():
print("Please wait while your call is connected...")
board = pyfirmata.util.get_the_board(identifier="tty.usbmodem")
it = pyfirmata.util.Iterator(board)
it.start()
spider = board.get_pin("d:3:i")
tiger = board.get_pin("d:4:i")
turtle = board.get_pin("d:5:i")
while True:
show_menu()
pin = wait_for_pin([spider, tiger, turtle], True)
if pin == spider:
print_latest()
elif pin == tiger:
print(inspect.cleandoc('''
RAWR! 🐅
The computer will reset and load PRINT SHOP!
Keep holding the tiger button if you want this!
'''))
time.sleep(4) # Intentionally shorter timeout than Print Master
if pin.read() == True:
load_print_shop()
else:
print("🐅 tigers need hugs, try again")
elif pin == turtle:
print(inspect.cleandoc('''
flelelele! 🐢
The computer will reset and load PRINT MASTER!
Keep holding the turtle button if you want this!
'''))
time.sleep(5)
if pin.read() == True:
load_print_master()
else:
print("🐢 turtles need bugs, try again")
wait_for_pin([pin], False)
def show_menu():
print()
print(inspect.cleandoc('''
MAIN MENU
~~~~~~~~~
🕷 PRINT latest creation
🐅 Load Print Shop (fastest, easiest)
🐢 Load Print Master
'''))
print()
def wait_for_pin(pins, status):
"""
Waits for any of the given pins to reach the given status
:param pins: list of pins from board.get_pin (must be digital inputs)
:param status: boolean status to wait for
:return: first pin to reach the given status
"""
while True:
for pin in pins:
if pin.read() == status:
return pin
time.sleep(0.1)
if __name__ == "__main__":
main()