- led-simulator: the rig runs the C++ led-driver as WebAssembly (sim-driver/), one single-threaded worker per bar, no cross-origin isolation needed. Rooms (one JSON per room) with an on-page editor, and a pattern gallery. The Python server, Pyodide boot and ring buffer are removed. - sim-controller sim_rig.c: serves /sim/ from an embedded pack, the page's WebSocket and the rooms/flash API. The desktop build embeds it too. - bridge.c: a "browser" bridge kind that carries ESP-NOW frames to the page; devices announced through it are marked sim. - UI: Simulator in the Menu, split view with resize and pop-out, swipe between controller and rig on phones; SIM/REAL badges in Devices. - Fades: preset pushes and Wi-Fi driver bodies always carry fade and beat_time, so "off" no longer inherits an earlier fade. - Also the sequences-v2 work in progress: desktop port, bridge firmware, serial bridge, Wi-Fi drivers, sequence timeline, audio and API changes. - led-driver: ESP-NOW link, beat sync, control messages, sim hooks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
4.0 KiB
C
81 lines
4.0 KiB
C
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include "cJSON.h"
|
|
#include "esp_err.h"
|
|
#include "esp_http_server.h"
|
|
|
|
// Helpers shared by the REST handlers (api.c and the res_*.c resource modules)
|
|
|
|
// Path segments of "/res/id/action?query" (at most three)
|
|
typedef char api_seg_t[3][64];
|
|
int api_split(const char *uri, api_seg_t seg);
|
|
|
|
// Send obj as JSON; own=true deletes it afterwards
|
|
esp_err_t api_json(httpd_req_t *req, const char *status, cJSON *obj, bool own);
|
|
esp_err_t api_error(httpd_req_t *req, const char *status, const char *msg);
|
|
esp_err_t api_message(httpd_req_t *req, const char *status, const char *msg);
|
|
// 200 {message} for ESP_OK, otherwise a matching error status
|
|
esp_err_t api_result(httpd_req_t *req, esp_err_t err, const char *ok_msg);
|
|
|
|
// Parsed JSON object body, or NULL after an error response has been sent. api_body_opt treats an
|
|
// empty body as {}.
|
|
cJSON *api_body(httpd_req_t *req);
|
|
cJSON *api_body_opt(httpd_req_t *req);
|
|
|
|
// Shallow merge of src into dst, skipping "id"
|
|
void api_merge(cJSON *dst, const cJSON *src);
|
|
// Set (replace or add) one key
|
|
void api_set(cJSON *obj, const char *key, cJSON *val);
|
|
// Record id as text from a string or number value; false (buf empty) otherwise
|
|
bool api_id(const cJSON *v, char *buf, size_t len);
|
|
|
|
// Add rec under the collection's next id (with an "id" field when rec is an object); id gets the key
|
|
void api_add(const char *coll, cJSON *rec, char *id, size_t len);
|
|
|
|
// "aa:bb:..", "AA-BB-.." or "aabb.." -> lowercase 12-hex MAC; false when not a MAC
|
|
bool api_mac(const cJSON *v, char out[13]);
|
|
// device_config from the fields a request may set (name, num_leds, color_order, startup_mode); NULL when
|
|
// none is valid. Caller owns the result.
|
|
cJSON *api_driver_config(const cJSON *name, const cJSON *num_leds, const cJSON *color_order, const cJSON *startup);
|
|
// Combined 0..255 brightness for a driver: global x its groups x device [x zone_b when >= 0]
|
|
int api_effective_brightness(const char *mac, int zone_b);
|
|
|
|
// Merge settings a driver reported (num_leds, color_order, startup_mode, max_brightness, reversed)
|
|
// into its device record. cfg is the JSON object, len bytes (not terminated). True when the record changed.
|
|
bool api_apply_driver_cfg(cJSON *rec, const char *cfg, int len);
|
|
// Blink every member of a group, then "off"
|
|
esp_err_t api_identify_group(const char *group_id);
|
|
|
|
// New records with every field set (callers merge in the request)
|
|
cJSON *api_preset_defaults(const char *profile_id);
|
|
cJSON *api_sequence_defaults(void);
|
|
|
|
// Current profile id (settings.current_profile_id, else the first profile), or NULL
|
|
const char *api_current_profile(void);
|
|
bool api_preset_in_profile(const cJSON *rec);
|
|
|
|
// Bring records written by older versions into the current shape (at boot)
|
|
void api_migrate_sequences(void);
|
|
void api_seed_defaults(void);
|
|
// A new group with the defaults, saved; its id in id
|
|
void api_add_group(const char *name, char *id, size_t len);
|
|
void api_migrate_zones(void);
|
|
// Move a zone's older animation_ids into sequence_ids (one-shots and looping sequences sit together)
|
|
bool api_zone_fold_oneshots(cJSON *z);
|
|
void api_migrate_groups(void);
|
|
|
|
// Resource handlers, called with the store locked. Each returns true when it answered the request
|
|
// (its result in *ret); false hands the request to the generic collection CRUD.
|
|
bool bundles_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
|
|
bool profiles_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
|
|
bool zones_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
|
|
bool presets_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
|
|
bool palettes_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
|
|
bool sequences_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
|
|
bool groups_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
|
|
bool devices_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
|
|
bool patterns_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
|
|
bool outputs_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
|