#pragma once #include #include #include #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 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; } env_blob_t; void env_blob_init(env_blob_t *b); // Append one preset (short keys p,c,d,b,a,n1..n6 or long pattern/colors/...); false if it does not fit 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);