Skip to content

Commit b5e75fa

Browse files
authored
Merge pull request #54 from rhooper/blink-color-fix
Blink color fix
2 parents 3dbe521 + beaa41f commit b5e75fa

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

adafruit_led_animation/animation/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, pixel_object, speed, color, peers=None, paused=False, name=No
6868
self._time_left_at_pause = 0
6969
self._also_notify = []
7070
self.speed = speed # sets _speed_ns
71-
self.color = color # Triggers _recompute_color
71+
self.color = color # Triggers _set_color
7272
self.name = name
7373
self.cycle_complete = False
7474
self.notify_cycles = 1
@@ -187,8 +187,14 @@ def color(self, color):
187187
return
188188
if isinstance(color, int):
189189
color = (color >> 16 & 0xFF, color >> 8 & 0xFF, color & 0xFF)
190+
self._set_color(color)
191+
192+
def _set_color(self, color):
193+
"""
194+
Called after the color is changed, which includes at initialization.
195+
Override as needed.
196+
"""
190197
self._color = color
191-
self._recompute_color(color)
192198

193199
@property
194200
def speed(self):
@@ -201,12 +207,6 @@ def speed(self):
201207
def speed(self, seconds):
202208
self._speed_ns = int(seconds * NANOS_PER_SECOND)
203209

204-
def _recompute_color(self, color):
205-
"""
206-
Called if the color is changed, which includes at initialization.
207-
Override as needed.
208-
"""
209-
210210
def on_cycle_complete(self):
211211
"""
212212
Called by some animations when they complete an animation cycle.

adafruit_led_animation/animation/blink.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ class Blink(ColorCycle):
6060
def __init__(self, pixel_object, speed, color, name=None):
6161
super().__init__(pixel_object, speed, [color, BLACK], name=name)
6262

63-
def _recompute_color(self, color):
63+
def _set_color(self, color):
6464
self.colors = [color, BLACK]

adafruit_led_animation/animation/comet.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ def __init__(
9292

9393
on_cycle_complete_supported = True
9494

95-
def _recompute_color(self, color):
96-
self._comet_recompute_color(color)
97-
98-
def _comet_recompute_color(self, color):
95+
def _set_color(self, color):
9996
self._comet_colors = [BLACK]
10097
for n in range(self._tail_length):
10198
self._comet_colors.append(

adafruit_led_animation/animation/rainbowcomet.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(
8282
self._colorwheel_offset = colorwheel_offset
8383
super().__init__(pixel_object, speed, 0, tail_length, reverse, bounce, name)
8484

85-
def _comet_recompute_color(self, color):
85+
def _set_color(self, color):
8686
self._comet_colors = [BLACK]
8787
for n in range(self._tail_length):
8888
invert = self._tail_length - n - 1

adafruit_led_animation/animation/solid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ class Solid(ColorCycle):
5858
def __init__(self, pixel_object, color, name=None):
5959
super().__init__(pixel_object, speed=1, colors=[color], name=name)
6060

61-
def _recompute_color(self, color):
61+
def _set_color(self, color):
6262
self.colors = [color]

adafruit_led_animation/animation/sparkle.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(self, pixel_object, speed, color, num_sparkles=1, name=None):
7171
self._pixels = []
7272
super().__init__(pixel_object, speed, color, name=name)
7373

74-
def _recompute_color(self, color):
74+
def _set_color(self, color):
7575
half_color = tuple(color[rgb] // 4 for rgb in range(len(color)))
7676
dim_color = tuple(color[rgb] // 10 for rgb in range(len(color)))
7777
for pixel in range(len(self.pixel_object)):

adafruit_led_animation/animation/sparklepulse.py

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def __init__(
8080
)
8181
self._generator = pulse_generator(self._period, self, dotstar_pwm=dotstar)
8282

83+
def _set_color(self, color):
84+
self._color = color
85+
8386
def draw(self):
8487
self._sparkle_color = next(self._generator)
8588
super().draw()

0 commit comments

Comments
 (0)