feat: browser simulator served by the controller, desktop build, browser bridge
- 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>
This commit is contained in:
1 parent
698c1463c0
commit
581b751904
506 files changed
+42336
-3599
No files matched your search
+61
-24
@@ -87,11 +87,11 @@ typedef struct {
|
||||
// Everything below is guarded by the store lock (the beat task and the HTTP handlers both take it).
|
||||
// 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 animation over it
|
||||
static macs_t s_covered; // drivers the animation lights; the sequence's sends skip them
|
||||
static player_t s_ovl; // a one-shot sequence over it
|
||||
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;
|
||||
static bool s_base_clear_pending; // the sequence ended under the animation: clear once it is over
|
||||
static bool s_base_clear_pending; // the sequence ended under the one-shot: clear once it is over
|
||||
|
||||
static struct {
|
||||
bool set;
|
||||
@@ -145,6 +145,19 @@ static bool str_is(const cJSON *o, const char *k, const char *want)
|
||||
return cJSON_IsString(v) && !strcmp(v->valuestring, want);
|
||||
}
|
||||
|
||||
// A sequence loops unless its `loop` is off. Older records: kind "animation" with no `loop` plays once.
|
||||
static bool seq_oneshot(const cJSON *seq)
|
||||
{
|
||||
const cJSON *loop = cJSON_GetObjectItem(seq, "loop");
|
||||
if (cJSON_IsBool(loop)) {
|
||||
return cJSON_IsFalse(loop);
|
||||
}
|
||||
if (cJSON_IsNumber(loop)) {
|
||||
return loop->valuedouble == 0;
|
||||
}
|
||||
return str_is(seq, "kind", "animation");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- targets */
|
||||
|
||||
static void add_id(cJSON *arr, const char *id)
|
||||
@@ -309,7 +322,7 @@ static cJSON *groups_for(const player_t *p, uint32_t mask)
|
||||
return drivers;
|
||||
}
|
||||
|
||||
static void send(cJSON *msg)
|
||||
static void send_msg(cJSON *msg)
|
||||
{
|
||||
cJSON *messages = cJSON_CreateArray();
|
||||
cJSON_AddItemToArray(messages, msg);
|
||||
@@ -343,7 +356,7 @@ static void upload(const player_t *p, uint32_t mask, cJSON *presets)
|
||||
return;
|
||||
}
|
||||
cJSON_AddItemToObject(m, "presets", presets);
|
||||
send(m);
|
||||
send_msg(m);
|
||||
}
|
||||
|
||||
// Upload presets of steps [from, to) of a lane (each once) to all of the lane's targets
|
||||
@@ -373,7 +386,7 @@ static void select_on(const player_t *p, uint32_t mask, const char *preset)
|
||||
if (m) {
|
||||
cJSON *sel = cJSON_AddArrayToObject(m, "select");
|
||||
cJSON_AddItemToArray(sel, cJSON_CreateString(preset));
|
||||
send(m);
|
||||
send_msg(m);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,7 +483,8 @@ static int load_lanes(player_t *p, const cJSON *seq)
|
||||
const int nuser = p->ntargets;
|
||||
const cJSON *lgs = cJSON_GetObjectItem(seq, "lanes_group_ids");
|
||||
const cJSON *opts = cJSON_GetObjectItem(seq, "lane_opts");
|
||||
const bool seq_timed = str_is(seq, "advance_mode", "time");
|
||||
// A one-shot is always timed in seconds, whatever its advance_mode or lane modes say
|
||||
const bool seq_timed = seq_oneshot(seq) || str_is(seq, "advance_mode", "time");
|
||||
int n = 0, src = -1;
|
||||
cJSON_ArrayForEach(l, lanes)
|
||||
{
|
||||
@@ -482,7 +496,7 @@ static int load_lanes(player_t *p, const cJSON *seq)
|
||||
lane_t *lane = &p->lane[n];
|
||||
memset(lane, 0, sizeof(*lane));
|
||||
const cJSON *mode = cJSON_GetObjectItem(o, "mode");
|
||||
lane->timed = cJSON_IsString(mode) ? !strcmp(mode->valuestring, "time") : seq_timed;
|
||||
lane->timed = seq_oneshot(seq) || (cJSON_IsString(mode) ? !strcmp(mode->valuestring, "time") : seq_timed);
|
||||
double rate = num(o, "rate", 1);
|
||||
rate = rate < 0.25 ? 0.25 : (rate > 4 ? 4 : rate);
|
||||
// Targets: the lane's own list, else the older group fields, else the zone's
|
||||
@@ -599,7 +613,7 @@ static void clear_drivers(const char *zone)
|
||||
if (m) {
|
||||
cJSON_AddTrueToObject(m, "clear_presets");
|
||||
cJSON_AddTrueToObject(m, "save");
|
||||
send(m);
|
||||
send_msg(m);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,9 +670,8 @@ static esp_err_t load(player_t *p, const char *seq_id, const char *zone_id, cons
|
||||
*msg = "sequence has no steps";
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
const cJSON *loop = cJSON_GetObjectItem(seq, "loop");
|
||||
bool on = cJSON_IsTrue(loop) || (cJSON_IsNumber(loop) && loop->valuedouble != 0);
|
||||
p->loop = p->overlay ? on : (!loop || on); // a sequence loops unless told not to; an animation plays once
|
||||
// Over the zone (a one-shot, or a clip in another sequence) it always plays once
|
||||
p->loop = !p->overlay && !seq_oneshot(seq);
|
||||
p->synced = synced;
|
||||
p->loop_beat = 0;
|
||||
p->lane0_looped = false;
|
||||
@@ -706,7 +719,7 @@ static esp_err_t start_now(const char *seq_id, const char *zone_id, const char *
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// Drivers an animation may light: every target its lanes name
|
||||
// Drivers a one-shot may light: every target its lanes name
|
||||
static void covered_by(const player_t *p, macs_t *out)
|
||||
{
|
||||
out->n = 0;
|
||||
@@ -725,7 +738,7 @@ static void covered_by(const player_t *p, macs_t *out)
|
||||
}
|
||||
}
|
||||
|
||||
// Bring back what the drivers in `drivers` showed before the animation: the sequence's current steps,
|
||||
// Bring back what the drivers in `drivers` showed before the one-shot: the sequence's current steps,
|
||||
// else the zone's last preset, else off
|
||||
static void restore(const macs_t *drivers, const char *zone)
|
||||
{
|
||||
@@ -775,13 +788,13 @@ static void overlay_end(void)
|
||||
return;
|
||||
}
|
||||
s_ovl.active = false;
|
||||
ESP_LOGI(TAG, "animation %s over", s_ovl.seq);
|
||||
ESP_LOGI(TAG, "one-shot %s over", s_ovl.seq);
|
||||
macs_t was = s_covered;
|
||||
s_covered.n = 0;
|
||||
restore(&was, s_ovl.zone);
|
||||
}
|
||||
|
||||
// Play animation seq_id once over whatever runs. A new one replaces the one playing; drivers the new one
|
||||
// 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)
|
||||
{
|
||||
@@ -789,10 +802,10 @@ static void fire(const char *seq_id, const char *zone_id, const char *profile_id
|
||||
macs_t was = s_ovl.active ? s_covered : (macs_t){ 0 };
|
||||
s_ovl.active = false;
|
||||
const char *msg = NULL;
|
||||
// Work out what the animation covers before it sends anything, so the sequence keeps off those drivers
|
||||
// Work out what the one-shot covers before it sends anything, so the sequence keeps off those drivers
|
||||
s_covered.n = 0;
|
||||
if (load(&s_ovl, seq_id, zone_id, profile_id, synced, &msg) != ESP_OK) {
|
||||
ESP_LOGW(TAG, "animation %s did not start: %s", seq_id, msg ? msg : "not found");
|
||||
ESP_LOGW(TAG, "one-shot %s did not start: %s", seq_id, msg ? msg : "not found");
|
||||
restore(&was, zone_id);
|
||||
return;
|
||||
}
|
||||
@@ -804,7 +817,7 @@ static void fire(const char *seq_id, const char *zone_id, const char *profile_id
|
||||
}
|
||||
}
|
||||
restore(&back, zone_id);
|
||||
ESP_LOGI(TAG, "animation %s in zone %s: %d lane(s), %d driver(s)", seq_id, zone_id, s_ovl.nlanes, s_covered.n);
|
||||
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);
|
||||
}
|
||||
|
||||
// Move a lane on once its step is over
|
||||
@@ -859,7 +872,7 @@ static void finish_if_done(player_t *p)
|
||||
readout(s_done_readout, sizeof(s_done_readout));
|
||||
p->active = false;
|
||||
if (s_ovl.active) {
|
||||
s_base_clear_pending = true; // the animation still shows; clear once it is over
|
||||
s_base_clear_pending = true; // the one-shot still shows; clear once it is over
|
||||
} else {
|
||||
clear_drivers(p->zone);
|
||||
}
|
||||
@@ -1072,6 +1085,15 @@ esp_err_t seqplay_init(void)
|
||||
return xTaskCreate(beat_task, "seqplay", 8192, NULL, 4, NULL) == pdPASS ? ESP_OK : ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
bool seqplay_is_oneshot(const char *seq_id)
|
||||
{
|
||||
store_lock();
|
||||
const cJSON *seq = cJSON_GetObjectItem(store_coll("sequence"), seq_id);
|
||||
bool one = seq && seq_oneshot(seq);
|
||||
store_unlock();
|
||||
return one;
|
||||
}
|
||||
|
||||
static bool owned(const char *seq_id, const char *profile_id)
|
||||
{
|
||||
const cJSON *seq = cJSON_GetObjectItem(store_coll("sequence"), seq_id);
|
||||
@@ -1103,7 +1125,7 @@ esp_err_t seqplay_fire(const char *seq_id, const char *zone_id, const char *prof
|
||||
{
|
||||
*msg = NULL;
|
||||
if (!owned(seq_id, profile_id)) {
|
||||
*msg = "animation not found";
|
||||
*msg = "sequence not found";
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
if (!zone_id || !zone_id[0]) {
|
||||
@@ -1123,7 +1145,7 @@ esp_err_t seqplay_fire(const char *seq_id, const char *zone_id, const char *prof
|
||||
}
|
||||
fire(seq_id, zone_id, profile_id, false);
|
||||
if (!s_ovl.active) {
|
||||
*msg = "animation has no steps";
|
||||
*msg = "sequence has no steps";
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
return ESP_OK;
|
||||
@@ -1161,6 +1183,21 @@ void seqplay_stop(bool clear)
|
||||
store_unlock();
|
||||
}
|
||||
|
||||
void seqplay_end_base_in(const char *zone_id)
|
||||
{
|
||||
store_lock();
|
||||
if (s_pend.set && !strcmp(s_pend.zone, zone_id)) {
|
||||
s_pend.set = false;
|
||||
s_base.pending_switch = false;
|
||||
}
|
||||
if (s_base.active && !strcmp(s_base.zone, zone_id)) {
|
||||
s_base.active = false;
|
||||
s_base_clear_pending = false;
|
||||
ESP_LOGI(TAG, "sequence %s in zone %s: a preset took over", s_base.seq, zone_id);
|
||||
}
|
||||
store_unlock();
|
||||
}
|
||||
|
||||
void seqplay_stop_if(const char *seq_id)
|
||||
{
|
||||
store_lock();
|
||||
@@ -1210,7 +1247,7 @@ void seqplay_length(const char *seq_id, double *beats, double *secs)
|
||||
{
|
||||
const cJSON *seq = cJSON_GetObjectItem(store_coll("sequence"), seq_id);
|
||||
const cJSON *opts = cJSON_GetObjectItem(seq, "lane_opts");
|
||||
bool seq_timed = str_is(seq, "advance_mode", "time");
|
||||
bool seq_timed = seq_oneshot(seq) || str_is(seq, "advance_mode", "time");
|
||||
double b = 0, s = 0;
|
||||
int src = -1;
|
||||
const cJSON *l;
|
||||
@@ -1219,7 +1256,7 @@ void seqplay_length(const char *seq_id, double *beats, double *secs)
|
||||
src++;
|
||||
const cJSON *o = cJSON_GetArrayItem(opts, src);
|
||||
const cJSON *mode = cJSON_GetObjectItem(o, "mode");
|
||||
bool timed = cJSON_IsString(mode) ? !strcmp(mode->valuestring, "time") : seq_timed;
|
||||
bool timed = seq_oneshot(seq) || (cJSON_IsString(mode) ? !strcmp(mode->valuestring, "time") : seq_timed);
|
||||
double rate = num(o, "rate", 1);
|
||||
rate = rate < 0.25 ? 0.25 : (rate > 4 ? 4 : rate);
|
||||
double total = 0;
|
||||
|
||||
Reference in new issue
Block a user