Skip to content

Commit fed9ec0

Browse files
authored
Merge pull request adafruit#39 from rhooper/bugfixes
Various bugfixes and simplifications
2 parents 4eefc34 + aa0eef2 commit fed9ec0

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

adafruit_led_animation/animation/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ def __init__(self, pixel_object, speed, color, peers=None, paused=False, name=No
8181
def __str__(self):
8282
return "<%s: %s>" % (self.__class__.__name__, self.name)
8383

84-
def animate(self):
84+
def animate(self, show=True):
8585
"""
8686
Call animate() from your code's main loop. It will draw the animation draw() at intervals
8787
configured by the speed property (set from init).
8888
89+
:param bool show: Whether to automatically call show on the pixel object when an animation
90+
fires. Default True.
8991
:return: True if the animation draw cycle was triggered, otherwise False.
9092
"""
9193
if self._paused:
@@ -97,12 +99,14 @@ def animate(self):
9799

98100
# Draw related animations together
99101
for anim in self._peers:
102+
anim.draw_count += 1
100103
anim.draw()
101104
anim.after_draw()
102105
anim.draw_count += 1
103106

104-
for anim in self._peers:
105-
anim.show()
107+
if show:
108+
for anim in self._peers:
109+
anim.show()
106110

107111
# Note that the main animation cycle_complete flag is used, not the peer flag.
108112
for anim in self._peers:

adafruit_led_animation/group.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,20 @@ def add_cycle_complete_receiver(self, callback):
148148
"""
149149
self._also_notify.append(callback)
150150

151-
def animate(self):
151+
def animate(self, show=True):
152152
"""
153153
Call animate() from your code's main loop. It will draw all of the animations
154154
in the group.
155155
156156
:return: True if any animation draw cycle was triggered, otherwise False.
157157
"""
158158
if self._sync:
159-
return self._members[0].animate()
159+
result = self._members[0].animate(show=False)
160+
if result and show:
161+
self._members[0].show()
162+
return result
160163

161-
return any([item.animate() for item in self._members])
164+
return any([item.animate(show) for item in self._members])
162165

163166
@property
164167
def color(self):

adafruit_led_animation/sequence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def random(self):
204204
"""
205205
self.activate(random.randint(0, len(self._members) - 1))
206206

207-
def animate(self):
207+
def animate(self, show=True):
208208
"""
209209
Call animate() from your code's main loop. It will draw the current animation
210210
or go to the next animation based on the advance_interval if set.
@@ -213,7 +213,7 @@ def animate(self):
213213
"""
214214
if not self._paused and self._advance_interval:
215215
self._auto_advance()
216-
return self.current_animation.animate()
216+
return self.current_animation.animate(show)
217217

218218
@property
219219
def current_animation(self):

0 commit comments

Comments
 (0)