forked from woodenphone/lego_dimensions_protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblinkenlights.py
106 lines (89 loc) · 7.38 KB
/
blinkenlights.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
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
102
103
104
105
106
import usb.core
import usb.util
import time
def init_usb():
global dev
# 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()
# Initialise portal
print "Initialising portal"
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
return dev
def cycle_fade():
"""Cycle through fade colours"""
commands = [
[0x55, 0x14, 0xc6, 0x26, 0x01, 0x1e, 0x01, 0x00, 0x00, 0x18, 0x01, 0x1e, 0x01, 0x00, 0x00, 0x18, 0x01, 0x1e, 0x01, 0x00, 0x00, 0x18, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# All dark Blue
[0x55, 0x14, 0xc6, 0x27, 0x01, 0x1e, 0x01, 0xff, 0x00, 0x18, 0x01, 0x1e, 0x01, 0xff, 0x00, 0x18, 0x01, 0x1e, 0x01, 0xff, 0x00, 0x18, 0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# All pink
[0x55, 0x14, 0xc6, 0x28, 0x01, 0x1e, 0x01, 0xff, 0x00, 0x00, 0x01, 0x1e, 0x01, 0xff, 0x00, 0x00, 0x01, 0x1e, 0x01, 0xff, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# All red
[0x55, 0x14, 0xc6, 0x29, 0x01, 0x1e, 0x01, 0xff, 0x6e, 0x00, 0x01, 0x1e, 0x01, 0xff, 0x6e, 0x00, 0x01, 0x1e, 0x01, 0xff, 0x6e, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# All yellow
[0x55, 0x14, 0xc6, 0x2a, 0x01, 0x1e, 0x01, 0x00, 0x6e, 0x00, 0x01, 0x1e, 0x01, 0x00, 0x6e, 0x00, 0x01, 0x1e, 0x01, 0x00, 0x6e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# All green
[0x55, 0x14, 0xc6, 0x2b, 0x01, 0x1e, 0x01, 0x00, 0x6e, 0x18, 0x01, 0x1e, 0x01, 0x00, 0x6e, 0x18, 0x01, 0x1e, 0x01, 0x00, 0x6e, 0x18, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# All cyan
[0x55, 0x14, 0xc6, 0x2c, 0x01, 0x1e, 0x01, 0x00, 0x00, 0x18, 0x01, 0x1e, 0x01, 0x00, 0x00, 0x18, 0x01, 0x1e, 0x01, 0x00, 0x00, 0x18, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# All dark blue
]
print "cycle_fade"
for command in commands:
print command
dev.write(1, command)
time.sleep(2)
return
def cycle_immediate_all():
"""Cycle through immediate switch of all pad colours"""
commands = [
[0x55, 0x06, 0xc0, 0x02, 0x00, 0xff, 0x00, 0x00, 28, 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 red
[0x55, 0x06, 0xc0, 0x02, 0x00, 0x00, 0xff, 0x00, 28, 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 green (found via fuzzing)
[0x55, 0x06, 0xc0, 0x02, 0x00, 0x00, 0x00, 0xff, 28, 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 dark blue (found via fuzzing)
[0x55, 0x06, 0xc0, 0x02, 0x00, 0x00, 0x00, 0x00, 29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# Switch all pads off (Found by fuzzing)
]
print "cycle_immediate_all"
for command in commands:
print command
dev.write(1, command)
time.sleep(2)
return
def cycle_immediate_individual():
"""Cycle through immediate switch of all pad colours"""
commands = [
# Center
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:off center:red right:off
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0x00, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:off center:green right:off
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:off center:blue right:off
# Left
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:red center:off right:off
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:green center:off right:off
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00, 51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:blue center:off right: off
# Right
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:off center:off right:red
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0xff, 0x00, 51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:off center:off right:green
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff, 51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:off center:off right:blue
# Misc
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0xff, 0x6e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x18, 184, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:off, center:yellow, right:pink
[0x55, 0x0e, 0xc8, 0x06, 0x01, 0xff, 0x6e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 160, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# left:off, center:yellow, right:red
]
print "cycle_immediate_individual"
for command in commands:
print command
dev.write(1, command)
time.sleep(2)
return
def demo():
"""Show off cycle functions"""
print "Running demo"
while True:
cycle_fade()
dev.write(1, [0x55, 0x06, 0xc0, 0x02, 0x00, 0x00, 0x00, 0x00, 29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])# Switch all pads off (Found by fuzzing)
cycle_immediate_all()
dev.write(1, [0x55, 0x06, 0xc0, 0x02, 0x00, 0x00, 0x00, 0x00, 29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])# Switch all pads off (Found by fuzzing)
cycle_immediate_individual()
dev.write(1, [0x55, 0x06, 0xc0, 0x02, 0x00, 0x00, 0x00, 0x00, 29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])# Switch all pads off (Found by fuzzing)
def main():
init_usb()
demo()
return
if __name__ == '__main__':
main()