-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGamepadInput.py
74 lines (56 loc) · 1.96 KB
/
GamepadInput.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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import import_ipynb
import Gamepad
from configure import ConnType,InputType
class GamepadInput():
def __init__(self):
self.key=None
print("Gamepad Chosen")
self.Gp=Gamepad.Gamepad()
if not Gamepad.available():
print("Connect your Gamepad")
while not Gamepad.available():
time.sleep(1)
print("Waiting for Connection!!!")
print("Gamepad Connected")
def readInput(self):
print("Press 'START' button to continue")
e,i,v=self.Gp.getNextEvent(self)
self.mapInput(e,i,v)
def getInput(self):
return self.key
def getConnType(self):
return self.type
def mapInput(self,event,index,value):
if value==0.0 or value=='False':
self.key = InputType.PAUSE
else:
if event=='AXIS':
if index==4 :
if value==1.0:
self.key = InputType.RIGHT
else:
self.key = InputType.LEFT
elif index==5:
if value==1:
self.key = InputType.BACKWARD
else:
self.key = InputType.FORWARD
elif event=='BUTTON':
if index==9:
self.key = InputType.START
elif index==0:
self.key = InputType.STOP
elif index==1:
self.key = InputType.LOWSPEED
elif index==2:
self.key = InputType.MEDIUMSPEED
elif index==3:
self.key = InputType.HIGHSPEED
elif index==8:
self.key = InputType.EXIT
else:
self.key = InputType.STOP
# In[ ]: