Color change tracking. Minor fixes.

This commit is contained in:
Blaz Kristan 2022-01-15 21:15:37 +01:00
parent 3da70c3e8b
commit b0c40e1e37
6 changed files with 45 additions and 39 deletions

View File

@ -162,14 +162,14 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
byte fxPrev = fx; byte fxPrev = fx;
if (getVal(elem["fx"], &fx, 1, strip.getModeCount())) { //load effect ('r' random, '~' inc/dec, 1-255 exact value) if (getVal(elem["fx"], &fx, 1, strip.getModeCount())) { //load effect ('r' random, '~' inc/dec, 1-255 exact value)
strip.setMode(id, fx); strip.setMode(id, fx);
if (!presetId && seg.mode != fxPrev) { if (!presetId && seg.mode != fxPrev) effectChanged = true; //send UDP
effectChanged = true; //send UDP
unloadPlaylist(); //stop playlist if active and FX changed manually
} }
} byte prevSpd = seg.speed;
seg.speed = elem[F("sx")] | seg.speed; byte prevInt = seg.intensity;
seg.intensity = elem[F("ix")] | seg.intensity; byte prevPal = seg.palette;
getVal(elem["pal"], &seg.palette, 1, strip.getPaletteCount()); if (getVal(elem[F("sx")], &seg.speed, 0, 255) && !presetId && prevSpd != seg.speed) effectChanged = true; //also supports inc/decrementing and random
if (getVal(elem[F("ix")], &seg.intensity, 0, 255) && !presetId && prevInt != seg.intensity) effectChanged = true; //also supports inc/decrementing and random
if (getVal(elem["pal"], &seg.palette, 1, strip.getPaletteCount()) && !presetId && prevPal != seg.palette) effectChanged = true; //also supports inc/decrementing and random
JsonArray iarr = elem[F("i")]; //set individual LEDs JsonArray iarr = elem[F("i")]; //set individual LEDs
if (!iarr.isNull()) { if (!iarr.isNull()) {
@ -332,6 +332,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
} }
} }
setValuesFromMainSeg(); //to make transition work on main segment setValuesFromMainSeg(); //to make transition work on main segment
if (effectChanged) unloadPlaylist(); //if any of the effect parameter changed unload playlist
#ifndef WLED_DISABLE_CRONIXIE #ifndef WLED_DISABLE_CRONIXIE
if (root["nx"].is<const char*>()) { if (root["nx"].is<const char*>()) {

View File

@ -65,21 +65,17 @@ void colorUpdated(int callMode)
{ {
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification) //call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification)
// 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa 11: ws send only 12: button preset // 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa 11: ws send only 12: button preset
// if (callMode != CALL_MODE_INIT &&
// callMode != CALL_MODE_DIRECT_CHANGE &&
// callMode != CALL_MODE_NO_NOTIFY &&
// callMode != CALL_MODE_BUTTON_PRESET) strip.applyToAllSelected = true; //if not from JSON api, which directly sets segments
if (effectChanged || colorChanged) { if (bri != briOld || effectChanged || colorChanged) {
effectChanged = false;
colorChanged = false;
if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0; if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0;
currentPreset = 0; //something changed, so we are no longer in the preset if (effectChanged) currentPreset = 0; //something changed, so we are no longer in the preset
if (callMode != CALL_MODE_NOTIFICATION && callMode != CALL_MODE_NO_NOTIFY) notify(callMode); if (callMode != CALL_MODE_NOTIFICATION && callMode != CALL_MODE_NO_NOTIFY) notify(callMode);
//set flag to update blynk, ws and mqtt //set flag to update blynk, ws and mqtt
interfaceUpdateCallMode = callMode; interfaceUpdateCallMode = callMode;
effectChanged = false;
colorChanged = false;
} else { } else {
if (nightlightActive && !nightlightActiveOld && callMode != CALL_MODE_NOTIFICATION && callMode != CALL_MODE_NO_NOTIFY) { if (nightlightActive && !nightlightActiveOld && callMode != CALL_MODE_NOTIFICATION && callMode != CALL_MODE_NO_NOTIFY) {
notify(CALL_MODE_NIGHTLIGHT); notify(CALL_MODE_NIGHTLIGHT);

View File

@ -63,7 +63,6 @@ void handlePresets()
if (!errorFlag && presetToApply < 255) currentPreset = presetToApply; if (!errorFlag && presetToApply < 255) currentPreset = presetToApply;
effectChanged = true; //force UDP notification
colorUpdated(callModeToApply); colorUpdated(callModeToApply);
updateInterfaces(callModeToApply); updateInterfaces(callModeToApply);

View File

@ -619,7 +619,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
//set brightness //set brightness
updateVal(&req, "&A=", &bri); updateVal(&req, "&A=", &bri);
bool col0Changed = false, col1Changed = false; bool col0Changed = false, col1Changed = false, col2Changed = false;
//set colors //set colors
updateVal(&req, "&R=", &col[0]); updateVal(&req, "&R=", &col[0]);
updateVal(&req, "&G=", &col[1]); updateVal(&req, "&G=", &col[1]);
@ -661,42 +661,51 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
if (pos > 0) { if (pos > 0) {
tempsat = getNumVal(&req, pos); tempsat = getNumVal(&req, pos);
} }
colorHStoRGB(temphue,tempsat,(req.indexOf(F("H2"))>0)? colSec:col); byte sec = req.indexOf(F("H2"));
colorHStoRGB(temphue, tempsat, (sec>0) ? colSec : col);
if (sec>0) col1Changed = true;
else col0Changed = true;
colorChanged = true;
} }
//set white spectrum (kelvin) //set white spectrum (kelvin)
pos = req.indexOf(F("&K=")); pos = req.indexOf(F("&K="));
if (pos > 0) { if (pos > 0) {
colorKtoRGB(getNumVal(&req, pos),(req.indexOf(F("K2"))>0)? colSec:col); byte sec = req.indexOf(F("K2"));
colorKtoRGB(getNumVal(&req, pos), (sec>0) ? colSec : col);
if (sec>0) col1Changed = true;
else col0Changed = true;
colorChanged = true;
} }
//set color from HEX or 32bit DEC //set color from HEX or 32bit DEC
byte tmpCol[4];
pos = req.indexOf(F("CL=")); pos = req.indexOf(F("CL="));
if (pos > 0) { if (pos > 0) {
byte t[4]; colorFromDecOrHexString(col, (char*)req.substring(pos + 3).c_str());
colorFromDecOrHexString(t, (char*)req.substring(pos + 3).c_str()); selseg.setColor(0, RGBW32(col[0], col[1], col[2], col[3]), selectedSeg); // defined above (SS= or main)
selseg.setColor(0, RGBW32(t[0], t[1], t[2], t[3]), selectedSeg); // defined above (SS=)
col0Changed = colorChanged = true; col0Changed = colorChanged = true;
} }
pos = req.indexOf(F("C2=")); pos = req.indexOf(F("C2="));
if (pos > 0) { if (pos > 0) {
byte t[4];
colorFromDecOrHexString(colSec, (char*)req.substring(pos + 3).c_str()); colorFromDecOrHexString(colSec, (char*)req.substring(pos + 3).c_str());
selseg.setColor(1, RGBW32(t[0], t[1], t[2], t[3]), selectedSeg); // defined above (SS=) selseg.setColor(1, RGBW32(colSec[0], colSec[1], colSec[2], colSec[3]), selectedSeg); // defined above (SS= or main)
col1Changed = colorChanged = true; col1Changed = colorChanged = true;
} }
pos = req.indexOf(F("C3=")); pos = req.indexOf(F("C3="));
if (pos > 0) { if (pos > 0) {
byte t[4]; colorFromDecOrHexString(tmpCol, (char*)req.substring(pos + 3).c_str());
colorFromDecOrHexString(t, (char*)req.substring(pos + 3).c_str()); selseg.setColor(2, RGBW32(tmpCol[0], tmpCol[1], tmpCol[2], tmpCol[3]), selectedSeg); // defined above (SS= or main)
selseg.setColor(2, RGBW32(t[0], t[1], t[2], t[3]), selectedSeg); // defined above (SS=) col2Changed = colorChanged = true;
colorChanged = true;
} }
//set to random hue SR=0->1st SR=1->2nd //set to random hue SR=0->1st SR=1->2nd
pos = req.indexOf(F("SR")); pos = req.indexOf(F("SR"));
if (pos > 0) { if (pos > 0) {
_setRandomColor(getNumVal(&req, pos)); byte sec = getNumVal(&req, pos);
_setRandomColor(sec);
if (sec>0) col1Changed = true;
else col0Changed = true;
colorChanged = true; colorChanged = true;
} }
@ -704,13 +713,12 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
pos = req.indexOf(F("SC")); pos = req.indexOf(F("SC"));
if (pos > 0) { if (pos > 0) {
byte temp; byte temp;
for (uint8_t i=0; i<4; i++) for (uint8_t i=0; i<4; i++) {
{
temp = col[i]; temp = col[i];
col[i] = colSec[i]; col[i] = colSec[i];
colSec[i] = temp; colSec[i] = temp;
} }
colorChanged = true; col0Changed = col1Changed = colorChanged = true;
} }
//set effect parameters //set effect parameters
@ -861,11 +869,10 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
if (effectSpeed != prevSpeed) seg.speed = effectSpeed; if (effectSpeed != prevSpeed) seg.speed = effectSpeed;
if (effectIntensity != prevIntensity) seg.intensity = effectIntensity; if (effectIntensity != prevIntensity) seg.intensity = effectIntensity;
if (effectPalette != prevPalette) seg.palette = effectPalette; if (effectPalette != prevPalette) seg.palette = effectPalette;
if (col0Changed) seg.colors[0] = RGBW32(col[0],col[1],col[2],col[3]); if (col0Changed) seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]);
if (col1Changed) seg.colors[1] = RGBW32(colSec[0],colSec[1],colSec[2],colSec[3]); if (col1Changed) seg.colors[1] = RGBW32(colSec[0], colSec[1], colSec[2], colSec[3]);
if (col2Changed) seg.colors[2] = RGBW32(tmpCol[0], tmpCol[1], tmpCol[2], tmpCol[3]);
} }
//if (col0Changed) strip.setColor(0, RGBW32(col[0],col[1],col[2],col[3]));
//if (col1Changed) strip.setColor(1, RGBW32(colSec[0],colSec[1],colSec[2],colSec[3]));
} }
strip.applyToAllSelected = false; strip.applyToAllSelected = false;
setValuesFromMainSeg(); setValuesFromMainSeg();

