Merge effectChanged and colorChanged to stateChanged

This commit is contained in:
cschwinne 2022-02-21 22:12:13 +01:00
parent 5f871bc01f
commit 44739c5198
6 changed files with 24 additions and 31 deletions

View File

@ -501,7 +501,7 @@ public:
#endif #endif
effectCurrentIndex = max(min((increase ? effectCurrentIndex+1 : effectCurrentIndex-1), strip.getModeCount()-1), 0); effectCurrentIndex = max(min((increase ? effectCurrentIndex+1 : effectCurrentIndex-1), strip.getModeCount()-1), 0);
effectCurrent = modes_alpha_indexes[effectCurrentIndex]; effectCurrent = modes_alpha_indexes[effectCurrentIndex];
effectChanged = true; stateChanged = true;
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getMaxSegments(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); WS2812FX::Segment& seg = strip.getSegment(i);
@ -529,7 +529,7 @@ public:
display->updateRedrawTime(); display->updateRedrawTime();
#endif #endif
effectSpeed = max(min((increase ? effectSpeed+fadeAmount : effectSpeed-fadeAmount), 255), 0); effectSpeed = max(min((increase ? effectSpeed+fadeAmount : effectSpeed-fadeAmount), 255), 0);
effectChanged = true; stateChanged = true;
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getMaxSegments(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); WS2812FX::Segment& seg = strip.getSegment(i);
@ -557,7 +557,7 @@ public:
display->updateRedrawTime(); display->updateRedrawTime();
#endif #endif
effectIntensity = max(min((increase ? effectIntensity+fadeAmount : effectIntensity-fadeAmount), 255), 0); effectIntensity = max(min((increase ? effectIntensity+fadeAmount : effectIntensity-fadeAmount), 255), 0);
effectChanged = true; stateChanged = true;
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getMaxSegments(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); WS2812FX::Segment& seg = strip.getSegment(i);
@ -586,7 +586,7 @@ public:
#endif #endif
effectPaletteIndex = max(min((increase ? effectPaletteIndex+1 : effectPaletteIndex-1), strip.getPaletteCount()-1), 0); effectPaletteIndex = max(min((increase ? effectPaletteIndex+1 : effectPaletteIndex-1), strip.getPaletteCount()-1), 0);
effectPalette = palettes_alpha_indexes[effectPaletteIndex]; effectPalette = palettes_alpha_indexes[effectPaletteIndex];
effectChanged = true; stateChanged = true;
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getMaxSegments(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); WS2812FX::Segment& seg = strip.getSegment(i);
@ -615,7 +615,7 @@ public:
#endif #endif
currentHue1 = max(min((increase ? currentHue1+fadeAmount : currentHue1-fadeAmount), 255), 0); currentHue1 = max(min((increase ? currentHue1+fadeAmount : currentHue1-fadeAmount), 255), 0);
colorHStoRGB(currentHue1*256, currentSat1, col); colorHStoRGB(currentHue1*256, currentSat1, col);
colorChanged = true; stateChanged = true;
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getMaxSegments(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); WS2812FX::Segment& seg = strip.getSegment(i);

View File

@ -135,17 +135,13 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
byte sz = colX.size(); byte sz = colX.size();
if (sz == 0) continue; //do nothing on empty array if (sz == 0) continue; //do nothing on empty array
byte cp = copyArray(colX, rgbw, 4); byte cp = copyArray(colX, rgbw, 4);
if (cp == 1 && rgbw[0] == 0)
seg.setColor(i, 0, id);
colValid = true; colValid = true;
} }
if (!colValid) continue; if (!colValid) continue;
uint32_t color = RGBW32(rgbw[0],rgbw[1],rgbw[2],rgbw[3]); seg.setColor(i, RGBW32(rgbw[0],rgbw[1],rgbw[2],rgbw[3]), id);
colorChanged |= (seg.colors[i] != color);
seg.setColor(i, color, id);
if (seg.mode == FX_MODE_STATIC) strip.trigger(); //instant refresh if (seg.mode == FX_MODE_STATIC) strip.trigger(); //instant refresh
} }
} }
@ -231,7 +227,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
seg.setOption(SEG_OPTION_FREEZE, false); seg.setOption(SEG_OPTION_FREEZE, false);
} }
//send UDP if not in preset and something changed that is not just selection //send UDP if not in preset and something changed that is not just selection
if (!presetId && (seg.differs(prev) & 0x7F)) effectChanged = true; if (!presetId && (seg.differs(prev) & 0x7F)) stateChanged = true;
return; return;
} }

View File

