Skip to content

Commit

Permalink
Fixed an overflow bug in the cadence calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
msimms committed May 29, 2024
1 parent 4a62c5d commit 8d52c39
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions IOS/Sensors/SensorMgr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ class SensorMgr : ObservableObject {
self.firstCadenceUpdate = true
}

if currentCrankTime >= self.lastCrankCountTime { // handle wrap-around
// Handle wrap-around
if currentCrankTime >= self.lastCrankCountTime { // normal case
elapsedSecs = Double(currentCrankTime - self.lastCrankCountTime) / 1024.0
}
else {
let temp: UInt32 = 0x0000ffff + UInt32(currentCrankTime)
let temp: UInt32 = 0x0000ffff + (UInt32(currentCrankTime) << 16)
elapsedSecs = Double(temp - UInt32(self.lastCrankCountTime)) / 1024.0
}

Expand Down

0 comments on commit 8d52c39

Please sign in to comment.