Skip to content

Commit 8daf9d9

Browse files
committed
transition optimization (small speedup)
* move "progress()" into FX.h so the compiler can inline it * removed redundant checks in currentBri()
1 parent bd31dd2 commit 8daf9d9

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

wled00/FX.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,18 @@ typedef struct Segment {
607607
// transition functions
608608
void startTransition(uint16_t dur); // transition has to start before actual segment values change
609609
void handleTransition(void);
610-
uint16_t progress(void) const; //transition progression between 0-65535
610+
// transition progression between 0-65535
611+
[[gnu::hot]] inline uint16_t progress() const {
612+
if (!transitional || !_t) return 0xFFFFU;
613+
unsigned long timeNow = millis();
614+
if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU;
615+
return (timeNow - _t->_start) * 0xFFFFU / _t->_dur;
616+
}
611617

612618
// WLEDMM method inlined for speed (its called at each setPixelColor)
613619
[[gnu::hot]] inline uint8_t currentBri(uint8_t briNew, bool useCct = false) {
614-
uint32_t prog = (transitional && _t) ? progress() : 0xFFFFU;
615-
if (transitional && _t && prog < 0xFFFFU) {
620+
uint32_t prog = progress();
621+
if (prog < 0xFFFFU) { // progress() < 0xFFFFU implies that _t is valid (see progress() function)
616622
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
617623
else return ((briNew * prog) + _t->_briT * (0xFFFFU - prog)) >> 16;
618624
} else {

wled00/FX_fcn.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,16 @@ void Segment::startTransition(uint16_t dur) {
451451
transitional = true; // setOption(SEG_OPTION_TRANSITIONAL, true);
452452
}
453453

454+
// WLEDMM Segment::progress() is declared inline, see FX.h
455+
#if 0
454456
// transition progression between 0-65535
455457
uint16_t IRAM_ATTR_YN Segment::progress() const {
456458
if (!transitional || !_t) return 0xFFFFU;
457459
unsigned long timeNow = millis();
458460
if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU;
459461
return (timeNow - _t->_start) * 0xFFFFU / _t->_dur;
460462
}
463+
#endif
461464

462465
// WLEDMM Segment::currentBri() is declared inline, see FX.h
463466
#if 0

0 commit comments

Comments
 (0)