forked from woodenphone/lego_dimensions_protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyusb_tutorial.py
36 lines (28 loc) · 2.77 KB
/
pyusb_tutorial.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
import usb.core
import usb.util
import time
# find our device
dev = usb.core.find(idVendor=0x0e6f)# 0x0e6f Logic3 (made lego dimensions portal hardware)
# was it found?
if dev is None:
raise ValueError('Device not found')
# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()
#print dev.write(1, [85, 20, 198, 9, 1, 30, 1, 255, 0, 24, 1, 30, 1, 255, 0, 24, 1, 30, 1, 255, 0, 24, 221, 0, 0, 0, 0, 0, 0, 0, 0, 0])#line_number: 265
print dev.write(1, [0x55, 0x0f, 0xb0, 0x01, 0x28, 0x63, 0x29, 0x20, 0x4c, 0x45, 0x47, 0x4f, 0x20, 0x32, 0x30, 0x31, 0x34, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])# Startup
time.sleep(1)
print dev.write(1, [0x55, 0x14, 0xc6, 0x06, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])# Fade to green
time.sleep(1)
print dev.write(1, [0x55, 0x06, 0xc0, 0x02, 0x00, 0xff, 0xff, 0xff, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])# Switch to blue
time.sleep(1)
print dev.write(1, [0x55, 0x14, 0xc6, 0x06, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])# Fade to green
#print dev.write(1, [0x55, 0x0a, 0xb1, 0x03, 0x17, 0x4c, 0x4c, 0x9f, 0x82, 0xde, 0xfc, 0xe2, 0x9f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
#print dev.write(1, [0x55, 0x0a, 0xb3, 0x04, 0x13, 0x95, 0x7b, 0xe0, 0x4f, 0x36, 0xd8, 0xbb, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
#print dev.write(1, [0x55, 0x14, 0xc6, 0x05, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
#print dev.write(1, [0x55, 0x14, 0xc6, 0x06, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
##while True:
## time.sleep(1)
## print dev.write(1, [0x55, 0x06, 0xc0, 0x02, 0x00, 0xff, 0xff, 0xff, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])# Switch to blue
## time.sleep(1)
## print dev.write(1, [0x55, 0x14, 0xc6, 0x06, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x01, 0x0f, 0x01, 0x99, 0x42, 0x0e, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])# Fade to green