Fix n_chase pattern to properly chase through all LED positions
- Replace oscillating behavior with proper chasing movement - Use pattern_step for internal tracking instead of controller's step - Calculate position relative to chase head: (i - pattern_step) % num_leds - Chase head moves through all LED positions with n3 step multiplier - n1 controls width of lit chase segment
This commit is contained in:
10
src/main.py
10
src/main.py
@@ -47,7 +47,7 @@ def main():
|
||||
last_msg = msg
|
||||
|
||||
if last_msg:
|
||||
# try:
|
||||
try:
|
||||
data = json.loads(last_msg)
|
||||
defaults = data.get("d", {})
|
||||
bar = data.get(settings.get("name"), {})
|
||||
@@ -62,7 +62,7 @@ def main():
|
||||
patterns.n1 = bar.get("n1", defaults.get("n1", patterns.n1))
|
||||
patterns.n2 = bar.get("n2", defaults.get("n2", patterns.n2))
|
||||
patterns.n3 = bar.get("n3", defaults.get("n3", patterns.n3))
|
||||
patterns.step = bar.get("pattern_step", defaults.get("step", patterns.step))
|
||||
patterns.step = bar.get("s", defaults.get("s", patterns.step))
|
||||
|
||||
# Only execute pattern if it's a beat message
|
||||
if message_type == "b": # Beat message
|
||||
@@ -77,9 +77,9 @@ def main():
|
||||
print(f"Parameters updated: brightness={patterns.brightness}, delay={patterns.delay}")
|
||||
else:
|
||||
print(f"Unknown message type: {message_type}")
|
||||
# except Exception as ex:
|
||||
# print(f"Failed to load espnow data {last_msg}: {ex}")
|
||||
# continue
|
||||
except Exception as ex:
|
||||
print(f"Failed to load espnow data {last_msg}: {ex}")
|
||||
continue
|
||||
|
||||
|
||||
main()
|
||||
|
@@ -89,13 +89,21 @@ class Patterns(PatternBase): # Inherit from PatternBase
|
||||
self.last_update = current_time
|
||||
return self.delay
|
||||
|
||||
# Use pattern_step for internal chasing, not the controller's step
|
||||
if not hasattr(self, 'pattern_step'):
|
||||
self.pattern_step = 0
|
||||
|
||||
for i in range(self.num_leds):
|
||||
if (i + self.pattern_step) % segment_length < self.n1:
|
||||
# Calculate position relative to the chase head
|
||||
pos_from_head = (i - self.pattern_step) % self.num_leds
|
||||
if pos_from_head < self.n1:
|
||||
self.n[i] = self.apply_brightness(self.colors[0])
|
||||
else:
|
||||
self.n[i] = (0, 0, 0)
|
||||
self.n.write()
|
||||
self.pattern_step = (self.pattern_step + step_rate) % segment_length
|
||||
|
||||
# Update internal pattern step for chasing
|
||||
self.pattern_step = (self.pattern_step + step_rate) % self.num_leds
|
||||
self.last_update = current_time
|
||||
return self.delay
|
||||
|
||||
@@ -129,7 +137,7 @@ class Patterns(PatternBase): # Inherit from PatternBase
|
||||
self.n[i] = active_color
|
||||
|
||||
self.n.write()
|
||||
self.step = (self.step + 1) % 2
|
||||
# Don't update step - use the step value sent from controller for synchronization
|
||||
return max(1, int(self.delay // 2))
|
||||
|
||||
|
||||
@@ -189,10 +197,10 @@ class Patterns(PatternBase): # Inherit from PatternBase
|
||||
|
||||
step_rate = max(1, int(self.n3))
|
||||
for i in range(self.num_leds):
|
||||
rc_index = (i * 256 // max(1, self.num_leds)) + self.pattern_step
|
||||
rc_index = (i * 256 // max(1, self.num_leds)) + self.step
|
||||
self.n[i] = self.apply_brightness(wheel(rc_index & 255))
|
||||
self.n.write()
|
||||
self.pattern_step = (self.pattern_step + step_rate) % 256
|
||||
self.step = (self.step + step_rate) % 256
|
||||
return max(1, int(self.delay // 5))
|
||||
|
||||
def specto(self):
|
||||
|
Reference in New Issue
Block a user