-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathControllers.py
362 lines (333 loc) · 9.8 KB
/
Controllers.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# coding: utf-8
"""
Standard gamepad mappings.
Pulled in to Gamepad.py directly.
"""
class PS3(Gamepad):
fullName = 'PlayStation 3 controller'
def __init__(self, joystickNumber = 0):
Gamepad.__init__(self, joystickNumber)
self.axisNames = {
0: 'LEFT-X',
1: 'LEFT-Y',
2: 'L2',
3: 'RIGHT-X',
4: 'RIGHT-Y',
5: 'R2'
}
self.buttonNames = {
0: 'CROSS',
1: 'CIRCLE',
2: 'TRIANGLE',
3: 'SQUARE',
4: 'L1',
5: 'R1',
6: 'L2',
7: 'R2',
8: 'SELECT',
9: 'START',
10: 'PS',
11: 'L3',
12: 'R3',
13: 'DPAD-UP',
14: 'DPAD-DOWN',
15: 'DPAD-LEFT',
16: 'DPAD-RIGHT'
}
self._setupReverseMaps()
# PS3 controller settings for older Raspbian versions
#class PS3(Gamepad):
# fullName = 'PlayStation 3 controller'
#
# def __init__(self, joystickNumber = 0):
# Gamepad.__init__(self, joystickNumber)
# self.axisNames = {
# 0: 'LEFT-X',
# 1: 'LEFT-Y',
# 2: 'RIGHT-X',
# 3: 'RIGHT-Y',
# 4: 'roll-1',
# 5: 'pitch',
# 6: 'roll-2',
# 8: 'DPAD-UP',
# 9: 'DPAD-RIGHT',
# 10: 'DPAD-DOWN',
# 11: 'DPAD-LEFT',
# 12: 'L2',
# 13: 'R2',
# 14: 'L1',
# 15: 'R1',
# 16: 'TRIANGLE',
# 17: 'CIRCLE',
# 18: 'CROSS',
# 19: 'SQUARE'
# }
# self.buttonNames = {
# 0: 'SELECT',
# 1: 'L3',
# 2: 'R3',
# 3: 'START',
# 4: 'DPAD-UP',
# 5: 'DPAD-RIGHT',
# 6: 'DPAD-DOWN',
# 7: 'DPAD-LEFT',
# 8: 'L2',
# 9: 'R2',
# 10: 'L1',
# 11: 'R1',
# 12: 'TRIANGLE',
# 13: 'CIRCLE',
# 14: 'CROSS',
# 15: 'SQUARE',
# 16: 'PS'
# }
# self._setupReverseMaps()
class PS4(Gamepad):
fullName = 'PlayStation 4 controller'
def __init__(self, joystickNumber = 0):
Gamepad.__init__(self, joystickNumber)
self.axisNames = {
0: 'LEFT-X',
1: 'LEFT-Y',
2: 'L2',
3: 'RIGHT-X',
4: 'RIGHT-Y',
5: 'R2',
6: 'DPAD-X',
7: 'DPAD-Y'
}
self.buttonNames = {
0: 'CROSS',
1: 'CIRCLE',
2: 'TRIANGLE',
3: 'SQUARE',
4: 'L1',
5: 'R1',
6: 'L2',
7: 'R2',
8: 'SHARE',
9: 'OPTIONS',
10: 'PS',
11: 'L3',
12: 'R3'
}
self._setupReverseMaps()
# PS4 controller settings for older Raspbian versions
#class PS4(Gamepad):
# fullName = 'PlayStation 4 controller'
#
# def __init__(self, joystickNumber = 0):
# Gamepad.__init__(self, joystickNumber)
# self.axisNames = {
# 0: 'LEFT-X',
# 1: 'LEFT-Y',
# 2: 'RIGHT-X',
# 3: 'L2',
# 4: 'R2',
# 5: 'RIGHT-Y',
# 6: 'DPAD-X',
# 7: 'DPAD-Y'
# }
# self.buttonNames = {
# 0: 'SQUARE',
# 1: 'CROSS',
# 2: 'CIRCLE',
# 3: 'TRIANGLE',
# 4: 'L1',
# 5: 'R1',
# 6: 'L2',
# 7: 'R2',
# 8: 'SHARE',
# 9: 'OPTIONS',
# 10: 'L3',
# 11: 'R3',
# 12: 'PS',
# 13: 'PAD'
# }
# self._setupReverseMaps()
class Xbox360(Gamepad):
fullName = 'Xbox 360 controller'
def __init__(self, joystickNumber = 0):
Gamepad.__init__(self, joystickNumber)
self.axisNames = {
0: 'LEFT-X',
1: 'LEFT-Y',
2: 'LT',
3: 'RIGHT-X',
4: 'RIGHT-Y',
5: 'RT'
}
self.buttonNames = {
0: 'A',
1: 'B',
2: 'X',
3: 'Y',
4: 'LB',
5: 'RB',
6: 'BACK',
7: 'START',
8: 'XBOX',
9: 'LA',
10: 'RA'
}
self._setupReverseMaps()
class XboxONE(Gamepad):
fullName = 'Xbox ONE controller'
def __init__(self, joystickNumber = 0):
Gamepad.__init__(self, joystickNumber)
self.axisNames = {
0: 'LAS -X', #Left Analog Stick Left/Right
1: 'LAS -Y', #Left Analog Stick Up/Down
2: 'RAS -X', #Right Analog Stick Left/Right
3: 'RAS -Y', #Right Analog Stick Up/Down
4: 'RT', #Right Trigger
5: 'LT', #Left Trigger
6: 'DPAD -X', #D-Pad Left/Right
7: 'DPAD -Y' #D-Pad Up/Down
}
self.buttonNames = {
0: 'A', #A Button
1: 'B', #B Button
3: 'X', #X Button
4: 'Y', #Y Button
6: 'LB', #Left Bumper
7: 'RB', #Right Bumper
11: 'START', #Hamburger Button
12: 'HOME', #XBOX Button
13: 'LASB', #Left Analog Stick button
14: 'RASB' #Right Analog Stick button
}
self._setupReverseMaps()
class Steam(Gamepad):
fullName = 'Steam controller'
def __init__(self, joystickNumber = 0):
Gamepad.__init__(self, joystickNumber)
self.axisNames = {
0: 'AS -X', #Analog Stick Left/Right
1: 'AS -Y', #Analog Stick Up/Down
2: 'RTP -X', #Right Track Pad Left/Right
3: 'RTP -Y', #Right Track Pad Up/Down
4: 'LTP -Y', #Left Track Pad Up/Down
5: 'LTP -X', #Left Track Pad Left/Right
6: 'RTA', #Right Trigger Axis
7: 'LTA' #Left Trigger Axis
}
self.buttonNames = {
0: 'LPTBUTTON', #Left TrackPad button
1: 'RTPBUTTON', #Right TrackPad button
2: 'A', #A Button
3: 'B', #B Button
4: 'X', #X Button
5: 'Y', #Y Button
6: 'LB', #Left Bumper
7: 'RB', #Right Bumper
8: 'LT', #Left Trigger
9: 'RT', #Right Trigger
10: 'SELECT', #Select Button <
11: 'START', #Start button >
12: 'HOME', #Steam Button
13: 'STICKBUTTON', #Analog Stick button
15: 'LG', #Left Grip
16: 'RG', #Right Grip
17: 'LTP -DUP', #Left TrackPad D-PAD Up
18: 'LTP -DDOWN', #Left TrackPad D-PAD Down
19: 'LTP -DLEFT', #Left TrackPad D-PAD Left
20: 'LTP -DRIGHT', #Left TrackPad D-PAD Right
}
self._setupReverseMaps()
class MMP1251(Gamepad):
fullName = "ModMyPi Raspberry Pi Wireless USB Gamepad"
def __init__(self, joystickNumber = 0):
Gamepad.__init__(self, joystickNumber)
self.axisNames = {
0: 'LEFT-X',
1: 'LEFT-Y',
2: 'L2',
3: 'RIGHT-X',
4: 'RIGHT-Y',
5: 'R2',
6: 'DPAD-X',
7: 'DPAD-Y'
}
self.buttonNames = {
0: 'A',
1: 'B',
2: 'X',
3: 'Y',
4: 'L1',
5: 'R1',
6: 'SELECT',
7: 'START',
8: 'HOME',
9: 'L3',
10: 'R3'
}
self._setupReverseMaps()
class GameHat(Gamepad):
fullName = "WaveShare rpi GameHat "
def __init__(self, joystickNumber = 0):
Gamepad.__init__(self, joystickNumber)
self.axisNames = {
0: 'LEFT-X',
1: 'LEFT-Y'
}
self.buttonNames = {
0: 'A',
1: 'B',
2: 'X',
3: 'Y',
4: 'TR',
5: 'TL',
6: 'SELECT',
7: 'START'
}
self._setupReverseMaps()
class PG9099(Gamepad):
fullName = 'ipega PG-9099 Bluetooth Controller'
def __init__(self, joystickNumber = 0):
Gamepad.__init__(self, joystickNumber)
self.axisNames = {
0: 'LAS -X', #Left Analog Stick Left/Right
1: 'LAS -Y', #Left Analog Stick Up/Down
2: 'RAS -X', #Right Analog Stick Left/Right
3: 'RAS -Y', #Right Analog Stick Up/Down
4: 'RT', #Right Trigger
5: 'LT', #Left Trigger
6: 'DPAD -X', #D-Pad Left/Right
7: 'DPAD -Y' #D-Pad Up/Down
}
self.buttonNames = {
0: 'A', #A Button
1: 'B', #B Button
3: 'X', #X Button
4: 'Y', #Y Button
6: 'LB', #Left Bumper
7: 'RB', #Right Bumper
10: 'SELECT', #Select Button
11: 'START', #Hamburger Button
13: 'LASB', #Left Analog Stick button
14: 'RASB' #Right Analog Stick button
}
self._setupReverseMaps()
class example(Gamepad):
# This class must have self.axisNames with a map
# of numbers to capitalised strings. Follow the
# conventions the other classes use for generic
# axes, make up your own names for axes unique
# to your device.
# self.buttonNames needs the same treatment.
# Use python Gamepad.py to get the event mappings.
fullName = 'Enter the human readable name of the device here'
def __init__(self, joystickNumber = 0):
Gamepad.__init__(self, joystickNumber)
self.axisNames = {
0: 'AXIS0',
1: 'AXIS1',
2: 'AXIS2'
}
self.buttonNames = {
0: 'BUTTON0',
1: 'BUTTON1',
2: 'BUTTON2'
}
self._setupReverseMaps()