Embed gzipped web assets at build time and type LED edit commands.

Generate the web UI headers from c/web/ via scripts/embed_file.py (minify + gzip) and serve them with Content-Encoding, replacing the checked-in web_*.h blobs. Move the LED driver/presets into lib/leds, and parse preset edits into a typed cmd_preset_t on core0 instead of passing raw JSON to core1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-11-08 22:18:10 +13:00
1 parent b3e9fc9663
commit bf0429c505
19 files changed
+395 -2205

No files matched your search

+50 -10
View File
@@ -11,6 +11,7 @@
#include "cmd_queue.h"
#define WS_MSG_MAX 2048
#define JSON_OBJ_MAX 1024
static httpserver_t *g_http;
static char g_buttons_json[FLASH_STORE_MAX];
@@ -25,19 +26,22 @@ static void buttons_load(void) {
static void on_index(httpserver_conn_t *conn, const char *path, const char *query) {
(void)path;
(void)query;
httpserver_send_static(conn, 200, "text/html; charset=utf-8", web_index_html, web_index_html_len);
httpserver_send_static(conn, 200, "text/html; charset=utf-8",
web_index_html, web_index_html_len, "gzip");
}
static void on_main_js(httpserver_conn_t *conn, const char *path, const char *query) {
(void)path;
(void)query;
httpserver_send_static(conn, 200, "application/javascript; charset=utf-8", web_main_js, web_main_js_len);
httpserver_send_static(conn, 200, "application/javascript; charset=utf-8",
web_main_js, web_main_js_len, "gzip");
}
static void on_styles_css(httpserver_conn_t *conn, const char *path, const char *query) {
(void)path;
(void)query;
httpserver_send_static(conn, 200, "text/css; charset=utf-8", web_styles_css, web_styles_css_len);
httpserver_send_static(conn, 200, "text/css; charset=utf-8",
web_styles_css, web_styles_css_len, "gzip");
}
static void on_get_buttons(httpserver_conn_t *conn, const char *path, const char *query) {
@@ -77,6 +81,44 @@ static void push_select(const char *name) {
cmd_queue_push(&cmd);
}
static void parse_preset_fields(const char *json, cmd_preset_t *p) {
memset(p, 0, sizeof(*p));
p->d = 100;
p->b = 127;
snprintf(p->pattern, sizeof(p->pattern), "off");
char s[CMD_PATTERN_MAX];
if (json_get_string(json, "p", s, sizeof(s))) {
snprintf(p->pattern, sizeof(p->pattern), "%s", s);
}
json_get_int(json, "d", &p->d);
json_get_int(json, "b", &p->b);
json_get_int(json, "n1", &p->n1);
json_get_int(json, "n2", &p->n2);
json_get_int(json, "n3", &p->n3);
json_get_int(json, "n4", &p->n4);
json_get_int(json, "n5", &p->n5);
json_get_int(json, "n6", &p->n6);
json_get_int(json, "n7", &p->n7);
json_get_int(json, "n8", &p->n8);
uint8_t colors[CMD_COLORS_MAX][3];
size_t n = 0;
if (json_get_rgb_array(json, "c", colors, CMD_COLORS_MAX, &n) && n > 0) {
p->c_count = (uint8_t)n;
for (size_t i = 0; i < n; i++) {
p->c[i].r = colors[i][0];
p->c[i].g = colors[i][1];
p->c[i].b = colors[i][2];
}
} else {
p->c_count = 1;
p->c[0].r = 255;
p->c[0].g = 255;
p->c[0].b = 255;
}
}
static void on_ws_msg(httpserver_conn_t *ws, const uint8_t *data, size_t len, bool text) {
(void)text;
char msg[WS_MSG_MAX + 1];
@@ -90,7 +132,6 @@ static void on_ws_msg(httpserver_conn_t *ws, const uint8_t *data, size_t len, bo
char name[CMD_NAME_MAX];
if (json_get_select_name(msg, name, sizeof(name))) {
push_select(name);
/* broadcast selection so other clients update */
char out[96];
int n = snprintf(out, sizeof(out), "{\"select\":\"%s\"}", name);
if (g_http) {
@@ -101,7 +142,7 @@ static void on_ws_msg(httpserver_conn_t *ws, const uint8_t *data, size_t len, bo
return;
}
char obj[CMD_DATA_MAX];
char obj[JSON_OBJ_MAX];
if (json_get_object(msg, "preset_edit", obj, sizeof(obj))) {
led_cmd_t cmd;
memset(&cmd, 0, sizeof(cmd));
@@ -109,12 +150,11 @@ static void on_ws_msg(httpserver_conn_t *ws, const uint8_t *data, size_t len, bo
if (!json_get_string(obj, "name", cmd.name, sizeof(cmd.name))) {
return;
}
char data[CMD_DATA_MAX];
char data[JSON_OBJ_MAX];
if (json_get_object(obj, "data", data, sizeof(data))) {
snprintf(cmd.data, sizeof(cmd.data), "%s", data);
parse_preset_fields(data, &cmd.u.edit);
} else {
/* data may be inline in edit object without nested key in some payloads */
snprintf(cmd.data, sizeof(cmd.data), "%s", obj);
parse_preset_fields(obj, &cmd.u.edit);
}
cmd_queue_push(&cmd);
return;
@@ -143,7 +183,7 @@ static void on_ws_msg(httpserver_conn_t *ws, const uint8_t *data, size_t len, bo
led_cmd_t cmd;
memset(&cmd, 0, sizeof(cmd));
cmd.type = CMD_BRIGHTNESS;
cmd.ival = b;
cmd.u.brightness = b;
cmd_queue_push(&cmd);
}
}