diff --git a/frontend/src/pages/engineering/developer/ApiReferencePage.jsx b/frontend/src/pages/engineering/developer/ApiReferencePage.jsx index e7d12af..47ad8d3 100644 --- a/frontend/src/pages/engineering/developer/ApiReferencePage.jsx +++ b/frontend/src/pages/engineering/developer/ApiReferencePage.jsx @@ -105,9 +105,9 @@ const NAMESPACES = [ { field: 'url', type: 'string', required: false, notes: 'Download URL, used only when the melody is neither built-in nor on SD. The field is "url" — "download_url" is NOT read by playback.play (that name belongs to files.download). Not sticky: omitted = no download possible for this play.' }, { field: 'speed', type: 'int', required: false, notes: 'ms per beat, 0–65535. Boot default 500. 0 is coerced to 300.' }, { field: 'note_assignments', type: 'int[]', required: false, notes: 'Up to 16 integers, each 0–16. Index = melody note (0-based); value = 1-based BELL channel to ring for that note (0 = silent) — not a relay output. Boot default [1,2,…,16]. A shorter array leaves the remaining entries at their previous values.' }, - { field: 'mode', type: 'string', required: false, notes: '"single" | "timed" | "interval" | "infinite" — anything else is rejected. Selects the timing model (see warning). When present, segment_duration and continuous_loop are ignored.' }, - { field: 'duration', type: 'int', required: false, notes: 'ms, ≥ 0. Read only when mode is present; must be > 0 for "timed"/"interval". "timed": loop until duration elapses, finish the current loop, stop. "interval": length of each play segment. Ignored for "single"/"infinite".' }, - { field: 'pause_duration', type: 'int', required: false, notes: 'ms between segments. Read for mode "interval", or when mode is absent.' }, + { field: 'mode', type: 'string', required: false, notes: '"single" | "timed" | "interval" | "infinite" — anything else is rejected. When present, segment_duration and continuous_loop are ignored. "single": play the melody once, start to end, then stop. "timed": loop back-to-back; once duration has passed, finish the current loop and stop. No pauses. "interval": play duration, pause pause_duration, repeat; stop once total_duration has passed since the start, pauses included (0 = never). "infinite": never stops on its own (only playback.stop). With no duration/pause_duration it loops continuously; with both it plays duration, pauses pause_duration, and repeats forever. total_duration is ignored. See the warning for exact timing.' }, + { field: 'duration', type: 'int', required: false, notes: 'ms, ≥ 0. Read only when mode is present; must be > 0 for "timed"/"interval". "timed": loop until duration elapses, finish the current loop, stop. "interval": length of each play segment. "infinite": optional segment length; must be sent together with pause_duration (both > 0, or both omitted). Ignored for "single".' }, + { field: 'pause_duration', type: 'int', required: false, notes: 'ms of silence between segments, counted from the end of the loop that was playing when the segment ran out. Read for mode "interval" and "infinite", or when mode is absent.' }, { field: 'total_duration', type: 'int', required: false, notes: 'ms overall cap. Read for mode "interval" (0 = forever), or when mode is absent AND continuous_loop is true. With mode absent and continuous_loop false it is IGNORED (overwritten with segment_duration).' }, { field: 'segment_duration', type: 'int', required: false, notes: 'Legacy — read only when mode is absent. With continuous_loop false this is the whole run length (sticky, boot default 15000; 0 = play once). With continuous_loop true it is the segment length.' }, { field: 'continuous_loop', type: 'bool', required: false, notes: 'Legacy — read only when mode is absent. Defaults to false on every command (not sticky).' }, @@ -125,14 +125,15 @@ const NAMESPACES = [ { message: 'Invalid total_duration: must be a non-negative integer (ms)', condition: 'Same, for total_duration' }, { message: 'Invalid mode: must be single, timed, interval or infinite', condition: 'Unrecognised mode' }, { message: 'Invalid duration: mode timed and interval require duration > 0', condition: 'mode is timed/interval and duration is missing or 0' }, + { message: 'Invalid infinite segments: duration and pause_duration must both be > 0, or both omitted', condition: 'mode is infinite and only one of duration / pause_duration is > 0' }, { message: 'Playback blocked: bell mechanism is disabled (bells.enable)', condition: 'Bells master switch is off (bells.disable)' }, { message: 'Playback blocked: bell overload protection active — wait for the bells to cool', condition: 'Load guard enabled and a bell is over its max load (the guard would force-stop immediately)' }, { message: 'Melody failed to load: file is empty or corrupt', condition: '/melodies/{pid} exists on SD but is empty or has an odd byte count' }, { message: 'Melody not found: not built-in, not on SD card, and no url given', condition: 'Needs a download but no url was sent' }, { message: 'Melody not found locally and this device has no SD card to download it to', condition: 'Needs a download but the build has no SD card / FileManager (agnus)' }, ], - example: '// single — play once and stop\n{ "v": 2, "req_id": "a1", "cmd": "playback.play", "contents": { "pid": "westminster", "speed": 400, "mode": "single" } }\n\n// timed — loop for 2 minutes, finish the loop, stop (downloads first if needed)\n{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "url": "https://example.com/ABC123.bin", "mode": "timed", "duration": 120000 } }\n\n// interval — play 15 s, pause 5 s, repeat for 3 min total\n{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "mode": "interval", "duration": 15000, "pause_duration": 5000, "total_duration": 180000 } }\n\n// legacy timing (no mode)\n{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "segment_duration": 15000, "pause_duration": 5000, "continuous_loop": true } }', - warning: 'mode decides which timing fields are read. mode present: duration (+ pause_duration / total_duration for "interval") — segment_duration and continuous_loop are ignored. mode absent (legacy): continuous_loop false → run for segment_duration, total_duration ignored; continuous_loop true → segment_duration segments with pause_duration gaps, stopping after total_duration if given this command, else segment_duration if given, else the previous total_duration (0 = forever). Never mix the two sets expecting both to apply.', + example: '// single — play once and stop\n{ "v": 2, "req_id": "a1", "cmd": "playback.play", "contents": { "pid": "westminster", "speed": 400, "mode": "single" } }\n\n// timed — loop for 2 minutes, finish the loop, stop (downloads first if needed)\n{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "url": "https://example.com/ABC123.bin", "mode": "timed", "duration": 120000 } }\n\n// interval — play 15 s, pause 5 s, repeat for 3 min total\n{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "mode": "interval", "duration": 15000, "pause_duration": 5000, "total_duration": 180000 } }\n\n// infinite — loop until playback.stop\n{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "mode": "infinite" } }\n\n// infinite with segments — play 30 s, pause 10 s, forever\n{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "mode": "infinite", "duration": 30000, "pause_duration": 10000 } }\n\n// legacy timing (no mode)\n{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "segment_duration": 15000, "pause_duration": 5000, "continuous_loop": true } }', + warning: 'Exact timing: (1) timing is checked every 500 ms, so every duration / pause / total boundary is hit up to 0.5 s late. (2) A loop is never cut short (only playback.stop and the overload guard do that); when a segment or the run ends mid-loop, the current loop finishes first. (3) At a segment end status/playback goes "paused" straight away while that loop finishes ringing; at the end of a timed/interval run it goes "stopping", then "idle". "single" goes from "playing" directly to "idle". (4) The bells are then silent for the full pause_duration, counted from that loop end, and status goes back to "playing". (5) total_duration counts from the start, pauses included; if it runs out during a pause, playback stops at once. (6) When the run has no end time (single, infinite, interval with total_duration 0) the engine waits ~0.5 s between loops; timed and interval with a total_duration loop with no gap. Which timing fields are read: mode present → duration (+ pause_duration for "infinite", + pause_duration / total_duration for "interval"); segment_duration and continuous_loop are ignored. mode absent (legacy): continuous_loop false → run for segment_duration, total_duration ignored; continuous_loop true → segment_duration segments with pause_duration gaps, stopping after total_duration if given this command, else segment_duration if given, else the previous total_duration (0 = forever). Never mix the two sets expecting both to apply.', }, { cmd: 'playback.stop',