feat: sequences v2, driver frame sync and submodule updates
- Sequences v2, bridges and sim-controller changes from the working tree. - Records the led-driver, led-tool and led-simulator commits above. - Includes dmx-driver/ and graphify-out/. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3f8f67823b
commit
50ca46fee6
657 files changed
+15818
-1107
No files matched your search
@@ -10,12 +10,10 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include "api_util.h"
|
||||
#include "drv_ota.h"
|
||||
#include "esp_log.h"
|
||||
#include "store.h"
|
||||
#include "web.h"
|
||||
|
||||
static const char *TAG = "patterns";
|
||||
|
||||
#define PAT_DIR "/db/patterns"
|
||||
#define CODE_MAX (64 * 1024)
|
||||
@@ -410,76 +408,6 @@ static esp_err_t create_driver_pattern(httpd_req_t *req)
|
||||
return api_json(req, "201 Created", o, true);
|
||||
}
|
||||
|
||||
// POST /patterns/<name>/send {device_id?}: push the source to one driver or every ESP-NOW driver
|
||||
// (patterns/<name>.py on the driver), which then resets to load it
|
||||
static esp_err_t send_pattern(httpd_req_t *req, const char *name)
|
||||
{
|
||||
char base[NAME_MAX_LEN + 1];
|
||||
if (!base_name(name, base)) {
|
||||
return api_error(req, "400 Bad Request", "Invalid pattern name");
|
||||
}
|
||||
if (builtin(base)) {
|
||||
return api_error(req, "400 Bad Request", "on and off are built into the driver firmware");
|
||||
}
|
||||
cJSON *body = api_body_opt(req);
|
||||
if (!body) {
|
||||
return ESP_OK;
|
||||
}
|
||||
char macs[16] = "all";
|
||||
const cJSON *did = cJSON_GetObjectItem(body, "device_id");
|
||||
if (cJSON_IsString(did) && did->valuestring[0]) {
|
||||
const cJSON *dev = cJSON_GetObjectItem(store_coll("device"), did->valuestring);
|
||||
const cJSON *tr = cJSON_GetObjectItem(dev, "transport"), *addr = cJSON_GetObjectItem(dev, "address");
|
||||
if (!dev) {
|
||||
cJSON_Delete(body);
|
||||
return api_error(req, "404 Not Found", "Device not found");
|
||||
}
|
||||
if (!cJSON_IsString(tr) || strcmp(tr->valuestring, "espnow") || !cJSON_IsString(addr) ||
|
||||
strlen(addr->valuestring) != 12) {
|
||||
cJSON_Delete(body);
|
||||
return api_error(req, "400 Bad Request", "Device is not an ESP-NOW driver");
|
||||
}
|
||||
snprintf(macs, sizeof(macs), "%s", addr->valuestring);
|
||||
}
|
||||
cJSON_Delete(body);
|
||||
const uint8_t *data;
|
||||
size_t len;
|
||||
bool heap;
|
||||
if (!load(base, &data, &len, &heap)) {
|
||||
return api_error(req, "404 Not Found", "Pattern file not found");
|
||||
}
|
||||
char path[NAME_MAX_LEN + 16];
|
||||
snprintf(path, sizeof(path), "patterns/%s.py", base);
|
||||
esp_err_t err;
|
||||
store_unlock(); // the transfer takes seconds; the sequencer must keep running
|
||||
cJSON *results = drv_ota_send(macs, path, data, len, true, &err);
|
||||
store_lock();
|
||||
if (heap) {
|
||||
free((void *)data);
|
||||
}
|
||||
if (!results) {
|
||||
return err == ESP_ERR_INVALID_STATE ? api_error(req, "409 Conflict", "a driver update is already running")
|
||||
: err == ESP_ERR_NOT_FOUND ? api_error(req, "404 Not Found", "No ESP-NOW drivers")
|
||||
: api_error(req, "400 Bad Request", "Pattern cannot be sent");
|
||||
}
|
||||
cJSON *o = cJSON_CreateObject(), *ids = cJSON_CreateArray(), *it;
|
||||
cJSON_ArrayForEach(it, results)
|
||||
{
|
||||
const cJSON *res = cJSON_GetObjectItem(it, "result");
|
||||
if (cJSON_IsString(res) && strcmp(res->valuestring, "error")) {
|
||||
cJSON_AddItemToArray(ids, cJSON_CreateString(it->string));
|
||||
}
|
||||
}
|
||||
int sent = cJSON_GetArraySize(ids);
|
||||
ESP_LOGI(TAG, "%s sent to %d driver(s)", path, sent);
|
||||
cJSON_AddStringToObject(o, sent ? "message" : "error", sent ? "Pattern sent" : "No driver accepted the pattern");
|
||||
cJSON_AddStringToObject(o, "pattern", path + strlen("patterns/"));
|
||||
cJSON_AddItemToObject(o, "device_ids", ids);
|
||||
cJSON_AddNumberToObject(o, "sent_count", sent);
|
||||
cJSON_AddItemToObject(o, "results", results);
|
||||
return api_json(req, sent ? "200 OK" : "503 Service Unavailable", o, true);
|
||||
}
|
||||
|
||||
bool patterns_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret)
|
||||
{
|
||||
static const char FILE_PREFIX[] = "/patterns/ota/file/";
|
||||
@@ -522,8 +450,6 @@ bool patterns_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret)
|
||||
*ret = upload(req);
|
||||
} else if (n == 2 && !strcmp(seg[1], "driver")) {
|
||||
*ret = create_driver_pattern(req);
|
||||
} else if (n == 3 && !strcmp(seg[2], "send")) {
|
||||
*ret = send_pattern(req, seg[1]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user