Refactor patterns to use preset-based API and fix initialization order
- Fix initialization order: initialize self.presets before calling self.select() - Separate add() and edit() methods: add() creates new presets, edit() updates existing ones - Update all test files to use add() instead of edit() for creating presets - Add comprehensive auto/manual mode test - Remove tool.py (moved to led-tool project)
This commit is contained in:
@@ -24,52 +24,65 @@ def main():
|
||||
|
||||
# Test 1: Simple single-color pulse
|
||||
print("Test 1: Single-color pulse (attack=500, hold=500, decay=500, delay=500)")
|
||||
p.set_param("br", 255)
|
||||
p.set_param("cl", [(255, 0, 0)]) # Red
|
||||
p.set_param("n1", 500) # attack ms
|
||||
p.set_param("n2", 500) # hold ms
|
||||
p.set_param("n3", 500) # decay ms
|
||||
p.set_param("dl", 500) # delay ms between pulses
|
||||
p.set_param("auto", True)
|
||||
p.select("pulse")
|
||||
p.add("pulse1", {
|
||||
"pattern": "pulse",
|
||||
"brightness": 255,
|
||||
"colors": [(255, 0, 0)],
|
||||
"n1": 500, # attack ms
|
||||
"n2": 500, # hold ms
|
||||
"n3": 500, # decay ms
|
||||
"delay": 500, # delay ms between pulses
|
||||
"auto": True
|
||||
})
|
||||
p.select("pulse1")
|
||||
run_for(p, wdt, 5000)
|
||||
|
||||
# Test 2: Faster pulse
|
||||
print("Test 2: Fast pulse (attack=100, hold=100, decay=100, delay=100)")
|
||||
p.set_param("n1", 100)
|
||||
p.set_param("n2", 100)
|
||||
p.set_param("n3", 100)
|
||||
p.set_param("dl", 100)
|
||||
p.set_param("cl", [(0, 255, 0)]) # Green
|
||||
p.select("pulse")
|
||||
p.add("pulse2", {
|
||||
"pattern": "pulse",
|
||||
"n1": 100,
|
||||
"n2": 100,
|
||||
"n3": 100,
|
||||
"delay": 100,
|
||||
"colors": [(0, 255, 0)]
|
||||
})
|
||||
p.select("pulse2")
|
||||
run_for(p, wdt, 4000)
|
||||
|
||||
# Test 3: Multi-color pulse cycle
|
||||
print("Test 3: Multi-color pulse (red -> green -> blue)")
|
||||
p.set_param("n1", 300)
|
||||
p.set_param("n2", 300)
|
||||
p.set_param("n3", 300)
|
||||
p.set_param("dl", 200)
|
||||
p.set_param("cl", [(255, 0, 0), (0, 255, 0), (0, 0, 255)])
|
||||
p.set_param("auto", True)
|
||||
p.select("pulse")
|
||||
p.add("pulse3", {
|
||||
"pattern": "pulse",
|
||||
"n1": 300,
|
||||
"n2": 300,
|
||||
"n3": 300,
|
||||
"delay": 200,
|
||||
"colors": [(255, 0, 0), (0, 255, 0), (0, 0, 255)],
|
||||
"auto": True
|
||||
})
|
||||
p.select("pulse3")
|
||||
run_for(p, wdt, 6000)
|
||||
|
||||
# Test 4: One-shot pulse (auto=False)
|
||||
print("Test 4: Single pulse, auto=False")
|
||||
p.set_param("n1", 400)
|
||||
p.set_param("n2", 0)
|
||||
p.set_param("n3", 400)
|
||||
p.set_param("dl", 0)
|
||||
p.set_param("cl", [(255, 255, 255)])
|
||||
p.set_param("auto", False)
|
||||
p.select("pulse")
|
||||
p.add("pulse4", {
|
||||
"pattern": "pulse",
|
||||
"n1": 400,
|
||||
"n2": 0,
|
||||
"n3": 400,
|
||||
"delay": 0,
|
||||
"colors": [(255, 255, 255)],
|
||||
"auto": False
|
||||
})
|
||||
p.select("pulse4")
|
||||
# Run long enough to allow one full pulse cycle
|
||||
run_for(p, wdt, 1500)
|
||||
|
||||
# Cleanup
|
||||
print("Test complete, turning off")
|
||||
p.select("off")
|
||||
p.add("cleanup_off", {"pattern": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 200)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user