101 lines
2.8 KiB
Python
101 lines
2.8 KiB
Python
"""
|
|
Test the Presets.scale() helper on-device with mpremote.
|
|
|
|
Usage (from project root):
|
|
|
|
mpremote connect <device> cp pico/src/*.py : &&
|
|
mpremote connect <device> cp pico/src/patterns/*.py :patterns &&
|
|
mpremote connect <device> cp pico/lib/*.py : &&
|
|
mpremote connect <device> cp tests/test_scale.py : &&
|
|
mpremote connect <device> run test_scale.py
|
|
|
|
This script:
|
|
- Creates a minimal Presets instance
|
|
- Runs a few numeric test cases for scale()
|
|
- Optionally displays a short visual check on the LEDs
|
|
"""
|
|
|
|
from presets import Presets
|
|
|
|
|
|
def numeric_tests(presets):
|
|
"""
|
|
Numeric sanity checks for scale() using the actual strip config.
|
|
|
|
We treat strip 0 as the reference and print the mapped indices for
|
|
a few positions on each other strip.
|
|
"""
|
|
print("Numeric scale() tests (from strip 0):")
|
|
ref_len = presets.strip_length(0)
|
|
if ref_len <= 0:
|
|
print(" strip 0 length <= 0; skipping numeric tests.")
|
|
return
|
|
|
|
test_positions = [0, ref_len // 2, ref_len - 1]
|
|
for pos in test_positions:
|
|
print(" pos on strip 0:", pos)
|
|
for dst_idx in range(len(presets.strips)):
|
|
dst_len = presets.strip_length(dst_idx)
|
|
if dst_len <= 0:
|
|
continue
|
|
n2 = presets.scale(dst_idx, pos)
|
|
print(" -> strip", dst_idx, "len", dst_len, "pos", n2)
|
|
|
|
|
|
def visual_test(presets):
|
|
"""
|
|
Simple visual test:
|
|
- Use strip 0 as reference
|
|
- Move a pixel along strip 0
|
|
- Map position to all other strips with scale()
|
|
"""
|
|
import utime
|
|
|
|
strips = presets.strips
|
|
if not strips:
|
|
print("No strips available for visual test.")
|
|
return
|
|
|
|
src_strip_idx = 0
|
|
l1 = presets.strip_length(src_strip_idx)
|
|
if l1 <= 0:
|
|
print("strip_length(0) <= 0; aborting visual test.")
|
|
return
|
|
|
|
color = (50, 0, 0) # dim red so it doesn't blind you
|
|
|
|
# Run once across the full length of the reference strip,
|
|
# jumping 10 LEDs at a time.
|
|
step_size = 10
|
|
steps = (l1 + step_size - 1) // step_size
|
|
print("Starting visual scale() test with 10-LED jumps:", steps, "steps...")
|
|
for step in range(steps):
|
|
n1 = (step * step_size) % l1
|
|
|
|
# Clear all strips
|
|
for strip in strips:
|
|
strip.fill((0, 0, 0))
|
|
|
|
# Light mapped position on each strip using Presets.set/show
|
|
for dst_strip_idx, _ in enumerate(strips):
|
|
presets.set(dst_strip_idx, n1, color)
|
|
presets.show(dst_strip_idx)
|
|
|
|
print("Visual test finished.")
|
|
|
|
|
|
def main():
|
|
presets = Presets()
|
|
presets.load()
|
|
numeric_tests(presets)
|
|
# Comment this in/out depending on whether you want the LEDs to run:
|
|
try:
|
|
visual_test(presets)
|
|
except Exception as e:
|
|
print("Visual test error:", e)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|