2016-12-31 00:38:51 +01:00
|
|
|
/*
|
|
|
|
* LED methods
|
|
|
|
*/
|
|
|
|
|
2016-11-19 19:39:17 +01:00
|
|
|
void setAllLeds() {
|
2018-08-11 22:57:13 +02:00
|
|
|
if (!arlsTimeout || !arlsForceMaxBri)
|
2017-02-01 19:25:36 +01:00
|
|
|
{
|
2018-08-11 22:57:13 +02:00
|
|
|
double d = briT*briMultiplier;
|
|
|
|
int val = d/100;
|
|
|
|
if (val > 255) val = 255;
|
|
|
|
if (useGammaCorrectionBri)
|
|
|
|
{
|
|
|
|
strip.setBrightness(gamma8[val]);
|
|
|
|
} else {
|
|
|
|
strip.setBrightness(val);
|
|
|
|
}
|
2017-02-01 19:25:36 +01:00
|
|
|
}
|
2018-05-10 19:55:58 +02:00
|
|
|
if (disableSecTransition)
|
|
|
|
{
|
|
|
|
for (byte i = 0; i<3; i++)
|
|
|
|
{
|
|
|
|
colSecT[i] = colSec[i];
|
|
|
|
}
|
|
|
|
whiteSecT = whiteSec;
|
|
|
|
}
|
2018-05-31 19:26:16 +02:00
|
|
|
if (autoRGBtoRGBW)
|
|
|
|
{
|
|
|
|
colorRGBtoRGBW(colT,&whiteT);
|
|
|
|
colorRGBtoRGBW(colSecT,&whiteSecT);
|
|
|
|
}
|
2017-10-12 17:09:59 +02:00
|
|
|
if (useGammaCorrectionRGB)
|
|
|
|
{
|
2018-03-14 13:16:28 +01:00
|
|
|
strip.setColor(gamma8[colT[0]], gamma8[colT[1]], gamma8[colT[2]], gamma8[whiteT]);
|
2018-05-10 19:55:58 +02:00
|
|
|
strip.setSecondaryColor(gamma8[colSecT[0]], gamma8[colSecT[1]], gamma8[colSecT[2]], gamma8[whiteSecT]);
|
2017-10-12 17:09:59 +02:00
|
|
|
} else {
|
2018-03-14 13:16:28 +01:00
|
|
|
strip.setColor(colT[0], colT[1], colT[2], whiteT);
|
2018-05-10 19:55:58 +02:00
|
|
|
strip.setSecondaryColor(colSecT[0], colSecT[1], colSecT[2], whiteSecT);
|
2017-10-12 17:09:59 +02:00
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void setLedsStandard()
|
|
|
|
{
|
2018-05-10 19:55:58 +02:00
|
|
|
for (byte i = 0; i<3; i++)
|
|
|
|
{
|
|
|
|
colOld[i] = col[i];
|
|
|
|
colT[i] = col[i];
|
|
|
|
colSecOld[i] = colSec[i];
|
|
|
|
colSecT[i] = colSec[i];
|
|
|
|
}
|
2018-03-14 13:16:28 +01:00
|
|
|
whiteOld = white;
|
|
|
|
briOld = bri;
|
2018-05-10 19:55:58 +02:00
|
|
|
whiteSecOld = whiteSec;
|
2018-03-14 13:16:28 +01:00
|
|
|
whiteT = white;
|
|
|
|
briT = bri;
|
2018-05-10 19:55:58 +02:00
|
|
|
whiteSecT = whiteSec;
|
2016-11-19 19:39:17 +01:00
|
|
|
setAllLeds();
|
|
|
|
}
|
|
|
|
|
2017-11-28 16:04:11 +01:00
|
|
|
bool colorChanged()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
2018-03-14 13:16:28 +01:00
|
|
|
if (col[i] != colIT[i]) return true;
|
|
|
|
if (colSec[i] != colSecIT[i]) return true;
|
2017-11-28 16:04:11 +01:00
|
|
|
}
|
2018-03-14 13:16:28 +01:00
|
|
|
if (white != whiteIT || whiteSec != whiteSecIT) return true;
|
|
|
|
if (bri != briIT) return true;
|
2017-11-28 16:04:11 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-19 19:39:17 +01:00
|
|
|
void colorUpdated(int callMode)
|
|
|
|
{
|
2018-07-29 14:03:02 +02:00
|
|
|
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (NN)6: fx changed 7: hue 8: preset cycle 9: blynk
|
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-03-14 13:16:28 +01:00
|
|
|
briNlT = bri;
|
2017-04-26 14:04:53 +02:00
|
|
|
nightlightDelayMs -= (millis() - nightlightStartTime);
|
|
|
|
nightlightStartTime = millis();
|
|
|
|
}
|
2018-03-14 13:16:28 +01:00
|
|
|
colIT[0] = col[0];
|
|
|
|
colIT[1] = col[1];
|
|
|
|
colIT[2] = col[2];
|
|
|
|
colSecIT[0] = colSec[0];
|
|
|
|
colSecIT[1] = colSec[1];
|
|
|
|
colSecIT[2] = colSec[2];
|
|
|
|
whiteIT = white;
|
|
|
|
whiteSecIT = whiteSec;
|
|
|
|
briIT = bri;
|
|
|
|
if (bri > 0) briLast = bri;
|
2016-11-19 19:39:17 +01:00
|
|
|
notify(callMode);
|
2018-09-04 15:51:38 +02:00
|
|
|
if (fadeTransition)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2018-03-15 13:03:50 +01:00
|
|
|
//set correct delay if not using notification delay
|
|
|
|
if (callMode != 3) transitionDelayTemp = transitionDelay;
|
2018-04-11 23:50:35 +02:00
|
|
|
if (transitionDelayTemp == 0) {setLedsStandard();strip.trigger();return;}
|
2018-03-15 13:03:50 +01:00
|
|
|
|
2017-10-28 23:40:06 +02:00
|
|
|
if (transitionActive)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2018-03-14 13:16:28 +01:00
|
|
|
colOld[0] = colT[0];
|
|
|
|
colOld[1] = colT[1];
|
|
|
|
colOld[2] = colT[2];
|
|
|
|
whiteOld = whiteT;
|
2018-05-10 19:55:58 +02:00
|
|
|
colSecOld[0] = colSecT[0];
|
|
|
|
colSecOld[1] = colSecT[1];
|
|
|
|
colSecOld[2] = colSecT[2];
|
|
|
|
whiteSecOld = whiteSecT;
|
2018-03-14 13:16:28 +01:00
|
|
|
briOld = briT;
|
|
|
|
tperLast = 0;
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2018-09-06 02:05:56 +02:00
|
|
|
strip.setTransitionMode(true);
|
2016-11-19 19:39:17 +01:00
|
|
|
transitionActive = true;
|
|
|
|
transitionStartTime = millis();
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
setLedsStandard();
|
2017-11-19 15:31:17 +01:00
|
|
|
strip.trigger();
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2018-07-29 14:03:02 +02:00
|
|
|
if (callMode != 9 && callMode != 5 && callMode != 8) updateBlynk();
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleTransitions()
|
|
|
|
{
|
2018-03-15 13:03:50 +01:00
|
|
|
if (transitionActive && transitionDelayTemp > 0)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2018-03-15 13:03:50 +01:00
|
|
|
float tper = (millis() - transitionStartTime)/(float)transitionDelayTemp;
|
2016-11-19 19:39:17 +01:00
|
|
|
if (tper >= 1.0)
|
|
|
|
{
|
2018-09-06 02:05:56 +02:00
|
|
|
strip.setTransitionMode(false);
|
2016-11-19 19:39:17 +01:00
|
|
|
transitionActive = false;
|
2018-03-14 13:16:28 +01:00
|
|
|
tperLast = 0;
|
2016-11-19 19:39:17 +01:00
|
|
|
setLedsStandard();
|
|
|
|
return;
|
|
|
|
}
|
2018-04-11 23:50:35 +02:00
|
|
|
if (tper - tperLast < 0.004)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-03-14 13:16:28 +01:00
|
|
|
tperLast = tper;
|
2016-11-19 19:39:17 +01:00
|
|
|
if (fadeTransition)
|
|
|
|
{
|
2018-05-10 19:55:58 +02:00
|
|
|
for (byte i = 0; i<3; i++)
|
|
|
|
{
|
|
|
|
colT[i] = colOld[i]+((col[i] - colOld[i])*tper);
|
|
|
|
colSecT[i] = colSecOld[i]+((colSec[i] - colSecOld[i])*tper);
|
|
|
|
}
|
2018-03-14 13:16:28 +01:00
|
|
|
whiteT = whiteOld +((white - whiteOld )*tper);
|
2018-05-10 19:55:58 +02:00
|
|
|
whiteSecT = whiteSecOld +((whiteSec - whiteSecOld )*tper);
|
2018-03-14 13:16:28 +01:00
|
|
|
briT = briOld +((bri - briOld )*tper);
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2018-09-04 15:51:38 +02:00
|
|
|
//TODO: properly remove sweep transition
|
2017-10-28 22:22:37 +02:00
|
|
|
if (fadeTransition) setAllLeds();
|
2016-11-27 16:45:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleNightlight()
|
|
|
|
{
|
|
|
|
if (nightlightActive)
|
|
|
|
{
|
2018-03-14 13:16:28 +01:00
|
|
|
if (!nightlightActiveOld) //init
|
2016-11-27 16:45:54 +01:00
|
|
|
{
|
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);
|
2018-03-14 13:16:28 +01:00
|
|
|
nightlightActiveOld = true;
|
|
|
|
briNlT = 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-03-14 13:16:28 +01:00
|
|
|
bri = briNlT+((nightlightTargetBri - briNlT)*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-07-29 14:03:02 +02:00
|
|
|
updateBlynk();
|
2018-03-14 13:16:28 +01:00
|
|
|
if (bri == 0) briLast = briNlT;
|
2016-11-27 16:45:54 +01:00
|
|
|
}
|
2018-03-14 13:16:28 +01:00
|
|
|
} else if (nightlightActiveOld) //early de-init
|
2016-11-27 16:45:54 +01:00
|
|
|
{
|
2018-03-14 13:16:28 +01:00
|
|
|
nightlightActiveOld = false;
|
2016-11-27 16:45:54 +01:00
|
|
|
}
|
2018-04-11 23:50:35 +02:00
|
|
|
|
|
|
|
//also handle preset cycle here
|
|
|
|
if (presetCyclingEnabled && (millis() - presetCycledTime > presetCycleTime))
|
|
|
|
{
|
2018-05-10 19:55:58 +02:00
|
|
|
applyPreset(presetCycCurr,presetApplyBri,presetApplyCol,presetApplyFx);
|
2018-04-11 23:50:35 +02:00
|
|
|
presetCycCurr++; if (presetCycCurr > presetCycleMax) presetCycCurr = presetCycleMin;
|
|
|
|
if (presetCycCurr > 25) presetCycCurr = 1;
|
|
|
|
colorUpdated(8);
|
|
|
|
presetCycledTime = millis();
|
|
|
|
}
|
2016-11-27 16:45:54 +01:00
|
|
|
}
|