-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControlPs3.py
executable file
·35 lines (34 loc) · 1 KB
/
ControlPs3.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
from controllerF import Joystick
from api import Api
import time
#00 direccion 49 velovidad analoga, 294 arriba, 292 abajo
def callback(event):
global reversa
print(event)
if (event.code == 3 or event.code == 0) and event.type == 3:
direccionF = int((event.value + 32768)/256)
print("DireccionC2 "+ str(direccionF))
api.POSTDir(int(direccionF/(255/80))+50)
elif event.code == 5 or event.code == 2:
if event.code == 5 and reversa:
reversa = False
api.POSTSentido()
if event.code == 2 and not reversa:
reversa = True
api.POSTSentido()
api.POSTVel(int(event.value))
#time.sleep(1)
#print("Velocidad")
elif event.code == 292 and event.value == 1:
api.POSTSentido()
while True:
try:
api = Api("carrito")
reversa = False
joystick = Joystick("/dev/input/event0",callback)
except:
pass
else:
break
print("Reiniciando")
time.sleep(5)