From e3a5b65031c7ee57866272cc15b1b020e8364a9b Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg <Fabrice@weinberg.me> Date: Sun, 20 Dec 2015 18:27:04 +0100 Subject: [PATCH] Recalculate ticksPer* if target fps was changed --- SSD1306Ui.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SSD1306Ui.cpp b/SSD1306Ui.cpp index bcdb751..018e2d9 100644 --- a/SSD1306Ui.cpp +++ b/SSD1306Ui.cpp @@ -10,8 +10,13 @@ void SSD1306Ui::init() { } void SSD1306Ui::setTargetFPS(byte fps){ + int oldInterval = this->updateInterval; this->updateInterval = ((float) 1.0 / (float) fps) * 1000; - Serial.println(this->updateInterval); + + // Calculate new ticksPerFrame + float changeRatio = oldInterval / this->updateInterval; + this->ticksPerFrame *= changeRatio; + this->ticksPerTransition *= changeRatio; } // -/------ Automatic controll ------\- -- GitLab