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

+187
View File
@@ -0,0 +1,187 @@
/* led-fixture: one led-driver for a fixture of the controller's DMX bridge (main/bridge_dmx.c). The driver is
* led-driver/main's, unchanged, on sim-driver's platform shims, built natively: its pattern and ESP-NOW link tasks run
* as threads, as on the board. The bridge starts one per fixture and talks to it over stdin and stdout:
*
* [type u8][len u16 little endian][payload]
* 'R' in: src MAC (6) + packet, a frame the radio received
* 'T' out: dest MAC (6) + packet, a frame the driver sends
* 'F' out: the strip's frame, RGB, pixel 0 first, every 25 ms (40 Hz)
*
* 'B' out: one byte, the output level (device x master x ceiling), sent before each 'F'
*
* Logs go to stderr. The flash is the JSON file given on the command line (sim_nvs_dump's format); each commit
* writes it back. esp_restart() exits with status 3, and the bridge starts the driver again.
*
* With "dimmer", the fixture has a dimmer channel: the level goes to it ('B') and the colours are not scaled.
*
* led-fixture <mac: 12 hex digits> <flash.json> [dimmer]
*/
#include <cerrno>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <mutex>
#include <string>
#include <poll.h>
#include <unistd.h>
#include "esp_log.h"
#include "esp_timer.h"
#include "espnow_link.h"
#include "patterns.h"
#include "presets.h"
#include "settings.h"
#include "sim.h"
extern "C" void sim_rx(const uint8_t *frame, int len);
static const char *TAG = "fixture";
static const int64_t FRAME_US = 25000; // 40 Hz
static std::mutex s_out_mu;
static std::string s_flash_path;
static bool write_all(int fd, const uint8_t *p, size_t n)
{
while (n) {
ssize_t w = write(fd, p, n);
if (w < 0) {
if (errno == EINTR) continue;
return false;
}
p += w;
n -= (size_t)w;
}
return true;
}
static void send_msg(uint8_t type, const uint8_t *data, size_t len)
{
if (len > 0xFFFF) return;
uint8_t h[3] = { type, (uint8_t)len, (uint8_t)(len >> 8) };
std::lock_guard<std::mutex> g(s_out_mu);
if (!write_all(1, h, 3) || !write_all(1, data, len)) {
_exit(0); // the bridge is gone
}
}
extern "C" void sim_host_tx(const uint8_t *frame, size_t len)
{
send_msg('T', frame, len);
}
extern "C" void sim_host_flash(const char *json)
{
std::string tmp = s_flash_path + ".tmp";
FILE *f = fopen(tmp.c_str(), "w");
if (!f) {
ESP_LOGE(TAG, "cannot write %s: errno %d", tmp.c_str(), errno);
return;
}
bool ok = fputs(json, f) >= 0;
ok = fclose(f) == 0 && ok;
if (!ok || rename(tmp.c_str(), s_flash_path.c_str()) != 0) {
ESP_LOGE(TAG, "cannot save %s: errno %d", s_flash_path.c_str(), errno);
}
}
extern "C" void sim_host_restart(void)
{
fflush(stderr);
_exit(3);
}
static std::string read_file(const char *path)
{
std::string s;
FILE *f = fopen(path, "r");
if (!f) return s;
char buf[4096];
size_t n;
while ((n = fread(buf, 1, sizeof(buf), f)) > 0) s.append(buf, n);
fclose(f);
return s;
}
int main(int argc, char **argv)
{
bool dimmer = argc == 4 && !strcmp(argv[3], "dimmer");
if ((argc != 3 && !dimmer) || strlen(argv[1]) != 12) {
fprintf(stderr, "usage: %s <mac: 12 hex digits> <flash.json> [dimmer]\n", argv[0]);
return 2;
}
signal(SIGPIPE, SIG_IGN);
uint8_t mac[6];
for (int i = 0; i < 6; i++) {
char pair[3] = { argv[1][2 * i], argv[1][2 * i + 1], 0 };
char *end = nullptr;
mac[i] = (uint8_t)strtol(pair, &end, 16);
if (*end) {
fprintf(stderr, "bad MAC %s\n", argv[1]);
return 2;
}
}
s_flash_path = argv[2];
sim_set_mac(mac);
std::string flash = read_file(argv[2]);
if (!sim_nvs_load(flash.empty() ? "{}" : flash.c_str())) {
ESP_LOGW(TAG, "%s is not valid JSON: starting with the flash erased", argv[2]);
sim_nvs_load("{}");
}
hw_cfg_t hw;
settings_load_hw(&hw);
patterns_start(hw);
patterns_set_dimmer_out(dimmer);
if (presets_init() != ESP_OK) {
ESP_LOGE(TAG, "presets_init failed");
}
presets_apply_startup();
espnow_link_start();
net_cfg_t n;
settings_load_net(&n);
ESP_LOGI(TAG, "Ready: %s (%s), %d LEDs", n.hostname, argv[1], hw.num_leds);
// stdin: frames from the bridge. A partial message waits in buf until the rest arrives.
static uint8_t buf[3 + 0xFFFF];
size_t have = 0;
static uint8_t px[3 * 512];
int64_t next_frame = esp_timer_get_time();
for (;;) {
int64_t now = esp_timer_get_time();
int wait_ms = next_frame > now ? (int)((next_frame - now + 999) / 1000) : 0;
struct pollfd p = { 0, POLLIN, 0 };
int r = poll(&p, 1, wait_ms);
if (r < 0 && errno != EINTR) break;
if (r > 0) {
ssize_t got = read(0, buf + have, sizeof(buf) - have);
if (got <= 0) {
if (got < 0 && errno == EINTR) continue;
break; // the bridge closed the pipe
}
have += (size_t)got;
size_t off = 0;
while (have - off >= 3) {
size_t len = buf[off + 1] | ((size_t)buf[off + 2] << 8);
if (have - off < 3 + len) break;
if (buf[off] == 'R') sim_rx(buf + off + 3, (int)len);
off += 3 + len;
}
memmove(buf, buf + off, have - off);
have -= off;
}
now = esp_timer_get_time();
if (now >= next_frame) {
int leds = sim_frame(px, sizeof(px));
if (dimmer) {
uint8_t level = patterns_output_level();
send_msg('B', &level, 1);
}
send_msg('F', px, (size_t)leds * 3);
next_frame += FRAME_US;
if (now - next_frame > 4 * FRAME_US) next_frame = now + FRAME_US; // no burst after a stall
}
}
return 0;
}