Merge pull request #571 from Def3nder/SunRiseFading
SunRise using NightLight Fade
This commit is contained in:
commit
32c10e5ae8
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user