Skip to content

Commit 3398c97

Browse files
authored
Fix problem of transitions getting faster with each call of setTargetFPS (#275)
1 parent 3668f1a commit 3398c97

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/OLEDDisplayUi.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ OLEDDisplayUi::OLEDDisplayUi(OLEDDisplay *display) {
4848
inactiveSymbol = ANIMATION_inactiveSymbol;
4949
frameAnimationDirection = SLIDE_RIGHT;
5050
lastTransitionDirection = 1;
51-
ticksPerFrame = 151; // ~ 5000ms at 30 FPS
52-
ticksPerTransition = 15; // ~ 500ms at 30 FPS
5351
frameCount = 0;
5452
nextFrameNumber = -1;
5553
overlayCount = 0;
@@ -66,20 +64,19 @@ OLEDDisplayUi::OLEDDisplayUi(OLEDDisplay *display) {
6664
state.userData = NULL;
6765
shouldDrawIndicators = true;
6866
autoTransition = true;
67+
setTimePerFrame(5000);
68+
setTimePerTransition(500);
6969
}
7070

7171
void OLEDDisplayUi::init() {
7272
this->display->init();
7373
}
7474

7575
void OLEDDisplayUi::setTargetFPS(uint8_t fps){
76-
float oldInterval = this->updateInterval;
7776
this->updateInterval = ((float) 1.0 / (float) fps) * 1000;
7877

79-
// Calculate new ticksPerFrame
80-
float changeRatio = oldInterval / (float) this->updateInterval;
81-
this->ticksPerFrame *= changeRatio;
82-
this->ticksPerTransition *= changeRatio;
78+
this->ticksPerFrame = timePerFrame / updateInterval;
79+
this->ticksPerTransition = timePerTransition / updateInterval;
8380
}
8481

8582
// -/------ Automatic controll ------\-
@@ -99,10 +96,12 @@ void OLEDDisplayUi::setAutoTransitionBackwards(){
9996
this->lastTransitionDirection = -1;
10097
}
10198
void OLEDDisplayUi::setTimePerFrame(uint16_t time){
102-
this->ticksPerFrame = (uint16_t) ( (float) time / (float) updateInterval);
99+
this->timePerFrame = time;
100+
this->ticksPerFrame = timePerFrame / updateInterval;
103101
}
104102
void OLEDDisplayUi::setTimePerTransition(uint16_t time){
105-
this->ticksPerTransition = (uint16_t) ( (float) time / (float) updateInterval);
103+
this->timePerTransition = time;
104+
this->ticksPerTransition = timePerTransition / updateInterval;
106105
}
107106

108107
// -/------ Customize indicator position and style -------\-

src/OLEDDisplayUi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ class OLEDDisplayUi {
159159
// Bookeeping for update
160160
uint16_t updateInterval = 33;
161161

162+
uint16_t timePerFrame;
163+
uint16_t timePerTransition;
164+
162165
uint8_t getNextFrameNumber();
163166
void drawIndicator();
164167
void drawFrame();

0 commit comments

Comments
 (0)