Skip to content

Commit 600d74d

Browse files
committed
Merge pull request #42 from squix78/support-frames-switching
Reset state values when calling setFrames
2 parents bf5cb50 + 52701fd commit 600d74d

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

OLEDDisplayUi.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,20 @@ void OLEDDisplayUi::setFrameAnimation(AnimationDirection dir) {
9595
this->frameAnimationDirection = dir;
9696
}
9797
void OLEDDisplayUi::setFrames(FrameCallback* frameFunctions, uint8_t frameCount) {
98-
this->frameCount = frameCount;
9998
this->frameFunctions = frameFunctions;
99+
this->frameCount = frameCount;
100+
this->resetState();
100101
}
101102

102103
// -/----- Overlays ------\-
103104
void OLEDDisplayUi::setOverlays(OverlayCallback* overlayFunctions, uint8_t overlayCount){
104-
this->overlayCount = overlayCount;
105105
this->overlayFunctions = overlayFunctions;
106+
this->overlayCount = overlayCount;
106107
}
107108

108109
// -/----- Loading Process -----\-
109110

110111
void OLEDDisplayUi::runLoadingProcess(LoadingStage* stages, uint8_t stagesCount) {
111-
display->setTextAlignment(TEXT_ALIGN_CENTER);
112-
display->setFont(ArialMT_Plain_10);
113-
114112
uint8_t progress = 0;
115113
uint8_t increment = 100 / stagesCount;
116114

@@ -206,6 +204,14 @@ void OLEDDisplayUi::tick() {
206204
this->display->display();
207205
}
208206

207+
void OLEDDisplayUi::resetState() {
208+
this->state.lastUpdate = 0;
209+
this->state.ticksSinceLastStateSwitch = 0;
210+
this->state.frameState = FIXED;
211+
this->state.currentFrame = 0;
212+
this->state.isIndicatorDrawen = true;
213+
}
214+
209215
void OLEDDisplayUi::drawFrame(){
210216
switch (this->state.frameState){
211217
case IN_TRANSITION: {

OLEDDisplayUi.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ class OLEDDisplayUi {
135135

136136
// Loading screen
137137
LoadingDrawFunction loadingDrawFunction = [](OLEDDisplay *display, LoadingStage* stage, uint8_t progress) {
138-
display->drawString(64, 20, stage->process);
138+
display->setTextAlignment(TEXT_ALIGN_CENTER);
139+
display->setFont(ArialMT_Plain_10);
140+
display->drawString(64, 18, stage->process);
139141
display->drawProgressBar(4, 32, 120, 8, progress);
140142
};
141143

@@ -150,6 +152,7 @@ class OLEDDisplayUi {
150152
void drawFrame();
151153
void drawOverlays();
152154
void tick();
155+
void resetState();
153156

154157
public:
155158

@@ -255,7 +258,7 @@ class OLEDDisplayUi {
255258
* Set the function that will draw each step
256259
* in the loading animation
257260
*/
258-
void setLoadingDrawFunction(LoadingDrawFunction stage);
261+
void setLoadingDrawFunction(LoadingDrawFunction loadingFunction);
259262

260263

261264
/**

0 commit comments

Comments
 (0)