View File

@ -284,14 +284,17 @@ void handleNotifications()
//apply colors from notification //apply colors from notification
if (receiveNotificationColor || !someSel) { if (receiveNotificationColor || !someSel) {
if (version < 11 || !receiveSegmentOptions) { if (version < 11 || !receiveSegmentOptions) {
// only change col[] if not syncing full segments
col[0] = udpIn[3]; col[0] = udpIn[3];
col[1] = udpIn[4]; col[1] = udpIn[4];
col[2] = udpIn[5]; col[2] = udpIn[5];
} }
if (version > 0) //sending module's white val is intended if (version > 0) //sending module's white val is intended
{ {
// only change col[3] if not syncing full segments
if (version < 11 || !receiveSegmentOptions) col[3] = udpIn[10]; if (version < 11 || !receiveSegmentOptions) col[3] = udpIn[10];
if (version > 1 && (version < 11 || !receiveSegmentOptions)) { if (version > 1 && (version < 11 || !receiveSegmentOptions)) {
// only change colSec[] if not syncing full segments
colSec[0] = udpIn[12]; colSec[0] = udpIn[12];
colSec[1] = udpIn[13]; colSec[1] = udpIn[13];
colSec[2] = udpIn[14]; colSec[2] = udpIn[14];

View File

@ -187,7 +187,7 @@ void _setRandomColor(bool _sec, bool fromButton)
} else { } else {
colorHStoRGB(lastRandomIndex*256,255,col); colorHStoRGB(lastRandomIndex*256,255,col);
} }
if (fromButton) colorUpdated(2); if (fromButton) colorUpdated(CALL_MODE_BUTTON);
} }