forked from eriklindernoren/PyTorch-YOLOv3
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathps4_send_jsevent.py
65 lines (56 loc) · 2.44 KB
/
ps4_send_jsevent.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
import zmq
from time import sleep
from struct import *
class JSEvent:
def __init__(self, buttonA=False, buttonB=False, buttonX=False, buttonY=False,
buttonLeft=False, buttonRight=False, buttonUp=False, buttonDown=False,
buttonL1=False, buttonR1=False, buttonL3=False, buttonR3=False,
buttonStart=False, buttonSelect=False, buttonGuide=False, #_dummy,
buttonL2=False, buttonR2=False,
axisLeftX=0, axisLeftY=0, axisRightX=0, axisRightY=0):
self.buttonA = buttonA
self.buttonB = buttonB # Circle
self.buttonX = buttonX # Square
self.buttonY = buttonY
self.buttonLeft = buttonLeft
self.buttonRight = buttonRight
self.buttonUp = buttonUp
self.buttonDown = buttonDown
self.buttonL1 = buttonL1
self.buttonR1 = buttonR1
self.buttonL3 = buttonL3
self.buttonR3 = buttonR3
self.buttonStart = buttonStart
self.buttonSelect = buttonSelect
self.buttonGuide = buttonGuide
self._dummy = False # padding
self.buttonL2 = buttonL2
self.buttonR2 = buttonR2
self.axisLeftX = axisLeftX
self.axisLeftY = axisLeftY
self.axisRightX = axisRightX
self.axisRightY = axisRightY
def tobytes(self):
return pack('??????????????????hhhh', self.buttonA, self.buttonB, self.buttonX, self.buttonY,
self.buttonLeft, self.buttonRight, self.buttonUp, self.buttonDown,
self.buttonL1, self.buttonR1, self.buttonL3, self.buttonR3,
self.buttonStart, self.buttonSelect, self.buttonGuide, self._dummy,
self.buttonL2, self.buttonR2, self.axisLeftX, self.axisLeftY, self.axisRightX, self.axisRightY)
def reset(self):
for prop in self.__dict__.keys():
if prop[:2] != '__':
if type(self.__dict__[prop]) == bool:
self.__dict__[prop] = False
else:
self.__dict__[prop] = 0
context = zmq.Context()
# Socket to talk to server
print("Connecting to hello world server…")
socket = context.socket(zmq.PAIR)
socket.connect("tcp://localhost:5556")
e = JSEvent()
e.buttonX = True
socket.send(e.tobytes())
sleep(0.1)
e.reset()
socket.send(e.tobytes())