@@ -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
626621constexpr 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)
11881183void 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);
0 commit comments