]> git.zerfleddert.de Git - fnordlicht-mini/blob - firmware/tests/lib/fnordlicht.rb
rule to create eeprom binaries
[fnordlicht-mini] / firmware / tests / lib / fnordlicht.rb
1 module Fnordlicht
2 def sync(addr = 0)
3 1.upto(15) do
4 $dev.write "\e"
5 end
6 $dev.write addr.chr
7 $dev.flush
8 end
9
10 def fade_rgb(addr, r, g, b, step, delay)
11 $dev.write addr.chr
12 $dev.write "\x01"
13 $dev.write step.chr
14 $dev.write delay.chr
15 $dev.write r.chr
16 $dev.write g.chr
17 $dev.write b.chr
18 $dev.write "\x00\x00\x00\x00\x00"
19 $dev.write "\x00\x00\x00"
20 $dev.flush
21 end
22
23 def fade_hsv(addr, h, s, v, step, delay)
24 $dev.write addr.chr
25 $dev.write "\x02"
26 $dev.write step.chr
27 $dev.write delay.chr
28 $dev.write [h].pack('v')
29 $dev.write s.chr
30 $dev.write v.chr
31 $dev.write "\x00\x00\x00\x00\x00"
32 $dev.write "\x00\x00"
33 $dev.flush
34 end
35
36 def save_rgb(addr, slot, r, g, b, step, delay, pause)
37 $dev.write addr.chr
38 $dev.write "\x03"
39 $dev.write slot.chr
40 $dev.write step.chr
41 $dev.write delay.chr
42 $dev.write [pause].pack('S')
43 $dev.write r.chr
44 $dev.write g.chr
45 $dev.write b.chr
46 $dev.write "\x00\x00\x00\x00\x00"
47 $dev.flush
48 end
49
50 def save_hsv(addr, slot, h, s, v, step, delay, pause)
51 $dev.write addr.chr
52 $dev.write "\x04"
53 $dev.write slot.chr
54 $dev.write step.chr
55 $dev.write delay.chr
56 $dev.write [pause].pack('S')
57 $dev.write [h].pack('v')
58 $dev.write s.chr
59 $dev.write v.chr
60 $dev.write "\x00\x00\x00\x00"
61 $dev.flush
62 end
63
64 def save_current(addr, slot, step, delay, pause)
65 $dev.write addr.chr
66 $dev.write "\x05"
67 $dev.write slot.chr
68 $dev.write step.chr
69 $dev.write delay.chr
70 $dev.write [pause].pack('S')
71 $dev.write "\x00\x00\x00\x00"
72 $dev.write "\x00\x00\x00\x00"
73 $dev.flush
74 end
75
76 def config_offsets(addr, step, delay, h, s, v)
77 $dev.write addr.chr
78 $dev.write "\x06"
79 $dev.write [step].pack('c')
80 $dev.write [delay].pack('c')
81 $dev.write [h].pack('v')
82 $dev.write s.chr
83 $dev.write v.chr
84 $dev.write "\x00\x00\x00\x00\x00\x00\x00"
85 $dev.flush
86 end
87
88 def start_program(addr, program, params)
89 $dev.write addr.chr
90 $dev.write "\x07"
91 $dev.write program.chr
92 rest = 12-params.length
93 puts "rest: %u" % rest if $verbose
94 params.each do |p|
95 $dev.write(p.chr)
96 end
97 1.upto(rest) do
98 $dev.write("\x00")
99 end
100 $dev.flush
101 end
102
103 def stop(addr, fading = 1)
104 $dev.write addr.chr
105 $dev.write "\x08"
106 $dev.write fading.chr
107 $dev.write "\x00\x00\x00\x00"
108 $dev.write "\x00\x00\x00\x00\x00"
109 $dev.write "\x00\x00\x00"
110 $dev.flush
111 end
112
113 def modify_current(addr, step, delay, r, g, b, h, s, v)
114 $dev.write addr.chr
115 $dev.write "\x09"
116 $dev.write step.chr
117 $dev.write delay.chr
118 $dev.write [r].pack('c')
119 $dev.write [g].pack('c')
120 $dev.write [b].pack('c')
121 $dev.write [h].pack('v')
122 $dev.write [s].pack('c')
123 $dev.write [v].pack('c')
124 $dev.write "\x00\x00\x00\x00"
125 $dev.flush
126 end
127
128 def pull_int(addr, delay)
129 $dev.write addr.chr
130 $dev.write "\x0A"
131 $dev.write delay.chr
132
133 $dev.write "\x00\x00"
134 $dev.write "\x00\x00\x00\x00\x00"
135 $dev.write "\x00\x00\x00\x00\x00"
136 $dev.flush
137 end
138
139 def config_startup_nothing(addr)
140 mode = 0 # do nothing
141
142 $dev.write addr.chr
143 $dev.write "\x0B"
144 $dev.write mode.chr
145
146 $dev.write "\x00\x00"
147 $dev.write "\x00\x00\x00\x00\x00"
148 $dev.write "\x00\x00\x00\x00\x00"
149 $dev.flush
150 end
151
152 def config_startup_program(addr, program, params)
153 mode = 1 # start program
154
155 $dev.write addr.chr
156 $dev.write "\x0B"
157 $dev.write mode.chr
158 $dev.write program.chr
159
160 rest = 11-params.length
161 puts "rest: %u" % rest if $verbose
162 params.each do |p|
163 $dev.write(p.chr)
164 end
165 1.upto(rest) do
166 $dev.write("\x00")
167 end
168 $dev.flush
169 end
170
171 def powerdown(addr)
172 $dev.write(addr.chr)
173 $dev.write("\x0C")
174 $dev.write("\x00"*13)
175 $dev.flush
176 end
177
178 # secondary functions
179 def fade_updown_rgb(addr, r, g, b, step, delay, sleep_time)
180 fade_rgb(addr, r, g, b, step, delay)
181 sleep(sleep_time)
182 fade_rgb(addr, 0, 0, 0, step, delay)
183 sleep(sleep_time)
184 end
185
186 def fade_updown_hsv(addr, h, s, v, step, delay, sleep_time)
187 fade_hsv(addr, h, s, v, step, delay)
188 sleep(sleep_time)
189 fade_hsv(addr, h, s, 0, step, delay)
190 sleep(sleep_time)
191 end
192
193 # bootloader functions
194 def start_bootloader(addr)
195 $dev.write(addr.chr)
196 $dev.write("\x80")
197 $dev.write("\x6b\x56\x27\xfc")
198 $dev.write("\x00\x00\x00\x00\x00\x00\x00\x00\x00")
199 $dev.flush
200 end
201
202 def boot_config(addr, start_addr)
203 $dev.write(addr.chr)
204 $dev.write("\x81")
205 $dev.write [start_addr].pack('v')
206 $dev.write("\x00"*11)
207 $dev.flush
208 end
209
210 def boot_init(addr)
211 $dev.write(addr.chr)
212 $dev.write("\x82")
213 $dev.write("\xff" * 13)
214 $dev.flush
215 end
216
217 def boot_data(addr, data)
218 $dev.write(addr.chr)
219 $dev.write("\x83")
220
221 # just write the first 13 bytes
222 data = data[0..12]
223 $dev.write(data)
224
225 $dev.write("\xff" * (13-data.length))
226 $dev.flush
227 end
228
229 def boot_crc_check(addr, len, checksum, delay)
230 $dev.write(addr.chr)
231 $dev.write("\x84")
232 $dev.write [len].pack('v')
233 $dev.write [checksum].pack('v')
234 $dev.write delay.chr
235 $dev.write("\x00"*8)
236 $dev.flush
237 end
238
239 def boot_crc_flash(addr, start, len, checksum, delay)
240 $dev.write(addr.chr)
241 $dev.write("\x85")
242 $dev.write [start].pack('v')
243 $dev.write [len].pack('v')
244 $dev.write [checksum].pack('v')
245 $dev.write delay.chr
246 $dev.write("\x00"*6)
247 $dev.flush
248 end
249
250 def boot_flash(addr)
251 $dev.write(addr.chr)
252 $dev.write("\x86")
253 $dev.write("\x00"*13)
254 $dev.flush
255 end
256
257 def boot_enter_application(addr)
258 $dev.write(addr.chr)
259 $dev.write("\x87")
260 $dev.write("\x00"*13)
261 $dev.flush
262 end
263 end
Impressum, Datenschutz