Control brightness through JSON payload

This commit is contained in:
Robert Marshall 2021-08-27 07:20:50 +01:00
parent 44b91c86f2
commit 59ec76b52f
2 changed files with 22 additions and 11 deletions

View file

@ -8,6 +8,7 @@ class LED{
LEDOutput* _output;
bool _on;
unsigned long _fadeDurationOn, _fadeDurationOff, _fadeStart, _fadeEnd;
float _brightness;
unsigned long getFadeDuration(){
return _on ? _fadeDurationOn : _fadeDurationOff;
@ -20,12 +21,12 @@ class LED{
float getMultiplier() {
float value = getRemainingFadeTime() / (float)getFadeDuration();
return 1.0f - value;
return _brightness - value;
}
float getOutputMultiplier(){
float value = getMultiplier();
return _on ? value : 1.0f - value;
return _on ? value : _brightness - value;
}
void reset(bool on){
@ -42,6 +43,7 @@ public:
_output = output;
_fadeDurationOn = fadeDurationOn;
_fadeDurationOff = fadeDurationOff;
_brightness = 1.0f;
}
void on(){
@ -59,6 +61,10 @@ public:
void loop() {
_output->writeFraction(getOutputMultiplier());
}
void setBrightness(float brightness){
_brightness = brightness;
}
};
#endif