2016-12-31 00:38:51 +01:00
|
|
|
/*
|
|
|
|
* LED methods
|
|
|
|
*/
|
|
|
|
|
2016-11-19 19:39:17 +01:00
|
|
|
void setAllLeds() {
|
2016-12-11 20:11:14 +01:00
|
|
|
double d = bri_t*bri_n;
|
2016-12-14 23:40:47 +01:00
|
|
|
int val = d/100;
|
2017-02-01 19:25:36 +01:00
|
|
|
if (useGammaCorrectionBri)
|
|
|
|
{
|
|
|
|
strip.setBrightness(gamma8[val]);
|
|
|
|
} else {
|
|
|
|
strip.setBrightness(val);
|
|
|
|
}
|
|
|
|
if (useGammaCorrectionBri)
|
|
|
|
{
|
|
|
|
strip.setColor(gamma8[col_t[0]], gamma8[col_t[1]], gamma8[col_t[2]]);
|
|
|
|
} else {
|
|
|
|
strip.setColor(col_t[0], col_t[1], col_t[2]);
|
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void setLedsStandard()
|
|
|
|
{
|
|
|
|
col_old[0] = col[0];
|
|
|
|
col_old[1] = col[1];
|
|
|
|
col_old[2] = col[2];
|
|
|
|
bri_old = bri;
|
|
|
|
col_t[0] = col[0];
|
|
|
|
col_t[1] = col[1];
|
|
|
|
col_t[2] = col[2];
|
|
|
|
bri_t = bri;
|
|
|
|
setAllLeds();
|
|
|
|
}
|
|
|
|
|
|
|
|
void colorUpdated(int callMode)
|
|
|
|
{
|
2016-12-11 20:11:14 +01:00
|
|
|
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (no not.)
|
2016-11-20 00:07:04 +01:00
|
|
|
if (col[0] == col_it[0] && col[1] == col_it[1] && col[2] == col_it[2] && bri == bri_it)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2016-12-14 23:40:47 +01:00
|
|
|
if (callMode == 6) notify(6);
|
2016-11-19 19:39:17 +01:00
|
|
|
return; //no change
|
|
|
|
}
|
2016-11-20 00:07:04 +01:00
|
|
|
col_it[0] = col[0];
|
|
|
|
col_it[1] = col[1];
|
|
|
|
col_it[2] = col[2];
|
|
|
|
bri_it = bri;
|
2016-11-19 19:39:17 +01:00
|
|
|
if (bri > 0) bri_last = bri;
|
|
|
|
notify(callMode);
|
|
|
|
if (fadeTransition || seqTransition)
|
|
|
|
{
|
|
|
|
if (transitionActive)
|
|
|
|
{
|
|
|
|
col_old[0] = col_t[0];
|
|
|
|
col_old[1] = col_t[1];
|
|
|
|
col_old[2] = col_t[2];
|
|
|
|
bri_old = bri_t;
|
|
|
|
}
|
|
|
|
transitionActive = true;
|
|
|
|
transitionStartTime = millis();
|
2016-11-27 16:45:54 +01:00
|
|
|
transitionDelay = transitionDelay_old;
|
2016-11-19 19:39:17 +01:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
setLedsStandard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleTransitions()
|
|
|
|
{
|
|
|
|
if (transitionActive && transitionDelay > 0)
|
|
|
|
{
|
|
|
|
float tper = (millis() - transitionStartTime)/(float)transitionDelay;
|
|
|
|
if (tper >= 1.0)
|
|
|
|
{
|
|
|
|
transitionActive = false;
|
|
|
|
tper_last = 0;
|
|
|
|
setLedsStandard();
|
2016-11-27 16:45:54 +01:00
|
|
|
if (nightlightActive && nightlightFade)
|
|
|
|
{
|
|
|
|
initNightlightFade();
|
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tper - tper_last < transitionResolution)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tper_last = tper;
|
|
|
|
if (fadeTransition)
|
|
|
|
{
|
|
|
|
col_t[0] = col_old[0]+((col[0] - col_old[0])*tper);
|
|
|
|
col_t[1] = col_old[1]+((col[1] - col_old[1])*tper);
|
|
|
|
col_t[2] = col_old[2]+((col[2] - col_old[2])*tper);
|
|
|
|
bri_t = bri_old+((bri - bri_old)*tper);
|
|
|
|
}
|
|
|
|
if (seqTransition)
|
|
|
|
{
|
|
|
|
|
|
|
|
} else setAllLeds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 16:45:54 +01:00
|
|
|
void initNightlightFade()
|
|
|
|
{
|
|
|
|
float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs);
|
|
|
|
nightlightDelayMs = nightlightDelayMs*(1-nper);
|
|
|
|
if (nper >= 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-12-11 20:11:14 +01:00
|
|
|
bri = bri_nl;
|
|
|
|
bri_it = bri_nl;
|
2016-11-27 16:45:54 +01:00
|
|
|
transitionDelay = (int)(nightlightDelayMins*60000);
|
|
|
|
transitionStartTime = nightlightStartTime;
|
|
|
|
transitionActive = true;
|
|
|
|
nightlightStartTime = millis();
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleNightlight()
|
|
|
|
{
|
|
|
|
if (nightlightActive)
|
|
|
|
{
|
|
|
|
if (!nightlightActive_old) //init
|
|
|
|
{
|
2016-12-11 20:11:14 +01:00
|
|
|
nightlightStartTime = millis();
|
2016-11-27 22:37:51 +01:00
|
|
|
notify(4);
|
2016-11-27 16:45:54 +01:00
|
|
|
nightlightDelayMs = (int)(nightlightDelayMins*60000);
|
|
|
|
nightlightActive_old = true;
|
|
|
|
if (nightlightFade)
|
|
|
|
{
|
|
|
|
initNightlightFade();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs);
|
|
|
|
if (nper >= 1)
|
|
|
|
{
|
|
|
|
nightlightActive = false;
|
2016-12-11 20:11:14 +01:00
|
|
|
if (!nightlightFade)
|
|
|
|
{
|
|
|
|
bri = bri_nl;
|
|
|
|
colorUpdated(5);
|
|
|
|
}
|
2016-11-27 16:45:54 +01:00
|
|
|
}
|
2016-12-11 20:11:14 +01:00
|
|
|
} else if (nightlightActive_old) //early de-init
|
2016-11-27 16:45:54 +01:00
|
|
|
{
|
|
|
|
nightlightActive_old = false;
|
|
|
|
if (nightlightFade)
|
|
|
|
{
|
|
|
|
transitionDelay = transitionDelay_old;
|
|
|
|
transitionActive = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|