1 #include "FastLED_animation.h"
3 Animation::Animation() {
7 Animation::Animation(uint16_t frameCount_,
8 const prog_uint8_t* frameData_,
9 const uint8_t ledCount_)
11 init(frameCount_, frameData_, ledCount_);
15 void Animation::init(uint16_t frameCount_,
16 const prog_uint8_t* frameData_,
17 const uint8_t ledCount_)
19 frameCount = frameCount_;
20 frameData = const_cast<prog_uint8_t*>(frameData_);
23 // Load the color table into memory
24 // TODO: Free this memory somewhere?
25 colorTableEntries = pgm_read_byte(frameData) + 1;
26 colorTable = (CRGB *)malloc(colorTableEntries * sizeof(CRGB));
28 for(int i = 0; i < colorTableEntries; i++) {
29 colorTable[i] = CRGB(pgm_read_byte(frameData + 1 + i * 3 ),
30 pgm_read_byte(frameData + 1 + i * 3 + 1),
31 pgm_read_byte(frameData + 1 + i * 3 + 2));
37 void Animation::reset() {
41 void Animation::draw(struct CRGB strip[]) {
42 drawIndexed_RLE(strip);
45 frameIndex = (frameIndex + 1)%frameCount;
48 void Animation::drawIndexed_RLE(struct CRGB strip[]) {
50 currentFrameData = frameData
51 + 1 + 3 * colorTableEntries; // Offset for color table
54 // Read runs of RLE data until we get enough data.
56 while (count < ledCount) {
57 uint8_t run_length = pgm_read_byte(currentFrameData++);
58 uint8_t colorIndex = pgm_read_byte(currentFrameData++);
60 for(uint8_t i = 0; i < run_length; i++) {
61 strip[count++] = colorTable[colorIndex];