Skip to content

Blink color fix #54

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 2 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions adafruit_led_animation/animation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, pixel_object, speed, color, peers=None, paused=False, name=No
self._time_left_at_pause = 0
self._also_notify = []
self.speed = speed # sets _speed_ns
self.color = color # Triggers _recompute_color
self.color = color # Triggers _set_color
self.name = name
self.cycle_complete = False
self.notify_cycles = 1
Expand Down Expand Up @@ -187,8 +187,14 @@ def color(self, color):
return
if isinstance(color, int):
color = (color >> 16 & 0xFF, color >> 8 & 0xFF, color & 0xFF)
self._set_color(color)

def _set_color(self, color):
"""
Called after the color is changed, which includes at initialization.
Override as needed.
"""
self._color = color
self._recompute_color(color)

@property
def speed(self):
Expand All @@ -201,12 +207,6 @@ def speed(self):
def speed(self, seconds):
self._speed_ns = int(seconds * NANOS_PER_SECOND)

def _recompute_color(self, color):
"""
Called if the color is changed, which includes at initialization.
Override as needed.
"""

def on_cycle_complete(self):
"""
Called by some animations when they complete an animation cycle.
Expand Down
2 changes: 1 addition & 1 deletion adafruit_led_animation/animation/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ class Blink(ColorCycle):
def __init__(self, pixel_object, speed, color, name=None):
super().__init__(pixel_object, speed, [color, BLACK], name=name)

def _recompute_color(self, color):
def _set_color(self, color):
self.colors = [color, BLACK]
5 changes: 1 addition & 4 deletions adafruit_led_animation/animation/comet.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ def __init__(

on_cycle_complete_supported = True

def _recompute_color(self, color):
self._comet_recompute_color(color)

def _comet_recompute_color(self, color):
def _set_color(self, color):
self._comet_colors = [BLACK]
for n in range(self._tail_length):
self._comet_colors.append(
Expand Down
2 changes: 1 addition & 1 deletion adafruit_led_animation/animation/rainbowcomet.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(
self._colorwheel_offset = colorwheel_offset
super().__init__(pixel_object, speed, 0, tail_length, reverse, bounce, name)

def _comet_recompute_color(self, color):
def _set_color(self, color):
self._comet_colors = [BLACK]
for n in range(self._tail_length):
invert = self._tail_length - n - 1
Expand Down
2 changes: 1 addition & 1 deletion adafruit_led_animation/animation/solid.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ class Solid(ColorCycle):
def __init__(self, pixel_object, color, name=None):
super().__init__(pixel_object, speed=1, colors=[color], name=name)

def _recompute_color(self, color):
def _set_color(self, color):
self.colors = [color]
2 changes: 1 addition & 1 deletion adafruit_led_animation/animation/sparkle.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, pixel_object, speed, color, num_sparkles=1, name=None):
self._pixels = []
super().__init__(pixel_object, speed, color, name=name)

def _recompute_color(self, color):
def _set_color(self, color):
half_color = tuple(color[rgb] // 4 for rgb in range(len(color)))
dim_color = tuple(color[rgb] // 10 for rgb in range(len(color)))
for pixel in range(len(self.pixel_object)):
Expand Down
3 changes: 3 additions & 0 deletions adafruit_led_animation/animation/sparklepulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def __init__(
)
self._generator = pulse_generator(self._period, self, dotstar_pwm=dotstar)

def _set_color(self, color):
self._color = color

def draw(self):
self._sparkle_color = next(self._generator)
super().draw()
Expand Down