From 94687bab3694b7c6d7f28aa40560ce8cb5a4c12b Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Tue, 4 Jun 2019 05:56:33 +0200 Subject: [PATCH] CycleEffect now uses the ID of an effect within cycle_effects to prevent repeating an effect instead of comparing the objects. --- include/effect_cycle.h | 1 + src/effect_cycle.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/effect_cycle.h b/include/effect_cycle.h index b68c9c0..180da75 100644 --- a/include/effect_cycle.h +++ b/include/effect_cycle.h @@ -7,6 +7,7 @@ class CycleEffect : public Effect { private: Effect* effect; + uint16_t effect_id = -1; unsigned long effectSince = 0; public: void changeEffect(); diff --git a/src/effect_cycle.cpp b/src/effect_cycle.cpp index 4a724ca..5d56279 100644 --- a/src/effect_cycle.cpp +++ b/src/effect_cycle.cpp @@ -1,15 +1,13 @@ #include "effect_cycle.h" void CycleEffect::changeEffect() { - Effect* new_effect; int new_id; do { new_id = random8(cycle_effects->size()); - new_effect = cycle_effects->get(new_id); - } while (&new_effect == &effect); - LOG("CycleEffect * Changing effect to ID "); LOGln(new_id); + } while (new_id == effect_id); + LOG("CycleEffect * Changing effect to #"); LOGln(new_id); if (effect) effect->stop(); - effect = new_effect; + effect = cycle_effects->get(new_id); effect->start(); effectSince = millis(); } @@ -20,6 +18,7 @@ void CycleEffect::start() { } void CycleEffect::stop() { + effect_id = -1; if (effect) effect->stop(); }