diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-05-01 21:28:26 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-05-01 21:28:26 +0300 |
commit | 2bf1b349faedfca7594bf6296a2dec6c36e95b82 (patch) | |
tree | e679611fdf399b83f6859ad83c989a640aeafc2a /src/Accelerometers | |
parent | 31e191242d78fb96a327f281d7acbf91ad8ba93c (diff) |
Fix division by zero in accelerometer code
Diffstat (limited to 'src/Accelerometers')
-rw-r--r-- | src/Accelerometers/LIS3DH.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/Accelerometers/LIS3DH.cpp b/src/Accelerometers/LIS3DH.cpp index d4e22502..121ddb1c 100644 --- a/src/Accelerometers/LIS3DH.cpp +++ b/src/Accelerometers/LIS3DH.cpp @@ -160,8 +160,10 @@ unsigned int LIS3DH::CollectData(const uint16_t **collectedData, uint16_t &dataR *collectedData = reinterpret_cast<const uint16_t*>(dataBuffer); overflowed = (fifoStatus & 0x40) != 0; - dataRate = (totalNumRead == 0) ? 0 - : (totalNumRead * StepTimer::StepClockRate)/(lastInterruptTime - firstInterruptTime); + const uint32_t interval = lastInterruptTime - firstInterruptTime; + dataRate = (totalNumRead == 0 || interval == 0) + ? 0 + : (totalNumRead * StepTimer::StepClockRate)/interval; totalNumRead += numToRead; } return numToRead; |