adjusting code to fit within linter guidelines

This commit is contained in:
szelenka 2025-04-16 09:21:14 -04:00
parent 6a10a6fc5b
commit 2fb6c7d79c
2 changed files with 27 additions and 8 deletions

View file

@ -29,7 +29,18 @@ try:
except (ImportError, ModuleNotFoundError):
def colorwheel(pos):
# ref: https://github.com/adafruit/circuitpython/blob/main/shared-module/rainbowio/__init__.c
"""
Generate a color from a position value on a color wheel.
This function maps an input position (0-255) to a color on a
virtual RGB color wheel. The colors transition smoothly through
red, green, and blue.
:param float pos: Position on the color wheel (0-255). Values outside
this range will be wrapped around.
:return: color
"""
# ref:
# https://github.com/adafruit/circuitpython/blob/main/shared-module/rainbowio/__init__.c
pos = pos - ((pos // 256) * 256)
shift1 = 0
shift2 = 0
@ -44,9 +55,9 @@ except (ImportError, ModuleNotFoundError):
pos -= 170
shift1 = 16
shift2 = 0
p = (int)(pos * 3)
p = p if (p < 256) else 255
return (p << shift1) | ((255 - p) << shift2)
pos_new = (int)(pos * 3)
pos_new = pos_new if (pos_new < 256) else 255
return (pos_new << shift1) | ((255 - pos_new) << shift2)
RED = (255, 0, 0)

View file

@ -146,10 +146,7 @@ class AnimationGroup:
for member in self._members:
if isinstance(member, Animation):
if last_strip != member.pixel_object:
if hasattr(member.pixel_object, "show"):
member.pixel_object.show()
elif hasattr(member.pixel_object, "write"):
member.pixel_object.write()
self._pixel_object_show(member.pixel_object)
last_strip = member.pixel_object
else:
member.show()
@ -161,6 +158,17 @@ class AnimationGroup:
ret = True
return ret
def _pixel_object_show(self, pixel_object):
"""
Show the pixel object. This is a helper function to handle both
MicroPython and CircuitPython.
:param pixel_object: The pixel object to show/write to.
"""
if hasattr(pixel_object, "show"):
pixel_object.show()
elif hasattr(pixel_object, "write"):
pixel_object.write()
@property
def color(self):
"""