-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontroller_hid_test.py
More file actions
101 lines (87 loc) · 2.66 KB
/
Copy pathcontroller_hid_test.py
File metadata and controls
101 lines (87 loc) · 2.66 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import hid
import time
import sys
import matplotlib.pyplot as plt
def get_usb_devices():
for d in hid.enumerate():
keys = list(d.keys())
keys.sort()
for key in keys:
print("%s : %s" % (key, d[key]))
print()
h = hid.device()
h.open(0x054C,0x09CC)
h.set_nonblocking(1)
_f = [0xa2, 0x11, 0xc0, 0x20, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x43, 0x00, 0x4d, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x8e, 0x94, 0xdd]
_f1 = [0x11, 0x80, 0x0F, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x43, 0x00, 0x4d, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x8e, 0x94, 0xdd]
#_f[4] = 0xf3
#_f[9] = 100
#_f[10] = 100
#_f[11] = 100
# Set the device into detailed mode 0x02
#print h.get_feature_report(11, 100)
h.get_feature_report(2, 100)
# print h.send_feature_report(_f)
# Protoocol 0x11
send = []
for i in range(79):
send.append(0x00)
send[0] = 0xa2
send[1] = 0x11
send[2] = 0xc0
send[3] = 0x20
send[4] = 0xf3 # 240 disable motor, 243 enable motor
send[5] = 0x04
send[6] = 0x00
send[7] = 100 # motor
send[8] = 100 # motor
send[9] = 150 # r
send[10] = 150 # g
send[11] = 150 # b
send[22] = 0x43
send[23] = 0x43
send[24] = 0x00
send[25] = 0x4d
send[26] = 0x85
send[75] = 0xd8
send[76] = 0x8e
send[77] = 0x94
send[78] = 0xdd
string = ""
for i in send:
string += str(hex(i)) + ", "
if True:
a = int(sys.argv[1])
b = int(sys.argv[2])
max_v = 100
n = 0
plt.axis([0, max_v, 0, 255])
plt.ion()
plt.show()
x = [0]
y = [0]
x2 = [0]
y2 = [0]
line, = plt.plot(y)
line2, = plt.plot(y2)
while True:
data = h.read(128)
print data
print str(data[a-3]) + " : " + str(data[b-3])
# PLOTTING
if n % max_v == 0:
x = [0]
x2 = [0]
y = [0]
y2 = [0]
x.append(n % max_v)
y.append(data[a-3])
y2.append(data[b-3])
line.set_xdata(x)
line.set_ydata(y)
line2.set_ydata(y2)
line2.set_xdata(x)
# plt.plot(n_last % max_v, value_last,n % max_v, data[a-3], 'b-')
plt.pause(0.01)
plt.draw()
n += 1