-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathanimation.h
88 lines (71 loc) · 2.83 KB
/
animation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef ANIMATION_H
#define ANIMATION_H
#include <Arduino.h>
#include <FastLED.h>
class Animation {
public:
typedef enum {
RGB24 = 0,
RGB565_RLE = 1,
#ifdef SUPPORTS_PALLETE_ENCODING
INDEXED = 2,
INDEXED_RLE = 3
#endif
} Encoding;
// Initialize the animation with no data. This is intended for the case
// where the animation will be re-initialized from a memory structure in ROM
// after the sketch starts.
Animation();
// Initialize the animation
// @param frameCount Number of frames in this animation
// @param frameData Pointer to the frame data. Format of this data is encoding-specficic
// @param encoding Method used to encode the animation data
// @param ledCount Number of LEDs in the strip
// @param frameDelay Number of milliseconds to wait between frames
Animation(uint16_t frameCount,
PGM_VOID_P frameData,
Encoding encoding,
uint16_t ledCount,
uint16_t frameDelay);
// Re-initialize the animation with new information
// @param frameCount Number of frames in this animation
// @param frameData Pointer to the frame data. Format of this data is encoding-specficic
// @param encoding Method used to encode the animation data
// @param ledCount Number of LEDs in the strip
// @param frameDelay Number of milliseconds to wait between frames
void init(uint16_t frameCount,
PGM_VOID_P frameData,
Encoding encoding,
uint16_t ledCount,
uint16_t frameDelay);
// Reset the animation, causing it to start over from frame 0.
void reset();
// Draw the next frame of the animation
// @param strip[] LED strip to draw to.
void draw(struct CRGB strip[]);
uint16_t getLedCount() const;
uint16_t getFrameCount() const;
uint16_t getFrameDelay() const;
private:
uint16_t ledCount; // Number of LEDs in the strip
uint16_t frameCount; // Number of frames in this animation
uint16_t frameDelay; // Milliseconds to wait between frames
Encoding encoding; // Encoding type
PGM_VOID_P frameData; // Pointer to the begining of the frame data
uint16_t frameIndex; // Current animation frame
PGM_VOID_P currentFrameData; // Pointer to the current position in the frame data
#ifdef SUPPORTS_PALLETE_ENCODING
uint8_t colorTableEntries; // Number of entries in the color table, minus 1 (max 255)
struct CRGB colorTable[256]; // Color table
void loadColorTable(); // Load the color table from memory
#endif
typedef void (Animation::*DrawFunction)(struct CRGB strip[]);
DrawFunction drawFunction;
void drawRgb24(struct CRGB strip[]);
void drawRgb565_RLE(struct CRGB strip[]);
#ifdef SUPPORTS_PALLETE_ENCODING
void drawIndexed(struct CRGB strip[]);
void drawIndexed_RLE(struct CRGB strip[]);
#endif
};
#endif