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:
jimmyandClaude Opus 5.5 committed 2026-11-16 19:32:46 +13:00
1 parent 698c1463c0
commit 581b751904
506 files changed
+42336 -3599

No files matched your search

+73
View File
@@ -32,6 +32,27 @@ static int setting_int(const char *key, int dflt, int lo, int hi)
return x < lo ? lo : (x > hi ? hi : x);
}
#ifdef LED_DESKTOP_ALSA
// Desktop: the microphone reads the device chosen in the settings while audio is running
static void mic_follow_setting(bool start)
{
if (!start) {
mic_close();
return;
}
char dev[128] = "";
store_lock();
const cJSON *sel = cJSON_GetObjectItem(store_settings(), "audio_device_select");
if (cJSON_IsString(sel) && strlen(sel->valuestring) < sizeof(dev)) {
strcpy(dev, sel->valuestring);
}
store_unlock();
if (mic_open(dev) != ESP_OK) {
ESP_LOGW(TAG, "cannot use audio device \"%s\"", dev);
}
}
#endif
static cJSON *audio_run(void)
{
cJSON *o = cJSON_CreateObject();
@@ -57,8 +78,23 @@ static cJSON *status_payload(void)
store_lock();
int sim_bpm = setting_int("audio_simulated_bpm", 120, 60, 200);
cJSON_AddBoolToObject(o, "running", running);
#ifdef LED_DESKTOP_ALSA
const cJSON *dev = cJSON_GetObjectItem(store_settings(), "audio_device_select");
cJSON_AddStringToObject(o, "device", cJSON_IsString(dev) ? dev->valuestring : "");
#else
cJSON_AddStringToObject(o, "device", "i2s");
#endif
#ifdef LED_DESKTOP_ALSA
char mic_err[160];
mic_error(mic_err, sizeof(mic_err));
if (mic_err[0]) {
cJSON_AddStringToObject(o, "error", mic_err);
} else {
cJSON_AddNullToObject(o, "error");
}
#else
cJSON_AddNullToObject(o, "error");
#endif
if (!running) {
cJSON_AddNumberToObject(o, "bpm", sim_bpm);
} else if (bi.locked && bi.bpm > 0) {
@@ -238,6 +274,23 @@ static esp_err_t audio_handler(httpd_req_t *req)
if (req->method == HTTP_GET && !strcmp(act, "events")) {
return events(req);
}
#ifdef LED_DESKTOP_ALSA
if (req->method == HTTP_GET && !strcmp(act, "devices")) {
cJSON *o = cJSON_CreateObject(), *devs = cJSON_AddArrayToObject(o, "devices");
mic_device_t found[16];
int n = mic_list_devices(found, 16);
for (int i = 0; i < n; i++) {
cJSON *d = cJSON_CreateObject();
cJSON_AddStringToObject(d, "id", found[i].id);
cJSON_AddStringToObject(d, "name", found[i].name);
cJSON_AddStringToObject(d, "display_name", found[i].name);
cJSON_AddStringToObject(d, "label", found[i].label);
cJSON_AddItemToArray(devs, d);
}
cJSON_AddObjectToObject(o, "diagnostics");
return send_json(req, "200 OK", o);
}
#endif
if (req->method == HTTP_GET && !strcmp(act, "devices")) {
cJSON *o = cJSON_CreateObject(), *devs = cJSON_AddArrayToObject(o, "devices"), *d = cJSON_CreateObject();
cJSON_AddStringToObject(d, "id", "i2s");
@@ -257,10 +310,18 @@ static esp_err_t audio_handler(httpd_req_t *req)
store_lock();
api_set(store_settings(), "audio_device_select", cJSON_CreateString(cJSON_IsString(sel) ? sel->valuestring : ""));
store_save("settings");
#ifdef LED_DESKTOP_ALSA
bool reopen = mic_is_open(); // switch a running detector to the new device, after the store unlock
#endif
cJSON *o = cJSON_CreateObject();
cJSON_AddTrueToObject(o, "ok");
cJSON_AddItemToObject(o, "audio_run", audio_run());
store_unlock();
#ifdef LED_DESKTOP_ALSA
if (reopen) {
mic_follow_setting(true);
}
#endif
cJSON_Delete(body);
return send_json(req, "200 OK", o);
}
@@ -269,6 +330,9 @@ static esp_err_t audio_handler(httpd_req_t *req)
}
if (!strcmp(act, "start") || !strcmp(act, "stop")) {
seqplay_set_audio(act[2] == 'a'); // st[a]rt
#ifdef LED_DESKTOP_ALSA
mic_follow_setting(act[2] == 'a');
#endif
ESP_LOGI(TAG, "mic beats %s sequences", act[2] == 'a' ? "time" : "no longer time");
return ok_with_status(req);
}
@@ -289,6 +353,15 @@ static esp_err_t audio_handler(httpd_req_t *req)
return httpd_resp_send_404(req);
}
#ifdef LED_DESKTOP_ALSA
void audio_api_resume_mic(void)
{
if (seqplay_audio()) {
mic_follow_setting(true);
}
}
#endif
esp_err_t audio_api_register(httpd_handle_t server)
{
static const httpd_method_t METHODS[] = { HTTP_GET, HTTP_POST, HTTP_PUT };