How chasecee/loop works
Project Type and Purpose
• LOOP is a full-stack, embedded IoT application for Raspberry Pi that plays GIFs, videos, and images on a small SPI-driven LCD.
• It combines a Python-based backend (device control, media pipeline, REST API) with a Next.js SPA frontend for browser-based media management.
High-Level Architectural Overview
• Hardware Layer: Raspberry Pi OS, SPI display, WiFi chipset.
• Backend Layer (Python 3.9+):
• Boot/Networking (boot/wifi.py, hotspot.sh)
• Configuration (config/config.json + schema.py)
• Media Index (media_index.py): canonical state store
• Conversion Engine (convert.py): raw→RGB565 frames
• Player (player.py + spiout/framebuf): reads state, writes SPI
• Web Server (FastAPI in web/server.py + SPA assets)
• Sync & Updater (sync/, deployment/updater.py)
• Frontend Layer (Next.js SPA under backend/web/spa & frontend/loop-frontend): UI for uploads, queue management, playback controls.
Key Components & Responsibilities
• MEDIA_INDEX (central authority): holds loop queue, active media, config parameters; serves both server and player.
• SERVER (FastAPI): exposes REST & WebSocket endpoints; applies all state changes via MEDIA_INDEX; persists uploads to backend/media/raw.
• CONVERT ENGINE: picks up raw uploads, processes into per-frame data in backend/media/processed, strips RGB565 payload. Reports progress via WebSocket.
• PLAYER: polls MEDIA_INDEX to fetch “current media,” renders frames from processed cache to the LCD (via SPI). Never modifies state.
• WIFI MANAGER (boot module): auto-connects to WiFi or launches “LOOP-Setup” AP for configuration.
• UPDATER/DEPLOYMENT: shell scripts and Python updater that install dependencies, configure systemd, apply Git pull updates.
• FRONTEND SPA: static assets served by SERVER; makes API calls for upload/progress, loop reordering, playback controls.
Relationships & Data Flows
• Browser → (HTTP/WS) → SERVER → MEDIA_INDEX → CONVERT & PLAYER
• Upload path: Browser POST → /api/media → raw media dir → CONVERT → processed dir → MEDIA_INDEX updated → notify frontend
• Playback path: PLAYER polls MEDIA_INDEX → reads processed frames → writes to SPI → updates display
• Configuration path: Browser edits settings via API → SERVER updates MEDIA_INDEX and config file
• WiFi path: On boot, WIFI MANAGER configures network interfaces; once online, SERVER listens on port 8000
Architectural Patterns & Principles
• Single Source of Truth (media_index.py) to avoid race conditions
• Separation of Concerns:
• Conversion only reports progress
• Player only reads state
• Server only mutates state via controlled API
• Modular drivers: Python SPI driver in display/spiout abstracts Waveshare C/Python code
• Systemd service orchestrates lifecycle; deployment scripts automate provisioning