Skip to content

Commit 4cc2cc4

Browse files
committed
Multiple fixes
- increase WLED_MAX_BUSSES for C3 (fixes #4215) - fix for #4228 - fix for very long running effect (strip.now, strip.timebase) - C++ API change to allow `seg.setColor().setOpacity()`
1 parent 832599b commit 4cc2cc4

File tree

11 files changed

+62
-70
lines changed

11 files changed

+62
-70
lines changed

usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void setup() {
9696
jsonTransitionOnce = true;
9797
strip.setTransition(0); //no transition
9898
effectCurrent = FX_MODE_COLOR_WIPE;
99-
resetTimebase(); //make sure wipe starts from beginning
99+
strip.resetTimebase(); //make sure wipe starts from beginning
100100

101101
//set wipe direction
102102
Segment& seg = strip.getSegment(0);

usermods/stairway_wipe_basic/wled06_usermod.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void startWipe()
8686
bri = briLast; //turn on
8787
transitionDelayTemp = 0; //no transition
8888
effectCurrent = FX_MODE_COLOR_WIPE;
89-
resetTimebase(); //make sure wipe starts from beginning
89+
strip.resetTimebase(); //make sure wipe starts from beginning
9090

9191
//set wipe direction
9292
Segment& seg = strip.getSegment(0);

wled00/FX.h

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,12 @@ typedef struct Segment {
525525
inline static const CRGBPalette16 &getCurrentPalette() { return Segment::_currentPalette; }
526526

527527
void setUp(uint16_t i1, uint16_t i2, uint8_t grp=1, uint8_t spc=0, uint16_t ofs=UINT16_MAX, uint16_t i1Y=0, uint16_t i2Y=1);
528-
bool setColor(uint8_t slot, uint32_t c); //returns true if changed
529-
void setCCT(uint16_t k);
530-
void setOpacity(uint8_t o);
531-
void setOption(uint8_t n, bool val);
532-
void setMode(uint8_t fx, bool loadDefaults = false);
533-
void setPalette(uint8_t pal);
528+
Segment &setColor(uint8_t slot, uint32_t c);
529+
Segment &setCCT(uint16_t k);
530+
Segment &setOpacity(uint8_t o);
531+
Segment &setOption(uint8_t n, bool val);
532+
Segment &setMode(uint8_t fx, bool loadDefaults = false);
533+
Segment &setPalette(uint8_t pal);
534534
uint8_t differs(Segment& b) const;
535535
void refreshLightCapabilities();
536536

@@ -545,7 +545,7 @@ typedef struct Segment {
545545
* Call resetIfRequired before calling the next effect function.
546546
* Safe to call from interrupts and network requests.
547547
*/
548-
inline void markForReset() { reset = true; } // setOption(SEG_OPTION_RESET, true)
548+
inline Segment &markForReset() { reset = true; return *this; } // setOption(SEG_OPTION_RESET, true)
549549

550550
// transition functions
551551
void startTransition(uint16_t dur); // transition has to start before actual segment values change
@@ -599,9 +599,15 @@ typedef struct Segment {
599599
}
600600

601601
// 2D matrix
602-
[[gnu::hot]] uint16_t virtualWidth() const; // segment width in virtual pixels (accounts for groupping and spacing)
603-
[[gnu::hot]] uint16_t virtualHeight() const; // segment height in virtual pixels (accounts for groupping and spacing)
604-
uint16_t nrOfVStrips() const; // returns number of virtual vertical strips in 2D matrix (used to expand 1D effects into 2D)
602+
[[gnu::hot]] unsigned virtualWidth() const; // segment width in virtual pixels (accounts for groupping and spacing)
603+
[[gnu::hot]] unsigned virtualHeight() const; // segment height in virtual pixels (accounts for groupping and spacing)
604+
inline unsigned nrOfVStrips() const { // returns number of virtual vertical strips in 2D matrix (used to expand 1D effects into 2D)
605+
#ifndef WLED_DISABLE_2D
606+
return (is2D() && map1D2D == M12_pBar) ? virtualWidth() : 1;
607+
#else
608+
return 1;
609+
#endif
610+
}
605611
#ifndef WLED_DISABLE_2D
606612
[[gnu::hot]] uint16_t XY(int x, int y); // support function to get relative index within segment
607613
[[gnu::hot]] void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color
@@ -778,7 +784,8 @@ class WS2812FX { // 96 bytes
778784
setTargetFps(uint8_t fps),
779785
setupEffectData(); // add default effects to the list; defined in FX.cpp
780786

781-
inline void restartRuntime() { for (Segment &seg : _segments) seg.markForReset(); }
787+
inline void resetTimebase() { timebase = 0UL - millis(); }
788+
inline void restartRuntime() { for (Segment &seg : _segments) { seg.markForReset().resetIfRequired(); } }
782789
inline void setTransitionMode(bool t) { for (Segment &seg : _segments) seg.startTransition(t ? _transitionDur : 0); }
783790
inline void setColor(uint8_t slot, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) { setColor(slot, RGBW32(r,g,b,w)); }
784791
inline void setPixelColor(unsigned n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) { setPixelColor(n, RGBW32(r,g,b,w)); }
@@ -834,10 +841,8 @@ class WS2812FX { // 96 bytes
834841
inline uint16_t getLength() const { return _length; } // returns actual amount of LEDs on a strip (2D matrix may have less LEDs than W*H)
835842
inline uint16_t getTransition() const { return _transitionDur; } // returns currently set transition time (in ms)
836843

837-
uint32_t
838-
now,
839-
timebase,
840-
getPixelColor(uint16_t) const;
844+
unsigned long now, timebase;
845+
uint32_t getPixelColor(unsigned) const;
841846

842847
inline uint32_t getLastShow() const { return _lastShow; } // returns millis() timestamp of last strip.show() call
843848
inline uint32_t segColor(uint8_t i) const { return _colors_t[i]; } // returns currently valid color (for slot i) AKA SEGCOLOR(); may be blended between two colors while in transition

wled00/FX_2Dfcn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ uint16_t IRAM_ATTR_YN Segment::XY(int x, int y)
156156
void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col)
157157
{
158158
if (!isActive()) return; // not active
159-
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
159+
if ((unsigned)x >= virtualWidth() || (unsigned)y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
160160

161161
uint8_t _bri_t = currentBri();
162162
if (_bri_t < 255) {
@@ -251,7 +251,7 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa)
251251
// returns RGBW values of pixel
252252
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) const {
253253
if (!isActive()) return 0; // not active
254-
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return 0; // if pixel would fall out of virtual segment just exit
254+
if ((unsigned)x >= virtualWidth() || (unsigned)y >= virtualHeight() || x<0 || y<0) return 0; // if pixel would fall out of virtual segment just exit
255255
if (reverse ) x = virtualWidth() - x - 1;
256256
if (reverse_y) y = virtualHeight() - y - 1;
257257
if (transpose) { std::swap(x,y); } // swap X & Y if segment transposed

wled00/FX_fcn.cpp

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -509,46 +509,53 @@ void Segment::setUp(uint16_t i1, uint16_t i2, uint8_t grp, uint8_t spc, uint16_t
509509
}
510510

511511

512-
bool Segment::setColor(uint8_t slot, uint32_t c) { //returns true if changed
513-
if (slot >= NUM_COLORS || c == colors[slot]) return false;
512+
Segment &Segment::setColor(uint8_t slot, uint32_t c) {
513+
if (slot >= NUM_COLORS || c == colors[slot]) return *this;
514514
if (!_isRGB && !_hasW) {
515-
if (slot == 0 && c == BLACK) return false; // on/off segment cannot have primary color black
516-
if (slot == 1 && c != BLACK) return false; // on/off segment cannot have secondary color non black
515+
if (slot == 0 && c == BLACK) return *this; // on/off segment cannot have primary color black
516+
if (slot == 1 && c != BLACK) return *this; // on/off segment cannot have secondary color non black
517517
}
518518
if (fadeTransition) startTransition(strip.getTransition()); // start transition prior to change
519519
colors[slot] = c;
520520
stateChanged = true; // send UDP/WS broadcast
521-
return true;
521+
return *this;
522522
}
523523

524-
void Segment::setCCT(uint16_t k) {
524+
Segment &Segment::setCCT(uint16_t k) {
525525
if (k > 255) { //kelvin value, convert to 0-255
526526
if (k < 1900) k = 1900;
527527
if (k > 10091) k = 10091;
528528
k = (k - 1900) >> 5;
529529
}
530-
if (cct == k) return;
531-
if (fadeTransition) startTransition(strip.getTransition()); // start transition prior to change
532-
cct = k;
533-
stateChanged = true; // send UDP/WS broadcast
530+
if (cct != k) {
531+
//DEBUGFX_PRINTF_P(PSTR("- Starting CCT transition: %d\n"), k);
532+
startTransition(strip.getTransition()); // start transition prior to change
533+
cct = k;
534+
stateChanged = true; // send UDP/WS broadcast
535+
}
536+
return *this;
534537
}
535538

536-
void Segment::setOpacity(uint8_t o) {
537-
if (opacity == o) return;
538-
if (fadeTransition) startTransition(strip.getTransition()); // start transition prior to change
539-
opacity = o;
540-
stateChanged = true; // send UDP/WS broadcast
539+
Segment &Segment::setOpacity(uint8_t o) {
540+
if (opacity != o) {
541+
//DEBUGFX_PRINTF_P(PSTR("- Starting opacity transition: %d\n"), o);
542+
startTransition(strip.getTransition()); // start transition prior to change
543+
opacity = o;
544+
stateChanged = true; // send UDP/WS broadcast
545+
}
546+
return *this;
541547
}
542548

543-
void Segment::setOption(uint8_t n, bool val) {
549+
Segment &Segment::setOption(uint8_t n, bool val) {
544550
bool prevOn = on;
545551
if (fadeTransition && n == SEG_OPTION_ON && val != prevOn) startTransition(strip.getTransition()); // start transition prior to change
546552
if (val) options |= 0x01 << n;
547553
else options &= ~(0x01 << n);
548554
if (!(n == SEG_OPTION_SELECTED || n == SEG_OPTION_RESET)) stateChanged = true; // send UDP/WS broadcast
555+
return *this;
549556
}
550557

551-
void Segment::setMode(uint8_t fx, bool loadDefaults) {
558+
Segment &Segment::setMode(uint8_t fx, bool loadDefaults) {
552559
// skip reserved
553560
while (fx < strip.getModeCount() && strncmp_P("RSVD", strip.getModeData(fx), 4) == 0) fx++;
554561
if (fx >= strip.getModeCount()) fx = 0; // set solid mode
@@ -580,47 +587,35 @@ void Segment::setMode(uint8_t fx, bool loadDefaults) {
580587
markForReset();
581588
stateChanged = true; // send UDP/WS broadcast
582589
}
590+
return *this;
583591
}
584592

585-
void Segment::setPalette(uint8_t pal) {
593+
Segment &Segment::setPalette(uint8_t pal) {
586594
if (pal < 245 && pal > GRADIENT_PALETTE_COUNT+13) pal = 0; // built in palettes
587595
if (pal > 245 && (strip.customPalettes.size() == 0 || 255U-pal > strip.customPalettes.size()-1)) pal = 0; // custom palettes
588596
if (pal != palette) {
589597
if (strip.paletteFade) startTransition(strip.getTransition());
590598
palette = pal;
591599
stateChanged = true; // send UDP/WS broadcast
592600
}
601+
return *this;
593602
}
594603

595604
// 2D matrix
596-
uint16_t IRAM_ATTR Segment::virtualWidth() const {
605+
unsigned IRAM_ATTR Segment::virtualWidth() const {
597606
unsigned groupLen = groupLength();
598607
unsigned vWidth = ((transpose ? height() : width()) + groupLen - 1) / groupLen;
599608
if (mirror) vWidth = (vWidth + 1) /2; // divide by 2 if mirror, leave at least a single LED
600609
return vWidth;
601610
}
602611

603-
uint16_t IRAM_ATTR Segment::virtualHeight() const {
612+
unsigned IRAM_ATTR Segment::virtualHeight() const {
604613
unsigned groupLen = groupLength();
605614
unsigned vHeight = ((transpose ? width() : height()) + groupLen - 1) / groupLen;
606615
if (mirror_y) vHeight = (vHeight + 1) /2; // divide by 2 if mirror, leave at least a single LED
607616
return vHeight;
608617
}
609618

610-
uint16_t IRAM_ATTR_YN Segment::nrOfVStrips() const {
611-
unsigned vLen = 1;
612-
#ifndef WLED_DISABLE_2D
613-
if (is2D()) {
614-
switch (map1D2D) {
615-
case M12_pBar:
616-
vLen = virtualWidth();
617-
break;
618-
}
619-
}
620-
#endif
621-
return vLen;
622-
}
623-
624619
// Constants for mapping mode "Pinwheel"
625620
#ifndef WLED_DISABLE_2D
626621
constexpr int Pinwheel_Steps_Small = 72; // no holes up to 16x16
@@ -1187,10 +1182,7 @@ uint32_t Segment::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8_
11871182
//do not call this method from system context (network callback)
11881183
void WS2812FX::finalizeInit() {
11891184
//reset segment runtimes
1190-
for (segment &seg : _segments) {
1191-
seg.markForReset();
1192-
seg.resetIfRequired();
1193-
}
1185+
restartRuntime();
11941186

11951187
// for the lack of better place enumerate ledmaps here
11961188
// if we do it in json.cpp (serializeInfo()) we are getting flashes on LEDs
@@ -1402,7 +1394,7 @@ void IRAM_ATTR WS2812FX::setPixelColor(unsigned i, uint32_t col) {
14021394
BusManager::setPixelColor(i, col);
14031395
}
14041396

1405-
uint32_t IRAM_ATTR WS2812FX::getPixelColor(uint16_t i) const {
1397+
uint32_t IRAM_ATTR WS2812FX::getPixelColor(unsigned i) const {
14061398
i = getMappedPixelIndex(i);
14071399
if (i >= _length) return 0;
14081400
return BusManager::getPixelColor(i);

wled00/button.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ void handleAnalog(uint8_t b)
215215
briLast = bri;
216216
bri = 0;
217217
} else {
218+
if (bri == 0) strip.restartRuntime();
218219
bri = aRead;
219220
}
220221
} else if (macroDoublePress[b] == 249) {

wled00/const.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#else
5454
#define WLED_MAX_ANALOG_CHANNELS (LEDC_CHANNEL_MAX*LEDC_SPEED_MODE_MAX)
5555
#if defined(CONFIG_IDF_TARGET_ESP32C3) // 2 RMT, 6 LEDC, only has 1 I2S but NPB does not support it ATM
56-
#define WLED_MAX_BUSSES 4 // will allow 2 digital & 2 analog RGB
56+
#define WLED_MAX_BUSSES 6 // will allow 2 digital & 2 analog RGB or 6 PWM white
5757
#define WLED_MAX_DIGITAL_CHANNELS 2
5858
//#define WLED_MAX_ANALOG_CHANNELS 6
5959
#define WLED_MIN_VIRTUAL_BUSSES 3

wled00/fcn_declare.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient = 0);
169169
void setValuesFromSegment(uint8_t s);
170170
void setValuesFromMainSeg();
171171
void setValuesFromFirstSelectedSeg();
172-
void resetTimebase();
173172
void toggleOnOff();
174173
void applyBri();
175174
void applyFinalBri();

wled00/json.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
346346
}
347347
}
348348

349-
int tr = -1;
349+
long tr = -1;
350350
if (!presetId || currentPlaylist < 0) { //do not apply transition time from preset if playlist active, as it would override playlist transition times
351351
tr = root[F("transition")] | -1;
352352
if (tr >= 0) {
@@ -363,7 +363,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
363363
}
364364

365365
tr = root[F("tb")] | -1;
366-
if (tr >= 0) strip.timebase = ((uint32_t)tr) - millis();
366+
if (tr >= 0) strip.timebase = (unsigned long)tr - millis();
367367

368368
JsonObject nl = root["nl"];
369369
nightlightActive = getBoolVal(nl["on"], nightlightActive);

wled00/led.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,12 @@ void applyValuesToSelectedSegs()
4747
}
4848

4949

50-
void resetTimebase()
51-
{
52-
strip.timebase = 0 - millis();
53-
}
54-
55-
5650
void toggleOnOff()
5751
{
5852
if (bri == 0)
5953
{
6054
bri = briLast;
55+
strip.restartRuntime();
6156
} else
6257
{
6358
briLast = bri;
@@ -122,7 +117,7 @@ void stateUpdated(byte callMode) {
122117
nightlightStartTime = millis();
123118
}
124119
if (briT == 0) {
125-
if (callMode != CALL_MODE_NOTIFICATION) resetTimebase(); //effect start from beginning
120+
if (callMode != CALL_MODE_NOTIFICATION) strip.resetTimebase(); //effect start from beginning
126121
}
127122

128123
if (bri > 0) briLast = bri;

0 commit comments

Comments
 (0)