feat(engine): Pi-side animation engine with protocol outputs and sequencer
Add src/engine, modelled on technicalkiwi/portal's player and sequence runner: - Pixel generator: runs the unchanged led-driver patterns under CPython (utime shim + NeoPixel-like buffer) on a per-zone render thread and streams frames to pixel outputs, with keepalive for static frames. - Output drivers: DDP, Art-Net (ArtDMX/ArtSync), sACN/E1.31, USB-DMX (Enttec Pro / Open DMX), plus an ESP32 preset output that reuses the existing preset + select delivery path. Registry in db/output.json, CRUD and test pattern at /outputs. - Sequencer: timed preset chains per zone (portal step shape), deadline scheduling, loop/repeat, resume after restart; legacy sequence records are migrated. Zone play/stop, sequence and scene play/stop endpoints. - CLI (python -m engine.cli), Outputs and Sequences modals, preset tiles drive pixel outputs, API/README docs, engine test suite. ESP32 firmware is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
827eb97203
commit
a5a7fc575f
42 files changed
+4117
-75
No files matched your search
+51
-3
@@ -159,6 +159,9 @@ Stored preset records can include:
|
||||
| DELETE | `/zones/<id>` | Delete zone; can delete `current` to remove the active zone; updates profile zone list. |
|
||||
| POST | `/zones/<id>/set-current` | Sets `current_zone` cookie. |
|
||||
| POST | `/zones/<id>/clone` | Clone zone into current profile. |
|
||||
| POST | `/zones/<id>/play` | Body **`{"preset_id": "16", "drivers": true}`**. Runs the preset on every target in the zone through the Pi engine: pixel **outputs** are rendered on the Pi, ESP32 drivers get the preset + `select` (skipped when **`drivers`** is `false`; the UI sends to drivers itself and passes `false`). Stops any sequence on the zone. Returns the zone's player status. |
|
||||
| POST | `/zones/<id>/stop` | Stops the zone's sequence and Pi rendering (pixel outputs go black). ESP32 drivers keep their current preset. |
|
||||
| GET | `/zones/engine/status` | Engine state: `zones` (per-zone player: preset, pattern, error, per-output frame/packet/error counters) and `sequences`. |
|
||||
|
||||
### Palettes — `/palettes`
|
||||
|
||||
@@ -190,15 +193,60 @@ Stored preset records can include:
|
||||
| PUT | `/scenes/<id>` | Update. |
|
||||
| DELETE | `/scenes/<id>` | Delete. |
|
||||
|
||||
### Scene playback
|
||||
|
||||
| Method | Path | Description |
|
||||
|--------|------|-------------|
|
||||
| POST | `/scenes/<id>/play` | Starts every sequence listed in the scene's `sequences`. Returns `started` ids and per-sequence `errors`. |
|
||||
| POST | `/scenes/<id>/stop` | Stops the scene's sequences. |
|
||||
|
||||
### Sequences — `/sequences`
|
||||
|
||||
Timed preset chains for one zone, run by the Pi engine (hard cuts). Stored in **`db/sequence.json`**:
|
||||
|
||||
```json
|
||||
{"name": "Showcase", "zone_id": "2", "loop": true, "repeat_count": 0,
|
||||
"steps": [{"preset_id": "16", "duration_s": 8}, {"preset_id": "17", "duration_s": 8}],
|
||||
"active": false}
|
||||
```
|
||||
|
||||
`duration_s` is clamped to 0.5–600 (default 5). `repeat_count` counts passes when `loop` is true (0 = forever). `active` is maintained by the engine; active sequences resume after a restart. Legacy records (`group_name`, `presets`, `sequence_duration` in ms) are migrated on load.
|
||||
|
||||
| Method | Path | Description |
|
||||
|--------|------|-------------|
|
||||
| GET | `/sequences` | All sequences. |
|
||||
| GET | `/sequences/status` | Runtime state per sequence: `zone_id`, `step_index`, `preset_id`, `pass`, `next_at`, `running`, optional `error`. |
|
||||
| GET | `/sequences/<id>` | One sequence. |
|
||||
| POST | `/sequences` | Create; may use `group_name`, `presets` in body. |
|
||||
| PUT | `/sequences/<id>` | Update. |
|
||||
| DELETE | `/sequences/<id>` | Delete. |
|
||||
| POST | `/sequences` | Create (body as above). 400 on invalid steps. |
|
||||
| PUT | `/sequences/<id>` | Update (merged, then re-validated). |
|
||||
| DELETE | `/sequences/<id>` | Stop if running, then delete. |
|
||||
| POST | `/sequences/<id>/play` | Start on its zone; replaces a sequence already running there. 400 without `zone_id`/steps. |
|
||||
| POST | `/sequences/<id>/stop` | Stop; the zone keeps its current preset. |
|
||||
|
||||
Picking a preset manually on a zone (`/zones/<id>/play`) stops that zone's sequence.
|
||||
|
||||
### Outputs — `/outputs`
|
||||
|
||||
Pixel outputs the Pi renders frames for, stored in **`db/output.json`**. A zone drives an output when the output's **`name`** appears in the zone's `names` (the same list that holds ESP32 device names).
|
||||
|
||||
| Field | Notes |
|
||||
|-------|-------|
|
||||
| `name` | Matched against zone `names`. |
|
||||
| `protocol` | `ddp` (UDP 4048), `artnet` (ArtDMX, UDP 6454), `sacn` (E1.31, UDP 5568), `dmx_serial` (USB-DMX). |
|
||||
| `host`, `port` | Network outputs. `ddp` needs a host; Art-Net without host broadcasts; sACN without host uses multicast `239.255.<hi>.<lo>`. Blank port = protocol default. |
|
||||
| `universe` | Art-Net/sACN start universe (sACN 1–63999). 170 RGB pixels per universe; consecutive universes are used for longer strips. |
|
||||
| `serial_port`, `dmx_mode`, `channel` | USB-DMX: `enttec_pro` (Enttec DMX USB Pro) or `open_dmx` (FTDI); start channel 1–512; one universe max. |
|
||||
| `pixel_count`, `pixel_offset` | Pixels this output takes from the zone frame, starting at `pixel_offset`. Outputs at offset 0 mirror the frame start. |
|
||||
| `color_order`, `reverse`, `brightness`, `fps`, `enabled` | Per-output wiring order, direction, 0–255 brightness (× global brightness), frame-rate cap (default 40). |
|
||||
|
||||
| Method | Path | Description |
|
||||
|--------|------|-------------|
|
||||
| GET | `/outputs` | All outputs. |
|
||||
| GET | `/outputs/<id>` | One output. |
|
||||
| POST | `/outputs` | Create; 400 with `error` on validation failure. |
|
||||
| PUT | `/outputs/<id>` | Update. |
|
||||
| DELETE | `/outputs/<id>` | Delete. |
|
||||
| POST | `/outputs/<id>/test` | Sends red, green, blue, white (optional body `step_s`, default 1 s each) then black. Returns per-output counters. |
|
||||
|
||||
### Patterns — `/patterns`
|
||||
|
||||
|
||||
Reference in new issue
Block a user