diff --git a/OLEDDisplayUi.cpp b/OLEDDisplayUi.cpp index d8e1cb3efa92eda69281a3bc8ba677618ad1d8ae..f827c326bcd35d35cee36ee05cd947ed8a7106be 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 73f09657569cb30db881ce2b1465437c4a246e58..77a31cec401569900612bc5d48768fd76b0763eb 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 78a5cab3ef09770ff18df96b1cb215959c9921fe..17d6d636ad24f96a23be88defe1533b492a37680 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();