-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput_monitor.py
98 lines (83 loc) · 3.04 KB
/
Input_monitor.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# coding: Latin-1
# Load library functions we want
import sys
import os
from inputs import get_gamepad
safety_flag = True
try:
print 'Press CTRL+C to quit'
# Loop indefinitely
while True:
events = get_gamepad()
for event in events:
print(event.code, event.state)
if event.code == "ABS_Y":
if event.state > 130:
print("Backwards")
elif event.state < 125:
print("Forward")
if event.code == "ABS_Z":
if event.state > 130:
print("Right")
elif event.state < 125:
print("Left")
if event.code == "BTN_TL":
if event.state == True:
print("Turbo")
if event.code == "BTN_TR":
if event.state == True:
print("Tank")
if event.code == "BTN_NORTH":
if event.state == True:
print("Triangle")
if event.code == "BTN_SOUTH":
if event.state == True:
print("Square")
if event.code == "BTN_EAST":
if event.state == True:
print("Cross")
if event.code == "BTN_C":
if event.state == True:
print("Circle")
if event.code == "BTN_TR2":
if event.state == True:
print("Start")
if safety_flag:
os.system("flite -voice rms -t 'safety off' &")
safety_flag = False
else:
os.system("flite -voice rms -t 'safety on' &")
safety_flag = True
if event.code == "BTN_TL2":
if event.state == True:
print("Select")
if event.code == "ABS_HAT0Y":
if event.state == -1:
print("D pad Up")
os.system("play /home/pi/Sounds/squirrel01.mp3 &")
elif event.state == 1:
print("D pad Down")
if event.code == "ABS_HAT0X":
if event.state == -1:
print("D pad Left")
elif event.state == 1:
print("D pad Right")
if event.code == "BTN_WEST":
if event.state == True:
print("Top left")
if event.code == "BTN_Z":
if event.state == True:
print("Top right")
os.system("python /home/pi/randomFart.py &")
if event.code == "BTN_MODE":
if event.state == True:
print("Home")
if safety_flag:
os.system("flite -voice rms -t 'Home Menu' &")
print("#### End ####")
# print(event.ev_type, event.code, event.state)
except KeyboardInterrupt:
# CTRL+C exit, disable all drives
print("stop")
print("bye")