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.
This commit is contained in:
13
wled00/FX.h
13
wled00/FX.h
@@ -589,7 +589,18 @@ typedef struct Segment {
|
|||||||
void startTransition(uint16_t dur); // transition has to start before actual segment values change
|
void startTransition(uint16_t dur); // transition has to start before actual segment values change
|
||||||
void handleTransition(void);
|
void handleTransition(void);
|
||||||
uint16_t progress(void); //transition progression between 0-65535
|
uint16_t progress(void); //transition progression between 0-65535
|
||||||
uint8_t currentBri(uint8_t briNew, bool useCct = false);
|
|
||||||
|
// WLEDMM method inlined for speed (its called at each setPixelColor)
|
||||||
|
inline uint8_t currentBri(uint8_t briNew, bool useCct = false) {
|
||||||
|
uint32_t prog = (transitional && _t) ? progress() : 0xFFFFU;
|
||||||
|
if (transitional && _t && prog < 0xFFFFU) {
|
||||||
|
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
|
||||||
|
else return ((briNew * prog) + _t->_briT * (0xFFFFU - prog)) >> 16;
|
||||||
|
} else {
|
||||||
|
return (useCct ? briNew : (on ? briNew : 0)); // WLEDMM aligned with upstream
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t currentMode(uint8_t modeNew);
|
uint8_t currentMode(uint8_t modeNew);
|
||||||
uint32_t currentColor(uint8_t slot, uint32_t colorNew);
|
uint32_t currentColor(uint8_t slot, uint32_t colorNew);
|
||||||
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal);
|
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal);
|
||||||
|
|||||||
@@ -416,22 +416,25 @@ void Segment::startTransition(uint16_t dur) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// transition progression between 0-65535
|
// transition progression between 0-65535
|
||||||
uint16_t Segment::progress() {
|
uint16_t IRAM_ATTR_YN Segment::progress() {
|
||||||
if (!transitional || !_t) return 0xFFFFU;
|
if (!transitional || !_t) return 0xFFFFU;
|
||||||
unsigned long timeNow = millis();
|
unsigned long timeNow = millis();
|
||||||
if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU;
|
if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU;
|
||||||
return (timeNow - _t->_start) * 0xFFFFU / _t->_dur;
|
return (timeNow - _t->_start) * 0xFFFFU / _t->_dur;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Segment::currentBri(uint8_t briNew, bool useCct) {
|
// WLEDMM Segment::currentBri() is declared inline, see FX.h
|
||||||
uint32_t prog = progress();
|
#if 0
|
||||||
|
uint8_t IRAM_ATTR_YN Segment::currentBri(uint8_t briNew, bool useCct) {
|
||||||
|
uint32_t prog = (transitional && _t) ? progress() : 0xFFFFU;
|
||||||
if (transitional && _t && prog < 0xFFFFU) {
|
if (transitional && _t && prog < 0xFFFFU) {
|
||||||
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
|
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
|
||||||
else return ((briNew * prog) + _t->_briT * (0xFFFFU - prog)) >> 16;
|
else return ((briNew * prog) + _t->_briT * (0xFFFFU - prog)) >> 16;
|
||||||
} else {
|
} else {
|
||||||
return briNew;
|
return (useCct ? briNew : (on ? briNew : 0)); // WLEDMM aligned with upstream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
uint8_t Segment::currentMode(uint8_t newMode) {
|
uint8_t Segment::currentMode(uint8_t newMode) {
|
||||||
return (progress()>32767U) ? newMode : _t->_modeP; // change effect in the middle of transition
|
return (progress()>32767U) ? newMode : _t->_modeP; // change effect in the middle of transition
|
||||||
|
|||||||
Reference in New Issue
Block a user