52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
#include "static.h"
|
|
|
|
void StaticMode::init(IStairs* stairs, uint32_t currentTime)
|
|
{
|
|
_dln("Initializing static mode:");
|
|
_d("currentBrightness: "); _dln(this->currentBrightness);
|
|
_d("brightness: "); _dln(this->parameters.brightness);
|
|
_d("easeTime: "); _dln(this->parameters.easeTime);
|
|
|
|
if (this->parameters.easeTime > 0 && this->parameters.brightness != this->currentBrightness)
|
|
{
|
|
_dln("Easing...");
|
|
|
|
this->easeStartTime = currentTime;
|
|
this->easeStartBrightness = currentBrightness;
|
|
|
|
if (this->parameters.brightness > this->currentBrightness)
|
|
this->easeState = Up;
|
|
else
|
|
this->easeState = Down;
|
|
}
|
|
else
|
|
{
|
|
_dln("Updating immediately...");
|
|
this->easeState = None;
|
|
|
|
stairs->setAll(this->parameters.brightness);
|
|
this->currentBrightness = this->parameters.brightness;
|
|
}
|
|
}
|
|
|
|
|
|
void StaticMode::tick(IStairs* stairs, uint32_t currentTime)
|
|
{
|
|
if (this->easeState == None)
|
|
return;
|
|
|
|
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 (elapsedTime >= this->parameters.easeTime)
|
|
{
|
|
this->currentBrightness = this->parameters.brightness;
|
|
this->easeState = None;
|
|
}
|
|
|
|
stairs->setAll(this->currentBrightness);
|
|
} |