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:
parent
d3f94d0c67
commit
7ec99f0657
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue