feat: device groups, combined brightness and beat-driven sequences from main
Groups (registry of driver MACs, optionally scoped to a profile) become
the drivers' group membership, alongside z<zone id> for zones that still
name drivers. Zones play to their group_ids. Group and device routes for
driver config, brightness (global x groups x device x zone) and identify.
The push path takes main's message shape: select as a list, groups as a
filter (one GROUP_CMD per group, or JSON when a preset has a background),
short keys so JSON fits a frame.
Sequences follow main: lanes of {preset_id, beats} steps played to each
lane's groups, advanced by the mic's beats or a clock at
audio_simulated_bpm; a switch waits for the next beat or downbeat; sync-
phase, stop (clears the zone's drivers) and status. This replaces the
time-based per-zone sequencer and scene playback, as in main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
19fea0b0a1
commit
04b56c6ef2
12 files changed
+1922
-579
No files matched your search
+35
-27
@@ -3,6 +3,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "api_util.h"
|
||||
#include "cJSON.h"
|
||||
#include "esp_log.h"
|
||||
@@ -210,7 +211,7 @@ static bool route(const char *res, httpd_req_t *req, int n, api_seg_t seg, esp_e
|
||||
} ROUTERS[] = {
|
||||
{ "profiles", profiles_route }, { "zones", zones_route }, { "presets", presets_route },
|
||||
{ "palettes", palettes_route }, { "sequences", sequences_route }, { "devices", devices_route },
|
||||
{ "patterns", patterns_route }, { "outputs", outputs_route },
|
||||
{ "patterns", patterns_route }, { "outputs", outputs_route }, { "groups", groups_route },
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(ROUTERS) / sizeof(ROUTERS[0]); i++) {
|
||||
if (!strcmp(ROUTERS[i].res, res)) {
|
||||
@@ -238,14 +239,6 @@ static esp_err_t collection_handler_inner(httpd_req_t *req)
|
||||
cJSON *all = store_coll(coll);
|
||||
const int method = req->method;
|
||||
|
||||
if (n == 3 && method == HTTP_POST && !strcmp(seg[0], "scenes")) {
|
||||
if (!strcmp(seg[2], "play")) {
|
||||
return api_result(req, engine_scene_play(seg[1]), "Scene started");
|
||||
}
|
||||
if (!strcmp(seg[2], "stop")) {
|
||||
return api_result(req, engine_scene_stop(seg[1]), "Scene stopped");
|
||||
}
|
||||
}
|
||||
if (n == 3) {
|
||||
return api_error(req, "404 Not Found", "unknown action");
|
||||
}
|
||||
@@ -369,30 +362,42 @@ static esp_err_t put_settings(httpd_req_t *req)
|
||||
if (!body) {
|
||||
return ESP_OK;
|
||||
}
|
||||
const cJSON *ch = cJSON_GetObjectItem(body, "wifi_channel");
|
||||
const cJSON *gb = cJSON_GetObjectItem(body, "global_brightness");
|
||||
const char *bad = (ch && !int_in(ch, 1, 11)) ? "wifi_channel must be an integer between 1 and 11"
|
||||
: (gb && !int_in(gb, 0, 255)) ? "global_brightness must be an integer between 0 and 255"
|
||||
: NULL;
|
||||
static const struct {
|
||||
const char *key;
|
||||
int lo, hi;
|
||||
const char *err;
|
||||
} INTS[] = {
|
||||
{ "wifi_channel", 1, 11, "wifi_channel must be an integer between 1 and 11" },
|
||||
{ "global_brightness", 0, 255, "global_brightness must be between 0 and 255" },
|
||||
{ "audio_beat_phase_ms", 0, 500, "audio_beat_phase_ms must be between 0 and 500" },
|
||||
{ "audio_input_volume", 0, 200, "audio_input_volume must be between 0 and 200" },
|
||||
};
|
||||
const char *bad = NULL;
|
||||
for (size_t i = 0; i < sizeof(INTS) / sizeof(INTS[0]) && !bad; i++) {
|
||||
const cJSON *v = cJSON_GetObjectItem(body, INTS[i].key);
|
||||
if (v && !cJSON_IsNull(v) && !int_in(v, INTS[i].lo, INTS[i].hi)) {
|
||||
bad = INTS[i].err;
|
||||
}
|
||||
}
|
||||
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")))) {
|
||||
bad = "sequence_switch_wait must be beat or downbeat";
|
||||
}
|
||||
if (bad) {
|
||||
cJSON_Delete(body);
|
||||
return api_error(req, "400 Bad Request", bad);
|
||||
}
|
||||
const cJSON *old = cJSON_GetObjectItem(store_settings(), "global_brightness");
|
||||
bool push = gb && !(cJSON_IsNumber(old) && old->valuedouble == gb->valuedouble);
|
||||
int level = gb ? (int)gb->valuedouble : 0;
|
||||
const cJSON *bpm = cJSON_GetObjectItem(body, "audio_simulated_bpm");
|
||||
if (bpm && !cJSON_IsNull(bpm)) { // clamped to the BPM range, like main's clamp_bpm
|
||||
double v = cJSON_IsNumber(bpm) ? bpm->valuedouble : (cJSON_IsString(bpm) ? strtod(bpm->valuestring, NULL) : 120);
|
||||
api_set(body, "audio_simulated_bpm", cJSON_CreateNumber((int)(v < 60 ? 60 : (v > 200 ? 200 : v))));
|
||||
}
|
||||
// global_brightness is only stored: the UI pushes each driver its combined brightness
|
||||
// (POST /devices/<id>/brightness, /groups/<id>/brightness)
|
||||
api_merge(store_settings(), body);
|
||||
cJSON_Delete(body);
|
||||
store_save("settings");
|
||||
if (push) {
|
||||
// Server-wide brightness goes to every driver
|
||||
cJSON *msgs = cJSON_CreateArray(), *m = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(m, "v", "1");
|
||||
cJSON_AddNumberToObject(m, "b", level);
|
||||
cJSON_AddItemToArray(msgs, m);
|
||||
engine_push(msgs, NULL);
|
||||
cJSON_Delete(msgs);
|
||||
}
|
||||
return api_message(req, "200 OK", "Settings updated successfully");
|
||||
}
|
||||
|
||||
@@ -406,7 +411,7 @@ 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], "settings") == 0 && req->method == HTTP_PUT) {
|
||||
if (req->method == HTTP_PUT && (n == 1 || (n == 2 && strcmp(seg[1], "settings") == 0))) {
|
||||
return put_settings(req);
|
||||
}
|
||||
return api_error(req, "404 Not Found", "unknown settings route");
|
||||
@@ -500,7 +505,10 @@ LOCKED(test_handler)
|
||||
|
||||
esp_err_t api_register(httpd_handle_t server)
|
||||
{
|
||||
store_lock();
|
||||
api_settings_defaults();
|
||||
api_migrate_sequences();
|
||||
store_unlock();
|
||||
static const char *const ROUTES[] = {
|
||||
"/devices*", "/zones*", "/presets*", "/profiles*", "/palettes*",
|
||||
"/patterns*", "/sequences*", "/scenes*", "/groups*", "/outputs*",
|
||||
|
||||
Reference in new issue
Block a user