ebf01531c5
Markdown artifact caused a compile error: stray '`' in program. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
51 lines
1.7 KiB
C
51 lines
1.7 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
|
||
|
||
// 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
|
||
};
|
||
|
||
// 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);
|
||
return sd;
|
||
} |