test(led-driver): add pattern smoke harness
Made-with: Cursor
This commit is contained in:
43
tests/fake_driver.py
Normal file
43
tests/fake_driver.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""Minimal Presets-like stub for pattern smoke tests (no machine / NeoPixel)."""
|
||||
|
||||
|
||||
class _FakeNeo:
|
||||
def __init__(self, count):
|
||||
self._count = count
|
||||
self.pixels = [(0, 0, 0)] * count
|
||||
|
||||
def fill(self, color):
|
||||
self.pixels = [tuple(color) for _ in range(self._count)]
|
||||
|
||||
def __setitem__(self, index, value):
|
||||
self.pixels[index] = tuple(value)
|
||||
|
||||
def __getitem__(self, index):
|
||||
return self.pixels[index]
|
||||
|
||||
def write(self):
|
||||
pass
|
||||
|
||||
|
||||
class FakePresets:
|
||||
"""Subset of led-driver Presets API used by patterns/*.py."""
|
||||
|
||||
def __init__(self, num_leds=24):
|
||||
self.num_leds = num_leds
|
||||
self.n = _FakeNeo(num_leds)
|
||||
self.b = 255
|
||||
self.step = 0
|
||||
|
||||
def apply_brightness(self, color, brightness_override=None):
|
||||
local = brightness_override if brightness_override is not None else 255
|
||||
effective_brightness = int(local * self.b / 255)
|
||||
return tuple(int(c * effective_brightness / 255) for c in color)
|
||||
|
||||
def fill(self, color=None):
|
||||
fill_color = color if color is not None else (0, 0, 0)
|
||||
for i in range(self.num_leds):
|
||||
self.n[i] = fill_color
|
||||
self.n.write()
|
||||
|
||||
def off(self):
|
||||
self.fill((0, 0, 0))
|
||||
Reference in New Issue
Block a user