forked from unbit/foohid-py
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_joypad.py
47 lines (44 loc) · 945 Bytes
/
test_joypad.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
import foohid
import struct
import random
import time
joypad = (
0x05, 0x01,
0x09, 0x05,
0xa1, 0x01,
0xa1, 0x00,
0x05, 0x09,
0x19, 0x01,
0x29, 0x10,
0x15, 0x00,
0x25, 0x01,
0x95, 0x10,
0x75, 0x01,
0x81, 0x02,
0x05, 0x01,
0x09, 0x30,
0x09, 0x31,
0x09, 0x32,
0x09, 0x33,
0x15, 0x81,
0x25, 0x7f,
0x75, 0x08,
0x95, 0x04,
0x81, 0x02,
0xc0,
0xc0)
try:
foohid.destroy("FooHID simple joypad")
except:
pass
foohid.create("FooHID simple joypad", struct.pack('{0}B'.format(len(joypad)), *joypad), "SN 123", 2, 3)
try:
while True:
x = random.randrange(0,255)
y = random.randrange(0,255)
z = random.randrange(0,255)
rx = random.randrange(0,255)
foohid.send("FooHID simple joypad", struct.pack('H4B', 0, x, y, z, rx))
time.sleep(1)
except KeyboardInterrupt:
foohid.destroy("FooHID simple joypad")