diff --git a/include/tomo_scene.h b/include/tomo_scene.h index 0565c95..ff26262 100644 --- a/include/tomo_scene.h +++ b/include/tomo_scene.h @@ -21,18 +21,21 @@ class TomoScene { void disableInterrupt(); void hasNoInterrupt(); bool hasInterrupt(); + bool wasInterrupted(); void setRepeatCount(uint8_t repeatCount); uint8_t getRepeatCount() const; template - static void renderScene(uint8_t repeatCount, bool interruptEnabled = true) { + static bool renderScene(uint8_t repeatCount, bool interruptEnabled = true) { T scene; if(!interruptEnabled) scene.disableInterrupt(); scene.setRepeatCount(repeatCount); scene.render(); + + return scene.wasInterrupted(); } }; diff --git a/src/scenes/tomo_blink.cpp b/src/scenes/tomo_blink.cpp index d32caa3..1713256 100644 --- a/src/scenes/tomo_blink.cpp +++ b/src/scenes/tomo_blink.cpp @@ -9,8 +9,11 @@ TomoBlinkScene::TomoBlinkScene() { } void TomoBlinkScene::rendition() { - TomoScene::renderScene(1); - TomoScene::renderScene(1); + if(TomoScene::renderScene(1)) + return; + + if(TomoScene::renderScene(1)) + return; } void TomoBlinkScene::onInteract() { } \ No newline at end of file diff --git a/src/scenes/tomo_rest.cpp b/src/scenes/tomo_rest.cpp index 8e977d2..cb9630d 100644 --- a/src/scenes/tomo_rest.cpp +++ b/src/scenes/tomo_rest.cpp @@ -11,11 +11,17 @@ TomoRestScene::TomoRestScene() { } void TomoRestScene::rendition() { - TomoScene::renderScene(1); - TomoScene::renderScene(1); - TomoScene::renderScene(12); - TomoScene::renderScene(1); - TomoScene::renderScene(1); + if(TomoScene::renderScene(1)) + return; + + if(TomoScene::renderScene(1)) + return; + + if(TomoScene::renderScene(12)) + return; + + if(TomoScene::renderScene(1)) + return; } void TomoRestScene::onInteract() { } \ No newline at end of file diff --git a/src/tomo_scene.cpp b/src/tomo_scene.cpp index 9a29d53..7a57d1d 100644 --- a/src/tomo_scene.cpp +++ b/src/tomo_scene.cpp @@ -1,11 +1,10 @@ #include -bool shouldContinue = true; -TomoScene* instancePtr = nullptr; +bool shouldContinue = true, + interrupted = false; void IRAM_ATTR touchInterruptWrapper() { - if(instancePtr != nullptr) - shouldContinue = false; + shouldContinue = false; } void TomoScene::disableInterrupt() { @@ -22,20 +21,25 @@ void TomoScene::initializeTouchPin() { } void TomoScene::render() { - instancePtr = this; - for(uint8_t i = 0; i < this->getRepeatCount(); i++) { if(!shouldContinue && this->_hasInterrupt && this->_interruptEnabled) { this->onInteract(); + shouldContinue = true; + interrupted = true; break; } this->rendition(); + interrupted = false; } } +bool TomoScene::wasInterrupted() { + return interrupted; +} + void TomoScene::setRepeatCount(uint8_t repeatCount) { this->repeatCount = repeatCount; }