Files
led-controller/main/envelope.h
T
jimmyandClaude Sonnet 5.5 2543673bd8 feat: sequences v2, bridges, and sim-controller
Rework sequences (engine, seqplay, envelope, API, web UI), add bridge
support, add the host sim-controller and rig simulation tests, and
update docs, presets and project tooling config.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 17:47:27 +13:00

36 lines
1.6 KiB
C

#pragma once
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "cJSON.h"
// Native binary (v2) driver envelope, byte-compatible with
// src/util/binary_envelope.py. Presets and select entries go in separate
// frames so each frame is 5 + blob <= ENV_FRAME_MAX (one ESP-NOW payload).
#define ENV_FRAME_MAX 224 // + 4C 04 <group> wrapper must fit REL_FRAG_MAX
#define ENV_BLOB_MAX (ENV_FRAME_MAX - 5)
typedef struct {
uint8_t data[ENV_BLOB_MAX + 1]; // data[0] is the entry count
size_t len;
bool v3; // preset records carry an extension block (fade, beat timing): a v3 frame
} env_blob_t;
// Envelope v3: v2, except that each preset record is followed by [ext_len][key, len, value]... Keys:
#define ENV_EXT_FADE 1 // u16: fade-in ms when the preset is selected
#define ENV_EXT_BEAT 2 // u8: 1 = durations are quarter beats, not ms
void env_blob_init(env_blob_t *b);
// Append one preset (short keys p,c,d,b,a,n1..n6,f,tb or long pattern/colors/.../fade/beat_time); false if
// it does not fit. A preset with a fade or beat timing makes the blob v3; v2 and v3 records never share a
// blob, so mixing them also returns false (callers send what they have and start a new blob).
bool env_add_preset(env_blob_t *b, const char *name, const cJSON *preset);
// Append one select entry; step < 0 means none
bool env_add_select(env_blob_t *b, const char *device, const char *preset, int step);
// Frame with either a presets blob or a select blob (the other empty);
// brightness < 0 leaves device brightness unchanged. Returns frame length.
size_t env_frame(uint8_t *out, int brightness, const env_blob_t *presets, const env_blob_t *select);