Effects now use Constructor and Destructor to initialize or delete their data, instead of using start() and stop().
This commit is contained in:
@ -1,24 +1,21 @@
|
||||
#include "effect_animation.h"
|
||||
#include "functions.h"
|
||||
|
||||
AnimationEffect::AnimationEffect(AnimationData* anim, CRGB* bg, int x, int y) {
|
||||
this->animation_data = anim;
|
||||
AnimationEffect::AnimationEffect(const char* name, CRGB* bg, int x, int y) {
|
||||
this->bg_color = bg;
|
||||
this->xOffset = x;
|
||||
this->yOffset = y;
|
||||
}
|
||||
|
||||
void AnimationEffect::start() {
|
||||
this->animation = new Animation(this->animation_data);
|
||||
this->animation = new Animation(name, window);
|
||||
this->animation->setBgColor(this->bg_color);
|
||||
this->animation->setOffsets(this->xOffset, this->yOffset);
|
||||
}
|
||||
|
||||
void AnimationEffect::stop() {
|
||||
AnimationEffect::~AnimationEffect() {
|
||||
delete this->animation;
|
||||
}
|
||||
|
||||
void AnimationEffect::loop() {
|
||||
this->animation->drawFrame(this->window);
|
||||
this->animation->drawFrame();
|
||||
this->animation->advance();
|
||||
}
|
||||
|
@ -4,13 +4,13 @@
|
||||
#include "my_fastled.h"
|
||||
#include "functions.h"
|
||||
|
||||
void FireEffect::start() {
|
||||
FireEffect::FireEffect() {
|
||||
this->data = new uint8_t[this->window->width * this->window->height];
|
||||
for (int i=0; i<(this->window->width * this->window->height); i++) this->data[i]=0;
|
||||
for (int i=0; i<this->window->width; i++) this->data[i]=this->spark_temp();
|
||||
}
|
||||
|
||||
void FireEffect::stop() {
|
||||
FireEffect::~FireEffect() {
|
||||
delete [] this->data;
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,7 @@
|
||||
|
||||
GolEffect::GolEffect() {
|
||||
this->window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
}
|
||||
|
||||
bool GolEffect::can_be_shown_with_clock() { return true; }
|
||||
|
||||
void GolEffect::start() {
|
||||
|
||||
_data = new uint8_t[this->window->count];
|
||||
_old = new uint8_t[this->window->count];
|
||||
for(uint16_t i=0; i<this->window->count; i++) {
|
||||
@ -16,6 +12,8 @@ void GolEffect::start() {
|
||||
_initialize();
|
||||
}
|
||||
|
||||
bool GolEffect::can_be_shown_with_clock() { return true; }
|
||||
|
||||
void GolEffect::_initialize() {
|
||||
for(uint16_t i=0; i<this->window->count; i++) {
|
||||
_data[i] = random8() < EFFECT_GOL_START_PERCENTAGE ? 1 : 0;
|
||||
@ -25,7 +23,7 @@ void GolEffect::_initialize() {
|
||||
_step = 0;
|
||||
}
|
||||
|
||||
void GolEffect::stop() {
|
||||
GolEffect::~GolEffect() {
|
||||
delete[] _data;
|
||||
delete[] _old;
|
||||
}
|
||||
|
@ -2,17 +2,14 @@
|
||||
#include "my_color_palettes.h"
|
||||
#include "functions.h"
|
||||
|
||||
MatrixEffectColumn::MatrixEffectColumn() {
|
||||
}
|
||||
|
||||
MatrixEffectColumn::MatrixEffectColumn(Window* win, int xPos) : MatrixEffectColumn() {
|
||||
MatrixEffectColumn::MatrixEffectColumn(Window* win, int xPos) {
|
||||
window = win;
|
||||
x = xPos;
|
||||
start();
|
||||
restart();
|
||||
y = random8(0, window->height);
|
||||
}
|
||||
|
||||
void MatrixEffectColumn::start() {
|
||||
void MatrixEffectColumn::restart() {
|
||||
y=-1;
|
||||
length = random8(EFFECT_MATRIX_LENGTH_MIN, EFFECT_MATRIX_LENGTH_MAX);
|
||||
running = true;
|
||||
@ -35,7 +32,7 @@ void MatrixEffectColumn::loop() {
|
||||
if (!running) {
|
||||
if (random8() < 20) {
|
||||
// Start the column again.
|
||||
start();
|
||||
restart();
|
||||
}
|
||||
} else {
|
||||
if (millis() - last_move > speed) {
|
||||
@ -78,8 +75,8 @@ CRGB RandomMatrixEffectColumn::_getColor(uint8_t i) {
|
||||
return color;
|
||||
}
|
||||
|
||||
void RandomMatrixEffectColumn::start() {
|
||||
MatrixEffectColumn::start();
|
||||
void RandomMatrixEffectColumn::restart() {
|
||||
MatrixEffectColumn::restart();
|
||||
_hue = random8();
|
||||
}
|
||||
|
||||
@ -95,24 +92,23 @@ void RandomMatrixEffectColumn::start() {
|
||||
boolean MatrixEffect::can_be_shown_with_clock() { return true; };
|
||||
|
||||
MatrixEffect::MatrixEffect() {
|
||||
_columns = new MatrixEffectColumn* [window->width];
|
||||
_init();
|
||||
}
|
||||
|
||||
void MatrixEffect::start() {
|
||||
_columns = new MatrixEffectColumn* [window->width];
|
||||
void MatrixEffect::_init() {
|
||||
for (int i=0; i<window->width; i++) _columns[i] = new MatrixEffectColumn(window, i);
|
||||
}
|
||||
|
||||
void RandomMatrixEffect::start() {
|
||||
_columns = new MatrixEffectColumn* [window->width];
|
||||
void RandomMatrixEffect::_init() {
|
||||
for (int i=0; i<window->width; i++) _columns[i] = new RandomMatrixEffectColumn(window, i);
|
||||
}
|
||||
|
||||
void RainbowMatrixEffect::start() {
|
||||
_columns = new MatrixEffectColumn* [window->width];
|
||||
void RainbowMatrixEffect::_init() {
|
||||
for (int i=0; i<window->width; i++) _columns[i] = new RainbowMatrixEffectColumn(window, i);
|
||||
}
|
||||
|
||||
void MatrixEffect::stop() {
|
||||
MatrixEffect::~MatrixEffect() {
|
||||
for (int i=0; i<window->width; i++) {
|
||||
delete _columns[i];
|
||||
}
|
||||
|
@ -3,14 +3,11 @@
|
||||
|
||||
PixelClockEffect::PixelClockEffect() {
|
||||
window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
}
|
||||
|
||||
void PixelClockEffect::start() {
|
||||
_color_seconds = new CRGB(0x00FF00);
|
||||
_color_minutes = new CRGB(0xFFFF00);
|
||||
}
|
||||
|
||||
void PixelClockEffect::stop() {
|
||||
PixelClockEffect::~PixelClockEffect() {
|
||||
delete _color_seconds;
|
||||
delete _color_minutes;
|
||||
}
|
||||
|
@ -44,8 +44,6 @@ void setup() {
|
||||
mqtt_setup();
|
||||
#endif
|
||||
LOGln("Core * Setup complete");
|
||||
|
||||
current_effect->start();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
Reference in New Issue
Block a user