Files
led-driver/src/startup.py
T
jimmyandClaude Sonnet 5.5 97df6e3cbe feat: max_brightness ceiling set from the controller's device config
Neither the global nor a preset's brightness goes above max_brightness; a
change redraws a static pattern under the new ceiling.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 01:48:42 +13:00

53 lines
1.4 KiB
Python

import gc
import machine
import network
import utime
from presets import Presets
from settings import Settings
from controller_messages import apply_startup_pattern
def initialize_runtime():
machine.freq(160000000)
settings = Settings()
wdt = machine.WDT(timeout=10000)
wdt.feed()
gc.collect()
presets = Presets(settings["led_pin"], settings["num_leds"])
presets.load(settings)
presets.b = settings.get("brightness", 255)
presets.max_b = settings.get("max_brightness", 255)
presets.debug = bool(settings.get("debug", False))
gc.collect()
apply_startup_pattern(settings, presets)
# On ESP32-C3, soft reboots can leave Wi-Fi driver state allocated.
# Reset both interfaces and collect before bringing STA up.
ap_if = network.WLAN(network.AP_IF)
ap_if.active(False)
sta_if = network.WLAN(network.STA_IF)
if sta_if.active():
sta_if.active(False)
utime.sleep_ms(100)
gc.collect()
sta_if.active(True)
sta_if.config(pm=network.WLAN.PM_NONE)
sta_if.connect(settings["ssid"], settings["password"])
while not sta_if.isconnected():
utime.sleep(1)
wdt.feed()
try:
led_ip = sta_if.ifconfig()[0]
except Exception:
led_ip = "?"
print("led-driver IP:", led_ip, " led-controller IP:", "(not connected)")
return settings, presets, wdt, sta_if