/* * SPDX-License-Identifier: Apache-2.0 */ #pragma once #include #include #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 Run one frame of the pattern engine and show it. The pattern task calls it every 10 ms. */ void patterns_frame(void); /** @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);