Skip to content

Commit f116099

Browse files
committed
Correct estimated delay for RL
1 parent 7b137c4 commit f116099

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

LoopFollow/BackgroundRefresh/BT/BLEManager.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,26 @@ extension BLEManager {
228228
return nil
229229
}
230230

231+
let heartbeatLast: Date? = {
232+
if matchedType.estimatedDelayBasedOnHeartbeat {
233+
guard device.isConnected, let lastHeartbeat = activeDevice?.lastHeartbeatTime else {
234+
return nil
235+
}
236+
return lastHeartbeat
237+
} else {
238+
return device.lastSeen
239+
}
240+
}()
241+
242+
guard let heartbeatLast = heartbeatLast else {
243+
return nil
244+
}
245+
231246
let pollingDelay: TimeInterval = Double(UserDefaultsRepository.bgUpdateDelay.value)
232247

233248
let expectedOffset = sensorOffset + pollingDelay
234249

235-
let effectiveDelay = CycleHelper.computeDelay(sensorOffset: expectedOffset, heartbeatLast: device.lastSeen, heartbeatInterval: heartBeatInterval)
250+
let effectiveDelay = CycleHelper.computeDelay(sensorOffset: expectedOffset, heartbeatLast: heartbeatLast, heartbeatInterval: heartBeatInterval)
236251

237252
return "\(Int(effectiveDelay)) sec"
238253
}

LoopFollow/BackgroundRefresh/BT/Devices/RileyLinkHeartbeatBluetoothDevice.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class RileyLinkHeartbeatBluetoothDevice: BluetoothDevice {
2727

2828
override func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
2929
super.centralManager(central, didConnect: peripheral)
30-
31-
self.bluetoothDeviceDelegate?.heartBeat()
3230
}
3331

3432
override func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {

LoopFollow/BackgroundRefresh/BackgroundRefreshType.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ enum BackgroundRefreshType: String, Codable, CaseIterable {
3434
}
3535
}
3636

37+
var estimatedDelayBasedOnHeartbeat: Bool {
38+
switch self {
39+
case .rileyLink:
40+
return true
41+
case .dexcom, .silentTune, .none:
42+
return false
43+
}
44+
}
45+
3746
/// Determines if a BLEDevice matches the specific device type
3847
func matches(_ device: BLEDevice) -> Bool {
3948
switch self {

0 commit comments

Comments
 (0)