|
@@ -23,49 +23,50 @@ class HeartBeatManager {
|
|
|
/// - parameters:
|
|
/// - parameters:
|
|
|
/// - sharedData : shared User Defaults
|
|
/// - sharedData : shared User Defaults
|
|
|
public func checkCGMBluetoothTransmitter(sharedUserDefaults: UserDefaults) {
|
|
public func checkCGMBluetoothTransmitter(sharedUserDefaults: UserDefaults) {
|
|
|
-
|
|
|
|
|
|
|
+ if let sharedTransmitterAddress = sharedUserDefaults.string(forKey: keyForcgmTransmitterDeviceAddress) {
|
|
|
|
|
+ debug(.deviceManager, "in checkCGMBluetoothTransmitter, sharedTransmitterAddress = \(sharedTransmitterAddress)")
|
|
|
|
|
+ } else {
|
|
|
|
|
+ debug(.deviceManager, "in checkCGMBluetoothTransmitter, sharedTransmitterAddress = nil")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if !initialSetupDone {
|
|
if !initialSetupDone {
|
|
|
-
|
|
|
|
|
debug(.deviceManager, "in checkCGMBluetoothTransmitter, initial setup")
|
|
debug(.deviceManager, "in checkCGMBluetoothTransmitter, initial setup")
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
initialSetupDone = true
|
|
initialSetupDone = true
|
|
|
|
|
|
|
|
// set to nil, this will force recreation of bluetooth transmitter at app startup
|
|
// set to nil, this will force recreation of bluetooth transmitter at app startup
|
|
|
UserDefaults.standard.cgmTransmitterDeviceAddress = nil
|
|
UserDefaults.standard.cgmTransmitterDeviceAddress = nil
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if UserDefaults.standard.cgmTransmitterDeviceAddress != sharedUserDefaults
|
|
if UserDefaults.standard.cgmTransmitterDeviceAddress != sharedUserDefaults
|
|
|
.string(forKey: keyForcgmTransmitterDeviceAddress)
|
|
.string(forKey: keyForcgmTransmitterDeviceAddress)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
- debug(.deviceManager, "UserDefaults.standard.cgmTransmitterDeviceAddress != sharedUserDefaults.string(forKey: keyForcgmTransmitterDeviceAddress)")
|
|
|
|
|
|
|
+ debug(
|
|
|
|
|
+ .deviceManager,
|
|
|
|
|
+ "UserDefaults.standard.cgmTransmitterDeviceAddress != sharedUserDefaults.string(forKey: keyForcgmTransmitterDeviceAddress)"
|
|
|
|
|
+ )
|
|
|
if let sharedTransmitterAddress = sharedUserDefaults.string(forKey: keyForcgmTransmitterDeviceAddress) {
|
|
if let sharedTransmitterAddress = sharedUserDefaults.string(forKey: keyForcgmTransmitterDeviceAddress) {
|
|
|
debug(.deviceManager, "in checkCGMBluetoothTransmitter, sharedTransmitterAddress = \(sharedTransmitterAddress)")
|
|
debug(.deviceManager, "in checkCGMBluetoothTransmitter, sharedTransmitterAddress = \(sharedTransmitterAddress)")
|
|
|
} else {
|
|
} else {
|
|
|
debug(.deviceManager, "in checkCGMBluetoothTransmitter, sharedTransmitterAddress = nil")
|
|
debug(.deviceManager, "in checkCGMBluetoothTransmitter, sharedTransmitterAddress = nil")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// assign local copy of cgmTransmitterDeviceAddress to the value stored in sharedUserDefaults (possibly nil value)
|
|
// assign local copy of cgmTransmitterDeviceAddress to the value stored in sharedUserDefaults (possibly nil value)
|
|
|
UserDefaults.standard.cgmTransmitterDeviceAddress = sharedUserDefaults
|
|
UserDefaults.standard.cgmTransmitterDeviceAddress = sharedUserDefaults
|
|
|
.string(forKey: keyForcgmTransmitterDeviceAddress)
|
|
.string(forKey: keyForcgmTransmitterDeviceAddress)
|
|
|
|
|
|
|
|
// assign new bluetoothTransmitter. If return value is nil, and if it was not nil before, and if it was currently connected then it will disconnect automatically, because there's no other reference to it, hence deinit will be called
|
|
// assign new bluetoothTransmitter. If return value is nil, and if it was not nil before, and if it was currently connected then it will disconnect automatically, because there's no other reference to it, hence deinit will be called
|
|
|
bluetoothTransmitter = setupBluetoothTransmitter(sharedData: sharedUserDefaults)
|
|
bluetoothTransmitter = setupBluetoothTransmitter(sharedData: sharedUserDefaults)
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private func setupBluetoothTransmitter(sharedData: UserDefaults) -> BluetoothTransmitter? {
|
|
private func setupBluetoothTransmitter(sharedData: UserDefaults) -> BluetoothTransmitter? {
|
|
|
-
|
|
|
|
|
// if sharedUserDefaults.cgmTransmitterDeviceAddress is not nil then, create a new bluetoothTranmsitter instance
|
|
// if sharedUserDefaults.cgmTransmitterDeviceAddress is not nil then, create a new bluetoothTranmsitter instance
|
|
|
if let cgmTransmitterDeviceAddress = sharedData.string(forKey: keyForcgmTransmitterDeviceAddress) {
|
|
if let cgmTransmitterDeviceAddress = sharedData.string(forKey: keyForcgmTransmitterDeviceAddress) {
|
|
|
-
|
|
|
|
|
// unwrap cgmTransmitter_CBUUID_Service and cgmTransmitter_CBUUID_Receive
|
|
// unwrap cgmTransmitter_CBUUID_Service and cgmTransmitter_CBUUID_Receive
|
|
|
if let cgmTransmitter_CBUUID_Service = sharedData.string(forKey: keyForcgmTransmitter_CBUUID_Service),
|
|
if let cgmTransmitter_CBUUID_Service = sharedData.string(forKey: keyForcgmTransmitter_CBUUID_Service),
|
|
|
let cgmTransmitter_CBUUID_Receive = sharedData.string(forKey: keycgmTransmitter_CBUUID_Receive)
|
|
let cgmTransmitter_CBUUID_Receive = sharedData.string(forKey: keycgmTransmitter_CBUUID_Receive)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
// a new cgm transmitter has been setup in xDrip4iOS
|
|
// a new cgm transmitter has been setup in xDrip4iOS
|
|
|
// we will connect to the same transmitter here so it can be used as heartbeat
|
|
// we will connect to the same transmitter here so it can be used as heartbeat
|
|
|
let newBluetoothTransmitter = BluetoothTransmitter(
|
|
let newBluetoothTransmitter = BluetoothTransmitter(
|
|
@@ -75,8 +76,11 @@ class HeartBeatManager {
|
|
|
heartbeat: {}
|
|
heartbeat: {}
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- debug(.deviceManager, "in setupBluetoothTransmitter, cgmTransmitterDeviceAddress in shared user defaults is not nil")
|
|
|
|
|
-
|
|
|
|
|
|
|
+ debug(
|
|
|
|
|
+ .deviceManager,
|
|
|
|
|
+ "in setupBluetoothTransmitter, cgmTransmitterDeviceAddress in shared user defaults is not nil"
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
return newBluetoothTransmitter
|
|
return newBluetoothTransmitter
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
@@ -87,7 +91,7 @@ class HeartBeatManager {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
debug(.deviceManager, "in setupBluetoothTransmitter, cgmTransmitterDeviceAddress in shared user defaults is nil")
|
|
debug(.deviceManager, "in setupBluetoothTransmitter, cgmTransmitterDeviceAddress in shared user defaults is nil")
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|