From c93d12abd8bc964dd041654eb4d3ac803a60d33a Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sat, 20 May 2017 11:16:31 +0200 Subject: [PATCH] Fixed #1: Weird easing behaviour --- TODO | 3 --- src/modes/static.cpp | 9 ++++++--- 2 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 TODO diff --git a/TODO b/TODO deleted file mode 100644 index 69998eb..0000000 --- a/TODO +++ /dev/null @@ -1,3 +0,0 @@ -1. Add an "ease" option to the static mode - other mode to static: from 0 - static to static: depends on current brightness \ No newline at end of file diff --git a/src/modes/static.cpp b/src/modes/static.cpp index 26144bf..7398bf2 100644 --- a/src/modes/static.cpp +++ b/src/modes/static.cpp @@ -35,11 +35,14 @@ void StaticMode::tick(IStairs* stairs, uint32_t currentTime) if (this->easeState == None) return; - this->currentBrightness = (currentTime - this->easeStartTime) * ((this->parameters.brightness - this->easeStartBrightness) / this->parameters.easeTime); + uint32_t elapsedTime = currentTime - this->easeStartTime; + uint32_t diff = this->easeState == Up ? this->parameters.brightness - this->easeStartBrightness : this->easeStartBrightness - this->parameters.brightness; + uint32_t delta = (diff * elapsedTime) / this->parameters.easeTime; + + this->currentBrightness = this->easeState == Up ? this->easeStartBrightness + delta : this->easeStartBrightness - delta; - if ((this->easeState == Up && this->currentBrightness >= this->parameters.brightness) || - (this->easeState == Down && this->currentBrightness <= this->parameters.brightness)) + if (elapsedTime >= this->parameters.easeTime) { this->currentBrightness = this->parameters.brightness; this->easeState = None;