feat: sequences v2, bridges, and sim-controller

Rework sequences (engine, seqplay, envelope, API, web UI), add bridge
support, add the host sim-controller and rig simulation tests, and
update docs, presets and project tooling config.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Sonnet 5.5 committed 2026-11-10 17:47:27 +13:00
1 parent d664026ee5
commit 2543673bd8
68 files changed
+5761 -460

No files matched your search

+44 -8
View File
@@ -59,7 +59,7 @@ static bool s_save; // append the CMD save byte (driver persists presets / br
// drivers in that group apply them. JSON messages go as they are.
static size_t wrap_wire(uint8_t *out, const uint8_t *frame, size_t len)
{
if (len == 0 || frame[0] != 2) { // not a v2 envelope
if (len == 0 || (frame[0] != 2 && frame[0] != 3)) { // not a v2/v3 envelope (JSON goes as it is)
memcpy(out, frame, len);
return len;
}
@@ -257,6 +257,9 @@ static bool in_group(const uint8_t mac[6], const char *name, const char *gid)
}
char hex[13];
snprintf(hex, sizeof(hex), "%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
if (gid[0] == 'd' && strlen(gid) == 13) { // a driver's own group, d<mac>
return !strcmp(gid + 1, hex);
}
return mac_listed(cJSON_GetObjectItem(cJSON_GetObjectItem(store_coll("group"), gid), "devices"), hex);
}
@@ -355,6 +358,32 @@ static esp_err_t play_locked(const char *zone_id, const char *preset_id)
return ret;
}
const char *engine_zone_current(const char *zone_id)
{
for (int i = 0; i < 16; i++) {
if (s_cur[i].zone[0] && !strcmp(s_cur[i].zone, zone_id)) {
return s_cur[i].preset;
}
}
return NULL;
}
int engine_group_macs(const char *gid, char out[][13], int max)
{
int n = 0;
const cJSON *d;
cJSON_ArrayForEach(d, store_coll("device"))
{
uint8_t mac[6];
const cJSON *name = cJSON_GetObjectItem(d, "name");
if (n < max && d->string && parse_mac(d->string, mac) &&
in_group(mac, cJSON_IsString(name) ? name->valuestring : NULL, gid)) {
snprintf(out[n++], 13, "%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
}
return n;
}
esp_err_t engine_play(const char *zone_id, const char *preset_id)
{
store_lock();
@@ -493,8 +522,9 @@ static const char *const TOP_SHORT[][2] = {
};
static const char *const PRESET_SHORT[][2] = {
{ "pattern", "p" }, { "colors", "c" }, { "delay", "d" }, { "brightness", "b" }, { "auto", "a" }, { "background", "bg" },
{ "fade", "f" }, { "beat_time", "tb" },
};
static const char *const PRESET_KEYS[] = { "p", "c", "d", "b", "a", "bg", "n1", "n2", "n3", "n4", "n5", "n6" };
static const char *const PRESET_KEYS[] = { "p", "c", "d", "b", "a", "bg", "n1", "n2", "n3", "n4", "n5", "n6", "f", "tb" };
static const char *short_key(const char *const map[][2], size_t n, const char *k)
{
@@ -758,17 +788,22 @@ static esp_err_t send_cmd(const uint8_t mac[6], const uint8_t *env, size_t len,
return rel_send(mac, wire, len + 2, commit, 1);
}
// GROUPS packet: the ids of every zone whose driver names include `name`. An empty list replaces
// whatever the driver stored, so it is only sent when allow_empty is set (a zone or device was edited);
// a driver that merely announced itself and is in no zone keeps the groups it already has.
// GROUPS packet for a driver: [4C][02][count] then per zone [len][zone id]. Returns its length;
// *count gets the number of zones.
// GROUPS packet: the driver's own group d<mac> (sequences address single drivers with it), then every
// group and zone it belongs to. A list with nothing but its own group replaces whatever the driver
// stored, so it is only sent when allow_empty is set (a zone or device was edited); a driver that merely
// announced itself and is in no zone keeps the groups it already has.
// Wire: [4C][02][count] then per id [len][id]. Returns its length; *count gets the number of groups and
// zones (not counting its own group).
static size_t build_groups(uint8_t pkt[REL_FRAG_MAX], const uint8_t mac[6], const char *name, int *count)
{
size_t off = 3;
*count = 0;
const cJSON *g;
char gid[GROUP_ID_MAX];
// Its own group first, so a long list never cuts it off
pkt[off++] = 13;
off += snprintf((char *)pkt + off, REL_FRAG_MAX - off, "d%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3],
mac[4], mac[5]);
cJSON_ArrayForEach(g, store_coll("group"))
{
size_t gl = strlen(g->string);
@@ -795,7 +830,8 @@ static size_t build_groups(uint8_t pkt[REL_FRAG_MAX], const uint8_t mac[6], cons
}
pkt[0] = 0x4C;
pkt[1] = 0x02; // GROUPS
pkt[2] = *count;
pkt[2] = *count + 1; // *count leaves out the driver's own group
return off;
}