Wire the Pico to UART-driven preset selection, add pattern modules and presets data, remove old p2p/settings code, and update tests and LED driver. Made-with: Cursor
79 lines
2.3 KiB
Python
79 lines
2.3 KiB
Python
import sys
|
|
if "lib" not in sys.path:
|
|
sys.path.insert(0, "lib")
|
|
if "../lib" not in sys.path:
|
|
sys.path.insert(0, "../lib")
|
|
from ws2812 import WS2812B
|
|
import time
|
|
|
|
# --- Chase test: pregenerated double buffer per strip, show via head offset (same as rainbow) ---
|
|
|
|
# (pin, num_leds) per strip — same config as rainbow
|
|
STRIP_CONFIG = (
|
|
(2, 291),
|
|
(3, 290),
|
|
(4, 283),
|
|
(7, 278),
|
|
(0, 275),
|
|
(28, 278),
|
|
(29, 283),
|
|
(6, 290),
|
|
)
|
|
|
|
strips = []
|
|
sm = 0
|
|
for pin, num_leds in STRIP_CONFIG:
|
|
print(pin, num_leds)
|
|
ws = WS2812B(num_leds, pin, sm, brightness=1.0)
|
|
strips.append(ws)
|
|
sm += 1
|
|
|
|
cumulative_leds = [0]
|
|
for ws in strips[:-1]:
|
|
cumulative_leds.append(cumulative_leds[-1] + ws.num_leds)
|
|
total_ring_leds = cumulative_leds[-1] + strips[-1].num_leds
|
|
|
|
# Chase: trail length (0 = single LED), color (R,G,B)
|
|
TRAIL_LEN = 8
|
|
CHASE_COLOR = (0, 255, 100) # cyan-green
|
|
|
|
|
|
def make_chase_double(num_leds, cumulative_leds, total_ring_leds, color, trail_len=0):
|
|
"""Pregenerate strip double buffer: when head shows index b first, that pixel is at
|
|
distance (2*cumulative_leds - b) % total_ring_leds from chase head. GRB order."""
|
|
n = 2 * num_leds
|
|
buf = bytearray(n * 3)
|
|
for b in range(n):
|
|
dist = (2 * cumulative_leds - b) % total_ring_leds
|
|
if dist == 0:
|
|
r, grn, b_ = color[0], color[1], color[2]
|
|
elif trail_len and 0 < dist <= trail_len:
|
|
fade = 1.0 - (dist / (trail_len + 1))
|
|
r = int(color[0] * fade)
|
|
grn = int(color[1] * fade)
|
|
b_ = int(color[2] * fade)
|
|
else:
|
|
r = grn = b_ = 0
|
|
o = b * 3
|
|
buf[o] = grn
|
|
buf[o + 1] = r
|
|
buf[o + 2] = b_
|
|
return buf
|
|
|
|
|
|
# Pregenerate one double buffer per strip
|
|
chase_buffers = [
|
|
make_chase_double(ws.num_leds, cumulative_leds[i], total_ring_leds, CHASE_COLOR, TRAIL_LEN)
|
|
for i, ws in enumerate(strips)
|
|
]
|
|
|
|
chase_pos = 0
|
|
while True:
|
|
for i, strip in enumerate(strips):
|
|
# head in [0, strip_len) so DMA read head..head+num_leds*3 stays in double buffer (same as rainbow)
|
|
strip_len = strip.num_leds * 3
|
|
head = (chase_pos + cumulative_leds[i]) * 3 % strip_len
|
|
strip.show(chase_buffers[i], head)
|
|
chase_pos = (chase_pos + 1) % total_ring_leds
|
|
time.sleep_ms(20)
|