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
+121
@@ -8,7 +8,10 @@
|
||||
#include "cJSON.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "bench.h"
|
||||
#include "bridge.h"
|
||||
#include "engine.h"
|
||||
#include "espnow_tx.h"
|
||||
#include "sdkconfig.h"
|
||||
@@ -408,6 +411,10 @@ static esp_err_t put_settings(httpd_req_t *req)
|
||||
if (!bad && br && !cJSON_IsNull(br) && !(cJSON_IsString(br) && strlen(br->valuestring) < 64)) {
|
||||
bad = "bridge must be \"host:port\", empty or null";
|
||||
}
|
||||
const cJSON *brs = cJSON_GetObjectItem(body, "bridges");
|
||||
if (!bad && brs && !cJSON_IsNull(brs) && !(cJSON_IsArray(brs) && cJSON_GetArraySize(brs) <= BRIDGE_MAX_LINKS)) {
|
||||
bad = "bridges must be a list of up to 8 addresses";
|
||||
}
|
||||
const cJSON *sw = cJSON_GetObjectItem(body, "sequence_switch_wait");
|
||||
if (!bad && sw && !cJSON_IsNull(sw) &&
|
||||
!(cJSON_IsString(sw) && (!strcasecmp(sw->valuestring, "beat") || !strcasecmp(sw->valuestring, "downbeat")))) {
|
||||
@@ -430,6 +437,114 @@ static esp_err_t put_settings(httpd_req_t *req)
|
||||
return api_message(req, "200 OK", "Settings updated successfully");
|
||||
}
|
||||
|
||||
// The bridges the controller sends its ESP-NOW frames to (USB boards, network boards, the simulator).
|
||||
// GET /settings/bridge: {supported, bridges: [{addr, kind, status}], ports}.
|
||||
// PUT /settings/bridge: {bridges: [addr, ...]} sets the whole list; {addr, channel} sets a board's channel.
|
||||
// Both apply at once on the host; a device reads the list at the next restart.
|
||||
static esp_err_t bridge_get(httpd_req_t *req)
|
||||
{
|
||||
char links[1536], ports[512];
|
||||
bridge_status_json(links, sizeof(links));
|
||||
bridge_ports_json(ports, sizeof(ports));
|
||||
cJSON *out = cJSON_CreateObject();
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
cJSON_AddBoolToObject(out, "supported", true);
|
||||
#else
|
||||
cJSON_AddBoolToObject(out, "supported", false);
|
||||
#endif
|
||||
cJSON_AddItemToObject(out, "bridges", cJSON_Parse(links));
|
||||
cJSON_AddItemToObject(out, "ports", cJSON_Parse(ports));
|
||||
return api_json(req, "200 OK", out, true);
|
||||
}
|
||||
|
||||
// Save the list the running bridges actually have (a bridge that failed to open is not kept)
|
||||
static void bridge_store(void)
|
||||
{
|
||||
char addrs[BRIDGE_MAX_LINKS][BRIDGE_ADDR_MAX];
|
||||
size_t n = bridge_list(addrs, BRIDGE_MAX_LINKS);
|
||||
cJSON *list = cJSON_CreateArray();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
cJSON_AddItemToArray(list, cJSON_CreateString(addrs[i]));
|
||||
}
|
||||
cJSON *patch = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(patch, "bridges", list);
|
||||
cJSON_AddStringToObject(patch, "bridge", n ? addrs[0] : "");
|
||||
api_merge(store_settings(), patch);
|
||||
cJSON_Delete(patch);
|
||||
store_save("settings");
|
||||
}
|
||||
|
||||
static esp_err_t bridge_put(httpd_req_t *req)
|
||||
{
|
||||
#if !CONFIG_IDF_TARGET_LINUX
|
||||
return api_error(req, "404 Not Found", "the bridges are set in the controller settings on this build");
|
||||
#endif
|
||||
cJSON *body = api_body(req);
|
||||
if (!body) {
|
||||
return ESP_OK;
|
||||
}
|
||||
const cJSON *list = cJSON_GetObjectItem(body, "bridges");
|
||||
const cJSON *addr = cJSON_GetObjectItem(body, "addr");
|
||||
const cJSON *ch = cJSON_GetObjectItem(body, "channel");
|
||||
const char *bad = NULL;
|
||||
if (!list && !(addr && ch)) {
|
||||
bad = "send bridges (a list), or addr and channel";
|
||||
} else if (list && !cJSON_IsArray(list)) {
|
||||
bad = "bridges must be a list of addresses";
|
||||
} else if (list && cJSON_GetArraySize(list) > BRIDGE_MAX_LINKS) {
|
||||
bad = "too many bridges";
|
||||
} else if (addr && !cJSON_IsString(addr)) {
|
||||
bad = "addr must be a board port (/dev/...) or host:port";
|
||||
} else if (ch && !(cJSON_IsNumber(ch) && ch->valueint >= 1 && ch->valueint <= 13)) {
|
||||
bad = "channel must be 1 to 13";
|
||||
}
|
||||
const cJSON *item = NULL;
|
||||
if (!bad && list) {
|
||||
cJSON_ArrayForEach(item, list) {
|
||||
if (!cJSON_IsString(item) || strlen(item->valuestring) >= BRIDGE_ADDR_MAX) {
|
||||
bad = "each bridge must be a board port (/dev/...), host:port or serial:/dev/...";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bad) {
|
||||
cJSON_Delete(body);
|
||||
return api_error(req, "400 Bad Request", bad);
|
||||
}
|
||||
if (list) {
|
||||
char addrs[BRIDGE_MAX_LINKS][BRIDGE_ADDR_MAX];
|
||||
size_t n = 0;
|
||||
cJSON_ArrayForEach(item, list) {
|
||||
snprintf(addrs[n], BRIDGE_ADDR_MAX, "%s", item->valuestring);
|
||||
n++;
|
||||
}
|
||||
esp_err_t err = espnow_tx_change_bridges(addrs, n);
|
||||
bridge_store();
|
||||
if (err != ESP_OK) {
|
||||
cJSON_Delete(body);
|
||||
return api_error(req, "400 Bad Request", "one of the bridges could not be opened (the others are running)");
|
||||
}
|
||||
}
|
||||
if (addr && ch) {
|
||||
// A board just switched in answers its INFO a moment later: wait up to 3 s for it before giving up
|
||||
esp_err_t err = ESP_OK;
|
||||
for (int tries = 0; tries < 30; tries++) {
|
||||
err = bridge_board_set_channel(addr->valuestring, (uint8_t)ch->valueint);
|
||||
if (err != ESP_ERR_INVALID_STATE) {
|
||||
break;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
}
|
||||
if (err != ESP_OK) {
|
||||
cJSON_Delete(body);
|
||||
return api_error(req, "400 Bad Request",
|
||||
err == ESP_ERR_INVALID_STATE ? "the board did not answer, so its channel was not set"
|
||||
: "no running bridge board has that address");
|
||||
}
|
||||
}
|
||||
cJSON_Delete(body);
|
||||
return api_message(req, "200 OK", "Bridges updated");
|
||||
}
|
||||
|
||||
static esp_err_t settings_handler_inner(httpd_req_t *req)
|
||||
{
|
||||
api_seg_t seg;
|
||||
@@ -443,6 +558,12 @@ static esp_err_t settings_handler_inner(httpd_req_t *req)
|
||||
if (n == 1 && req->method == HTTP_GET) {
|
||||
return api_json(req, "200 OK", store_settings(), false);
|
||||
}
|
||||
if (n == 2 && strcmp(seg[1], "bridge") == 0 && req->method == HTTP_GET) {
|
||||
return bridge_get(req);
|
||||
}
|
||||
if (n == 2 && strcmp(seg[1], "bridge") == 0 && req->method == HTTP_PUT) {
|
||||
return bridge_put(req);
|
||||
}
|
||||
if (req->method == HTTP_PUT && (n == 1 || (n == 2 && strcmp(seg[1], "settings") == 0))) {
|
||||
return put_settings(req);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user