ab2c1b34b4
- Rename all show .txt files with NNN_ numeric prefix so order is explicit and controlled by filename (001_heartbeat_red through 006_party) - Drop HOME_SHOW special-casing from convert_all.py; show 0 is simply the lowest-numbered file - Add SHOW_FLAG_SPARKLE support: shows can declare '// flags: sparkle' to overlay random white flashes on top of the base color each frame - Wire sparkle into led_controller and config.h (SPARKLE_CHANCE/FRAMES) - Replace old placeholder/example shows with the six production shows Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
56 lines
1.9 KiB
C
56 lines
1.9 KiB
C
/*
|
||
* lightshow_format.h — Core data structures for show playback.
|
||
*
|
||
* All show data lives in PROGMEM (flash memory) to preserve the
|
||
* Arduino Uno's 2KB of RAM. The read_* helpers copy values out of
|
||
* PROGMEM so the rest of the code can work with them normally.
|
||
*
|
||
* SPDX-License-Identifier: BSD-2-Clause
|
||
*/
|
||
|
||
#pragma once
|
||
#include <avr/pgmspace.h>
|
||
#include <stdint.h>
|
||
|
||
// Show playback modes.
|
||
#define SHOW_LOOP 0 // repeat the show indefinitely
|
||
#define SHOW_SINGLE 1 // play once, then auto-advance to the next show
|
||
|
||
// Show flags (bitfield for ShowDef.flags).
|
||
#define SHOW_FLAG_SPARKLE 0x01 // overlay random white sparkles on this show
|
||
|
||
// One step in a lightshow: a target color and the time to reach it.
|
||
struct Step {
|
||
uint8_t r, g, b; // Target RGB color (0–255 each)
|
||
uint16_t duration_ms; // Milliseconds to fade from the previous color (0 = instant)
|
||
};
|
||
|
||
// Descriptor for one complete show.
|
||
struct ShowDef {
|
||
const Step* steps; // Pointer to a PROGMEM Step array
|
||
uint16_t length; // Number of steps in the array
|
||
uint8_t mode; // SHOW_LOOP or SHOW_SINGLE
|
||
uint8_t flags; // Bitfield: see SHOW_FLAG_* above
|
||
};
|
||
|
||
// Read one Step from PROGMEM into a regular struct.
|
||
// Direct pointer access does not work for PROGMEM on AVR — use this helper.
|
||
inline Step read_step(const Step* ptr) {
|
||
Step s;
|
||
s.r = pgm_read_byte(&ptr->r);
|
||
s.g = pgm_read_byte(&ptr->g);
|
||
s.b = pgm_read_byte(&ptr->b);
|
||
s.duration_ms = pgm_read_word(&ptr->duration_ms);
|
||
return s;
|
||
}
|
||
|
||
// Read one ShowDef from a PROGMEM ShowDef array.
|
||
// On AVR, pointers are 2 bytes wide, so pgm_read_word works for both fields.
|
||
inline ShowDef read_show_def(const ShowDef* ptr) {
|
||
ShowDef sd;
|
||
sd.steps = (const Step*)pgm_read_word(&ptr->steps);
|
||
sd.length = pgm_read_word(&ptr->length);
|
||
sd.mode = pgm_read_byte(&ptr->mode);
|
||
sd.flags = pgm_read_byte(&ptr->flags);
|
||
return sd;
|
||
} |