mirror of
https://github.com/wled/WLED.git
synced 2025-07-25 11:46:34 +00:00
Merge pull request #4250 from DedeHai/FPS_calc_averaging
Fixed & improved FPS calculation
This commit is contained in:
commit
271a07a7d6
11
wled00/FX.h
11
wled00/FX.h
@ -47,6 +47,15 @@
|
|||||||
#define FRAMETIME_FIXED (1000/WLED_FPS)
|
#define FRAMETIME_FIXED (1000/WLED_FPS)
|
||||||
#define FRAMETIME strip.getFrameTime()
|
#define FRAMETIME strip.getFrameTime()
|
||||||
|
|
||||||
|
// FPS calculation (can be defined as compile flag for debugging)
|
||||||
|
#ifndef FPS_CALC_AVG
|
||||||
|
#define FPS_CALC_AVG 7 // average FPS calculation over this many frames (moving average)
|
||||||
|
#endif
|
||||||
|
#ifndef FPS_MULTIPLIER
|
||||||
|
#define FPS_MULTIPLIER 1 // dev option: multiplier to get sub-frame FPS without floats
|
||||||
|
#endif
|
||||||
|
#define FPS_CALC_SHIFT 7 // bit shift for fixed point math
|
||||||
|
|
||||||
/* each segment uses 82 bytes of SRAM memory, so if you're application fails because of
|
/* each segment uses 82 bytes of SRAM memory, so if you're application fails because of
|
||||||
insufficient memory, decreasing MAX_NUM_SEGMENTS may help */
|
insufficient memory, decreasing MAX_NUM_SEGMENTS may help */
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
@ -729,7 +738,7 @@ class WS2812FX { // 96 bytes
|
|||||||
_transitionDur(750),
|
_transitionDur(750),
|
||||||
_targetFps(WLED_FPS),
|
_targetFps(WLED_FPS),
|
||||||
_frametime(FRAMETIME_FIXED),
|
_frametime(FRAMETIME_FIXED),
|
||||||
_cumulativeFps(2),
|
_cumulativeFps(50 << FPS_CALC_SHIFT),
|
||||||
_isServicing(false),
|
_isServicing(false),
|
||||||
_isOffRefreshRequired(false),
|
_isOffRefreshRequired(false),
|
||||||
_hasWhiteChannel(false),
|
_hasWhiteChannel(false),
|
||||||
|
@ -1412,10 +1412,12 @@ void WS2812FX::show() {
|
|||||||
|
|
||||||
unsigned long showNow = millis();
|
unsigned long showNow = millis();
|
||||||
size_t diff = showNow - _lastShow;
|
size_t diff = showNow - _lastShow;
|
||||||
size_t fpsCurr = 200;
|
|
||||||
if (diff > 0) fpsCurr = 1000 / diff;
|
if (diff > 0) { // skip calculation if no time has passed
|
||||||
_cumulativeFps = (3 * _cumulativeFps + fpsCurr +2) >> 2; // "+2" for proper rounding (2/4 = 0.5)
|
size_t fpsCurr = (1000 << FPS_CALC_SHIFT) / diff; // fixed point math
|
||||||
_lastShow = showNow;
|
_cumulativeFps = (FPS_CALC_AVG * _cumulativeFps + fpsCurr + FPS_CALC_AVG / 2) / (FPS_CALC_AVG + 1); // "+FPS_CALC_AVG/2" for proper rounding
|
||||||
|
_lastShow = showNow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1432,7 +1434,7 @@ bool WS2812FX::isUpdating() const {
|
|||||||
*/
|
*/
|
||||||
uint16_t WS2812FX::getFps() const {
|
uint16_t WS2812FX::getFps() const {
|
||||||
if (millis() - _lastShow > 2000) return 0;
|
if (millis() - _lastShow > 2000) return 0;
|
||||||
return _cumulativeFps +1;
|
return (FPS_MULTIPLIER * _cumulativeFps) >> FPS_CALC_SHIFT; // _cumulativeFps is stored in fixed point
|
||||||
}
|
}
|
||||||
|
|
||||||
void WS2812FX::setTargetFps(uint8_t fps) {
|
void WS2812FX::setTargetFps(uint8_t fps) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user