Skip to content

Commit

Permalink
drivers/led/neopixel: Continue lint fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Mount <[email protected]>
  • Loading branch information
tmountjr committed Oct 4, 2023
1 parent f683608 commit 0014eac
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions micropython/drivers/led/neopixel/neopixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ class NeoPixel:
# G R B W
ORDER = (1, 0, 2, 3)

def _clamp(self, v, c_min, c_max):
return min(max(v, c_min), c_max)

def __init__(self, pin, n, bpp=3, timing=1, brightness=None):
self.pin = pin
self.n = n
self.bpp = bpp
self.brightness = (
min(max(float(brightness), 0.0), 1.0) if brightness is not None else None
)
self.brightness = None
if brightness is not None:
self.brightness = self._clamp(float(brightness), 0.0, 1.0)
self.buf = bytearray(n * bpp)
self.pin.init(pin.OUT)
# Timing arg can either be 1 for 800kHz or 0 for 400kHz,
Expand Down Expand Up @@ -56,7 +59,7 @@ def fill(self, v):
j += bpp

def set_brightness(self, b: float):
self.brightness = min(max(b, 0.0), 1.0)
self.brightness = self._clamp(b, 0.0, 1.0)
# This may look odd but because __getitem__ and __setitem__ handle all the
# brightness logic already, we can offload the work to those methods.
for i in range(self.n):
Expand Down

0 comments on commit 0014eac

Please sign in to comment.