From a672fa494514325035ceaca5474732043660a3db Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg <Fabrice@weinberg.me> Date: Fri, 24 Jun 2016 18:12:59 +0200 Subject: [PATCH] Implement frame control function proposed in #54 --- OLEDDisplayUi.cpp | 27 ++++++++++++++++++++++----- OLEDDisplayUi.h | 14 ++++++++++++++ README.md | 11 +++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/OLEDDisplayUi.cpp b/OLEDDisplayUi.cpp index d8e1cb3..f827c32 100644 --- a/OLEDDisplayUi.cpp +++ b/OLEDDisplayUi.cpp @@ -150,6 +150,25 @@ void OLEDDisplayUi::previousFrame() { } } +void OLEDDisplayUi::switchToFrame(uint8_t frame) { + if (frame >= this->frameCount || frame != this->state.currentFrame) return; + this->state.lastUpdate = 0; + this->state.ticksSinceLastStateSwitch = 0; + this->state.frameState = FIXED; + this->state.currentFrame = frame; + this->state.isIndicatorDrawen = true; +} + +void OLEDDisplayUi::transitionToFrame(uint8_t frame) { + if (frame >= this->frameCount || frame != this->state.currentFrame) return; + this->nextFrameNumber = frame; + this->lastTransitionDirection = this->state.frameTransitionDirection; + this->state.manuelControll = true; + this->state.frameState = IN_TRANSITION; + this->state.ticksSinceLastStateSwitch = 0; + this->state.frameTransitionDirection = frame < this->state.currentFrame ? -1 : 1; +} + // -/----- State information -----\- OLEDDisplayUiState* OLEDDisplayUi::getUiState(){ @@ -180,6 +199,7 @@ void OLEDDisplayUi::tick() { this->state.frameState = FIXED; this->state.currentFrame = getNextFrameNumber(); this->state.ticksSinceLastStateSwitch = 0; + this->nextFrameNumber = -1; } break; case FIXED: @@ -366,9 +386,6 @@ void OLEDDisplayUi::drawOverlays() { } uint8_t OLEDDisplayUi::getNextFrameNumber(){ - int8_t nextFrame = (this->state.currentFrame + this->state.frameTransitionDirection) % this->frameCount; - if (nextFrame < 0){ - nextFrame = this->frameCount + nextFrame; - } - return nextFrame; + if (this->nextFrameNumber != -1) return this->nextFrameNumber; + return (this->state.currentFrame + this->frameCount + this->state.frameTransitionDirection) % this->frameCount; } diff --git a/OLEDDisplayUi.h b/OLEDDisplayUi.h index 73f0965..77a31ce 100644 --- a/OLEDDisplayUi.h +++ b/OLEDDisplayUi.h @@ -122,6 +122,9 @@ class OLEDDisplayUi { FrameCallback* frameFunctions; uint8_t frameCount = 0; + // Internally used to transition to a specific frame + int8_t nextFrameNumber = -1; + // Values for Overlays OverlayCallback* overlayFunctions; uint8_t overlayCount = 0; @@ -271,6 +274,17 @@ class OLEDDisplayUi { void nextFrame(); void previousFrame(); + /** + * Switch without transition to frame `frame`. + */ + void switchToFrame(uint8_t frame); + + /** + * Transition to frame `frame`, when the `frame` number is bigger than the current + * frame the forward animation will be used, otherwise the backwards animation is used. + */ + void transitionToFrame(uint8_t frame); + // State Info OLEDDisplayUiState* getUiState(); diff --git a/README.md b/README.md index 78a5cab..17d6d63 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,17 @@ void runLoadingProcess(LoadingStage* stages, uint8_t stagesCount); void nextFrame(); void previousFrame(); +/** + * Switch without transition to frame `frame`. + */ +void switchToFrame(uint8_t frame); + +/** + * Transition to frame `frame`, when the `frame` number is bigger than the current + * frame the forward animation will be used, otherwise the backwards animation is used. + */ +void transitionToFrame(uint8_t frame); + // State Info OLEDDisplayUiState* getUiState(); -- GitLab