drivers/led/neopixel: Continue lint fixes.

Signed-off-by: Tom Mount <tmountjr@gmail.com>
pull/739/head
Tom Mount 2023-10-04 10:40:43 -04:00
rodzic f683608542
commit 0014eac906
1 zmienionych plików z 7 dodań i 4 usunięć

Wyświetl plik

@ -8,13 +8,16 @@ class NeoPixel:
# G R B W # G R B W
ORDER = (1, 0, 2, 3) 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): def __init__(self, pin, n, bpp=3, timing=1, brightness=None):
self.pin = pin self.pin = pin
self.n = n self.n = n
self.bpp = bpp self.bpp = bpp
self.brightness = ( self.brightness = None
min(max(float(brightness), 0.0), 1.0) if brightness is not None else None if brightness is not None:
) self.brightness = self._clamp(float(brightness), 0.0, 1.0)
self.buf = bytearray(n * bpp) self.buf = bytearray(n * bpp)
self.pin.init(pin.OUT) self.pin.init(pin.OUT)
# Timing arg can either be 1 for 800kHz or 0 for 400kHz, # Timing arg can either be 1 for 800kHz or 0 for 400kHz,
@ -56,7 +59,7 @@ class NeoPixel:
j += bpp j += bpp
def set_brightness(self, b: float): 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 # This may look odd but because __getitem__ and __setitem__ handle all the
# brightness logic already, we can offload the work to those methods. # brightness logic already, we can offload the work to those methods.
for i in range(self.n): for i in range(self.n):