diff --git a/xdrip/BluetoothTransmitter/CGM/Dexcom/G7/CGMG7Transmitter.swift b/xdrip/BluetoothTransmitter/CGM/Dexcom/G7/CGMG7Transmitter.swift index c0c1c9e04..b67f5a98a 100644 --- a/xdrip/BluetoothTransmitter/CGM/Dexcom/G7/CGMG7Transmitter.swift +++ b/xdrip/BluetoothTransmitter/CGM/Dexcom/G7/CGMG7Transmitter.swift @@ -210,25 +210,29 @@ class CGMG7Transmitter: BluetoothTransmitter, CGMTransmitter { return } - var maxSensorAgeInDays = ConstantsDexcomG7.maxSensorAgeInDays - - // check if it's a Stelo and if so, update the maxSensorAge - if let transmitterIdString = UserDefaults.standard.activeSensorTransmitterId, transmitterIdString.startsWith("DX01") { - maxSensorAgeInDays = ConstantsDexcomG7.maxSensorAgeInDaysStelo - } - let sensorAgeInDays = Double(round((g7GlucoseMessage.sensorAge / 3600 / 24) * 10) / 10) - // G7/ONE+/Stelo has the peculiarity that it will keep sending/repeating the same BG value (without ever changing) via BLE even after the session officially ends. - // to avoid this, let's check if the sensor is still within maxSensorAge before we continue - guard sensorAgeInDays < maxSensorAgeInDays else { - trace(" G7 is expired so will not process reading. sensorAge: %{public}@ / maxSensorAgeInDays: %{public}@", log: log, category: ConstantsLog.categoryCGMG7, type: .error, sensorAgeInDays.description, maxSensorAgeInDays.description) - return + var maxSensorAgeInDays: Double = 0.0 + + // check if we already have the transmitterId (or device name). If so, set the maxSensorAge and then perform a quick check to see if the sensor hasn't expired. + if let transmitterIdString = UserDefaults.standard.activeSensorTransmitterId { + if transmitterIdString.startsWith("DX01") { + maxSensorAgeInDays = ConstantsDexcomG7.maxSensorAgeInDaysStelo + } else { + maxSensorAgeInDays = ConstantsDexcomG7.maxSensorAgeInDays + } + + // G7/ONE+/Stelo has the peculiarity that it will keep sending/repeating the same BG value (without ever changing) via BLE even after the session officially ends. + // to avoid this, let's check if the sensor is still within maxSensorAge before we continue + if sensorAgeInDays > maxSensorAgeInDays { + trace(" %{public}@ is expired so will not process reading. sensorAge: %{public}@ / maxSensorAgeInDays: %{public}@", log: log, category: ConstantsLog.categoryCGMG7, type: .error, UserDefaults.standard.activeSensorTransmitterId ?? "sensor", sensorAgeInDays.description, maxSensorAgeInDays.description) + return + } } trace(" received g7GlucoseMessage mesage, calculatedValue = %{public}@, timeStamp = %{public}@, sensorAge = %{public}@ / %{public}@", log: log, category: ConstantsLog.categoryCGMG7, type: .info, g7GlucoseMessage.calculatedValue.description, g7GlucoseMessage.timeStamp.description(with: .current)) - trace(" received g7GlucoseMessage mesage, sensorAge = %{public}@ / %{public}@", log: log, category: ConstantsLog.categoryCGMG7, type: .info, sensorAgeInDays.description, maxSensorAgeInDays.description) + trace(" received g7GlucoseMessage mesage, sensorAge = %{public}@ / %{public}@", log: log, category: ConstantsLog.categoryCGMG7, type: .info, sensorAgeInDays.description, maxSensorAgeInDays > 0 ? maxSensorAgeInDays.description : "waiting...") sensorAge = g7GlucoseMessage.sensorAge @@ -376,10 +380,15 @@ class CGMG7Transmitter: BluetoothTransmitter, CGMTransmitter { func maxSensorAgeInDays() -> Double? { - if let transmitterIdString = UserDefaults.standard.activeSensorTransmitterId, transmitterIdString.startsWith("DX01") { - return ConstantsDexcomG7.maxSensorAgeInDaysStelo + if let transmitterIdString = UserDefaults.standard.activeSensorTransmitterId { + if transmitterIdString.startsWith("DX01") { + return ConstantsDexcomG7.maxSensorAgeInDaysStelo + } else { + return ConstantsDexcomG7.maxSensorAgeInDays + } } else { - return ConstantsDexcomG7.maxSensorAgeInDays + // if we haven't yet established the activeSensorTransmitterId (or device name) then return 0 - RVC will use this to know that we're still waiting + return 0 } } diff --git a/xdrip/BluetoothTransmitter/CGM/Generic/CGMTransmitter.swift b/xdrip/BluetoothTransmitter/CGM/Generic/CGMTransmitter.swift index 13d7f7b58..d5298f4e5 100644 --- a/xdrip/BluetoothTransmitter/CGM/Generic/CGMTransmitter.swift +++ b/xdrip/BluetoothTransmitter/CGM/Generic/CGMTransmitter.swift @@ -316,9 +316,11 @@ enum CGMTransmitterType:String, CaseIterable { return "Dexcom Stelo" } else if transmitterIdString.startsWith("DX02") { return "Dexcom ONE+" + } else { + return "Dexcom G7" } } - return "Dexcom G7" + return "Dexcom - please wait..." case .Libre2: if let activeSensorMaxSensorAgeInDays = UserDefaults.standard.activeSensorMaxSensorAgeInDays, activeSensorMaxSensorAgeInDays >= 15 { diff --git a/xdrip/View Controllers/Root View Controller/RootViewController.swift b/xdrip/View Controllers/Root View Controller/RootViewController.swift index 016da0869..317aee22e 100644 --- a/xdrip/View Controllers/Root View Controller/RootViewController.swift +++ b/xdrip/View Controllers/Root View Controller/RootViewController.swift @@ -3102,16 +3102,11 @@ final class RootViewController: UIViewController, ObservableObject { // check if there is a transmitter connected (needed as Dexcom will only connect briefly every 5 minutes) // if there is a transmitter connected, pull the current maxSensorAgeInDays and store in in UserDefaults if let cgmTransmitter = self.bluetoothPeripheralManager?.getCGMTransmitter(), let maxDays = cgmTransmitter.maxSensorAgeInDays() { - - if maxDays > 0 { - UserDefaults.standard.activeSensorMaxSensorAgeInDays = maxDays - } - + UserDefaults.standard.activeSensorMaxSensorAgeInDays = maxDays UserDefaults.standard.activeSensorDescription = cgmTransmitter.cgmTransmitterType().detailedDescription() // update the sensor type - needed to make sure we test with the correct warm-up times later sensorType = cgmTransmitter.cgmTransmitterType().sensorType() - } // let's just check that we've got enough information to display the view diff --git a/xdrip/View Controllers/Treatments/TreatmentTableViewCell.swift b/xdrip/View Controllers/Treatments/TreatmentTableViewCell.swift index 8cbb0c13f..dc2c88af6 100644 --- a/xdrip/View Controllers/Treatments/TreatmentTableViewCell.swift +++ b/xdrip/View Controllers/Treatments/TreatmentTableViewCell.swift @@ -40,6 +40,9 @@ class TreatmentTableViewCell: UITableViewCell { case .BgCheck: self.iconImageView.tintColor = ConstantsGlucoseChart.bgCheckTreatmentColorInner + default: + self.iconImageView.tintColor = nil + } switch treatment.treatmentType { @@ -56,6 +59,9 @@ class TreatmentTableViewCell: UITableViewCell { case .BgCheck: self.iconImageView.image = UIImage(systemName: "drop.fill") ?? nil + default: + self.iconImageView.tintColor = nil + } // treatment type label