Update LED bar to handle message type field

- Process 't' field to distinguish between beat ('b') and update ('u') messages
- Beat messages: execute pattern immediately using current parameters
- Update messages: only update parameters, don't execute pattern
- Maintains backward compatibility with default to beat if 't' not specified
- Enables proper synchronization between controller and bars
This commit is contained in:
2025-09-18 22:10:23 +12:00
parent 748ad4b507
commit 67c4a1a6f6
5 changed files with 171 additions and 13 deletions

View File

@@ -15,6 +15,7 @@ class Patterns(PatternBase): # Inherit from PatternBase
self.n3 = 1 # Default step factor
self.oneshot = False # New: One-shot flag for patterns like fill_range
self.patterns = {
"off": self.off,
"flicker": self.flicker,
"fill_range": self.fill_range,
"n_chase": self.n_chase,
@@ -23,9 +24,25 @@ class Patterns(PatternBase): # Inherit from PatternBase
"rainbow": self.rainbow,
"specto": self.specto,
"radiate": self.radiate,
# Shortened pattern names for optimized JSON payloads
"o": self.off,
"f": self.flicker,
"fr": self.fill_range,
"nc": self.n_chase,
"a": self.alternating,
"p": self.pulse,
"r": self.rainbow,
"s": self.specto,
"rd": self.radiate,
}
self.step = 0
def off(self):
"""Turn off all LEDs"""
self.fill((0, 0, 0))
self.n.write()
return self.delay
def flicker(self):
current_time = utime.ticks_ms()
base_color = self.colors[0]