Fixed #1: Weird easing behaviour

This commit is contained in:
Mark van Renswoude 2017-05-20 11:16:31 +02:00
parent 4e9601a71e
commit c93d12abd8
2 changed files with 6 additions and 6 deletions

3
TODO
View File

@ -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

View File

@ -35,11 +35,14 @@ void StaticMode::tick(IStairs* stairs, uint32_t currentTime)
if (this->easeState == None) if (this->easeState == None)
return; 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) || if (elapsedTime >= this->parameters.easeTime)
(this->easeState == Down && this->currentBrightness <= this->parameters.brightness))
{ {
this->currentBrightness = this->parameters.brightness; this->currentBrightness = this->parameters.brightness;
this->easeState = None; this->easeState = None;