kopia lustrzana https://github.com/micropython/micropython-lib
drivers/led/neopixel: Refactor brightness() for speed.
Signed-off-by: Tom Mount <tmountjr@gmail.com>pull/739/head
rodzic
866fd2f74a
commit
9e80530a74
|
@ -53,14 +53,12 @@ class NeoPixel:
|
||||||
b[j] = c
|
b[j] = c
|
||||||
j += bpp
|
j += bpp
|
||||||
|
|
||||||
def brightness(self, b: float):
|
def brightness(self, b=None):
|
||||||
if b is None:
|
if b is None:
|
||||||
return self.b
|
return self.b
|
||||||
self.b = min(max(b, 0), 1)
|
self.b = min(max(b, 0), 1)
|
||||||
# This may look odd but because __getitem__ and __setitem__ handle all the
|
for i in range(self.n * self.bpp):
|
||||||
# brightness logic already, we can offload the work to those methods.
|
self.buf[i] = round(self.buf[i] * self.b)
|
||||||
for i in range(self.n):
|
|
||||||
self[i] = self[i]
|
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
# BITSTREAM_TYPE_HIGH_LOW = 0
|
# BITSTREAM_TYPE_HIGH_LOW = 0
|
||||||
|
|
Ładowanie…
Reference in New Issue