Add portal web simulator, SPI bridges, and Pico firmware updates.
Bring the five-panel hex portal online with a browser 3D/schematic preview, Pi SPI backends, and renamed multi-panel Pico UDP firmware. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
67
examples/portal_simulator.py
Normal file
67
examples/portal_simulator.py
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Web portal simulator — FastAPI + live reload."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="Portal web simulator (FastAPI)")
|
||||
parser.add_argument("--host", default="127.0.0.1")
|
||||
parser.add_argument("--port", type=int, default=8765)
|
||||
parser.add_argument(
|
||||
"--reload",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
default=True,
|
||||
help="reload Python on code changes (default: on)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--browser-reload",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
default=True,
|
||||
help="reload browser when web/ files change (default: on)",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
web_dir = Path(__file__).resolve().parent.parent / "web"
|
||||
if not web_dir.is_dir():
|
||||
print(f"Missing web directory: {web_dir}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
try:
|
||||
import uvicorn
|
||||
except ImportError:
|
||||
print(
|
||||
"FastAPI simulator requires: pipenv install fastapi 'uvicorn[standard]'",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 1
|
||||
|
||||
os.environ["PORTAL_DEV_RELOAD"] = "1" if args.browser_reload else "0"
|
||||
|
||||
leds_dir = Path(__file__).resolve().parent.parent / "leds"
|
||||
reload_dirs = [str(web_dir), str(leds_dir)] if args.reload else None
|
||||
|
||||
print(f"Portal simulator → http://{args.host}:{args.port}/")
|
||||
if args.reload:
|
||||
print("Python reload: on")
|
||||
if args.browser_reload:
|
||||
print("Browser reload: on (watches web/)")
|
||||
print("Ctrl+C to stop")
|
||||
|
||||
uvicorn.run(
|
||||
"leds.portal_web:app",
|
||||
host=args.host,
|
||||
port=args.port,
|
||||
reload=args.reload,
|
||||
reload_dirs=reload_dirs,
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user