Merge pull request #571 from Def3nder/SunRiseFading

SunRise using NightLight Fade
This commit is contained in:
Aircoookie 2020-01-08 19:25:05 +01:00 committed by GitHub
commit 32c10e5ae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

@ -136,6 +136,7 @@ byte briS = 128; //default brightness
byte nightlightTargetBri = 0; //brightness after nightlight is over
byte nightlightDelayMins = 60;
bool nightlightFade = true; //if enabled, light will gradually dim towards the target bri. Otherwise, it will instantly set after delay over
bool nightlightColorFade = false; //if enabled, light will gradually fade color from primary to secondary color.
bool fadeTransition = true; //enable crossfading color transition
bool enableSecTransition = true; //also enable transition for secondary color
uint16_t transitionDelay = 750; //default crossfade duration in ms
@ -271,6 +272,7 @@ uint32_t nightlightDelayMs = 10;
uint8_t nightlightDelayMinsDefault = nightlightDelayMins;
unsigned long nightlightStartTime;
byte briNlT = 0; //current nightlight brightness
byte colNlT[]{0, 0, 0, 0}; //current nightlight color
//brightness
unsigned long lastOnTime = 0;

View File

@ -511,6 +511,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req)
if (pos > 0)
{
nightlightFade = (req.charAt(pos+3) != '0');
nightlightColorFade = (req.charAt(pos+3) == '2'); //NighLightColorFade can only be enabled via API or Macro with "NF=2"
nightlightActiveOld = false; //re-init
}

View File

@ -217,11 +217,16 @@ void handleNightlight()
nightlightDelayMs = (int)(nightlightDelayMins*60000);
nightlightActiveOld = true;
briNlT = bri;
for (byte i=0; i<4; i++) colNlT[i] = col[i]; // remember starting color
}
float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs);
if (nightlightFade)
{
bri = briNlT + ((nightlightTargetBri - briNlT)*nper);
if (nightlightColorFade) // color fading only is enabled with "NF=2"
{
for (byte i=0; i<4; i++) col[i] = colNlT[i]+ ((colSec[i] - colNlT[i])*nper); // fading from actual color to secondary color
}
colorUpdated(5);
}
if (nper >= 1)