Skip to content
Snippets Groups Projects
Commit e9ea4802 authored by Daniel Eichhorn's avatar Daniel Eichhorn Committed by GitHub
Browse files

Merge pull request #55 from squix78/improve-manuell-controll

Implement frame control function proposed in #54
parents 9a4f05df a672fa49
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -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();
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment