Skip to content

Commit afa32a6

Browse files
committed
fix broken parse_pattern calls
1 parent 17eec90 commit afa32a6

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Attempting to select a color outside the plausible range will generate an Invali
129129

130130
The blink(1) device has a 16-line non-volatile color pattern memory.
131131
This color pattern plays automatically if power is applied but not connected to a computer.
132-
you can also trigger this pattern (or sub-patterns) over USB,
132+
You can also trigger this pattern (or sub-patterns) over USB,
133133
leaving your application free to do other things besides blink lights.
134134

135135
Each line in the color pattern consists of an R,G,B triplet and a fade time to reach that color.
@@ -157,6 +157,17 @@ To save the pattern to non-volatile memory (overwriting the factory pattern):
157157
blink1.savePattern()
158158
```
159159

160+
To quickly play a pattern in Blink1Control-style string format:
161+
```
162+
# play purple on LED1 in 300ms, green on LED2 in 100ms, then swap, for 10 times
163+
pattern_str = '10, #ff00ff,0.3,1, #00ff00,0.1,2, #ff00ff,0.3,2, #00ff00,0.1,1'
164+
blink1.play_pattern(pattern_str)
165+
# wait 5 seconds while the pattern plays on the blink1
166+
# (or go do something more useful)
167+
time.sleep(5.0)
168+
# flash red-off 5 times fast on all LEDs
169+
blink1.play_pattern('5, #FF0000,0.2,0,#000000,0.2,0')
170+
160171
### Servertickle watchdog
161172
blink(1) also has a "watchdog" of sorts called "servertickle".
162173
When enabled, you must periodically send it to the blink(1) or it will

blink1/blink1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def play_pattern(self,pattern_str, onDevice=True):
316316
return self.playPatternLocal(pattern_str)
317317

318318
# else, play it in the blink(1)
319-
(num_repeats,colorlist) = self.parsePattern(pattern_str)
319+
(num_repeats,colorlist) = self.parse_pattern(pattern_str)
320320
pattlen = len(colorlist)
321321
if( pattlen < 32 ): # extend out pattern to fill
322322
for i in range(0,32-pattlen):
@@ -336,7 +336,7 @@ def play_pattern_local(self,pattern_str):
336336
:param pattern_str: The Blink1Control-style pattern string to play
337337
:raises: Blink1ConnectionFailed: if blink(1) is disconnected
338338
"""
339-
(num_repeats,colorlist) = self.parsePattern(pattern_str)
339+
(num_repeats,colorlist) = self.parse_pattern(pattern_str)
340340
if num_repeats == 0: num_repeats = -1;
341341
while( num_repeats ):
342342
num_repeats = num_repeats - 1
@@ -345,13 +345,13 @@ def play_pattern_local(self,pattern_str):
345345
time.sleep(c['time'])
346346

347347
@staticmethod
348-
def parsePattern(pattern_str):
348+
def parse_pattern(pattern_str):
349349
""" Parse a Blink1Control pattern string to a list of pattern lines
350350
e.g. of the form '10,#ff00ff,0.1,0,#00ff00,0.1,0'
351351
:param pattern_str: The Blink1Control-style pattern string to parse
352352
:returns: an list of dicts of the parsed out pieces
353353
"""
354-
pattparts = pattstr.replace(' ','').split(',')
354+
pattparts = pattern_str.replace(' ','').split(',')
355355
num_repeats = int(pattparts[0]) # FIXME
356356
pattparts = pattparts[1:]
357357

blink1_demo/demo_pattern3.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
pattern_strs = [
1010
'3, #ff00ff,0.3,1, #00ff00,0.1,2,#ff00ff,0.3,2,#00ff00,0.1,1,#000000,0.5,0',
11+
'5, #FF0000,0.2,0,#000000,0.2,0',
1112
' 10, #ff00ff,0.3,1, #00ff00,0.1,2, #ff00ff,0.3,2, #00ff00,0.1,1' ,
1213
' 10, #ff00ff,0.3,1, #00ff00,0.1,2 ',
1314
' 7, #ff00ff,0.3,1, #00ff00,0.1,2, #ff3333 ',
@@ -16,9 +17,9 @@
1617
' 0, #ff00ff,0.3',
1718
]
1819

19-
patt_str = pattern_strs[0]
20+
patt_str = pattern_strs[1]
2021

21-
(num_repeats,pattern_list) = Blink1.parsePattern(patt_str)
22+
(num_repeats,pattern_list) = Blink1.parse_pattern(patt_str)
2223
print('num_repeats: ', num_repeats)
2324
print('pattern_list: ', pattern_list)
2425

@@ -32,7 +33,7 @@
3233
play_on_blink1 = True
3334
#play_on_blink1 = False
3435

35-
if( play_on_blink1 ):
36+
if( play_on_blink1 ):
3637
print("playing on blink1 device (thus not blocking)");
3738
blink1.play_pattern( patt_str )
3839
print("sleeping for 10 secs...")

0 commit comments

Comments
 (0)