Skip to content

Commit

Permalink
Fixed interrupt animation bugs on scenes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Mar 18, 2024
1 parent 305e69c commit 5fcc5f3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
5 changes: 4 additions & 1 deletion include/tomo_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ class TomoScene {
void disableInterrupt();
void hasNoInterrupt();
bool hasInterrupt();
bool wasInterrupted();

void setRepeatCount(uint8_t repeatCount);
uint8_t getRepeatCount() const;

template <typename T>
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();
}
};

Expand Down
7 changes: 5 additions & 2 deletions src/scenes/tomo_blink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ TomoBlinkScene::TomoBlinkScene() {
}

void TomoBlinkScene::rendition() {
TomoScene::renderScene<TomoClosingEyesScene>(1);
TomoScene::renderScene<TomoOpeningEyesScene>(1);
if(TomoScene::renderScene<TomoClosingEyesScene>(1))
return;

if(TomoScene::renderScene<TomoOpeningEyesScene>(1))
return;
}

void TomoBlinkScene::onInteract() { }
16 changes: 11 additions & 5 deletions src/scenes/tomo_rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ TomoRestScene::TomoRestScene() {
}

void TomoRestScene::rendition() {
TomoScene::renderScene<TomoClosingEyesScene>(1);
TomoScene::renderScene<TomoExhaustedScene>(1);
TomoScene::renderScene<TomoSleepingScene>(12);
TomoScene::renderScene<TomoExhaustedScene>(1);
TomoScene::renderScene<TomoOpeningEyesScene>(1);
if(TomoScene::renderScene<TomoClosingEyesScene>(1))
return;

if(TomoScene::renderScene<TomoExhaustedScene>(1))
return;

if(TomoScene::renderScene<TomoSleepingScene>(12))
return;

if(TomoScene::renderScene<TomoOpeningEyesScene>(1))
return;
}

void TomoRestScene::onInteract() { }
16 changes: 10 additions & 6 deletions src/tomo_scene.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include <tomo_scene.h>

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() {
Expand All @@ -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;
}
Expand Down

0 comments on commit 5fcc5f3

Please sign in to comment.