78 lines
1.6 KiB
C++
78 lines
1.6 KiB
C++
#ifndef ANIMATION
|
|
#define ANIMATION
|
|
|
|
#include <FastLED.h>
|
|
#include <elapsedMillis.h>
|
|
#include "Utilities.h"
|
|
|
|
class Animation {
|
|
public:
|
|
Animation(long _updateTime, uint16_t _finishedAfterCycles) : updateTime(_updateTime),
|
|
finishedAfterCycles(_finishedAfterCycles), cycles(0), enabled(false),
|
|
initialized(false), timer(0) {}
|
|
|
|
virtual void initialize(CRGB* leds) {
|
|
|
|
}
|
|
virtual void execute(CRGB* leds) {}
|
|
virtual bool isFinished() {
|
|
return cycles > finishedAfterCycles;
|
|
}
|
|
|
|
void update(CRGB* leds) {
|
|
if(enabled) {
|
|
if(timer >= updateTime) {
|
|
if(!initialized) {
|
|
initialize(leds);
|
|
cycles = 0;
|
|
initialized = true;
|
|
}
|
|
|
|
if(!isFinished()) {
|
|
execute(leds);
|
|
}
|
|
|
|
resetTimer();
|
|
}
|
|
}
|
|
}
|
|
|
|
void enable() {
|
|
enabled = true;
|
|
}
|
|
|
|
void disable() {
|
|
enabled = false;
|
|
}
|
|
|
|
void reinitialize() {
|
|
initialized = false;
|
|
}
|
|
|
|
bool isEnabled() {
|
|
return enabled;
|
|
}
|
|
|
|
protected:
|
|
void resetTimer() {
|
|
timer = 0;
|
|
}
|
|
|
|
void cycleCompleted() {
|
|
cycles = cycles += 1;
|
|
}
|
|
|
|
private:
|
|
long
|
|
updateTime;
|
|
uint16_t
|
|
cycles,
|
|
finishedAfterCycles;
|
|
bool
|
|
enabled,
|
|
initialized;
|
|
elapsedMillis
|
|
timer;
|
|
};
|
|
|
|
#endif |