Work in progress from the same tree as the controller's sequences-v2 changes. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""Boot one simulated led-driver inside Pyodide (run by web/driver-worker.js).
|
|
|
|
The worker has already written the strip's flash into ``LED_SIM_FLASH``
|
|
(``led-driver/src`` including ``patterns/``, plus this strip's
|
|
``settings.json`` and ``presets.json``) and the stubs into ``LED_SIM_STUBS``.
|
|
This then runs the real ``main.py`` as ``__main__``, as the board does at
|
|
power-on: settings, presets, startup preset, ESP-NOW hello, main loop.
|
|
"""
|
|
|
|
import gc
|
|
import os
|
|
import runpy
|
|
import sys
|
|
import time
|
|
|
|
|
|
def boot():
|
|
flash = os.environ.get("LED_SIM_FLASH", "/flash")
|
|
stubs = os.environ.get("LED_SIM_STUBS", "/stubs")
|
|
|
|
# Stubs replace the hardware modules; the flash root plays the device's
|
|
# "/" (cwd), where main.py, settings.json, presets.json and patterns/ live.
|
|
for p in (flash, stubs):
|
|
while p in sys.path:
|
|
sys.path.remove(p)
|
|
sys.path[:0] = [stubs, flash]
|
|
os.chdir(flash)
|
|
|
|
import _simlink
|
|
|
|
# No threads and no event loop turns while main.py runs: sleeps block on
|
|
# Atomics.wait, and the ping-reply "thread" runs from the main loop.
|
|
time.sleep = _simlink.real_sleep
|
|
import _thread
|
|
|
|
_thread.start_new_thread = _simlink.start_new_thread
|
|
|
|
if not hasattr(gc, "mem_free"):
|
|
gc.mem_free = lambda: 256 * 1024
|
|
gc.mem_alloc = lambda: 64 * 1024
|
|
|
|
import settings as led_settings
|
|
|
|
led_settings.Settings.SETTINGS_FILE = flash.rstrip("/") + "/settings.json"
|
|
|
|
runpy.run_path(flash.rstrip("/") + "/main.py", run_name="__main__")
|
|
|
|
|
|
boot()
|