Files
led-driver/main/patterns.h
T
jimmyandClaude Haiku 5.5 4cd3bc7973 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>
2026-11-11 14:10:55 +13:00

85 lines
3.6 KiB
C++

/*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <cstddef>
#include <cstdint>
#include "esp_err.h"
#define PATTERN_MAX_COLOURS 8
// Preset fields follow the MicroPython presets: pattern, colours, background, delay (d), brightness (b),
// auto (a), reverse, fade, beat_time (tb) and the pattern-specific numbers n1..n6 (n6 is the style).
struct preset_t {
char name[32]; // "" for the live settings
int pattern; // index into the pattern table
int ncol; // 0 uses each pattern's own default colours
uint8_t col[PATTERN_MAX_COLOURS][3];
uint8_t bg[3]; // background (d off colour)
uint32_t delay; // d, ms
uint8_t brightness; // b, 0-255
bool autorun; // a: keep running; false runs one cycle and holds
bool reverse; // run the other way along the strip
uint32_t fade; // crossfade in from the previous frame, ms
bool beat_time; // tb: durations are quarter beats (500 ms beat here)
int n[7]; // n[1]..n[6]
};
/** @brief Start the LED strip and the pattern task, with the strip settings. */
void patterns_start(const struct hw_cfg_t &hw);
/** @brief Apply new strip settings (count, colour order, brightness ceiling) while running. */
esp_err_t patterns_set_hardware(const struct hw_cfg_t &hw);
/** @brief Live update of the preset on the strip. A new pattern restarts; other changes keep its place. */
void patterns_set(const preset_t &p);
/** @brief Select a preset: always restarts the pattern, crossfading from the frame on the strip. */
void patterns_select(const preset_t &p);
/** @brief DDP pixel data for the strip: byte offset into the RGB buffer, data, length. Replaces the pattern. */
void patterns_ddp_write(uint32_t offset, const uint8_t *data, size_t len, bool push);
void patterns_ddp_sync(uint32_t seq);
/** @brief Whether DDP pixels are arriving, and how many packets have come in. */
void patterns_ddp_status(bool *active, uint32_t *packets);
/** @brief Frame sync counters, for diagnosing the sync test. */
typedef struct {
uint32_t syncs; // sync packets received
uint32_t sync_seq; // seq of the last sync
uint32_t sync_age_ms; // ms since the last sync (UINT32_MAX: never)
uint32_t frames; // DDP frames completed (PUSH)
uint32_t shown; // frames shown on the strip
bool held; // a frame is waiting for the next sync
} patterns_ddp_debug_t;
void patterns_ddp_debug(patterns_ddp_debug_t *out);
/** @brief The colour last shown on LED i, as RGB. */
void patterns_shown_pixel(int i, uint8_t out[3]);
/** @brief Live brightness for every pattern, 0-255 (applied under the max brightness ceiling). */
void patterns_set_global(uint8_t level);
uint8_t patterns_get_global(void);
/** @brief Master scale for this device, 0-255: multiplies the device brightness (under the max brightness ceiling). */
void patterns_set_master(uint8_t level);
uint8_t patterns_get_master(void);
/** @brief Copy of the preset being shown. */
void patterns_get(preset_t *out);
/** @brief Number of patterns. */
int patterns_count(void);
/** @brief Name of pattern i, e.g. "chase". */
const char *patterns_name(int i);
/** @brief Index for a pattern name, or -1 if unknown. */
int patterns_index(const char *name);
/** @brief Fill a preset with the defaults for a pattern: colours and timing as the MicroPython presets. */
void preset_defaults(preset_t *p, int pattern);