diff --git a/include/Effect.h b/include/Effect.h index 49620b4..de02f05 100644 --- a/include/Effect.h +++ b/include/Effect.h @@ -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 diff --git a/include/effect_cycle.h b/include/effect_cycle.h index fcecea3..6422380 100644 --- a/include/effect_cycle.h +++ b/include/effect_cycle.h @@ -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(); diff --git a/include/effect_fire.h b/include/effect_fire.h index 448146d..684a7e4 100644 --- a/include/effect_fire.h +++ b/include/effect_fire.h @@ -13,7 +13,7 @@ private: static CRGBPalette16 palette; public: - void start(); - void stop(); + FireEffect(); + ~FireEffect(); void loop(); }; diff --git a/include/effect_gol.h b/include/effect_gol.h index c982610..6646764 100644 --- a/include/effect_gol.h +++ b/include/effect_gol.h @@ -16,8 +16,7 @@ private: public: GolEffect(); - void start(); - void stop(); + ~GolEffect(); void loop(); bool can_be_shown_with_clock(); }; diff --git a/include/effect_matrix.h b/include/effect_matrix.h index 0d6e5c7..56a1723 100644 --- a/include/effect_matrix.h +++ b/include/effect_matrix.h @@ -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; }; diff --git a/include/effect_pixelclock.h b/include/effect_pixelclock.h index a51cd07..d6baee9 100644 --- a/include/effect_pixelclock.h +++ b/include/effect_pixelclock.h @@ -9,8 +9,7 @@ private: CRGB* _color_minutes; public: PixelClockEffect(); - void start(); - void stop(); + ~PixelClockEffect(); void loop(); bool can_be_shown_with_clock(); }; diff --git a/src/effect_animation.cpp b/src/effect_animation.cpp index 47ec116..725c0e5 100644 --- a/src/effect_animation.cpp +++ b/src/effect_animation.cpp @@ -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(); } diff --git a/src/effect_fire.cpp b/src/effect_fire.cpp index e05148a..b1b553b 100644 --- a/src/effect_fire.cpp +++ b/src/effect_fire.cpp @@ -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; iwindow->width; i++) this->data[i]=this->spark_temp(); } -void FireEffect::stop() { +FireEffect::~FireEffect() { delete [] this->data; } diff --git a/src/effect_gol.cpp b/src/effect_gol.cpp index 6cc13de..fed162e 100644 --- a/src/effect_gol.cpp +++ b/src/effect_gol.cpp @@ -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; iwindow->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; iwindow->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; } diff --git a/src/effect_matrix.cpp b/src/effect_matrix.cpp index 0bc68a2..be83788 100644 --- a/src/effect_matrix.cpp +++ b/src/effect_matrix.cpp @@ -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; iwidth; i++) _columns[i] = new MatrixEffectColumn(window, i); } -void RandomMatrixEffect::start() { - _columns = new MatrixEffectColumn* [window->width]; +void RandomMatrixEffect::_init() { for (int i=0; iwidth; i++) _columns[i] = new RandomMatrixEffectColumn(window, i); } -void RainbowMatrixEffect::start() { - _columns = new MatrixEffectColumn* [window->width]; +void RainbowMatrixEffect::_init() { for (int i=0; iwidth; i++) _columns[i] = new RainbowMatrixEffectColumn(window, i); } -void MatrixEffect::stop() { +MatrixEffect::~MatrixEffect() { for (int i=0; iwidth; i++) { delete _columns[i]; } diff --git a/src/effect_pixelclock.cpp b/src/effect_pixelclock.cpp index f7fb05e..8ad3793 100644 --- a/src/effect_pixelclock.cpp +++ b/src/effect_pixelclock.cpp @@ -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; } diff --git a/src/pitrix.cpp b/src/pitrix.cpp index 0f629c5..8f578b1 100644 --- a/src/pitrix.cpp +++ b/src/pitrix.cpp @@ -44,8 +44,6 @@ void setup() { mqtt_setup(); #endif LOGln("Core * Setup complete"); - - current_effect->start(); } void loop() { diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..240fa21 --- /dev/null +++ b/test.txt @@ -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)