Files
led-controller/test/env_host.c
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

38 lines
1.5 KiB
C

// Host test: pack a preset and a select with envelope.c and print hex
#include <stdio.h>
#include "../main/envelope.h"
static void hex(const uint8_t *b, size_t n)
{
for (size_t i = 0; i < n; i++) printf("%02x", b[i]);
printf("\n");
}
int main(void)
{
const char *json =
"{\"p\":\"chase\",\"c\":[\"#ff0000\",\"#0f8\"],\"d\":120,\"b\":200,\"a\":false,\"n1\":5,\"n2\":-3,\"n3\":0,\"n4\":7,\"n5\":0,\"n6\":300}";
const char *json2 = "{\"pattern\":\"on\",\"colors\":[\"#102030\"],\"delay\":0,\"brightness\":0,\"auto\":true}";
cJSON *p = cJSON_Parse(json), *p2 = cJSON_Parse(json2);
env_blob_t pb, sb;
uint8_t out[256];
env_blob_init(&pb); env_blob_init(&sb);
env_add_preset(&pb, "7", p);
env_add_preset(&pb, "8", p2);
env_add_select(&sb, "mirror", "7", -1);
env_add_select(&sb, "roof", "8", 12);
hex(out, env_frame(out, 128, &pb, NULL));
hex(out, env_frame(out, -1, NULL, &sb));
// v3: presets with a fade or beat timing
cJSON *p3 = cJSON_Parse("{\"p\":\"hit\",\"c\":[\"#ffffff\"],\"d\":0,\"b\":255,\"a\":false,\"n1\":10,\"n3\":400,\"f\":250,\"tb\":1}");
cJSON *p4 = cJSON_Parse("{\"pattern\":\"keyframes\",\"colors\":[\"#ff0000\",\"#0000ff\"],\"delay\":800,\"fade\":1200}");
env_blob_t vb;
env_blob_init(&vb);
env_add_preset(&vb, "9", p3);
env_add_preset(&vb, "10", p4);
hex(out, env_frame(out, -1, &vb, NULL));
// A v2 preset does not join a v3 blob
printf("%d\n", env_add_preset(&vb, "7", p) ? 1 : 0);
return 0;
}