Skip to content

Various bugfixes and simplifications #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions adafruit_led_animation/animation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ def __init__(self, pixel_object, speed, color, peers=None, paused=False, name=No
def __str__(self):
return "<%s: %s>" % (self.__class__.__name__, self.name)

def animate(self):
def animate(self, show=True):
"""
Call animate() from your code's main loop. It will draw the animation draw() at intervals
configured by the speed property (set from init).

:param bool show: Whether to automatically call show on the pixel object when an animation
fires. Default True.
:return: True if the animation draw cycle was triggered, otherwise False.
"""
if self._paused:
Expand All @@ -97,11 +99,13 @@ def animate(self):

# Draw related animations together
for anim in self._peers:
anim.draw_count += 1
anim.draw()
anim.after_draw()

for anim in self._peers:
anim.show()
if show:
for anim in self._peers:
anim.show()

# Note that the main animation cycle_complete flag is used, not the peer flag.
for anim in self._peers:
Expand Down
Empty file.
9 changes: 6 additions & 3 deletions adafruit_led_animation/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,20 @@ def add_cycle_complete_receiver(self, callback):
"""
self._also_notify.append(callback)

def animate(self):
def animate(self, show=True):
"""
Call animate() from your code's main loop. It will draw all of the animations
in the group.

:return: True if any animation draw cycle was triggered, otherwise False.
"""
if self._sync:
return self._members[0].animate()
result = self._members[0].animate(show=False)
if result and show:
self._members[0].show()
return result

return any([item.animate() for item in self._members])
return any([item.animate(show) for item in self._members])

@property
def color(self):
Expand Down
4 changes: 2 additions & 2 deletions adafruit_led_animation/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __setitem__(self, index, val):
else:
self._set_pixels(index, val)

if not self._pixels.auto_write:
if self.auto_write:
self.show()

def __getitem__(self, index):
Expand Down Expand Up @@ -310,7 +310,7 @@ def __setitem__(self, index, val):
else:
self._pixels[index + self._start] = val

if not self._pixels.auto_write:
if self.auto_write:
self.show()

def __getitem__(self, index):
Expand Down
4 changes: 2 additions & 2 deletions adafruit_led_animation/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def random(self):
"""
self.activate(random.randint(0, len(self._members) - 1))

def animate(self):
def animate(self, show=True):
"""
Call animate() from your code's main loop. It will draw the current animation
or go to the next animation based on the advance_interval if set.
Expand All @@ -214,7 +214,7 @@ def animate(self):
"""
if not self._paused and self._advance_interval:
self._auto_advance()
return self.current_animation.animate()
return self.current_animation.animate(show)

@property
def current_animation(self):
Expand Down