Skip to content

Commit e9ea480

Browse files
authored
Merge pull request #55 from squix78/improve-manuell-controll
Implement frame control function proposed in #54
2 parents 9a4f05d + a672fa4 commit e9ea480

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

OLEDDisplayUi.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,25 @@ void OLEDDisplayUi::previousFrame() {
150150
}
151151
}
152152

153+
void OLEDDisplayUi::switchToFrame(uint8_t frame) {
154+
if (frame >= this->frameCount || frame != this->state.currentFrame) return;
155+
this->state.lastUpdate = 0;
156+
this->state.ticksSinceLastStateSwitch = 0;
157+
this->state.frameState = FIXED;
158+
this->state.currentFrame = frame;
159+
this->state.isIndicatorDrawen = true;
160+
}
161+
162+
void OLEDDisplayUi::transitionToFrame(uint8_t frame) {
163+
if (frame >= this->frameCount || frame != this->state.currentFrame) return;
164+
this->nextFrameNumber = frame;
165+
this->lastTransitionDirection = this->state.frameTransitionDirection;
166+
this->state.manuelControll = true;
167+
this->state.frameState = IN_TRANSITION;
168+
this->state.ticksSinceLastStateSwitch = 0;
169+
this->state.frameTransitionDirection = frame < this->state.currentFrame ? -1 : 1;
170+
}
171+
153172

154173
// -/----- State information -----\-
155174
OLEDDisplayUiState* OLEDDisplayUi::getUiState(){
@@ -180,6 +199,7 @@ void OLEDDisplayUi::tick() {
180199
this->state.frameState = FIXED;
181200
this->state.currentFrame = getNextFrameNumber();
182201
this->state.ticksSinceLastStateSwitch = 0;
202+
this->nextFrameNumber = -1;
183203
}
184204
break;
185205
case FIXED:
@@ -366,9 +386,6 @@ void OLEDDisplayUi::drawOverlays() {
366386
}
367387

368388
uint8_t OLEDDisplayUi::getNextFrameNumber(){
369-
int8_t nextFrame = (this->state.currentFrame + this->state.frameTransitionDirection) % this->frameCount;
370-
if (nextFrame < 0){
371-
nextFrame = this->frameCount + nextFrame;
372-
}
373-
return nextFrame;
389+
if (this->nextFrameNumber != -1) return this->nextFrameNumber;
390+
return (this->state.currentFrame + this->frameCount + this->state.frameTransitionDirection) % this->frameCount;
374391
}

OLEDDisplayUi.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class OLEDDisplayUi {
122122
FrameCallback* frameFunctions;
123123
uint8_t frameCount = 0;
124124

125+
// Internally used to transition to a specific frame
126+
int8_t nextFrameNumber = -1;
127+
125128
// Values for Overlays
126129
OverlayCallback* overlayFunctions;
127130
uint8_t overlayCount = 0;
@@ -271,6 +274,17 @@ class OLEDDisplayUi {
271274
void nextFrame();
272275
void previousFrame();
273276

277+
/**
278+
* Switch without transition to frame `frame`.
279+
*/
280+
void switchToFrame(uint8_t frame);
281+
282+
/**
283+
* Transition to frame `frame`, when the `frame` number is bigger than the current
284+
* frame the forward animation will be used, otherwise the backwards animation is used.
285+
*/
286+
void transitionToFrame(uint8_t frame);
287+
274288
// State Info
275289
OLEDDisplayUiState* getUiState();
276290

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,17 @@ void runLoadingProcess(LoadingStage* stages, uint8_t stagesCount);
301301
void nextFrame();
302302
void previousFrame();
303303

304+
/**
305+
* Switch without transition to frame `frame`.
306+
*/
307+
void switchToFrame(uint8_t frame);
308+
309+
/**
310+
* Transition to frame `frame`, when the `frame` number is bigger than the current
311+
* frame the forward animation will be used, otherwise the backwards animation is used.
312+
*/
313+
void transitionToFrame(uint8_t frame);
314+
304315
// State Info
305316
OLEDDisplayUiState* getUiState();
306317

0 commit comments

Comments
 (0)