-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py.save
34 lines (30 loc) · 1.28 KB
/
controller.py.save
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
from evdev import InputDevice, categorize, ecodes, KeyEvent
import time
class Joystick:
def __init__(self):
self.joystickDirectionManager()
def joystickDirectionManager(self):
gamepad = InputDevice("/dev/input/event0")
#print(gamepad.capabilities())
print(gamepad)
valuesDirection = 0
constantDirection = 255/80
for event in gamepad.read_loop():
if event.type == ecodes.EV_ABS and event.code == 00:
absevent = categorize(event)
if(valuesDirection != int(event.value/constantDirection)):
valuesDirection = int(event.value/constantDirection)
print(valuesDirection-40)
if event.type == ecodes.EV_KEY:
keyevent = categorize(event)
if keyevent.keystate == KeyEvent.key_down:
if keyevent.keycode == 'BTN_BASE2':
print ("Left")
elif keyevent.keycode == 'BTN_PINKIE':
print ("Right")
elif keyevent.keycode == 'BTN_TOP2':
print ("Forward")
elif keyevent.keycode == 'BTN_BASE':
print ("Backward")
control = Joystick()
#control.joystickManager()