-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8bitdocontroller.py
209 lines (192 loc) · 8.58 KB
/
8bitdocontroller.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#import evdev
from evdev import InputDevice, categorize, ecodes
import alsaaudio
from picamera import PiCamera
from picamera import Color
import time
import subprocess
import sys
import os
#m = alsaaudio.Mixer() #change later to audio hat
m = alsaaudio.Mixer('Speaker')
#m = alsaaudio.Mixer('Headphones', cardindex=0)
current_volume = m.getvolume() # Get the current Volume
#m.setvolume(80) # Set the volume to 80%.
camera = PiCamera()
camera.resolution = (1920, 1080)
camera.start_preview()
camera.rotation = -90
camera.annotate_text_size = 160
camera.annotate_text = "\n\n\nLauncher"
#creates object 'gamepad' to store the data
#you can call it whatever you like
gamepad = InputDevice('/dev/input/event0')
#button code variables (change to suit your device)
aBtn = 305
bBtn = 304
xBtn = 307
yBtn = 306
#up = 'ABS_Y'
#down = 'ABS_Y'
#left = 'ABS_X'
#right = 'ABS_X'
start = 313
select = 312
lTrig = 308
rTrig = 309
prev_hold = None
#prints out device info at start
print(gamepad)
#loop and filter by event code and print the mapped label
for event in gamepad.read_loop():
if event.type == ecodes.EV_ABS:
camera.annotate_background = None
absevent = categorize(event)
if ecodes.bytype[absevent.event.type][absevent.event.code] == 'ABS_X':
print(absevent.event.value)
if(absevent.event.value > 32512):
print("right")
camera.annotate_text = "\n\n\nRIGHT"
elif (absevent.event.value < 32512):
print("left")
camera.annotate_text = "\n\n\nLEFT"
if ecodes.bytype[absevent.event.type][absevent.event.code] == 'ABS_Y':
print(absevent.event.value)
if(absevent.event.value == 32512):
if (prev_hold < 32512):
subprocess.Popen(["sudo", "mpg123", "/home/pi/PiGlassv2/volume.mp3"], shell=False)
prev_hold = absevent.event.value
if (prev_hold > 32512):
camera.annotate_text = "\n\n\nExiting"
# prev_hold = absevent.event.value
#subprocess.Popen(["ls"], shell=False)
sys.exit(0)
if(absevent.event.value > 32512):
print("down")
camera.annotate_text = "\n\n\nDOWN"
prev_hold = absevent.event.value
elif (absevent.event.value < 32512):
print("up")
prev_hold = absevent.event.value
camera.annotate_text = "\n\n\nTesting Volume"
# subprocess.Popen(["sudo", "mpg123", "/home/pi/PiGlassv2/volume.mp3"], shell=False)
# camera.annotate_text = "\n\n\nTesting Volume"
if event.type == ecodes.EV_KEY:
if event.value == 1:
camera.annotate_background = None
if event.code == yBtn:
camera.annotate_text = "\n\n\nY: Steamlink"
# stat = subprocess.call(["systemctl", "is-active", "bt_speaker"])
# if(stat == 0): # if 0 (active), print "Active"
# print("BT Active")
# camera.annotate_text = "\n\n\nBluetooth Headphones\nEnabled"
# else:
# print("BT not active")
# camera.annotate_text = "\n\n\nBluetooth Headphones\nDisabled"
print("Y")
elif event.code == bBtn:
camera.annotate_text = "\n\n\nB: Kodi"
print("B")
elif event.code == aBtn:
camera.annotate_text = "\n\n\nA: EmulationStation"
print("A")
elif event.code == xBtn:
camera.annotate_text = "\n\n\nX: Camera"
print("X")
elif event.code == start:
camera.annotate_text = "\n\n\nYT Livestream"
print("start")
elif event.code == select:
camera.annotate_text = "\n\n\nSELECT"
print("select")
elif event.code == lTrig:
#camera.annotate_text = "\n\n\nHold for Volume down"
print("left bumper")
current_volume = m.getvolume()
print(current_volume)
# camera.annotate_text = "\nVol: "+str(current_volume)+"\n\nVolume Down"
newVolume = int(current_volume[0])-1
if(newVolume >= 75):
m.setvolume(newVolume)
camera.annotate_text = "\nVol: "+str(current_volume)+"\n\nVolume Down"
elif event.code == rTrig:
#camera.annotate_text = "\n\n\nHold for Volume up"
print("right bumper")
current_volume = m.getvolume()
print(current_volume)
# camera.annotate_text = "\nVol: "+str(current_volume)+"\n\nVolume Up"
newVolume = int(current_volume[0])+1
if(newVolume <= 100):
m.setvolume(newVolume)
camera.annotate_text = "\nVol: "+str(current_volume)+"\n\nVolume Up"
if event.value == 0:
prev_hold = None
if event.code == start:
print("start")
if event.code == lTrig:
print("left bumper")
if event.code == rTrig:
print("right bumper")
if event.value == 2 and event.code != prev_hold:
camera.annotate_background = Color('green')
if event.code == yBtn:
subprocess.Popen(["sudo", "-u", "pi", "steamlink"], shell=False)
#
camera.close()
# subprocess.Popen(["export", "DISPLAY=:0"], shell=False)
#os.system("python3 /home/pi/PiGlassv2/facedetect.py")
# subprocess.Popen(["sudo", "ttyecho", "-n", "/dev/tty1", "python3", "/home/pi/PiGlassv2/facedetect.py"], shell=False)
sys.exit(0)
# prev_hold = event.code
# stat = subprocess.call(["systemctl", "is-active", "--quiet", "bt_speaker"])
# if(stat == 0): # if 0 (active), print "Active"
# print("BT Active")
# subprocess.Popen(["systemctl", "stop", "/opt/bt-speaker/bt_speaker.service"], shell=False)
# subprocess.Popen(["/usr/bin/sudo", "systemctl", "start", "bt_speaker.service"], shell=False)
# camera.annotate_text = "\n\n\nBluetooth Headphones\nEnabled"
# else:
# print("BT not active")
# #subprocess.Popen(["/usr/bin/sudo", "systemctl", "stop", "bt_speaker.service"], shell=False)
# subprocess.Popen(["systemctl", "start", "/opt/bt-speaker/bt_speaker.service"], shell=False)
# camera.annotate_text = "\n\n\nBluetooth Headphones\nDisabled"
print("Y")
elif event.code == bBtn:
subprocess.Popen(["kodi"], shell=False)
sys.exit(0)
print("B")
elif event.code == aBtn:
subprocess.Popen(["sudo", "ttyecho", "-n", "/dev/tty1", "emulationstation"], shell=False)
print("A")
sys.exit(0)
elif event.code == xBtn:
# subprocess.Popen(["/usr/bin/python3", "/home/pi/PiGlassv2/PiGlassBeta-Python3.py"], shell=False)
camera.close()
os.system("python3 /home/pi/PiGlassv2/PiGlassBeta-Python3.py")
print("X")
sys.exit(0)
elif event.code == start:
prev_hold = event.code
camera.close()
subprocess.Popen(["sh", "/home/pi/PiGlassv2/syncedaudio.sh"], shell=False)
print("start")
sys.exit(0)
elif event.code == select:
print("select")
elif event.code == lTrig:
print("left bumper")
current_volume = m.getvolume()
print(current_volume)
# camera.annotate_text = "\nVol: "+str(current_volume)+"\n\nVolume Down"
newVolume = int(current_volume[0])-1
if(newVolume >= 75):
m.setvolume(newVolume)
camera.annotate_text = "\nVol: "+str(current_volume)+"\n\nVolume Down"
elif event.code == rTrig:
print("right bumper")
current_volume = m.getvolume()
print(current_volume)
# camera.annotate_text = "\nVol: "+str(current_volume)+"\n\nVolume Up"
newVolume = int(current_volume[0])+1
if(newVolume <= 100):
m.setvolume(newVolume)
camera.annotate_text = "\nVol: "+str(current_volume)+"\n\nVolume Up"