Clean up chaser.py because AI doesn't follow instructions well

This commit is contained in:
Geens 2024-08-07 19:30:39 +02:00
parent a221cd04b7
commit 46916ce781

View File

@ -28,7 +28,8 @@ class Chaser:
11, # Second display bottom segment
3, 4, 5 # First display remaining segments
]
self.last_update_time = time.time()
self.state_change_time = time.time()
self.time_in_current_state = 0
def update_state_machine(self, hardware: Hardware) -> None:
"""
@ -51,15 +52,23 @@ class Chaser:
elif hardware.get_button_3():
next_state = self.State.CHASING
self.current_led = 0
elif time.time() - self.last_update_time > 0.1: # 100ms delay
elif self.time_in_current_state > 0.1:
self.current_led = (self.current_led + 1) % len(self.chaser_sequence)
self.last_update_time = time.time()
# Time calculation
if next_state != self.current_state:
self.state_change_time = time.time()
self.time_in_current_state = 0
else:
self.time_in_current_state = time.time() - self.state_change_time
self.current_state = next_state
# Outputs
for i in range(32):
hardware.set_led(i, False)
if self.current_state == self.State.CHASING:
hardware.set_led(self.chaser_sequence[self.current_led], True)
match self.current_state:
case self.State.IDLE:
for i in range(32):
hardware.set_led(i, False)
case self.State.CHASING:
for i in range(32):
hardware.set_led(i, False)
hardware.set_led(self.chaser_sequence[self.current_led], True)