Skip to content

Commit

Permalink
Merge pull request #98 from cxrodgers/bugfix__set_led
Browse files Browse the repository at this point in the history
fix bug where LED_RGB.set ignored an input of zero
  • Loading branch information
sneakers-the-rat authored May 30, 2021
2 parents dc9833a + 11c36f3 commit c08d3ed
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions autopilot/hardware/gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,24 +1073,29 @@ def set(self, value=None, r=None, g=None, b=None):
g (float, int): value to set green channel
b (float, int): value to set blue channel
"""
# Stop any running scripts (like blinks)
self.stop_script()

# if we were given a value, ignore other arguments
# Set either by `value` or by individual r, g, b
if value is not None:
# Set by `value`
if isinstance(value, int) or isinstance(value, float):
# Apply `value` to each channel
for channel in self.channels.values():
channel.set(value)
elif len(value) == 3:
# Assume value is a tuple of r, g, b
for channel_key, color_val in zip(('r','g','b'), value):
self.channels[channel_key].set(color_val)
else:
raise ValueError('Value must either be a single value or a tuple of (r,g,b)')
else:
if r:
# Set by individually specified r, g, b arguments
if r is not None:
self.channels['r'].set(r)
if g:
if g is not None:
self.channels['g'].set(g)
if b:
if b is not None:
self.channels['b'].set(b)

def toggle(self):
Expand All @@ -1099,7 +1104,6 @@ def toggle(self):
def pulse(self, duration=None):
self.logger.warning('Use flash for LEDs instead')


def _series_script(self, colors, durations = None, unit="ms", repeat=None, finish_off = True):
"""
Create a script to flash a series of colors.
Expand Down

0 comments on commit c08d3ed

Please sign in to comment.