feat: DDP frame sync over UDP broadcast, DDP acks, DDP enable setting

- Driver acks each completed DDP frame; the test waits for the acks before broadcasting the sync.
- Sync listener on UDP 4049: a frame is held until the next sync, then shown.
- DDP pixels are shown at full brightness, ignoring the device brightness settings.
- "DDP and sync receive on" setting (NVS, network API, web UI); off ignores DDP and sync packets.
- ddp_test.py: finds devices on the subnet, drives them in lockstep at a fixed rate, runs animations.
- /api/ddp reports sync counters for diagnosis.
- Includes in-progress WebSocket, multi-driver web UI and Wi-Fi work from the same tree.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Haiku 5.5 committed 2026-11-11 14:10:55 +13:00
1 parent 47f4eba0d6
commit 4cd3bc7973
294 files changed
+48954 -301

No files matched your search

+62 -2
View File
@@ -9,9 +9,17 @@
#include "freertos/task.h"
#include "lwip/sockets.h"
#include "patterns.h"
#include "settings.h"
static const char *TAG = "ddp";
static volatile bool s_enabled = true;
void ddp_set_enabled(bool on)
{
s_enabled = on;
}
// Header: flags, sequence, data type, destination, data offset (4), data length (2); with the timecode
// flag, 4 more bytes follow. Version 1 is flags bits 6-7 = 01.
#define DDP_FLAG_VER1 0x40
@@ -52,7 +60,12 @@ static void ddp_task(void *arg)
uint8_t buf[1500];
while (true) {
int n = recv(sock, buf, sizeof(buf), 0);
struct sockaddr_in src = {};
socklen_t srclen = sizeof(src);
int n = recvfrom(sock, buf, sizeof(buf), 0, (struct sockaddr *)&src, &srclen);
if (!s_enabled) {
continue;
}
if (n < DDP_HEADER) {
continue;
}
@@ -73,12 +86,59 @@ static void ddp_task(void *arg)
if (len > (size_t)n - hdr) {
len = (size_t)n - hdr;
}
patterns_ddp_write(offset, buf + hdr, len, (flags & 0x01) != 0);
bool push = (flags & 0x01) != 0;
patterns_ddp_write(offset, buf + hdr, len, push);
if (push) {
// Ack the completed frame to its sender ("LAK1" + the DDP seq). The sender broadcasts the
// sync only after this, so the frame is already held when the sync arrives.
uint8_t ack[5] = { 'L', 'A', 'K', '1', buf[1] };
sendto(sock, ack, sizeof(ack), 0, (struct sockaddr *)&src, srclen);
}
}
}
// Sync broadcasts: a frame that arrived by DDP is shown when the next sync arrives (see patterns.cpp).
static void ddp_sync_task(void *arg)
{
(void)arg;
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock < 0) {
ESP_LOGE(TAG, "sync socket failed");
vTaskDelete(NULL);
return;
}
struct sockaddr_in addr = {};
addr.sin_family = AF_INET;
addr.sin_port = htons(DDP_SYNC_PORT);
addr.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
ESP_LOGE(TAG, "bind to sync port %d failed", DDP_SYNC_PORT);
close(sock);
vTaskDelete(NULL);
return;
}
ESP_LOGI(TAG, "sync listening on UDP port %d", DDP_SYNC_PORT);
uint8_t buf[64];
while (true) {
int n = recv(sock, buf, sizeof(buf), 0);
if (!s_enabled || n < 8 || memcmp(buf, "LSY1", 4) != 0) {
continue;
}
patterns_ddp_sync(be32(buf + 4));
}
}
esp_err_t ddp_start(void)
{
net_cfg_t net;
if (settings_load_net(&net) == ESP_OK) {
s_enabled = net.ddp_enabled;
}
BaseType_t ok = xTaskCreate(ddp_task, "ddp", 4096, NULL, 4, NULL);
if (ok != pdPASS) {
return ESP_ERR_NO_MEM;
}
ok = xTaskCreate(ddp_sync_task, "ddp_sync", 3072, NULL, 4, NULL);
return ok == pdPASS ? ESP_OK : ESP_ERR_NO_MEM;
}