Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
logs/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
Expand Down
6 changes: 1 addition & 5 deletions src/metar_map/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,4 @@ def get_metar(self, ids: list[str]) -> list[MetarData]:

if __name__ == "__main__":
client = MetarClient()
config = load_config()
codes = config.get("icao_codes", [])
for code in codes:
print(f"- {code}")
print(client.get_metar(config.get("icao_codes", [])))
print(client.get_metar(["KLHZ"]))
53 changes: 49 additions & 4 deletions src/metar_map/led_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def _set_led(self, led_index: int, color: tuple[int, int, int]):
def update_patterns(self, led_index: int, patterns: list[LEDPattern]):
with self._lock:
self._led_patterns[led_index] = patterns.copy()
# Reset last_states for this LED so pattern_index is always valid
if hasattr(self, "_last_states"):
self._last_states.pop(led_index, None)

def stop(self):
self._stop_event.set()
Expand All @@ -45,7 +48,7 @@ def clear_all(self):
self.strip.show()

def _run_loop(self):
last_states: dict[int, dict[str, Any]] = {}
self._last_states: dict[int, dict[str, Any]] = {}
while not self._stop_event.is_set():
now = time.monotonic()
with self._lock:
Expand All @@ -55,8 +58,8 @@ def _run_loop(self):
self._set_led(led_index, LEDColor.OFF.rgb)
continue

if led_index not in last_states:
last_states[led_index] = {
if led_index not in self._last_states:
self._last_states[led_index] = {
"pattern_index": 0,
"pattern_end": now + patterns[0].total_duration_s,
"led_on": True,
Expand All @@ -67,7 +70,18 @@ def _run_loop(self):
),
}

state = last_states[led_index]
state = self._last_states[led_index]
# Ensure pattern_index is always valid
if state["pattern_index"] >= len(patterns):
state["pattern_index"] = 0
state["pattern_end"] = now + patterns[0].total_duration_s
state["led_on"] = True
state["next_blink"] = (
now + patterns[0].blink_speed_s
if patterns[0].blink
else None
)

pattern = patterns[int(state["pattern_index"])]

if (
Expand Down Expand Up @@ -97,3 +111,34 @@ def _run_loop(self):
)

time.sleep(0.05)


if __name__ == "__main__":

NUM_LEDS = 10
controller = LEDController(num_leds=NUM_LEDS, brightness=0.2)

# Define three patterns: solid RED, blinking WHITE, solid GREEN
solid_red = LEDPattern(color=LEDColor.RED, total_duration_s=2, blink=False)
blink_white = LEDPattern(
color=LEDColor.WHITE, total_duration_s=2, blink=True, blink_speed_s=0.3
)
solid_green = LEDPattern(color=LEDColor.GREEN, total_duration_s=2, blink=False)
patterns1 = [solid_red, blink_white, solid_green]

blink_blue = LEDPattern(color=LEDColor.BLUE, total_duration_s=5, blink=True)
blink_pink = LEDPattern(color=LEDColor.PINK, total_duration_s=5, blink=True)
patterns2 = [blink_blue, blink_pink]

try:
while True:
for i in range(NUM_LEDS):
controller.update_patterns(i, patterns1)
time.sleep(60)
for i in range(NUM_LEDS):
controller.update_patterns(i, patterns2)
time.sleep(60)
except KeyboardInterrupt:
print("\nStopping LED controller...")
controller.stop()
print("Done.")