Libre 2 : removed sensor State because it's read only during NFC scan, which means may not be up to date if there's no frequent NFC scan done
This commit is contained in:
parent
c4e89c1bb0
commit
1c17115f88
|
@ -49,9 +49,6 @@ class CGMLibre2Transmitter:BluetoothTransmitter, CGMTransmitter {
|
|||
/// current sensor serial number, if nil then it's not known yet
|
||||
private var sensorSerialNumber:String?
|
||||
|
||||
/// temp storage of libreSensortate, value will be stored after NFC scanning, but possible there's no transmitter created yet (if this is a first scan for a new transmitter), so we can't store the state yet in coredata. As soon as transmitter is connected, and if tempSensorState is not nil, it will be sent to the delegate
|
||||
private var tempSensorState: LibreSensorState?
|
||||
|
||||
/// temp storage of libreSensorSerialNumber, value will be stored after NFC scanning, but possible there's no transmitter created yet (if this is a first scan for a new transmitter), so we can't store the serial number yet in coredata. As soon as transmitter is connected, and if tempSensorSerialNumber is not nil, it will be sent to the delegate
|
||||
private var tempSensorSerialNumber: LibreSensorSerialNumber?
|
||||
|
||||
|
@ -145,20 +142,9 @@ class CGMLibre2Transmitter:BluetoothTransmitter, CGMTransmitter {
|
|||
|
||||
super.centralManager(central, didConnect: peripheral)
|
||||
|
||||
if let sensorState = tempSensorState {
|
||||
|
||||
// we need to send the sensorState here. Possibly this is a new transmitter being scanned for, in which case the call to cGMLibre2TransmitterDelegate?.received(sensorStatus: ..) in NFCTagReaderSessionDelegate functions wouldn't have stored the status in coredata, because it' doesn't find the transmitter, so let's store it again, at each connect, if not nil
|
||||
//, value will be stored after NFC scanning, but possible there's no transmitter created yet (if this is a first scan for a new transmitter), so we can't store the state yet. Will do this as soon as transmitter is connected (each time again, although not necessary to do it each time)
|
||||
cGMLibre2TransmitterDelegate?.received(sensorStatus: sensorState, from: self)
|
||||
|
||||
// set tempSensorState to nil so we don't send it again to the delegate when there's a new connect
|
||||
tempSensorState = nil
|
||||
|
||||
}
|
||||
|
||||
if let sensorSerialNumber = tempSensorSerialNumber {
|
||||
|
||||
// delegate call, for same reason as for sensorState
|
||||
// we need to send the sensorSerialNumber here. Possibly this is a new transmitter being scanned for, in which case the call to cGMLibre2TransmitterDelegate?.received(sensorSerialNumber: ..) in NFCTagReaderSessionDelegate functions wouldn't have stored the status in coredata, because it' doesn't find the transmitter, so let's store it again, at each connect, if not nil
|
||||
cGMLibre2TransmitterDelegate?.received(serialNumber: sensorSerialNumber.serialNumber, from: self)
|
||||
|
||||
// set to nil so we don't send it again to the delegate when there's a new connect
|
||||
|
@ -343,17 +329,6 @@ extension CGMLibre2Transmitter: LibreNFCDelegate {
|
|||
|
||||
trace("received fram : %{public}@", log: log, category: ConstantsLog.categoryCGMLibre2, type: .info, fram.toHexString())
|
||||
|
||||
// first get sensor status and send to delegate
|
||||
if fram.count >= 5 {
|
||||
|
||||
let sensorState = LibreSensorState(stateByte: fram[4])
|
||||
|
||||
cGMLibre2TransmitterDelegate?.received(sensorStatus: sensorState, from: self)
|
||||
|
||||
self.tempSensorState = sensorState
|
||||
|
||||
}
|
||||
|
||||
// if we already know the patchinfo (which we should because normally received(patchInfo: Data gets called before received(fram: Data), then patchInfo should not be nil
|
||||
// same for sensorUID
|
||||
if let patchInfo = UserDefaults.standard.librePatchInfo, let sensorUID = UserDefaults.standard.libreSensorUID, let libreSensorType = LibreSensorType.type(patchInfo: patchInfo.hexEncodedString().uppercased()), let serialNumber = self.sensorSerialNumber {
|
||||
|
|
|
@ -5,7 +5,4 @@ protocol CGMLibre2TransmitterDelegate: AnyObject {
|
|||
/// received sensor Serial Number
|
||||
func received(serialNumber: String, from cGMLibre2Transmitter: CGMLibre2Transmitter)
|
||||
|
||||
/// Libre 2 is sending sensorStatus
|
||||
func received(sensorStatus: LibreSensorState, from cGMLibre2Transmitter: CGMLibre2Transmitter)
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,6 @@ import CoreData
|
|||
|
||||
public class Libre2: NSManagedObject {
|
||||
|
||||
// sensorState, not stored in coreData, will only be available after having received it from the Libre2
|
||||
public var sensorState: LibreSensorState = .unknown
|
||||
|
||||
/// create Libre2
|
||||
/// - parameters:
|
||||
init(address: String, name: String, alias: String?, nsManagedObjectContext:NSManagedObjectContext) {
|
||||
|
|
|
@ -13,17 +13,6 @@ extension BluetoothPeripheralManager: CGMLibre2TransmitterDelegate {
|
|||
|
||||
}
|
||||
|
||||
func received(sensorStatus: LibreSensorState, from cGMLibre2Transmitter: CGMLibre2Transmitter) {
|
||||
|
||||
guard let libre2 = findTransmitter(cGMLibre2Transmitter: cGMLibre2Transmitter) else {return}
|
||||
|
||||
// store sensor state Libre 2 object
|
||||
libre2.sensorState = sensorStatus
|
||||
|
||||
// no coredatamanager savechanges needed because sensor state is not stored in coredata
|
||||
|
||||
}
|
||||
|
||||
private func findTransmitter(cGMLibre2Transmitter: CGMLibre2Transmitter) -> Libre2? {
|
||||
|
||||
guard let index = bluetoothTransmitters.firstIndex(of: cGMLibre2Transmitter), let libre2 = bluetoothPeripherals[index] as? Libre2 else {return nil}
|
||||
|
|
|
@ -9,9 +9,6 @@ class Libre2BluetoothPeripheralViewModel {
|
|||
/// Sensor serial number
|
||||
case sensorSerialNumber = 0
|
||||
|
||||
/// sensor State
|
||||
case sensorState = 1
|
||||
|
||||
}
|
||||
|
||||
private let log = OSLog(subsystem: ConstantsLog.subSystem, category: "Libre2BluetoothPeripheralViewModel")
|
||||
|
@ -117,12 +114,6 @@ extension Libre2BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
|
|||
|
||||
switch setting {
|
||||
|
||||
case .sensorState:
|
||||
|
||||
cell.accessoryType = .none
|
||||
cell.textLabel?.text = Texts_Common.sensorStatus
|
||||
cell.detailTextLabel?.text = libre2.sensorState.translatedDescription
|
||||
|
||||
case .sensorSerialNumber:
|
||||
|
||||
cell.textLabel?.text = Texts_BluetoothPeripheralView.sensorSerialNumber
|
||||
|
@ -145,9 +136,6 @@ extension Libre2BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
|
|||
|
||||
switch setting {
|
||||
|
||||
case .sensorState:
|
||||
return .nothing
|
||||
|
||||
case .sensorSerialNumber:
|
||||
|
||||
// serial text could be longer than screen width, clicking the row allows to see it in a pop up with more text place
|
||||
|
@ -177,16 +165,6 @@ extension Libre2BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
|
|||
|
||||
extension Libre2BluetoothPeripheralViewModel: CGMLibre2TransmitterDelegate {
|
||||
|
||||
func received(sensorStatus: LibreSensorState, from cGMLibre2Transmitter: CGMLibre2Transmitter) {
|
||||
|
||||
// inform also bluetoothPeripheralManager
|
||||
(bluetoothPeripheralManager as? CGMLibre2TransmitterDelegate)?.received(sensorStatus: sensorStatus, from: cGMLibre2Transmitter)
|
||||
|
||||
// here's the trigger to update the table
|
||||
reloadRow(row: Settings.sensorState.rawValue)
|
||||
|
||||
}
|
||||
|
||||
func received(serialNumber: String, from cGMLibre2Transmitter: CGMLibre2Transmitter) {
|
||||
|
||||
// inform also bluetoothPeripheralManager
|
||||
|
|
Loading…
Reference in New Issue