From a830714ce67f8afa938026ca4f697d6256eb6ebe Mon Sep 17 00:00:00 2001 From: Paul Plant Date: Tue, 7 Feb 2023 19:39:16 +0100 Subject: [PATCH] add "warming up until xx:xx" to Dexcom bluetoothPeripheral screen - set to display "warming up until xx:xx" until 120 minutes after the sensor session was started in the transmitter) - most Dexcom users know this but it looks useful in the Libre 2 BLE UI, so we can just implement it here too --- xdrip/Constants/ConstantsMaster.swift | 10 ++++++--- ...DexcomG5BluetoothPeripheralViewModel.swift | 21 +++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/xdrip/Constants/ConstantsMaster.swift b/xdrip/Constants/ConstantsMaster.swift index 0bfaeebd..0097d999 100644 --- a/xdrip/Constants/ConstantsMaster.swift +++ b/xdrip/Constants/ConstantsMaster.swift @@ -4,9 +4,13 @@ enum ConstantsMaster { /// maximum age in seconds, of reading in alert flow. If age of latest reading is more than this number, then no alert check will be done static let maximumBgReadingAgeForAlertsInSeconds = 240.0 - /// minimum sensor warm-up time required for all sensors before allowing the app to process a BG reading - /// this will only be relevant for active sensors that hold a sensorAge value - /// some transmitters (such as Dexcom) enforce warm-up on the transmitter side before transmitting values + // minimum sensor warm-up time required for all transmitters/sensors before allowing the app to process a BG reading + // this will only be relevant for active sensors that hold a sensorAge value + + /// warm-up time considered for all sensors/transmitters after starting (enforced globally by the app) static let minimumSensorWarmUpRequiredInMinutes = 45.0 + /// warm-up time enfoced by the Dexcom G6 transmitter. In this case, this will actually only be used for the UI to show when the sensor is reading. + static let minimumSensorWarmUpRequiredInMinutesDexcomG5G6 = 120.0 + } diff --git a/xdrip/View Controllers/BluetoothPeripheralsNavigationController/BluetoothPeripheralsViewController/BluetoothPeripheralViewController/Models/CGM/Dexcom/DexcomG5/DexcomG5BluetoothPeripheralViewModel.swift b/xdrip/View Controllers/BluetoothPeripheralsNavigationController/BluetoothPeripheralsViewController/BluetoothPeripheralViewController/Models/CGM/Dexcom/DexcomG5/DexcomG5BluetoothPeripheralViewModel.swift index 9446384d..c8151d88 100644 --- a/xdrip/View Controllers/BluetoothPeripheralsNavigationController/BluetoothPeripheralsViewController/BluetoothPeripheralViewController/Models/CGM/Dexcom/DexcomG5/DexcomG5BluetoothPeripheralViewModel.swift +++ b/xdrip/View Controllers/BluetoothPeripheralsNavigationController/BluetoothPeripheralsViewController/BluetoothPeripheralViewController/Models/CGM/Dexcom/DexcomG5/DexcomG5BluetoothPeripheralViewModel.swift @@ -232,8 +232,25 @@ extension DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel { var startDateString = "" if let startDate = dexcomG5.sensorStartDate { - startDateString = dexcomG5.sensorStartDate?.toStringInUserLocale(timeStyle: .none, dateStyle: .short) ?? "" - startDateString += " (" + startDate.daysAndHoursAgo() + ")" + + let sensorTimeInMinutes = -Int(startDate.timeIntervalSinceNow / 60) + + if sensorTimeInMinutes < Int(ConstantsMaster.minimumSensorWarmUpRequiredInMinutesDexcomG5G6) { + + // the Dexcom is still in the transmitter forced warm-up time so let's make it clear to the user + let sensorReadyDateTime = startDate.addingTimeInterval(ConstantsMaster.minimumSensorWarmUpRequiredInMinutesDexcomG5G6 * 60) + + startDateString = Texts_BluetoothPeripheralView.warmingUpUntil + " " + sensorReadyDateTime.toStringInUserLocale(timeStyle: .short, dateStyle: .none) + + } else { + + // Dexcom is not warming up so let's show the sensor start date and age + startDateString = startDate.toStringInUserLocale(timeStyle: .none, dateStyle: .short) + + startDateString += " (" + startDate.daysAndHoursAgo() + ")" + + } + } cell.textLabel?.text = Texts_BluetoothPeripheralView.sensorStartDate