storing timestamp of last battery read in userdefaults, for Dexcom G5 it will now be ready only once every 48 hours

This commit is contained in:
Johan Degraeve 2020-10-12 15:37:52 +02:00
parent d3f94d0c67
commit 7ec99f0657
3 changed files with 20 additions and 2 deletions

View File

@ -118,7 +118,11 @@ class CGMG5Transmitter:BluetoothTransmitter, CGMTransmitter {
self.timeStampOfLastG5Reading = Date(timeIntervalSince1970: 0)
//set timeStampOfLastBatteryReading to 0
self.timeStampOfLastBatteryReading = Date(timeIntervalSince1970: 0)
if let timeStampOfLastBatteryReading = UserDefaults.standard.timeStampOfLastBatteryReading {
self.timeStampOfLastBatteryReading = timeStampOfLastBatteryReading
} else {
self.timeStampOfLastBatteryReading = Date(timeIntervalSince1970: 0)
}
//set timeStampTransmitterReset to 0
self.timeStampTransmitterReset = Date(timeIntervalSince1970: 0)

View File

@ -1,7 +1,7 @@
/// dexcom G5 specific constants
enum ConstantsDexcomG5 {
/// how often to read battery level
static let batteryReadPeriodInHours = 12.0
static let batteryReadPeriodInHours = 48.0
/// in case transmitter needs pairing, how long to keep connection up to give time to the user to accept the pairing request, inclusive opening the notification
static let maxTimeToAcceptPairingInSeconds = 60

View File

@ -182,6 +182,9 @@ extension UserDefaults {
/// Transmitter Battery Level
case transmitterBatteryInfo = "transmitterbatteryinfo"
/// timestamp last battery reading (will only be used for dexcom G5 where we need to explicitly ask for the battery)
case timeStampOfLastBatteryReading = "timeStampOfLastBatteryReading"
// HealthKit
/// did user authorize the storage of readings in healthkit or not
case storeReadingsInHealthkitAuthorized = "storeReadingsInHealthkitAuthorized"
@ -990,6 +993,17 @@ extension UserDefaults {
} else {
set(nil, forKey: Key.transmitterBatteryInfo.rawValue)
}
timeStampOfLastBatteryReading = Date()
}
}
/// timestamp latest calibration uploaded to NightScout
var timeStampOfLastBatteryReading:Date? {
get {
return object(forKey: Key.timeStampOfLastBatteryReading.rawValue) as? Date
}
set {
set(newValue, forKey: Key.timeStampOfLastBatteryReading.rawValue)
}
}