Effects now use Constructor and Destructor to initialize or delete their data, instead of using start() and stop().
This commit is contained in:
parent
72cdb46451
commit
1912772da3
@ -9,6 +9,7 @@ class Effect {
|
||||
protected:
|
||||
Window* window = Window::getFullWindow(); // Use a full screen window per default.
|
||||
public:
|
||||
virtual ~Effect() {};
|
||||
virtual void loop() = 0;
|
||||
boolean supports_window = false;
|
||||
virtual boolean can_be_shown_with_clock() { return false; };
|
||||
@ -16,8 +17,6 @@ public:
|
||||
void setWindow(Window* win) {
|
||||
window = win;
|
||||
};
|
||||
virtual void start() {}
|
||||
virtual void stop() {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -6,13 +6,13 @@
|
||||
|
||||
class CycleEffect : public Effect {
|
||||
private:
|
||||
Effect* effect;
|
||||
Effect* effect = NULL;
|
||||
uint16_t effect_id = -1;
|
||||
unsigned long effectSince = 0;
|
||||
public:
|
||||
CycleEffect();
|
||||
~CycleEffect();
|
||||
void changeEffect();
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
boolean can_be_shown_with_clock();
|
||||
boolean clock_as_mask();
|
||||
|
@ -13,7 +13,7 @@ private:
|
||||
static CRGBPalette16 palette;
|
||||
|
||||
public:
|
||||
void start();
|
||||
void stop();
|
||||
FireEffect();
|
||||
~FireEffect();
|
||||
void loop();
|
||||
};
|
||||
|
@ -16,8 +16,7 @@ private:
|
||||
|
||||
public:
|
||||
GolEffect();
|
||||
void start();
|
||||
void stop();
|
||||
~GolEffect();
|
||||
void loop();
|
||||
bool can_be_shown_with_clock();
|
||||
};
|
||||
|
@ -12,15 +12,14 @@ protected:
|
||||
int x, y;
|
||||
int length = 1;
|
||||
virtual CRGB _getColor(uint8_t height);
|
||||
virtual void restart();
|
||||
private:
|
||||
uint16_t speed;
|
||||
boolean running;
|
||||
unsigned long last_move = 0;
|
||||
public:
|
||||
MatrixEffectColumn();
|
||||
MatrixEffectColumn(Window* win, int xPos);
|
||||
|
||||
virtual void start();
|
||||
virtual ~MatrixEffectColumn() {};
|
||||
void advance();
|
||||
void draw();
|
||||
void loop();
|
||||
@ -30,7 +29,6 @@ class RainbowMatrixEffectColumn : public MatrixEffectColumn {
|
||||
protected:
|
||||
CRGB _getColor(uint8_t height) override;
|
||||
public:
|
||||
RainbowMatrixEffectColumn() : MatrixEffectColumn() {};
|
||||
RainbowMatrixEffectColumn(Window* win, int xPos) : MatrixEffectColumn(win, xPos) {};
|
||||
};
|
||||
|
||||
@ -38,29 +36,28 @@ class RandomMatrixEffectColumn : public MatrixEffectColumn {
|
||||
protected:
|
||||
uint8_t _hue = 42;
|
||||
CRGB _getColor(uint8_t height) override;
|
||||
void restart() override;
|
||||
public:
|
||||
void start() override;
|
||||
RandomMatrixEffectColumn() : MatrixEffectColumn() {};
|
||||
RandomMatrixEffectColumn(Window* win, int xPos) : MatrixEffectColumn(win, xPos) {};
|
||||
};
|
||||
|
||||
class MatrixEffect : public Effect {
|
||||
protected:
|
||||
MatrixEffectColumn** _columns;
|
||||
virtual void _init();
|
||||
public:
|
||||
boolean can_be_shown_with_clock();
|
||||
virtual void start();
|
||||
void stop();
|
||||
MatrixEffect();
|
||||
virtual ~MatrixEffect();
|
||||
void loop();
|
||||
};
|
||||
|
||||
class RainbowMatrixEffect : public MatrixEffect {
|
||||
public:
|
||||
void start() override;
|
||||
private:
|
||||
void _init() override;
|
||||
};
|
||||
|
||||
class RandomMatrixEffect : public MatrixEffect {
|
||||
public:
|
||||
void start() override;
|
||||
private:
|
||||
void _init() override;
|
||||
};
|
||||
|
@ -9,8 +9,7 @@ private:
|
||||
CRGB* _color_minutes;
|
||||
public:
|
||||
PixelClockEffect();
|
||||
void start();
|
||||
void stop();
|
||||
~PixelClockEffect();
|
||||
void loop();
|
||||
bool can_be_shown_with_clock();
|
||||
};
|
||||
|
@ -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() {
|
||||
|
18
test.txt
Normal file
18
test.txt
Normal file
@ -0,0 +1,18 @@
|
||||
Original:
|
||||
DATA: [==== ] 40.5% (used 33164 bytes from 81920 bytes)
|
||||
PROGRAM: [==== ] 36.0% (used 375664 bytes from 1044464 bytes)
|
||||
|
||||
|
||||
lots of compares:
|
||||
DATA: [==== ] 38.6% (used 31640 bytes from 81920 bytes)
|
||||
PROGRAM: [==== ] 35.6% (used 371740 bytes from 1044464 bytes)
|
||||
|
||||
crc32:
|
||||
DATA: [==== ] 38.5% (used 31532 bytes from 81920 bytes)
|
||||
PROGRAM: [==== ] 35.6% (used 371456 bytes from 1044464 bytes)
|
||||
|
||||
original:
|
||||
DATA: [==== ] 39.4% (used 32256 bytes from 81920 bytes) │pitrix_dev/log MQTT * Received data for topic pitrix_dev/uptime with payload 391
|
||||
PROGRAM: [==== ] 37.4% (used 390380 bytes from 1044464 bytes)
|
||||
DATA: [==== ] 37.4% (used 30608 bytes from 81920 bytes) │pitrix_dev/free_heap 43624
|
||||
PROGRAM: [==== ] 37.4% (used 390556 bytes from 1044464 bytes)
|
Loading…
Reference in New Issue
Block a user