Refine calibration, chase, and spin patterns and add spin test
Increase calibration brightness, update chase to use the new logical ring abstraction, and make spin start from a cleared frame with symmetric arm speed, alongside a dedicated on-device spin test script. Made-with: Cursor
This commit is contained in:
128
pico/test/test_spin.py
Normal file
128
pico/test/test_spin.py
Normal file
@@ -0,0 +1,128 @@
|
||||
"""
|
||||
On-device test for the Spin pattern using mpremote and Presets.
|
||||
|
||||
Usage (from pico/ dir or project root with adjusted paths):
|
||||
|
||||
mpremote connect <device> cp src/*.py :
|
||||
mpremote connect <device> cp src/patterns/*.py :patterns
|
||||
mpremote connect <device> cp lib/*.py :
|
||||
mpremote connect <device> cp presets.json :
|
||||
mpremote connect <device> cp test/test_spin.py :
|
||||
mpremote connect <device> run test_spin.py
|
||||
|
||||
This script:
|
||||
- Instantiates Presets
|
||||
- Creates a few in-memory spin presets with different parameters
|
||||
- Runs each one for a short time so you can visually compare behaviour
|
||||
"""
|
||||
|
||||
import utime
|
||||
from presets import Presets, Preset
|
||||
|
||||
|
||||
def make_spin_preset(
|
||||
name,
|
||||
color_inner,
|
||||
color_outer,
|
||||
rate=4,
|
||||
delay_ms=30,
|
||||
margin=0,
|
||||
brightness=255,
|
||||
):
|
||||
"""Helper to build a Preset dict for the spin pattern."""
|
||||
data = {
|
||||
"p": "spin",
|
||||
"c": [color_inner, color_outer],
|
||||
"b": brightness,
|
||||
"d": delay_ms,
|
||||
"n1": rate, # expansion step per tick
|
||||
"n2": margin, # margin from strip ends
|
||||
"a": True,
|
||||
}
|
||||
return name, Preset(data)
|
||||
|
||||
|
||||
def run_preset(presets, name, preset_obj, duration_ms):
|
||||
"""Run a given spin preset for duration_ms using the existing tick loop."""
|
||||
# Start each preset from a blank frame so both sides are balanced.
|
||||
presets.select("off")
|
||||
presets.tick()
|
||||
|
||||
presets.presets[name] = preset_obj
|
||||
presets.select(name)
|
||||
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < duration_ms:
|
||||
presets.tick()
|
||||
utime.sleep_ms(10)
|
||||
|
||||
|
||||
def main():
|
||||
presets = Presets()
|
||||
presets.load()
|
||||
|
||||
# Ensure we start from a blank frame.
|
||||
presets.select("off")
|
||||
presets.tick()
|
||||
|
||||
print("Starting spin pattern test...")
|
||||
|
||||
# Use strip 0 length to derive a reasonable margin.
|
||||
ref_len = presets.strip_length(0)
|
||||
margin_small = ref_len // 16 if ref_len > 0 else 0
|
||||
margin_large = ref_len // 8 if ref_len > 0 else 0
|
||||
|
||||
spin_presets = []
|
||||
|
||||
# 1. Slow spin, warm white to orange, small margin
|
||||
spin_presets.append(
|
||||
make_spin_preset(
|
||||
"spin_slow_warm",
|
||||
color_inner=(255, 200, 120),
|
||||
color_outer=(255, 100, 0),
|
||||
rate=2,
|
||||
delay_ms=40,
|
||||
margin=margin_small,
|
||||
brightness=255,
|
||||
)
|
||||
)
|
||||
|
||||
# 2. Medium spin, cyan to magenta, larger margin
|
||||
spin_presets.append(
|
||||
make_spin_preset(
|
||||
"spin_medium_cyan_magenta",
|
||||
color_inner=(0, 255, 180),
|
||||
color_outer=(255, 0, 180),
|
||||
rate=4,
|
||||
delay_ms=30,
|
||||
margin=margin_large,
|
||||
brightness=255,
|
||||
)
|
||||
)
|
||||
|
||||
# 3. Fast spin, white to off (fade outwards), no margin
|
||||
spin_presets.append(
|
||||
make_spin_preset(
|
||||
"spin_fast_white",
|
||||
color_inner=(255, 255, 255),
|
||||
color_outer=(0, 0, 0),
|
||||
rate=6,
|
||||
delay_ms=20,
|
||||
margin=0,
|
||||
brightness=255,
|
||||
)
|
||||
)
|
||||
|
||||
# Run each spin preset for about 6 seconds
|
||||
for name, preset_obj in spin_presets:
|
||||
print("Running spin preset:", name)
|
||||
run_preset(presets, name, preset_obj, duration_ms=6000)
|
||||
|
||||
print("Spin pattern test finished. Turning off LEDs.")
|
||||
presets.select("off")
|
||||
presets.tick()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user