Libre 2 : use sensorTimeInMinutes to show the sensor age in bluetooth screen

This commit is contained in:
Johan Degraeve 2021-01-10 23:05:32 +01:00
parent 1c17115f88
commit eb69a34636
5 changed files with 43 additions and 0 deletions

View File

@ -263,8 +263,12 @@ class CGMLibre2Transmitter:BluetoothTransmitter, CGMTransmitter {
// if oop web not enabled, then don't pass libre1DerivedAlgorithmParameters
var parsedBLEData = Libre2BLEUtilities.parseBLEData(Data(try Libre2BLEUtilities.decryptBLE(sensorUID: sensorUID, data: rxBuffer)), libre1DerivedAlgorithmParameters: isWebOOPEnabled() ? UserDefaults.standard.libre1DerivedAlgorithmParameters : nil)
// send glucoseData and sensorTimeInMinutes to cgmTransmitterDelegate
cgmTransmitterDelegate?.cgmTransmitterInfoReceived(glucoseData: &parsedBLEData.bleGlucose, transmitterBatteryInfo: nil, sensorTimeInMinutes: Int(parsedBLEData.sensorTimeInMinutes))
// send sensorTimeInMinutes also to cGMLibre2TransmitterDelegate
cGMLibre2TransmitterDelegate?.received(sensorTimeInMinutes: Int(parsedBLEData.sensorTimeInMinutes), from: self)
} catch {
trace("in peripheral didUpdateValueFor, error while parsing/decrypting data = %{public}@ ", log: log, category: ConstantsLog.categoryCGMLibre2, type: .info, error.localizedDescription)

View File

@ -5,4 +5,6 @@ protocol CGMLibre2TransmitterDelegate: AnyObject {
/// received sensor Serial Number
func received(serialNumber: String, from cGMLibre2Transmitter: CGMLibre2Transmitter)
/// received sensor time in minutes
func received(sensorTimeInMinutes: Int, from cGMLibre2Transmitter: CGMLibre2Transmitter)
}

View File

@ -3,6 +3,9 @@ import CoreData
public class Libre2: NSManagedObject {
/// sensor time in Minutes if known
var sensorTimeInMinutes: Int?
/// create Libre2
/// - parameters:
init(address: String, name: String, alias: String?, nsManagedObjectContext:NSManagedObjectContext) {

View File

@ -2,6 +2,16 @@ import Foundation
extension BluetoothPeripheralManager: CGMLibre2TransmitterDelegate {
func received(sensorTimeInMinutes: Int, from cGMLibre2Transmitter: CGMLibre2Transmitter) {
guard let libre2 = findTransmitter(cGMLibre2Transmitter: cGMLibre2Transmitter) else {return}
libre2.sensorTimeInMinutes = sensorTimeInMinutes
// sensorTimeInMinutes is not stored in coredata, not need to save
}
func received(serialNumber: String, from cGMLibre2Transmitter: CGMLibre2Transmitter) {
guard let libre2 = findTransmitter(cGMLibre2Transmitter: cGMLibre2Transmitter) else {return}

View File

@ -9,6 +9,9 @@ class Libre2BluetoothPeripheralViewModel {
/// Sensor serial number
case sensorSerialNumber = 0
/// sensor start time
case sensorStartTime = 1
}
private let log = OSLog(subsystem: ConstantsLog.subSystem, category: "Libre2BluetoothPeripheralViewModel")
@ -120,6 +123,13 @@ extension Libre2BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
cell.detailTextLabel?.text = libre2.blePeripheral.sensorSerialNumber
cell.accessoryType = .disclosureIndicator
case .sensorStartTime:
cell.textLabel?.text = Texts_HomeView.sensorStart
if let sensorTimeInMinutes = libre2.sensorTimeInMinutes {
cell.detailTextLabel?.text = Date(timeIntervalSinceNow: -Double(sensorTimeInMinutes*60)).toString(timeStyle: .short, dateStyle: .short)
}
cell.accessoryType = .none
}
@ -142,6 +152,10 @@ extension Libre2BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
if let serialNumber = libre2.blePeripheral.sensorSerialNumber {
return .showInfoText(title: Texts_HomeView.info, message: Texts_BluetoothPeripheralView.sensorSerialNumber + " : " + serialNumber)
}
case .sensorStartTime:
return .nothing
}
@ -165,6 +179,16 @@ extension Libre2BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
extension Libre2BluetoothPeripheralViewModel: CGMLibre2TransmitterDelegate {
func received(sensorTimeInMinutes: Int, from cGMLibre2Transmitter: CGMLibre2Transmitter) {
// inform also bluetoothPeripheralManager
(bluetoothPeripheralManager as? CGMLibre2TransmitterDelegate)?.received(sensorTimeInMinutes: sensorTimeInMinutes, from: cGMLibre2Transmitter)
// here's the trigger to update the table
reloadRow(row: Settings.sensorStartTime.rawValue)
}
func received(serialNumber: String, from cGMLibre2Transmitter: CGMLibre2Transmitter) {
// inform also bluetoothPeripheralManager