avoid 64 bit divide (!) exploding binary size

This commit is contained in:
Matthew Kennedy 2023-11-17 19:42:59 -08:00
parent 52f306b6f5
commit 4bdd8f5c44
1 changed files with 4 additions and 3 deletions

View File

@ -54,6 +54,8 @@ bool Timer::hasElapsedMs(float milliseconds) const {
return hasElapsedUs(milliseconds * 1000); return hasElapsedUs(milliseconds * 1000);
} }
static const float usPerTick = 1000000.0 / CH_CFG_ST_FREQUENCY;
bool Timer::hasElapsedUs(float microseconds) const { bool Timer::hasElapsedUs(float microseconds) const {
auto delta = getTimestamp() - m_lastReset; auto delta = getTimestamp() - m_lastReset;
@ -64,10 +66,9 @@ bool Timer::hasElapsedUs(float microseconds) const {
auto delta32 = (uint32_t)delta; auto delta32 = (uint32_t)delta;
return delta32 > TIME_US2I(microseconds); return delta32 > (microseconds / usPerTick);
} }
float Timer::getElapsedSeconds() const { float Timer::getElapsedSeconds() const {
return getElapsedSeconds(getTimestamp()); return getElapsedSeconds(getTimestamp());
} }
@ -96,7 +97,7 @@ float Timer::getElapsedUs(int64_t stamp) const {
auto delta32 = (uint32_t)deltaNt; auto delta32 = (uint32_t)deltaNt;
return TIME_I2US(delta32); return delta32 * usPerTick;
} }
float Timer::getElapsedSecondsAndReset() { float Timer::getElapsedSecondsAndReset() {