@@ -381,24 +381,31 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
381381 DEBUG_PRINT (F (" API req: " ));
382382 DEBUG_PRINTLN (req);
383383
384- strip.applyToAllSelected = true ;
384+ strip.applyToAllSelected = false ;
385+ // snapshot to check if request changed values later, temporary.
386+ byte prevCol[4 ] = {col[0 ], col[1 ], col[2 ], col[3 ]};
387+ byte prevColSec[4 ] = {colSec[0 ], colSec[1 ], colSec[2 ], colSec[3 ]};
388+ byte prevEffect = effectCurrent;
389+ byte prevSpeed = effectSpeed;
390+ byte prevIntensity = effectIntensity;
391+ byte prevPalette = effectPalette;
385392
386393 // segment select (sets main segment)
387394 byte prevMain = strip.getMainSegmentId ();
388395 pos = req.indexOf (F (" SM=" ));
389396 if (pos > 0 ) {
390397 strip.mainSegment = getNumVal (&req, pos);
391398 }
392- byte main = strip.getMainSegmentId ();
393- if (main != prevMain) setValuesFromMainSeg ();
399+ byte selectedSeg = strip.getMainSegmentId ();
400+ if (selectedSeg != prevMain) setValuesFromMainSeg ();
394401
395402 pos = req.indexOf (F (" SS=" ));
396403 if (pos > 0 ) {
397404 byte t = getNumVal (&req, pos);
398- if (t < strip.getMaxSegments ()) main = t;
405+ if (t < strip.getMaxSegments ()) selectedSeg = t;
399406 }
400407
401- WS2812FX::Segment& mainseg = strip.getSegment (main );
408+ WS2812FX::Segment& mainseg = strip.getSegment (selectedSeg );
402409 pos = req.indexOf (F (" SV=" )); // segment selected
403410 if (pos > 0 ) {
404411 byte t = getNumVal (&req, pos);
@@ -432,9 +439,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
432439 if (pos > 0 ) {
433440 spcI = getNumVal (&req, pos);
434441 }
435- strip.setSegment (main, startI, stopI, grpI, spcI);
436-
437- main = strip.getMainSegmentId ();
442+ strip.setSegment (selectedSeg, startI, stopI, grpI, spcI);
438443
439444 // set presets
440445 pos = req.indexOf (F (" P1=" )); // sets first preset for cycle
@@ -532,7 +537,12 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
532537 if (pos > 0 ) {
533538 byte t[4 ];
534539 colorFromDecOrHexString (t, (char *)req.substring (pos + 3 ).c_str ());
535- strip.setColor (2 , t[0 ], t[1 ], t[2 ], t[3 ]);
540+ if (selectedSeg != strip.getMainSegmentId ()) {
541+ strip.applyToAllSelected = true ;
542+ strip.setColor (2 , t[0 ], t[1 ], t[2 ], t[3 ]);
543+ } else {
544+ strip.getSegment (selectedSeg).colors [2 ] = ((t[0 ] << 16 ) + (t[1 ] << 8 ) + t[2 ] + (t[3 ] << 24 ));
545+ }
536546 }
537547
538548 // set to random hue SR=0->1st SR=1->2nd
@@ -647,19 +657,19 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
647657
648658 // Segment reverse
649659 pos = req.indexOf (F (" RV=" ));
650- if (pos > 0 ) strip.getSegment (main ).setOption (SEG_OPTION_REVERSED, req.charAt (pos+3 ) != ' 0' );
660+ if (pos > 0 ) strip.getSegment (selectedSeg ).setOption (SEG_OPTION_REVERSED, req.charAt (pos+3 ) != ' 0' );
651661
652662 // Segment reverse
653663 pos = req.indexOf (F (" MI=" ));
654- if (pos > 0 ) strip.getSegment (main ).setOption (SEG_OPTION_MIRROR, req.charAt (pos+3 ) != ' 0' );
664+ if (pos > 0 ) strip.getSegment (selectedSeg ).setOption (SEG_OPTION_MIRROR, req.charAt (pos+3 ) != ' 0' );
655665
656666 // Segment brightness/opacity
657667 pos = req.indexOf (F (" SB=" ));
658668 if (pos > 0 ) {
659669 byte segbri = getNumVal (&req, pos);
660- strip.getSegment (main ).setOption (SEG_OPTION_ON, segbri);
670+ strip.getSegment (selectedSeg ).setOption (SEG_OPTION_ON, segbri);
661671 if (segbri) {
662- strip.getSegment (main ).opacity = segbri;
672+ strip.getSegment (selectedSeg ).opacity = segbri;
663673 }
664674 }
665675
@@ -716,12 +726,44 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
716726 }
717727 // you can add more if you need
718728
729+ // apply to all selected manually to prevent #1618. Temporary
730+ bool col0Changed = false , col1Changed = false ;
731+ for (uint8_t i = 0 ; i < 4 ; i++) {
732+ if (col[i] != prevCol[i]) col0Changed = true ;
733+ if (colSec[i] != prevColSec[i]) col1Changed = true ;
734+ }
735+ for (uint8_t i = 0 ; i < strip.getMaxSegments (); i++)
736+ {
737+ WS2812FX::Segment& seg = strip.getSegment (i);
738+ if (!seg.isSelected ()) continue ;
739+ if (effectCurrent != prevEffect) seg.mode = effectCurrent;
740+ if (effectSpeed != prevSpeed) seg.speed = effectSpeed;
741+ if (effectIntensity != prevIntensity) seg.intensity = effectIntensity;
742+ if (effectPalette != prevPalette) seg.palette = effectPalette;
743+ }
744+
745+ if (col0Changed) {
746+ if (selectedSeg == strip.getMainSegmentId ()) {
747+ strip.applyToAllSelected = true ;
748+ strip.setColor (0 , colorFromRgbw (col));
749+ }
750+ }
751+ if (col1Changed) {
752+ if (selectedSeg == strip.getMainSegmentId ()) {
753+ strip.applyToAllSelected = true ;
754+ strip.setColor (1 , colorFromRgbw (colSec));
755+ }
756+ }
757+ // end of temporary fix code
758+
719759 if (!apply) return true ; // when called by JSON API, do not call colorUpdated() here
720760
721761 // internal call, does not send XML response
722762 pos = req.indexOf (F (" IN" ));
723763 if (pos < 1 ) XML_response (request);
724764
765+ strip.applyToAllSelected = false ;
766+
725767 pos = req.indexOf (F (" &NN" )); // do not send UDP notifications this time
726768 colorUpdated ((pos > 0 ) ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE);
727769
0 commit comments