Skip to content

Commit 302f18f

Browse files
committed
small speedup
* currentBri() is called for any setpixelColor(), so we can speed up everything (a bit) by allowing the compiler to inline which saves a few cycles of call/return overhead. * aligned the function with upstream, and added another optimization by only calling progress() when a transition is active.
1 parent f456e06 commit 302f18f

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

wled00/FX.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,18 @@ typedef struct Segment {
589589
void startTransition(uint16_t dur); // transition has to start before actual segment values change
590590
void handleTransition(void);
591591
uint16_t progress(void); //transition progression between 0-65535
592-
uint8_t currentBri(uint8_t briNew, bool useCct = false);
592+
593+
// WLEDMM method inlined for speed (its called at each setPixelColor)
594+
inline uint8_t currentBri(uint8_t briNew, bool useCct = false) {
595+
uint32_t prog = (transitional && _t) ? progress() : 0xFFFFU;
596+
if (transitional && _t && prog < 0xFFFFU) {
597+
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
598+
else return ((briNew * prog) + _t->_briT * (0xFFFFU - prog)) >> 16;
599+
} else {
600+
return (useCct ? briNew : (on ? briNew : 0)); // WLEDMM aligned with upstream
601+
}
602+
}
603+
593604
uint8_t currentMode(uint8_t modeNew);
594605
uint32_t currentColor(uint8_t slot, uint32_t colorNew);
595606
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal);

wled00/FX_fcn.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,22 +416,25 @@ void Segment::startTransition(uint16_t dur) {
416416
}
417417

418418
// transition progression between 0-65535
419-
uint16_t Segment::progress() {
419+
uint16_t IRAM_ATTR_YN Segment::progress() {
420420
if (!transitional || !_t) return 0xFFFFU;
421421
unsigned long timeNow = millis();
422422
if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU;
423423
return (timeNow - _t->_start) * 0xFFFFU / _t->_dur;
424424
}
425425

426-
uint8_t Segment::currentBri(uint8_t briNew, bool useCct) {
427-
uint32_t prog = progress();
426+
// WLEDMM Segment::currentBri() is declared inline, see FX.h
427+
#if 0
428+
uint8_t IRAM_ATTR_YN Segment::currentBri(uint8_t briNew, bool useCct) {
429+
uint32_t prog = (transitional && _t) ? progress() : 0xFFFFU;
428430
if (transitional && _t && prog < 0xFFFFU) {
429431
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
430432
else return ((briNew * prog) + _t->_briT * (0xFFFFU - prog)) >> 16;
431433
} else {
432-
return briNew;
434+
return (useCct ? briNew : (on ? briNew : 0)); // WLEDMM aligned with upstream
433435
}
434436
}
437+
#endif
435438

436439
uint8_t Segment::currentMode(uint8_t newMode) {
437440
return (progress()>32767U) ? newMode : _t->_modeP; // change effect in the middle of transition

0 commit comments

Comments
 (0)