- 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>
85 lines
2.0 KiB
C++
85 lines
2.0 KiB
C++
/* sim-driver: ESP-NOW through the page. Sends go to Module.simTx (dest MAC + packet); the page delivers
|
|
* received frames with sim_rx (src MAC + packet), which runs the driver's receive callback as the radio would. */
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
|
|
#include <emscripten.h>
|
|
|
|
#include "esp_mac.h"
|
|
#include "esp_now.h"
|
|
#include "esp_wifi.h"
|
|
#include "settings.h"
|
|
|
|
static esp_now_recv_cb_t s_cb;
|
|
static bool s_init;
|
|
|
|
extern "C" {
|
|
|
|
esp_err_t esp_now_init(void)
|
|
{
|
|
s_init = true;
|
|
return ESP_OK;
|
|
}
|
|
|
|
esp_err_t esp_now_deinit(void)
|
|
{
|
|
s_init = false;
|
|
s_cb = nullptr;
|
|
return ESP_OK;
|
|
}
|
|
|
|
esp_err_t esp_now_register_recv_cb(esp_now_recv_cb_t cb)
|
|
{
|
|
s_cb = cb;
|
|
return ESP_OK;
|
|
}
|
|
|
|
esp_err_t esp_now_add_peer(const esp_now_peer_info_t *peer)
|
|
{
|
|
(void)peer;
|
|
return ESP_OK;
|
|
}
|
|
|
|
bool esp_now_is_peer_exist(const uint8_t *mac)
|
|
{
|
|
(void)mac;
|
|
return true; // every peer is reachable through the page
|
|
}
|
|
|
|
esp_err_t esp_now_send(const uint8_t *mac, const uint8_t *data, size_t len)
|
|
{
|
|
if (!s_init) return ESP_ERR_ESPNOW_NOT_INIT;
|
|
if (len == 0 || len > ESP_NOW_MAX_DATA_LEN) return ESP_ERR_ESPNOW_ARG;
|
|
uint8_t *buf = (uint8_t *)malloc(6 + len);
|
|
if (!buf) return ESP_ERR_ESPNOW_NO_MEM;
|
|
memcpy(buf, mac, 6);
|
|
memcpy(buf + 6, data, len);
|
|
MAIN_THREAD_ASYNC_EM_ASM({
|
|
if (Module.simTx) Module.simTx(HEAPU8.slice($0, $0 + $1));
|
|
_free($0);
|
|
}, buf, (int)(6 + len));
|
|
return ESP_OK;
|
|
}
|
|
|
|
esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second)
|
|
{
|
|
net_cfg_t n;
|
|
settings_load_net(&n);
|
|
*primary = n.espnow_channel;
|
|
if (second) *second = WIFI_SECOND_CHAN_NONE;
|
|
return ESP_OK;
|
|
}
|
|
|
|
/** A frame the radio received: src MAC (6) + packet. */
|
|
EMSCRIPTEN_KEEPALIVE void sim_rx(const uint8_t *frame, int len)
|
|
{
|
|
if (!s_cb || len < 7) return;
|
|
uint8_t src[6], dst[6];
|
|
memcpy(src, frame, 6);
|
|
esp_read_mac(dst, ESP_MAC_WIFI_STA);
|
|
esp_now_recv_info_t info = { src, dst, nullptr };
|
|
s_cb(&info, frame + 6, len - 6);
|
|
}
|
|
|
|
} // extern "C"
|