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
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_log.h"
|
||||
#include "ctrl_sock.h"
|
||||
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
#define IPV4_ENABLED 1
|
||||
#define IPV6_ENABLED 1
|
||||
#define LOOPBACK_ENABLED 1
|
||||
#else // CONFIG_IDF_TARGET_LINUX
|
||||
#define IPV4_ENABLED CONFIG_LWIP_IPV4
|
||||
#define IPV6_ENABLED CONFIG_LWIP_IPV6
|
||||
#define LOOPBACK_ENABLED CONFIG_LWIP_NETIF_LOOPBACK
|
||||
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||
|
||||
/* Control socket, because in some network stacks select can't be woken up any
|
||||
* other way
|
||||
*/
|
||||
int cs_create_ctrl_sock(int port)
|
||||
{
|
||||
#if !LOOPBACK_ENABLED
|
||||
ESP_LOGE("esp_http_server", "Please enable LWIP_NETIF_LOOPBACK for %s API", __func__);
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret;
|
||||
struct sockaddr_storage addr = {};
|
||||
socklen_t addr_len = 0;
|
||||
#if IPV4_ENABLED
|
||||
struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr;
|
||||
addr4->sin_family = AF_INET;
|
||||
addr4->sin_port = htons(port);
|
||||
inet_aton("127.0.0.1", &addr4->sin_addr);
|
||||
addr_len = sizeof(struct sockaddr_in);
|
||||
#else
|
||||
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr;
|
||||
addr6->sin6_family = AF_INET6;
|
||||
addr6->sin6_port = htons(port);
|
||||
inet6_aton("::1", &addr6->sin6_addr);
|
||||
addr_len = sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
ret = bind(fd, (struct sockaddr *)&addr, addr_len);
|
||||
if (ret < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
void cs_free_ctrl_sock(int fd)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
int cs_send_to_ctrl_sock(int send_fd, int port, void *data, unsigned int data_len)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr_storage to_addr = {};
|
||||
socklen_t addr_len = 0;
|
||||
#if IPV4_ENABLED
|
||||
struct sockaddr_in *addr4 = (struct sockaddr_in *)&to_addr;
|
||||
addr4->sin_family = AF_INET;
|
||||
addr4->sin_port = htons(port);
|
||||
inet_aton("127.0.0.1", &addr4->sin_addr);
|
||||
addr_len = sizeof(struct sockaddr_in);
|
||||
#else
|
||||
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&to_addr;
|
||||
addr6->sin6_family = AF_INET6;
|
||||
addr6->sin6_port = htons(port);
|
||||
inet6_aton("::1", &addr6->sin6_addr);
|
||||
addr_len = sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
ret = sendto(send_fd, data, data_len, 0, (struct sockaddr *)&to_addr, addr_len);
|
||||
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int cs_recv_from_ctrl_sock(int fd, void *data, unsigned int data_len)
|
||||
{
|
||||
int ret;
|
||||
ret = recvfrom(fd, data, data_len, 0, NULL, NULL);
|
||||
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file ctrl_sock.h
|
||||
* \brief Control Socket for select() wakeup
|
||||
*
|
||||
* LWIP doesn't allow an easy mechanism to on-demand wakeup a thread
|
||||
* sleeping on select. This is a common requirement for sending
|
||||
* control commands to a network server. This control socket API
|
||||
* facilitates the same.
|
||||
*/
|
||||
#ifndef _CTRL_SOCK_H_
|
||||
#define _CTRL_SOCK_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Create a control socket
|
||||
*
|
||||
* LWIP doesn't allow an easy mechanism to on-demand wakeup a thread
|
||||
* sleeping on select. This is a common requirement for sending
|
||||
* control commands to a network server. This control socket API
|
||||
* facilitates the same.
|
||||
*
|
||||
* This API will create a UDP control socket on the specified port. It
|
||||
* will return a socket descriptor that can then be added to your
|
||||
* fd_set in select()
|
||||
*
|
||||
* @param[in] port the local port on which the control socket will listen
|
||||
*
|
||||
* @return - the socket descriptor that can be added to the fd_set in select.
|
||||
* - an error code if less than zero
|
||||
*/
|
||||
int cs_create_ctrl_sock(int port);
|
||||
|
||||
/**
|
||||
* @brief Free the control socket
|
||||
*
|
||||
* This frees up the control socket that was earlier created using
|
||||
* cs_create_ctrl_sock()
|
||||
*
|
||||
* @param[in] fd the socket descriptor associated with this control socket
|
||||
*/
|
||||
void cs_free_ctrl_sock(int fd);
|
||||
|
||||
/**
|
||||
* @brief Send data to control socket
|
||||
*
|
||||
* This API sends data to the control socket. If a server is blocked
|
||||
* on select() with the control socket, this call will wake up that
|
||||
* server.
|
||||
*
|
||||
* @param[in] send_fd the socket for sending ctrl messages
|
||||
* @param[in] port the port on which the control socket was created
|
||||
* @param[in] data pointer to a buffer that contains data to send on the socket
|
||||
* @param[in] data_len the length of the data contained in the buffer pointed to be data
|
||||
*
|
||||
* @return - the number of bytes sent to the control socket
|
||||
* - an error code if less than zero
|
||||
*/
|
||||
int cs_send_to_ctrl_sock(int send_fd, int port, void *data, unsigned int data_len);
|
||||
|
||||
/**
|
||||
* @brief Receive data from control socket
|
||||
*
|
||||
* This API receives any data that was sent to the control
|
||||
* socket. This will be typically called from the server thread to
|
||||
* process any commands on this socket.
|
||||
*
|
||||
* @param[in] fd the socket descriptor of the control socket
|
||||
* @param[in] data pointer to a buffer that will be used to store
|
||||
* received from the control socket
|
||||
* @param[in] data_len the maximum length of the data that can be
|
||||
* stored in the buffer pointed by data
|
||||
*
|
||||
* @return - the number of bytes received from the control socket
|
||||
* - an error code if less than zero
|
||||
*/
|
||||
int cs_recv_from_ctrl_sock(int fd, void *data, unsigned int data_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ! _CTRL_SOCK_H_ */
|
||||
Reference in new issue
Block a user