2016-12-31 00:38:51 +01:00
|
|
|
/*
|
|
|
|
* LED methods
|
|
|
|
*/
|
|
|
|
|
2016-11-19 19:39:17 +01:00
|
|
|
void setAllLeds() {
|
2018-02-20 22:29:48 +01:00
|
|
|
double d = bri_t*briMultiplier;
|
2016-12-14 23:40:47 +01:00
|
|
|
int val = d/100;
|
2017-02-21 23:13:05 +01:00
|
|
|
if (val > 255) val = 255;
|
2017-02-01 19:25:36 +01:00
|
|
|
if (useGammaCorrectionBri)
|
|
|
|
{
|
|
|
|
strip.setBrightness(gamma8[val]);
|
|
|
|
} else {
|
|
|
|
strip.setBrightness(val);
|
|
|
|
}
|
2017-10-12 17:09:59 +02:00
|
|
|
if (useGammaCorrectionRGB)
|
|
|
|
{
|
|
|
|
strip.setColor(gamma8[col_t[0]], gamma8[col_t[1]], gamma8[col_t[2]], gamma8[white_t]);
|
2017-11-28 16:04:11 +01:00
|
|
|
strip.setSecondaryColor(gamma8[col_sec[0]], gamma8[col_sec[1]], gamma8[col_sec[2]], gamma8[white_sec]);
|
2017-10-12 17:09:59 +02:00
|
|
|
} else {
|
|
|
|
strip.setColor(col_t[0], col_t[1], col_t[2], white_t);
|
2017-11-28 16:04:11 +01:00
|
|
|
strip.setSecondaryColor(col_sec[0], col_sec[1], col_sec[2], white_sec);
|
2017-10-12 17:09:59 +02:00
|
|
|
}
|
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];
|
2017-10-12 17:09:59 +02:00
|
|
|
white_old = white;
|
2016-11-19 19:39:17 +01:00
|
|
|
bri_old = bri;
|
|
|
|
col_t[0] = col[0];
|
|
|
|
col_t[1] = col[1];
|
|
|
|
col_t[2] = col[2];
|
2017-10-12 17:09:59 +02:00
|
|
|
white_t = white;
|
2016-11-19 19:39:17 +01:00
|
|
|
bri_t = bri;
|
|
|
|
setAllLeds();
|
|
|
|
}
|
|
|
|
|
2017-11-28 16:04:11 +01:00
|
|
|
bool colorChanged()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (col[i] != col_it[i]) return true;
|
|
|
|
if (col_sec[i] != col_sec_it[i]) return true;
|
|
|
|
}
|
|
|
|
if (white != white_it || white_sec != white_sec_it) return true;
|
|
|
|
if (bri != bri_it) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-19 19:39:17 +01:00
|
|
|
void colorUpdated(int callMode)
|
|
|
|
{
|
2017-02-21 23:59:47 +01:00
|
|
|
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (no not.) (NN)6: fx changed
|
2017-11-28 16:04:11 +01:00
|
|
|
if (!colorChanged())
|
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
|
|
|
|
}
|
2017-04-26 14:04:53 +02:00
|
|
|
if (callMode != 5 && nightlightActive && nightlightFade)
|
|
|
|
{
|
2018-02-20 22:29:48 +01:00
|
|
|
bri_nl_t = bri;
|
2017-04-26 14:04:53 +02:00
|
|
|
nightlightDelayMs -= (millis() - nightlightStartTime);
|
|
|
|
nightlightStartTime = millis();
|
|
|
|
}
|
2016-11-20 00:07:04 +01:00
|
|
|
col_it[0] = col[0];
|
|
|
|
col_it[1] = col[1];
|
|
|
|
col_it[2] = col[2];
|
2017-11-28 16:04:11 +01:00
|
|
|
col_sec_it[0] = col_sec[0];
|
|
|
|
col_sec_it[1] = col_sec[1];
|
|
|
|
col_sec_it[2] = col_sec[2];
|
2017-10-12 17:09:59 +02:00
|
|
|
white_it = white;
|
2017-11-28 16:04:11 +01:00
|
|
|
white_sec_it = white_sec;
|
2016-11-20 00:07:04 +01:00
|
|
|
bri_it = bri;
|
2016-11-19 19:39:17 +01:00
|
|
|
if (bri > 0) bri_last = bri;
|
|
|
|
notify(callMode);
|
2017-10-28 22:22:37 +02:00
|
|
|
if (fadeTransition || sweepTransition)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2017-10-28 23:40:06 +02:00
|
|
|
if (transitionActive)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
|
|
|
col_old[0] = col_t[0];
|
|
|
|
col_old[1] = col_t[1];
|
|
|
|
col_old[2] = col_t[2];
|
2017-10-12 17:09:59 +02:00
|
|
|
white_old = white_t;
|
2016-11-19 19:39:17 +01:00
|
|
|
bri_old = bri_t;
|
2017-04-26 14:04:53 +02:00
|
|
|
tper_last = 0;
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
|
|
|
transitionActive = true;
|
|
|
|
transitionStartTime = millis();
|
2017-11-19 15:31:17 +01:00
|
|
|
strip.setFastUpdateMode(true);
|
2016-11-19 19:39:17 +01:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
setLedsStandard();
|
2017-11-19 15:31:17 +01:00
|
|
|
strip.trigger();
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleTransitions()
|
|
|
|
{
|
|
|
|
if (transitionActive && transitionDelay > 0)
|
|
|
|
{
|
|
|
|
float tper = (millis() - transitionStartTime)/(float)transitionDelay;
|
|
|
|
if (tper >= 1.0)
|
|
|
|
{
|
|
|
|
transitionActive = false;
|
|
|
|
tper_last = 0;
|
2017-10-28 22:22:37 +02:00
|
|
|
if (sweepTransition) strip.unlockAll();
|
2016-11-19 19:39:17 +01:00
|
|
|
setLedsStandard();
|
2017-11-19 15:31:17 +01:00
|
|
|
strip.setFastUpdateMode(false);
|
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);
|
2017-10-12 17:09:59 +02:00
|
|
|
white_t = white_old +((white - white_old )*tper);
|
|
|
|
bri_t = bri_old +((bri - bri_old )*tper);
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2017-10-28 22:22:37 +02:00
|
|
|
if (sweepTransition)
|
|
|
|
{
|
|
|
|
strip.lockAll();
|
|
|
|
if (sweepDirection)
|
|
|
|
{
|
|
|
|
strip.unlockRange(0, (int)(tper*(double)ledcount));
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
strip.unlockRange(ledcount - (int)(tper*(double)ledcount), ledcount);
|
|
|
|
}
|
|
|
|
if (!fadeTransition)
|
|
|
|
{
|
|
|
|
setLedsStandard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fadeTransition) setAllLeds();
|
2016-11-27 16:45:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2018-02-20 22:29:48 +01:00
|
|
|
bri_nl_t = bri;
|
2016-11-27 16:45:54 +01:00
|
|
|
}
|
|
|
|
float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs);
|
2017-04-26 14:04:53 +02:00
|
|
|
if (nightlightFade)
|
|
|
|
{
|
2018-02-20 22:29:48 +01:00
|
|
|
bri = bri_nl_t+((nightlightTargetBri - bri_nl_t)*nper);
|
2017-04-26 14:04:53 +02:00
|
|
|
colorUpdated(5);
|
|
|
|
}
|
2016-11-27 16:45:54 +01:00
|
|
|
if (nper >= 1)
|
|
|
|
{
|
|
|
|
nightlightActive = false;
|
2016-12-11 20:11:14 +01:00
|
|
|
if (!nightlightFade)
|
|
|
|
{
|
2018-02-20 22:29:48 +01:00
|
|
|
bri = nightlightTargetBri;
|
2016-12-11 20:11:14 +01:00
|
|
|
colorUpdated(5);
|
|
|
|
}
|
2018-02-20 22:29:48 +01:00
|
|
|
if (bri == 0) bri_last = bri_nl_t;
|
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;
|
|
|
|
}
|
|
|
|
}
|