Skip to content

Commit 64b7bed

Browse files
authored
LED animation fix duration None (#703)
1 parent 8b43d6f commit 64b7bed

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
python-ev3dev2 (2.1.0) UNRELEASED; urgency=medium
22

33
[Matěj Volf]
4+
* LED animation fix duration None
45
* Add rest notes to sound.Sound.play_song()
56

67
[Kaelin Laundry]

ev3dev2/led.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ def all_off(self):
354354
if not self.leds:
355355
return
356356

357+
self.animate_stop()
358+
357359
for led in self.leds.values():
358360
led.brightness = 0
359361

@@ -401,7 +403,7 @@ def animate_police_lights(self, color1, color2, group1='LEFT', group2='RIGHT', s
401403
def _animate_police_lights():
402404
self.all_off()
403405
even = True
404-
duration_ms = duration * 1000
406+
duration_ms = duration * 1000 if duration is not None else None
405407
stopwatch = StopWatch()
406408
stopwatch.start()
407409

@@ -413,7 +415,7 @@ def _animate_police_lights():
413415
self.set_color(group1, color2)
414416
self.set_color(group2, color1)
415417

416-
if self.animate_thread_stop or stopwatch.value_ms >= duration_ms:
418+
if self.animate_thread_stop or stopwatch.is_elapsed_ms(duration_ms):
417419
break
418420

419421
even = not even
@@ -446,7 +448,7 @@ def animate_flash(self, color, groups=('LEFT', 'RIGHT'), sleeptime=0.5, duration
446448

447449
def _animate_flash():
448450
even = True
449-
duration_ms = duration * 1000
451+
duration_ms = duration * 1000 if duration is not None else None
450452
stopwatch = StopWatch()
451453
stopwatch.start()
452454

@@ -457,7 +459,7 @@ def _animate_flash():
457459
else:
458460
self.all_off()
459461

460-
if self.animate_thread_stop or stopwatch.value_ms >= duration_ms:
462+
if self.animate_thread_stop or stopwatch.is_elapsed_ms(duration_ms):
461463
break
462464

463465
even = not even
@@ -491,7 +493,7 @@ def animate_cycle(self, colors, groups=('LEFT', 'RIGHT'), sleeptime=0.5, duratio
491493
def _animate_cycle():
492494
index = 0
493495
max_index = len(colors)
494-
duration_ms = duration * 1000
496+
duration_ms = duration * 1000 if duration is not None else None
495497
stopwatch = StopWatch()
496498
stopwatch.start()
497499

@@ -504,7 +506,7 @@ def _animate_cycle():
504506
if index == max_index:
505507
index = 0
506508

507-
if self.animate_thread_stop or stopwatch.value_ms >= duration_ms:
509+
if self.animate_thread_stop or stopwatch.is_elapsed_ms(duration_ms):
508510
break
509511

510512
sleep(sleeptime)
@@ -545,7 +547,7 @@ def _animate_rainbow():
545547
MIN_VALUE = 0
546548
MAX_VALUE = 1
547549
self.all_off()
548-
duration_ms = duration * 1000
550+
duration_ms = duration * 1000 if duration is not None else None
549551
stopwatch = StopWatch()
550552
stopwatch.start()
551553

@@ -580,7 +582,7 @@ def _animate_rainbow():
580582
elif state == 3 and right_value == MIN_VALUE:
581583
state = 0
582584

583-
if self.animate_thread_stop or stopwatch.value_ms >= duration_ms:
585+
if self.animate_thread_stop or stopwatch.is_elapsed_ms(duration_ms):
584586
break
585587

586588
sleep(sleeptime)

0 commit comments

Comments
 (0)