@ -25,19 +25,19 @@ void applyValuesToSelectedSegs()
if (i != strip.getMainSegmentId() && (!seg.isActive() || !seg.isSelected())) continue; if (i != strip.getMainSegmentId() && (!seg.isActive() || !seg.isSelected())) continue;
if (effectSpeed != mainsegPrev.speed) { if (effectSpeed != mainsegPrev.speed) {
seg.speed = effectSpeed; effectChanged = true;} seg.speed = effectSpeed; stateChanged = true;}
if (effectIntensity != mainsegPrev.intensity) { if (effectIntensity != mainsegPrev.intensity) {
seg.intensity = effectIntensity; effectChanged = true;} seg.intensity = effectIntensity; stateChanged = true;}
if (effectPalette != mainsegPrev.palette) { if (effectPalette != mainsegPrev.palette) {
seg.palette = effectPalette; effectChanged = true;} seg.palette = effectPalette; stateChanged = true;}
if (effectCurrent != mainsegPrev.mode) { if (effectCurrent != mainsegPrev.mode) {
strip.setMode(i, effectCurrent); effectChanged = true;} strip.setMode(i, effectCurrent); stateChanged = true;}
uint32_t col0 = RGBW32(col[0],col[1],col[2],col[3]); uint32_t col0 = RGBW32(col[0],col[1],col[2],col[3]);
uint32_t col1 = RGBW32(colSec[0], colSec[1], colSec[2], colSec[3]); uint32_t col1 = RGBW32(colSec[0], colSec[1], colSec[2], colSec[3]);
if (col0 != mainsegPrev.colors[0]) { if (col0 != mainsegPrev.colors[0]) {
seg.setColor(0, col0, i); colorChanged = true;} seg.setColor(0, col0, i); stateChanged = true;}
if (col1 != mainsegPrev.colors[1]) { if (col1 != mainsegPrev.colors[1]) {
seg.setColor(1, col1, i); colorChanged = true;} seg.setColor(1, col1, i); stateChanged = true;}
} }
} }
@ -94,16 +94,15 @@ void stateUpdated(byte callMode) {
// 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
setValuesFromMainSeg(); setValuesFromMainSeg();
if (bri != briOld || effectChanged || colorChanged) { if (bri != briOld || stateChanged) {
if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0; if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0;
if (effectChanged) currentPreset = 0; //something changed, so we are no longer in the preset if (stateChanged) 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; stateChanged = 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

@ -779,7 +779,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
colorFromDecOrHexString(tmpCol, (char*)req.substring(pos + 3).c_str()); colorFromDecOrHexString(tmpCol, (char*)req.substring(pos + 3).c_str());
uint32_t col2 = RGBW32(tmpCol[0], tmpCol[1], tmpCol[2], tmpCol[3]); uint32_t col2 = RGBW32(tmpCol[0], tmpCol[1], tmpCol[2], tmpCol[3]);
selseg.setColor(2, col2, selectedSeg); // defined above (SS= or main) selseg.setColor(2, col2, selectedSeg); // defined above (SS= or main)
colorChanged = true; stateChanged = true;
if (!singleSegment) strip.setColor(2, col2); if (!singleSegment) strip.setColor(2, col2);
} }
@ -805,14 +805,14 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
// apply colors to selected segment, and all selected segments if applicable // apply colors to selected segment, and all selected segments if applicable
if (col0Changed) { if (col0Changed) {
colorChanged = true; stateChanged = true;
uint32_t colIn0 = RGBW32(colIn[0], colIn[1], colIn[2], colIn[3]); uint32_t colIn0 = RGBW32(colIn[0], colIn[1], colIn[2], colIn[3]);
selseg.setColor(0, colIn0, selectedSeg); selseg.setColor(0, colIn0, selectedSeg);
if (!singleSegment) strip.setColor(0, colIn0); if (!singleSegment) strip.setColor(0, colIn0);
} }
if (col1Changed) { if (col1Changed) {
colorChanged = true; stateChanged = true;
uint32_t colIn1 = RGBW32(colInSec[0], colInSec[1], colInSec[2], colInSec[3]); uint32_t colIn1 = RGBW32(colInSec[0], colInSec[1], colInSec[2], colInSec[3]);
selseg.setColor(1, colIn1, selectedSeg); selseg.setColor(1, colIn1, selectedSeg);
if (!singleSegment) strip.setColor(1, colIn1); if (!singleSegment) strip.setColor(1, colIn1);
@ -828,7 +828,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
intensityChanged = updateVal(&req, "IX=", &intensityIn); intensityChanged = updateVal(&req, "IX=", &intensityIn);
paletteChanged = updateVal(&req, "FP=", &paletteIn, 0, strip.getPaletteCount()-1); paletteChanged = updateVal(&req, "FP=", &paletteIn, 0, strip.getPaletteCount()-1);
effectChanged = (fxModeChanged || speedChanged || intensityChanged || paletteChanged); stateChanged |= (fxModeChanged || speedChanged || intensityChanged || paletteChanged);
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { for (uint8_t i = 0; i < strip.getMaxSegments(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); WS2812FX::Segment& seg = strip.getSegment(i);

View File

@ -359,8 +359,7 @@ void handleNotifications()
strip.setSegment(id, selseg.start, selseg.stop, udpIn[5+ofs], udpIn[6+ofs], selseg.offset); strip.setSegment(id, selseg.start, selseg.stop, udpIn[5+ofs], udpIn[6+ofs], selseg.offset);
} }
} }
effectChanged = true; stateChanged = true;
colorChanged = true;
} }
if (applyEffects && (version < 11 || !receiveSegmentOptions)) { //simple effect sync, applies to all selected if (applyEffects && (version < 11 || !receiveSegmentOptions)) { //simple effect sync, applies to all selected

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2202210 #define VERSION 2202211
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG
@ -478,8 +478,7 @@ WLED_GLOBAL byte effectCurrent _INIT(0);
WLED_GLOBAL byte effectSpeed _INIT(128); WLED_GLOBAL byte effectSpeed _INIT(128);
WLED_GLOBAL byte effectIntensity _INIT(128); WLED_GLOBAL byte effectIntensity _INIT(128);
WLED_GLOBAL byte effectPalette _INIT(0); WLED_GLOBAL byte effectPalette _INIT(0);
WLED_GLOBAL bool effectChanged _INIT(false); WLED_GLOBAL bool stateChanged _INIT(false);
WLED_GLOBAL bool colorChanged _INIT(false);
// network // network
WLED_GLOBAL bool udpConnected _INIT(false), udp2Connected _INIT(false), udpRgbConnected _INIT(false); WLED_GLOBAL bool udpConnected _INIT(false), udp2Connected _INIT(false), udpRgbConnected _INIT(false);