Skip to content

Commit 0df6826

Browse files
committed
Fixed HTTP changing segments uncommanded (wled#1618)
Replaced Red & Blue effect with Aurora effect (PR wled#1589) Updated copyright year and contributor page link
1 parent af61962 commit 0df6826

File tree

7 files changed

+74
-17
lines changed

7 files changed

+74
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
### Development versions after 0.11.1 release
44

5+
#### Build 2101040
6+
7+
- Replaced Red & Blue effect with Aurora effect (PR #1589)
8+
- Fixed HTTP changing segments uncommanded (#1618)
9+
- Updated copyright year and contributor page link
10+
511
#### Build 2012311
612

713
- Fixed Countdown mode

wled00/FX_fcn.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@ void WS2812FX::setColor(uint8_t slot, uint32_t c) {
394394
if (applyToAllSelected) {
395395
for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++)
396396
{
397-
if (_segments[i].isSelected()) _segments[i].colors[slot] = c;
397+
if (_segments[i].isSelected()) {
398+
_segments[i].colors[slot] = c;
399+
applied = true;
400+
}
398401
}
399402
}
400403

wled00/colors.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ void colorFromUint24(uint32_t in, bool secondary)
3333
}
3434
}
3535

36+
//store color components in uint32_t
37+
uint32_t colorFromRgbw(byte* rgbw) {
38+
return (rgbw[0] << 16) + (rgbw[1] << 8) + rgbw[2] + (rgbw[3] << 24);
39+
}
40+
3641
//relatively change white brightness, minumum A=5
3742
void relativeChangeWhite(int8_t amount, byte lowerBoundary)
3843
{

wled00/data/settings_sec.htm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ <h3>Software Update</h3>
4646
Enable ArduinoOTA: <input type="checkbox" name="AO"><br>
4747
<h3>About</h3>
4848
<a href="https://github.com/Aircoookie/WLED/" target="_blank">WLED</a> version ##VERSION##<!-- Autoreplaced from package.json --><br><br>
49-
<a href="https://github.com/Aircoookie/WLED/wiki/Contributors-&-About" target="_blank">Contributors, dependencies and special thanks</a><br>
49+
<a href="https://github.com/Aircoookie/WLED/wiki/Contributors-and-credits" target="_blank">Contributors, dependencies and special thanks</a><br>
5050
A huge thank you to everyone who helped me create WLED!<br><br>
51-
(c) 2016-2020 Christian Schwinne <br>
51+
(c) 2016-2021 Christian Schwinne <br>
5252
<i>Licensed under the <a href="https://github.com/Aircoookie/WLED/blob/master/LICENSE" target="_blank">MIT license</a></i><br><br>
5353
Server message: <span class="sip"> Response error! </span><hr>
5454
<button type="button" onclick="B()">Back</button><button type="submit">Save & Reboot</button>

wled00/fcn_declare.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void serializeConfigSec();
3434
//colors.cpp
3535
void colorFromUint32(uint32_t in, bool secondary = false);
3636
void colorFromUint24(uint32_t in, bool secondary = false);
37+
uint32_t colorFromRgbw(byte* rgbw);
3738
void relativeChangeWhite(int8_t amount, byte lowerBoundary = 0);
3839
void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb
3940
void colorKtoRGB(uint16_t kelvin, byte* rgb);

wled00/set.cpp

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// version code in format yymmddb (b = daily build)
11-
#define VERSION 2012311
11+
#define VERSION 2101040
1212

1313
//uncomment this if you have a "my_config.h" file you'd like to use
1414
//#define WLED_USE_MY_CONFIG

0 commit comments

Comments
 (0)