led-driver: channel default 11, bare ESP-NOW build, settings and USB config updates
Default ESP-NOW channel is now 11. Adds the bare ESP-NOW-only build option (CONFIG_LED_ESPNOW_ONLY) with its sdkconfig fragments, a default hostname from the Wi-Fi MAC, and the related net, link, web and settings changes. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
12a8e225ad
commit
c9838d1cbe
18 files changed
+268
-31
No files matched your search
+39
-3
@@ -9,6 +9,11 @@
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_mac.h"
|
||||
#include "esp_timer.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_system.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
@@ -347,6 +352,12 @@ void apply_device_config(const cJSON *dc)
|
||||
}
|
||||
}
|
||||
}
|
||||
// The strip's data pin: 0-10 or 20-21 (11-19 are the flash and USB), as /api/hardware allows
|
||||
v = cJSON_GetObjectItem(dc, "pin");
|
||||
if (cJSON_IsNumber(v) && ((v->valueint >= 0 && v->valueint <= 10) || v->valueint == 20 || v->valueint == 21)) {
|
||||
hw.pin = v->valueint;
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
settings_save_hw(&hw);
|
||||
patterns_set_hardware(hw);
|
||||
@@ -355,6 +366,25 @@ void apply_device_config(const cJSON *dc)
|
||||
if (cJSON_IsString(v) && strcmp(v->valuestring, "off") == 0) {
|
||||
presets_set_startup("");
|
||||
}
|
||||
// The ESP-NOW channel: saved, then the driver restarts onto it (after the ack has gone). Move the
|
||||
// controller's bridge to the same channel, or the driver is out of reach.
|
||||
v = cJSON_GetObjectItem(dc, "espnow_channel");
|
||||
if (cJSON_IsNumber(v) && v->valueint >= 1 && v->valueint <= 13) {
|
||||
net_cfg_t n;
|
||||
settings_load_net(&n);
|
||||
if (n.espnow_channel != v->valueint) {
|
||||
n.espnow_channel = (uint8_t)v->valueint;
|
||||
settings_save_net(&n);
|
||||
ESP_LOGI(TAG, "ESP-NOW channel %u saved: restarting onto it", n.espnow_channel);
|
||||
// A task, not an esp_timer: the fixture driver's host build (fixture-driver/) has no esp_timer
|
||||
static bool restarting;
|
||||
if (!restarting) {
|
||||
restarting = true;
|
||||
xTaskCreate([](void *) { vTaskDelay(pdMS_TO_TICKS(1000)); esp_restart(); }, "ch_restart", 2048, NULL, 1,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
// "reversed" is accepted and ignored: the C++ driver does not reverse its strip yet
|
||||
}
|
||||
|
||||
@@ -420,6 +450,10 @@ void apply_select(const cJSON *sel)
|
||||
// an entry is [name, step] or a bare name; step is not used by this driver
|
||||
const cJSON *name = cJSON_IsArray(e) ? cJSON_GetArrayItem(e, 0) : e;
|
||||
if (!cJSON_IsString(name) || !name->valuestring[0]) return;
|
||||
#ifdef CONFIG_LED_TIMING_LOG
|
||||
// Timing test: when each step's select arrives, on this chip's clock (see main/Kconfig.projbuild)
|
||||
ESP_LOGI(TAG, "step select %s t=%lld us", name->valuestring, (long long)esp_timer_get_time());
|
||||
#endif
|
||||
if (presets_select(name->valuestring) == ESP_OK) {
|
||||
return;
|
||||
}
|
||||
@@ -634,10 +668,12 @@ size_t ctrl_build_announce(uint8_t *out, size_t cap)
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (strcmp(hw.order, orders[i]) == 0) co = i;
|
||||
}
|
||||
char cfg[160];
|
||||
// The settings the controller can change over ESP-NOW (device_config), so it shows what the driver has
|
||||
char cfg[200];
|
||||
snprintf(cfg, sizeof(cfg),
|
||||
"{\"max_brightness\":%u,\"num_leds\":%d,\"color_order\":\"%s\",\"startup_mode\":\"default\",\"reversed\":false}",
|
||||
(unsigned)hw.max_brightness, hw.num_leds, hw.order);
|
||||
"{\"max_brightness\":%u,\"num_leds\":%d,\"color_order\":\"%s\",\"startup_mode\":\"default\",\"reversed\":false,"
|
||||
"\"pin\":%d,\"espnow_channel\":%u}",
|
||||
(unsigned)hw.max_brightness, hw.num_leds, hw.order, hw.pin, (unsigned)n.espnow_channel);
|
||||
size_t cl = strlen(cfg);
|
||||
size_t need = 3 + nl + 6 + 1 + cl;
|
||||
if (need > cap || need > 250) return 0;
|
||||
|
||||
Reference in new issue
Block a user