Channel 11 defaults, ESP-NOW driver config and rig/desktop updates

Moves the controller, bridge and led-driver default ESP-NOW channel to 11 and
updates the led-driver and led-tool submodule pointers. Includes the rest of the
working tree: web UI, desktop and sim-controller changes, API and bridge code,
graphify output, and the .gitea and fixture-driver folders.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Haiku 5.5 committed 2026-11-21 01:19:02 +13:00
1 parent 35207a868a
commit edf35e9c71
280 files changed
+24043 -1756

No files matched your search

+174 -85
View File
@@ -61,11 +61,11 @@ typedef struct {
int norder; // the lane's targets in order (chase)
bool chase, chase_off;
int corder, width, pos, dir;
char last[ID_MAX]; // preset last uploaded to the lane's targets
} lane_t;
typedef struct {
bool active, overlay;
bool preview; // the editor's preview: plays to the simulated drivers only (seqplay_preview)
char seq[ID_MAX], zone[ID_MAX], profile[ID_MAX];
lane_t *lane;
int nlanes;
@@ -88,6 +88,7 @@ typedef struct {
// Lanes and targets live in PSRAM, allocated by seqplay_init.
static player_t s_base; // the sequence
static player_t s_ovl; // a one-shot sequence over it
static player_t s_prev; // a preview on the simulated drivers; while it plays, the others skip them
static macs_t s_covered; // drivers the one-shot lights; the sequence's sends skip them
static macs_t s_restore; // while set (n > 0), sends go only to these drivers
static bool s_restoring;
@@ -293,8 +294,59 @@ static uint32_t mask_of(const player_t *p, const cJSON *list, int nuser)
return m;
}
// Group ids for a target mask; while an animation plays over the sequence, or while drivers are being
// restored after it, they become the drivers' own groups for just the drivers that may be sent to.
// Which drivers a player may reach: the preview only the simulated ones; while a preview plays, the others
// never the simulated ones
static bool sim_ok(const player_t *p, const char *mac)
{
if (p->preview) {
return engine_mac_is_sim(mac);
}
return !s_prev.active || !engine_mac_is_sim(mac);
}
// Groups as the drivers' own d<mac> groups for just the drivers player p may send to. restoring_rules: also apply
// the one-shot's rules (skip what it covers; while restoring, only the drivers being restored). Wi-Fi drivers
// count by the MAC in their record, like ESP-NOW ones. A group with no sim driver in it stays a group while only
// the preview's rule applies (members without a known MAC keep getting it).
static cJSON *drivers_for(const player_t *p, cJSON *groups, bool restoring_rules)
{
const bool restoring = restoring_rules && s_restoring;
const bool exclude = restoring_rules && p == &s_base && s_ovl.active && s_covered.n;
const bool sim_rule = p->preview || s_prev.active;
if (!restoring && !exclude && !sim_rule) {
return groups;
}
cJSON *drivers = cJSON_CreateArray();
const cJSON *g;
cJSON_ArrayForEach(g, groups)
{
if (!restoring && !exclude && !p->preview && !engine_group_has_sim(g->valuestring)) {
add_id(drivers, g->valuestring); // no simulated driver to leave out
continue;
}
char macs[MACS_MAX][13];
int n = engine_group_macs(g->valuestring, macs, MACS_MAX);
if (!n && !restoring && !p->preview) { // no known members: nothing to leave out
add_id(drivers, g->valuestring);
}
for (int i = 0; i < n; i++) {
bool keep = restoring ? macs_has(&s_restore, macs[i]) : !exclude || !macs_has(&s_covered, macs[i]);
if (keep && sim_rule) {
keep = sim_ok(p, macs[i]);
}
if (keep) {
char gid[GROUP_ID_MAX] = "d";
memcpy(gid + 1, macs[i], 13); // 12 hex digits and the NUL
add_id(drivers, gid);
}
}
}
cJSON_Delete(groups);
return drivers;
}
// Group ids for a target mask; while an animation plays over the sequence, while drivers are being restored
// after it, or while a preview plays, they become the drivers' own groups for just the drivers that may be sent to.
static cJSON *groups_for(const player_t *p, uint32_t mask)
{
cJSON *out = cJSON_CreateArray();
@@ -305,30 +357,7 @@ static cJSON *groups_for(const player_t *p, uint32_t mask)
}
}
}
bool exclude = p == &s_base && s_ovl.active && s_covered.n;
if (!s_restoring && !exclude) {
return out;
}
cJSON *drivers = cJSON_CreateArray();
const cJSON *g;
cJSON_ArrayForEach(g, out)
{
char macs[MACS_MAX][13];
int n = engine_group_macs(g->valuestring, macs, MACS_MAX);
if (!n && !s_restoring) { // no known members: nothing to leave out
add_id(drivers, g->valuestring);
}
for (int i = 0; i < n; i++) {
bool keep = s_restoring ? macs_has(&s_restore, macs[i]) : !macs_has(&s_covered, macs[i]);
if (keep) {
char gid[GROUP_ID_MAX] = "d";
memcpy(gid + 1, macs[i], 13); // 12 hex digits and the NUL
add_id(drivers, gid);
}
}
}
cJSON_Delete(out);
return drivers;
return drivers_for(p, out, true);
}
static void send_msg(cJSON *msg)
@@ -368,24 +397,6 @@ static void upload(const player_t *p, uint32_t mask, cJSON *presets)
send_msg(m);
}
// Upload presets of steps [from, to) of a lane (each once) to all of the lane's targets
static void send_presets(const player_t *p, int lane, int from, int to)
{
const lane_t *l = &p->lane[lane];
cJSON *presets = cJSON_CreateObject();
for (int i = from; i < to && i < l->n; i++) {
const step_t *st = &l->step[i];
if (st->anim || st->rest || !st->id[0] || cJSON_GetObjectItem(presets, st->id)) {
continue;
}
cJSON *pl = engine_preset_payload(st->id);
if (pl) {
cJSON_AddItemToObject(presets, st->id, pl);
}
}
upload(p, l->mask, presets);
}
static void select_on(const player_t *p, uint32_t mask, const char *preset)
{
if (!mask) {
@@ -448,17 +459,14 @@ static void send_lane(player_t *p, int lane)
}
const step_t *st = &l->step[l->idx];
if (st->anim) {
if (!p->overlay && !s_restoring) {
if (!p->overlay && !p->preview && !s_restoring) { // a preview leaves the live one-shot alone
fire(st->id, p->zone, p->profile, true);
}
return;
}
uint32_t lit = st->rest ? 0 : st->mask ? st->mask : l->chase ? chase_mask(l) : l->mask;
// Presets are on the drivers already (sent when saved, or by a sync): a step only selects one
if (lit && st->id[0]) {
if (strcmp(l->last, st->id)) {
send_presets(p, lane, l->idx, l->idx + 1);
memcpy(l->last, st->id, ID_MAX);
}
select_on(p, lit, st->id);
}
if (st->rest || st->others_off || (l->chase && l->chase_off)) {
@@ -611,7 +619,8 @@ static void anchor_bar(void)
}
// Turn off what a sequence lit: its own targets only (they may lie outside its zone). Sequences never use the zone's
// groups; those belong to presets played directly in a zone
// groups; those belong to presets played directly in a zone. Selects the saved "off" preset rather than clearing the
// drivers' preset stores, so the presets stay on the drivers for the next sequence or zone play
static void clear_sequence(const player_t *p)
{
cJSON *groups = cJSON_CreateArray();
@@ -624,10 +633,10 @@ static void clear_sequence(const player_t *p)
cJSON_Delete(groups);
return;
}
cJSON *m = message(groups);
cJSON *m = message(drivers_for(p, groups, false));
if (m) {
cJSON_AddTrueToObject(m, "clear_presets");
cJSON_AddTrueToObject(m, "save");
cJSON *sel = cJSON_AddArrayToObject(m, "select");
cJSON_AddItemToArray(sel, cJSON_CreateString("off"));
send_msg(m);
}
}
@@ -661,13 +670,15 @@ static void zone_brightness(const char *zone_id)
char m[MACS_MAX][13];
int k = engine_group_macs(t[i], m, MACS_MAX);
for (int j = 0; j < k; j++) {
macs_add(&macs, m[j]);
if (!engine_mac_is_wifi(m[j])) { // Wi-Fi drivers get theirs by hostname below
macs_add(&macs, m[j]);
}
}
}
for (int i = 0; i < macs.n; i++) {
zone_brightness_push(macs.m[i], zone_b);
}
// Wi-Fi drivers are listed by hostname, so they are not among the MACs above
// Wi-Fi drivers, by hostname (those with a MAC were left out above)
char w[MACS_MAX][GROUP_ID_MAX];
int nw = engine_zone_wifi_ids(zone_id, w, MACS_MAX);
for (int i = 0; i < nw; i++) {
@@ -709,23 +720,10 @@ static esp_err_t load(player_t *p, const char *seq_id, const char *zone_id, cons
l->t0 = now + (l->timed ? l->t0 : 0);
l->started = l->timed ? l->t0 <= now : l->wait == 0;
}
// Step-0 presets of the lanes that start now, their selects, then every other preset (main's
// _prime_all_lanes)
for (int i = 0; i < p->nlanes; i++) {
lane_t *l = &p->lane[i];
if (l->started) {
send_presets(p, i, 0, 1);
snprintf(l->last, ID_MAX, "%s", l->step[0].rest || l->step[0].anim ? "" : l->step[0].id);
}
}
p->active = true;
for (int i = 0; i < p->nlanes; i++) {
send_lane(p, i);
}
for (int i = 0; i < p->nlanes; i++) {
lane_t *l = &p->lane[i];
send_presets(p, i, l->started ? 1 : 0, l->n);
}
return ESP_OK;
}
@@ -825,16 +823,16 @@ static void note_was(const macs_t *covered)
}
// Put the drivers in `drivers` back to what they showed when the one-shot started: the running sequence, a
// preset, or off. A preset played or stopped on one of their zones since then wins. Wi-Fi drivers (hostname
// ids) are not handled here
static void restore(const macs_t *drivers)
// preset, or off. A preset played or stopped on one of their zones since then wins. Wi-Fi drivers count by
// the MAC in their record. after_ovl: the one-shot is over (not a preview ending: its notes stay)
static void restore(const macs_t *drivers, bool after_ovl)
{
if (!drivers->n) {
return;
}
s_restore = *drivers;
s_restoring = true;
if (s_base_clear_pending) { // the sequence ended under the one-shot
if (after_ovl && s_base_clear_pending) { // the sequence ended under the one-shot
s_base_clear_pending = false;
clear_sequence(&s_base);
}
@@ -862,7 +860,8 @@ static void restore(const macs_t *drivers)
// A noted WAS_BASE here means that sequence has stopped or no longer lights it: off
snprintf(show[nt], ID_MAX, "%s", w->kind == WAS_PRESET ? w->preset : "off");
t[nt].n = 1;
snprintf(t[nt].g[0], GROUP_ID_MAX, "d%s", mac);
t[nt].g[0][0] = 'd';
memcpy(t[nt].g[0] + 1, mac, 13); // 12 hex digits (checked above) and the NUL
nt++;
}
// One send per preset: upload it, then select it on its drivers
@@ -879,7 +878,8 @@ static void restore(const macs_t *drivers)
}
}
done |= mask;
ESP_LOGI(TAG, "one-shot over: %d driver(s) back to %s", __builtin_popcount(mask), show[i]);
ESP_LOGI(TAG, "%s over: %d driver(s) back to %s", after_ovl ? "one-shot" : "preview",
__builtin_popcount(mask), show[i]);
if (strcmp(show[i], "off")) {
cJSON *presets = cJSON_CreateObject();
cJSON *pl = engine_preset_payload(show[i]);
@@ -891,14 +891,14 @@ static void restore(const macs_t *drivers)
select_on(&pt, mask, show[i]);
}
if (back_on_base.n) {
ESP_LOGI(TAG, "one-shot over: %d driver(s) back to sequence %s", back_on_base.n, s_base.seq);
ESP_LOGI(TAG, "%s over: %d driver(s) back to sequence %s", after_ovl ? "one-shot" : "preview",
back_on_base.n, s_base.seq);
s_restore = back_on_base;
for (int i = 0; i < s_base.nlanes; i++) {
s_base.lane[i].last[0] = 0; // they may have missed its upload
send_lane(&s_base, i);
}
}
for (int i = 0; i < drivers->n; i++) {
for (int i = 0; after_ovl && i < drivers->n; i++) {
was_drop(drivers->m[i]);
}
s_restoring = false;
@@ -914,10 +914,44 @@ static void overlay_end(void)
ESP_LOGI(TAG, "one-shot %s over", s_ovl.seq);
macs_t was = s_covered;
s_covered.n = 0;
restore(&was);
restore(&was, true);
s_nwas = 0;
}
// End the preview: the simulated drivers it lit drop its presets, then go back to what the live players show
// them (the one-shot, the sequence, or their zones' last preset)
static void preview_end(void)
{
if (!s_prev.active) {
return;
}
macs_t lit = { 0 }, all = { 0 };
covered_by(&s_prev, &all);
for (int i = 0; i < all.n; i++) {
if (engine_mac_is_sim(all.m[i])) {
macs_add(&lit, all.m[i]);
}
}
s_prev.active = false;
ESP_LOGI(TAG, "preview %s over: %d simulated driver(s)", s_prev.seq, lit.n);
clear_sequence(&s_prev);
// Under the one-shot: it shows them again. The rest: the sequence, a preset, or off
macs_t on_ovl = { 0 }, rest = { 0 };
for (int i = 0; i < lit.n; i++) {
macs_add(s_ovl.active && macs_has(&s_covered, lit.m[i]) ? &on_ovl : &rest, lit.m[i]);
}
if (on_ovl.n) {
s_restore = on_ovl;
s_restoring = true;
for (int i = 0; i < s_ovl.nlanes; i++) {
send_lane(&s_ovl, i);
}
s_restoring = false;
s_restore.n = 0;
}
restore(&rest, false);
}
// Play sequence seq_id once over whatever runs (a one-shot). A new one replaces the one playing; drivers the new one
// leaves alone go back to what they showed.
static void fire(const char *seq_id, const char *zone_id, const char *profile_id, bool synced)
@@ -930,7 +964,7 @@ static void fire(const char *seq_id, const char *zone_id, const char *profile_id
s_covered.n = 0;
if (load(&s_ovl, seq_id, zone_id, profile_id, synced, &msg) != ESP_OK) {
ESP_LOGW(TAG, "one-shot %s did not start: %s", seq_id, msg ? msg : "not found");
restore(&was);
restore(&was, true);
s_nwas = 0;
return;
}
@@ -942,7 +976,7 @@ static void fire(const char *seq_id, const char *zone_id, const char *profile_id
macs_add(&back, was.m[i]);
}
}
restore(&back);
restore(&back, true);
ESP_LOGI(TAG, "one-shot %s in zone %s: %d lane(s), %d driver(s)", seq_id, zone_id, s_ovl.nlanes, s_covered.n);
}
@@ -969,7 +1003,7 @@ static void step_lane(player_t *p, int i, int64_t now)
l->count = 0;
l->idx = 0;
l->t0 = start;
l->last[0] = 0; // step 0 goes up again on each wrap
// no re-upload on a wrap: the lane's presets are still on the drivers from its start
if (l->chase) {
chase_move(l);
}
@@ -1005,6 +1039,10 @@ static void finish_if_done(player_t *p)
overlay_end();
return;
}
if (p->preview) {
preview_end();
return;
}
readout(s_done_readout, sizeof(s_done_readout));
p->active = false;
if (s_ovl.active) {
@@ -1066,7 +1104,7 @@ static void tick(player_t *p, bool beat)
}
}
}
if (beat && !p->overlay) {
if (beat && !p->overlay && !p->preview) {
if (p->anchor_next && !p->lane[0].timed) {
anchor_bar();
}
@@ -1100,6 +1138,7 @@ static void sub_tick(void)
store_lock();
tick(&s_base, false);
tick(&s_ovl, false);
tick(&s_prev, false);
store_unlock();
}
@@ -1146,6 +1185,7 @@ static void on_beat(bool downbeat)
if (!fired) {
tick(&s_ovl, true);
}
tick(&s_prev, true);
store_unlock();
}
@@ -1160,6 +1200,7 @@ static void beat_task(void *arg)
store_lock();
advance_time(&s_base);
advance_time(&s_ovl);
advance_time(&s_prev);
int64_t interval = 60LL * 1000000 / simulated_bpm();
store_unlock();
int64_t now = esp_timer_get_time();
@@ -1207,8 +1248,8 @@ static void beat_task(void *arg)
esp_err_t seqplay_init(void)
{
player_t *ps[] = { &s_base, &s_ovl };
for (int i = 0; i < 2; i++) {
player_t *ps[] = { &s_base, &s_ovl, &s_prev };
for (int i = 0; i < 3; i++) {
ps[i]->lane = heap_caps_calloc(LANES_MAX, sizeof(lane_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
ps[i]->target = heap_caps_calloc(TARGETS_MAX, sizeof(target_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
if (!ps[i]->lane || !ps[i]->target) {
@@ -1216,6 +1257,7 @@ esp_err_t seqplay_init(void)
}
}
s_ovl.overlay = true;
s_prev.preview = true;
store_lock();
const cJSON *a = cJSON_GetObjectItem(store_settings(), "audio_timing");
s_audio = !cJSON_IsFalse(a);
@@ -1290,6 +1332,36 @@ esp_err_t seqplay_fire(const char *seq_id, const char *zone_id, const char *prof
return ESP_OK;
}
esp_err_t seqplay_preview(const char *seq_id, const char *zone_id, const char *profile_id, const char **msg)
{
*msg = NULL;
if (!owned(seq_id, profile_id)) {
*msg = "sequence not found";
return ESP_ERR_NOT_FOUND;
}
if (!zone_id || !zone_id[0]) {
zone_id = s_base.active ? s_base.zone : NULL;
}
if (!zone_id || !cJSON_GetObjectItem(store_coll("zone"), zone_id)) {
*msg = "zone not found";
return ESP_ERR_INVALID_ARG;
}
preview_end(); // a new preview replaces the one playing
esp_err_t err = load(&s_prev, seq_id, zone_id, profile_id, false, msg);
if (err != ESP_OK) {
return err;
}
ESP_LOGI(TAG, "preview %s in zone %s: %d lane(s)", seq_id, zone_id, s_prev.nlanes);
return ESP_OK;
}
void seqplay_preview_stop(void)
{
store_lock();
preview_end();
store_unlock();
}
void seqplay_overlay_stop(void)
{
store_lock();
@@ -1347,6 +1419,9 @@ void seqplay_stop_if(const char *seq_id)
store_lock();
bool playing = s_base.active && !strcmp(s_base.seq, seq_id);
bool anim = s_ovl.active && !strcmp(s_ovl.seq, seq_id);
if (s_prev.active && !strcmp(s_prev.seq, seq_id)) {
preview_end();
}
store_unlock();
if (playing) {
seqplay_stop(true);
@@ -1525,11 +1600,25 @@ static cJSON *overlay_status(void)
return o;
}
static cJSON *preview_status(void)
{
cJSON *o = cJSON_CreateObject();
cJSON_AddBoolToObject(o, "active", s_prev.active);
if (s_prev.active) {
cJSON_AddStringToObject(o, "sequence_id", s_prev.seq);
cJSON_AddStringToObject(o, "zone_id", s_prev.zone);
cJSON_AddBoolToObject(o, "loop", s_prev.loop);
cJSON_AddItemToObject(o, "lanes", lanes_status(&s_prev));
}
return o;
}
cJSON *seqplay_status(void)
{
cJSON *o = cJSON_CreateObject();
store_lock();
cJSON_AddItemToObject(o, "overlay", overlay_status());
cJSON_AddItemToObject(o, "preview", preview_status());
if (!s_base.active) {
cJSON_AddFalseToObject(o, "active");
cJSON_AddStringToObject(o, "beat_readout", "");