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;
if (getVal(elem["fx"], &fx, 1, strip.getModeCount())) { //load effect ('r' random, '~' inc/dec, 1-255 exact value)
strip.setMode(id, fx);
if (!presetId && seg.mode != fxPrev) {
effectChanged = true; //send UDP
unloadPlaylist(); //stop playlist if active and FX changed manually
}
if (!presetId && seg.mode != fxPrev) effectChanged = true; //send UDP
}
seg.speed = elem[F("sx")] | seg.speed;
seg.intensity = elem[F("ix")] | seg.intensity;
getVal(elem["pal"], &seg.palette, 1, strip.getPaletteCount());
byte prevSpd = seg.speed;
byte prevInt = seg.intensity;
byte prevPal = seg.palette;
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
if (!iarr.isNull()) {
@ -332,6 +332,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
}
}
setValuesFromMainSeg(); //to make transition work on main segment
if (effectChanged) unloadPlaylist(); //if any of the effect parameter changed unload playlist
#ifndef WLED_DISABLE_CRONIXIE
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)
// 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) {
effectChanged = false;
colorChanged = false;
if (bri != briOld || effectChanged || colorChanged) {
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);
//set flag to update blynk, ws and mqtt
interfaceUpdateCallMode = callMode;
effectChanged = false;
colorChanged = false;
} else {
if (nightlightActive && !nightlightActiveOld && callMode != CALL_MODE_NOTIFICATION && callMode != CALL_MODE_NO_NOTIFY) {
notify(CALL_MODE_NIGHTLIGHT);

View File

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

View File

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

View File

@ -284,14 +284,17 @@ void handleNotifications()
//apply colors from notification
if (receiveNotificationColor || !someSel) {
if (version < 11 || !receiveSegmentOptions) {
// only change col[] if not syncing full segments
col[0] = udpIn[3];
col[1] = udpIn[4];
col[2] = udpIn[5];
}
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 > 1 && (version < 11 || !receiveSegmentOptions)) {
// only change colSec[] if not syncing full segments
colSec[0] = udpIn[12];
colSec[1] = udpIn[13];
colSec[2] = udpIn[14];

View File

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