compiles, but can't test yet for G5 as I have no working one, will continue now with bubble

This commit is contained in:
Johan Degraeve 2020-02-23 22:14:37 +01:00
parent d96fd7a5db
commit ac9354b539
33 changed files with 173 additions and 522 deletions

View File

@ -34,7 +34,6 @@
F821CF56229BF43A005C1E43 /* AlertKind.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF49229BF43A005C1E43 /* AlertKind.swift */; };
F821CF57229BF43A005C1E43 /* SnoozeParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF4A229BF43A005C1E43 /* SnoozeParameters.swift */; };
F821CF58229BF43A005C1E43 /* AlertManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF4B229BF43A005C1E43 /* AlertManager.swift */; };
F821CF59229BF43A005C1E43 /* AlertEntryUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF4C229BF43A005C1E43 /* AlertEntryUnit.swift */; };
F821CF5A229BF43A005C1E43 /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF4E229BF43A005C1E43 /* CoreDataManager.swift */; };
F821CF5D229BF43A005C1E43 /* NSDateFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF52229BF43A005C1E43 /* NSDateFormatter.swift */; };
F821CF5E229BF43A005C1E43 /* BgReading+NightScout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF53229BF43A005C1E43 /* BgReading+NightScout.swift */; };
@ -86,6 +85,12 @@
F889CB7F236D850600A81068 /* DexcomShareTestResults.strings in Resources */ = {isa = PBXBuildFile; fileRef = F889CB81236D850600A81068 /* DexcomShareTestResults.strings */; };
F897AAF92200F2D200CDDD10 /* CBPeripheralState.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897AAF82200F2D200CDDD10 /* CBPeripheralState.swift */; };
F897AAFB2201018800CDDD10 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897AAFA2201018800CDDD10 /* String.swift */; };
F897E24B23FC86CF0075E0E8 /* CGMG5TransmitterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897E24A23FC86CF0075E0E8 /* CGMG5TransmitterDelegate.swift */; };
F897E25023FC871C0075E0E8 /* BluetoothPeripheralManager+CGMG5TransmitterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897E24C23FC871C0075E0E8 /* BluetoothPeripheralManager+CGMG5TransmitterDelegate.swift */; };
F897E25123FC871C0075E0E8 /* BluetoothPeripheralManager+M5StackBluetoothTransmitterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897E24D23FC871C0075E0E8 /* BluetoothPeripheralManager+M5StackBluetoothTransmitterDelegate.swift */; };
F897E25223FC871C0075E0E8 /* BluetoothPeripheralManager+BluetoothTransmitterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897E24E23FC871C0075E0E8 /* BluetoothPeripheralManager+BluetoothTransmitterDelegate.swift */; };
F897E25323FC871C0075E0E8 /* BluetoothPeripheralManager+WatlaaBluetoothTransmitterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897E24F23FC871C0075E0E8 /* BluetoothPeripheralManager+WatlaaBluetoothTransmitterDelegate.swift */; };
F897E25723FDE97D0075E0E8 /* SettingsViewTransmitterSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F897E25623FDE97D0075E0E8 /* SettingsViewTransmitterSettingsViewModel.swift */; };
F898EDEA233F53BF00BFB79B /* UIButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = F898EDE9233F53BF00BFB79B /* UIButton.swift */; };
F898EDEC233F549100BFB79B /* UIBarButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = F898EDEB233F549100BFB79B /* UIBarButtonItem.swift */; };
F898EDF2234A8A0500BFB79B /* UInt8.swift in Sources */ = {isa = PBXBuildFile; fileRef = F898EDF1234A8A0500BFB79B /* UInt8.swift */; };
@ -162,7 +167,6 @@
F8B3A835227F08AC004BA588 /* PickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8B3A833227F08AC004BA588 /* PickerViewController.swift */; };
F8B3A844227F090E004BA588 /* SettingsViewAlertSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8B3A838227F090D004BA588 /* SettingsViewAlertSettingsViewModel.swift */; };
F8B3A845227F090E004BA588 /* SettingsViewDexcomSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8B3A839227F090D004BA588 /* SettingsViewDexcomSettingsViewModel.swift */; };
F8B3A846227F090E004BA588 /* SettingsViewTransmitterSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8B3A83A227F090D004BA588 /* SettingsViewTransmitterSettingsViewModel.swift */; };
F8B3A847227F090E004BA588 /* SettingsViewNightScoutSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8B3A83B227F090D004BA588 /* SettingsViewNightScoutSettingsViewModel.swift */; };
F8B3A848227F090E004BA588 /* SettingsViewHealthKitSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8B3A83C227F090D004BA588 /* SettingsViewHealthKitSettingsViewModel.swift */; };
F8B3A849227F090E004BA588 /* SettingsViewSpeakSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8B3A83D227F090D004BA588 /* SettingsViewSpeakSettingsViewModel.swift */; };
@ -310,7 +314,6 @@
F821CF49229BF43A005C1E43 /* AlertKind.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertKind.swift; sourceTree = "<group>"; };
F821CF4A229BF43A005C1E43 /* SnoozeParameters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnoozeParameters.swift; sourceTree = "<group>"; };
F821CF4B229BF43A005C1E43 /* AlertManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertManager.swift; sourceTree = "<group>"; };
F821CF4C229BF43A005C1E43 /* AlertEntryUnit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertEntryUnit.swift; sourceTree = "<group>"; };
F821CF4E229BF43A005C1E43 /* CoreDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = "<group>"; };
F821CF52229BF43A005C1E43 /* NSDateFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDateFormatter.swift; sourceTree = "<group>"; };
F821CF53229BF43A005C1E43 /* BgReading+NightScout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BgReading+NightScout.swift"; sourceTree = "<group>"; };
@ -395,6 +398,12 @@
F889CB9D236D8EEC00A81068 /* xdrip v4.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "xdrip v4.xcdatamodel"; sourceTree = "<group>"; };
F897AAF82200F2D200CDDD10 /* CBPeripheralState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CBPeripheralState.swift; sourceTree = "<group>"; };
F897AAFA2201018800CDDD10 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
F897E24A23FC86CF0075E0E8 /* CGMG5TransmitterDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGMG5TransmitterDelegate.swift; sourceTree = "<group>"; };
F897E24C23FC871C0075E0E8 /* BluetoothPeripheralManager+CGMG5TransmitterDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BluetoothPeripheralManager+CGMG5TransmitterDelegate.swift"; sourceTree = "<group>"; };
F897E24D23FC871C0075E0E8 /* BluetoothPeripheralManager+M5StackBluetoothTransmitterDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BluetoothPeripheralManager+M5StackBluetoothTransmitterDelegate.swift"; sourceTree = "<group>"; };
F897E24E23FC871C0075E0E8 /* BluetoothPeripheralManager+BluetoothTransmitterDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BluetoothPeripheralManager+BluetoothTransmitterDelegate.swift"; sourceTree = "<group>"; };
F897E24F23FC871C0075E0E8 /* BluetoothPeripheralManager+WatlaaBluetoothTransmitterDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BluetoothPeripheralManager+WatlaaBluetoothTransmitterDelegate.swift"; sourceTree = "<group>"; };
F897E25623FDE97D0075E0E8 /* SettingsViewTransmitterSettingsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewTransmitterSettingsViewModel.swift; sourceTree = "<group>"; };
F898EDE9233F53BF00BFB79B /* UIButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIButton.swift; sourceTree = "<group>"; };
F898EDEB233F549100BFB79B /* UIBarButtonItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIBarButtonItem.swift; sourceTree = "<group>"; };
F898EDF0234A494C00BFB79B /* xdrip v3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "xdrip v3.xcdatamodel"; sourceTree = "<group>"; };
@ -478,7 +487,6 @@
F8B3A833227F08AC004BA588 /* PickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PickerViewController.swift; sourceTree = "<group>"; };
F8B3A838227F090D004BA588 /* SettingsViewAlertSettingsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewAlertSettingsViewModel.swift; sourceTree = "<group>"; };
F8B3A839227F090D004BA588 /* SettingsViewDexcomSettingsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewDexcomSettingsViewModel.swift; sourceTree = "<group>"; };
F8B3A83A227F090D004BA588 /* SettingsViewTransmitterSettingsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewTransmitterSettingsViewModel.swift; sourceTree = "<group>"; };
F8B3A83B227F090D004BA588 /* SettingsViewNightScoutSettingsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewNightScoutSettingsViewModel.swift; sourceTree = "<group>"; };
F8B3A83C227F090D004BA588 /* SettingsViewHealthKitSettingsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewHealthKitSettingsViewModel.swift; sourceTree = "<group>"; };
F8B3A83D227F090D004BA588 /* SettingsViewSpeakSettingsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewSpeakSettingsViewModel.swift; sourceTree = "<group>"; };
@ -823,7 +831,6 @@
F821CF49229BF43A005C1E43 /* AlertKind.swift */,
F821CF4A229BF43A005C1E43 /* SnoozeParameters.swift */,
F821CF4B229BF43A005C1E43 /* AlertManager.swift */,
F821CF4C229BF43A005C1E43 /* AlertEntryUnit.swift */,
);
path = Alerts;
sourceTree = "<group>";
@ -894,6 +901,10 @@
F8297F42238DC4AC00D74D66 /* BluetoothPeripheral */ = {
isa = PBXGroup;
children = (
F897E24E23FC871C0075E0E8 /* BluetoothPeripheralManager+BluetoothTransmitterDelegate.swift */,
F897E24C23FC871C0075E0E8 /* BluetoothPeripheralManager+CGMG5TransmitterDelegate.swift */,
F897E24D23FC871C0075E0E8 /* BluetoothPeripheralManager+M5StackBluetoothTransmitterDelegate.swift */,
F897E24F23FC871C0075E0E8 /* BluetoothPeripheralManager+WatlaaBluetoothTransmitterDelegate.swift */,
F8297F55238ED07700D74D66 /* BluetoothPeripheralManager.swift */,
F8297F44238DC4AC00D74D66 /* BluetoothPeripheralManaging.swift */,
);
@ -1187,6 +1198,7 @@
F8B3A837227F090D004BA588 /* SettingsViewModels */ = {
isa = PBXGroup;
children = (
F897E25623FDE97D0075E0E8 /* SettingsViewTransmitterSettingsViewModel.swift */,
F8B3A838227F090D004BA588 /* SettingsViewAlertSettingsViewModel.swift */,
F8E3A2A423D78FBD00E5E98A /* SettingsViewAppleWatchSettingsViewModel.swift */,
F8A1584C22ECA445007F5B5D /* SettingsViewDevelopmentSettingsViewModel.swift */,
@ -1197,7 +1209,6 @@
F8A389EA233175A10010F405 /* SettingsViewM5StackSettingsViewModel.swift */,
F8B3A83B227F090D004BA588 /* SettingsViewNightScoutSettingsViewModel.swift */,
F8B3A83D227F090D004BA588 /* SettingsViewSpeakSettingsViewModel.swift */,
F8B3A83A227F090D004BA588 /* SettingsViewTransmitterSettingsViewModel.swift */,
);
path = SettingsViewModels;
sourceTree = "<group>";
@ -1454,6 +1465,7 @@
F8F971BE23A5915900C3F17D /* G5 */ = {
isa = PBXGroup;
children = (
F897E24A23FC86CF0075E0E8 /* CGMG5TransmitterDelegate.swift */,
F8F971BF23A5915900C3F17D /* CGMG5Transmitter.swift */,
F8F971C023A5915900C3F17D /* G5Messages */,
);
@ -1852,6 +1864,7 @@
F8B3A85B2280CCD1004BA588 /* AlertSettingsViewController.swift in Sources */,
F8F9722E23A5915900C3F17D /* M5StackTransmitterOpCode.swift in Sources */,
F8F9720223A5915900C3F17D /* CGMG6Transmitter.swift in Sources */,
F897E24B23FC86CF0075E0E8 /* CGMG5TransmitterDelegate.swift in Sources */,
F8F9723323A5915900C3F17D /* M5StackBluetoothTransmitterDelegate.swift in Sources */,
F8B3A81B227DEC92004BA588 /* SensorsAccessor.swift in Sources */,
F8F9721E23A5915900C3F17D /* LibreSensorState.swift in Sources */,
@ -1924,7 +1937,6 @@
F8297F4E238DCAD800D74D66 /* BluetoothPeripheralsViewController.swift in Sources */,
F8B3A848227F090E004BA588 /* SettingsViewHealthKitSettingsViewModel.swift in Sources */,
F8025E5021EE746400ECF0C0 /* Calibrator.swift in Sources */,
F821CF59229BF43A005C1E43 /* AlertEntryUnit.swift in Sources */,
F85DC2F421CFE3D400B9F74A /* Sensor+CoreDataClass.swift in Sources */,
F8B3A844227F090E004BA588 /* SettingsViewAlertSettingsViewModel.swift in Sources */,
F8A1586322EDB86E007F5B5D /* ConstantsSounds.swift in Sources */,
@ -1954,6 +1966,7 @@
F8AC425E21ADEBD60078C348 /* AppDelegate.swift in Sources */,
F804870D2336D90200EBDDB7 /* M5Stack+CoreDataProperties.swift in Sources */,
F8F9722F23A5915900C3F17D /* M5StackPacket.swift in Sources */,
F897E25223FC871C0075E0E8 /* BluetoothPeripheralManager+BluetoothTransmitterDelegate.swift in Sources */,
F821CF8E22AB090C005C1E43 /* DatePickerViewController.swift in Sources */,
F8691888239CEEFA0065B607 /* BluetoothPeripheralViewModel.swift in Sources */,
F8297F4F238DCAD800D74D66 /* BluetoothPeripheralNavigationController.swift in Sources */,
@ -1986,6 +1999,7 @@
F8B3A78E22622954004BA588 /* AlertType+CoreDataClass.swift in Sources */,
F8F9721D23A5915900C3F17D /* LibreDerivedAlgorithmRunner.swift in Sources */,
F821CF5A229BF43A005C1E43 /* CoreDataManager.swift in Sources */,
F897E25723FDE97D0075E0E8 /* SettingsViewTransmitterSettingsViewModel.swift in Sources */,
F85DC2F321CFE3D400B9F74A /* Calibration+CoreDataClass.swift in Sources */,
F8E3A2AB23DA520B00E5E98A /* ConstantsWatch.swift in Sources */,
F821CF7B22A1D359005C1E43 /* NightScoutFollowerDelegate.swift in Sources */,
@ -2012,9 +2026,11 @@
F8F9720B23A5915900C3F17D /* SensorDataRxMessage.swift in Sources */,
F830992C23C694F4005741DF /* WatlaaAccessor.swift in Sources */,
F8AC426021ADEBD60078C348 /* RootViewController.swift in Sources */,
F897E25023FC871C0075E0E8 /* BluetoothPeripheralManager+CGMG5TransmitterDelegate.swift in Sources */,
F8B3A78B225D473D004BA588 /* UIAlertController.swift in Sources */,
F8F9720E23A5915900C3F17D /* AuthRequestRxMessage.swift in Sources */,
F8BDD4242218790E006EAB84 /* UserDefaults.swift in Sources */,
F897E25323FC871C0075E0E8 /* BluetoothPeripheralManager+WatlaaBluetoothTransmitterDelegate.swift in Sources */,
F81D6D5222C27F18005EFAE2 /* BgReading+DexcomShare.swift in Sources */,
F8F9723023A5915900C3F17D /* M5StackUtilities.swift in Sources */,
F8297F52238ECA3200D74D66 /* BluetoothPeripheralViewController.swift in Sources */,
@ -2026,11 +2042,11 @@
F8F9722C23A5915900C3F17D /* GlucoseData.swift in Sources */,
F8A389E7232ECE7E0010F405 /* SettingsViewUtilities.swift in Sources */,
F8B3A7DF226E48C1004BA588 /* SoundPlayer.swift in Sources */,
F897E25123FC871C0075E0E8 /* BluetoothPeripheralManager+M5StackBluetoothTransmitterDelegate.swift in Sources */,
F8B3A820227DEC92004BA588 /* AlertTypesAccessor.swift in Sources */,
F8F9720623A5915900C3F17D /* AuthRequestTxMessage.swift in Sources */,
F8F9721123A5915900C3F17D /* KeepAliveTxMessage.swift in Sources */,
F8B3A81E227DEC92004BA588 /* BgReadingsAccessor.swift in Sources */,
F8B3A846227F090E004BA588 /* SettingsViewTransmitterSettingsViewModel.swift in Sources */,
F821CF6B229FC22D005C1E43 /* Endpoint.swift in Sources */,
F821CF58229BF43A005C1E43 /* AlertManager.swift in Sources */,
F8297F59238EE14E00D74D66 /* TextsBluetoothPeripheralsView.swift in Sources */,
@ -2514,8 +2530,13 @@
"$(inherited)",
"@executable_path/Frameworks",
);
<<<<<<< HEAD
MARKETING_VERSION = 3.10.2;
PRODUCT_BUNDLE_IDENTIFIER = net.johandegraeve.xdripswift;
=======
MARKETING_VERSION = 3.10.1;
PRODUCT_BUNDLE_IDENTIFIER = net.johandegraeve.xdriptest;
>>>>>>> compiles, but can't test yet for G5 as I have no working one, will continue now with bubble
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "xdrip/xdrip-Bridging-Header.h";

View File

@ -45,7 +45,7 @@ final class CGMG4xDripTransmitter: BluetoothTransmitter, CGMTransmitter {
//assign transmitterId
self.transmitterId = transmitterID
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: CBUUID_Advertisement_G4, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_G4)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_G4, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_G4, startScanningAfterInit: CGMTransmitterType.dexcomG4.startScanningAfterInit(), bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: CBUUID_Advertisement_G4, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_G4)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_G4, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_G4, startScanningAfterInit: false, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
}
@ -152,7 +152,7 @@ final class CGMG4xDripTransmitter: BluetoothTransmitter, CGMTransmitter {
/// this transmitter does not support oop web
func setWebOOPSiteAndToken(oopWebSite: String, oopWebToken: String) {}
func cgmTransmitterType() -> CGMTransmitterType? {
func cgmTransmitterType() -> CGMTransmitterType {
return .dexcomG4
}

View File

@ -130,7 +130,7 @@ class CGMG5Transmitter:BluetoothTransmitter, CGMTransmitter {
self.G5ResetRequested = false
// initialize - CBUUID_Receive_Authentication.rawValue and CBUUID_Write_Control.rawValue will probably not be used in the superclass
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: CBUUID_Advertisement_G5, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_G5)], CBUUID_ReceiveCharacteristic: CBUUID_Characteristic_UUID.CBUUID_Receive_Authentication.rawValue, CBUUID_WriteCharacteristic: CBUUID_Characteristic_UUID.CBUUID_Write_Control.rawValue, startScanningAfterInit: CGMTransmitterType.dexcomG5.startScanningAfterInit(), bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: CBUUID_Advertisement_G5, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_G5)], CBUUID_ReceiveCharacteristic: CBUUID_Characteristic_UUID.CBUUID_Receive_Authentication.rawValue, CBUUID_WriteCharacteristic: CBUUID_Characteristic_UUID.CBUUID_Write_Control.rawValue, startScanningAfterInit: true, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
//assign CGMTransmitterDelegate
self.cgmTransmitterDelegate = cGMTransmitterDelegate
@ -512,7 +512,7 @@ class CGMG5Transmitter:BluetoothTransmitter, CGMTransmitter {
/// this transmitter does not support oop web
func setWebOOPSiteAndToken(oopWebSite: String, oopWebToken: String) {}
func cgmTransmitterType() -> CGMTransmitterType? {
func cgmTransmitterType() -> CGMTransmitterType {
return .dexcomG5
}
@ -553,10 +553,10 @@ class CGMG5Transmitter:BluetoothTransmitter, CGMTransmitter {
if let resetRxMessage = ResetRxMessage(data: value) {
if resetRxMessage.status == 0 {
trace("resetRxMessage status is 0, considering reset successful", log: log, category: ConstantsLog.categoryCGMG5, type: .info)
bluetoothTransmitterDelegate.reset(successful: true)
bluetoothTransmitterDelegate.reset(for: self, successful: true)
} else {
trace("resetRxMessage status is %{public}d, considering reset failed", log: log, category: ConstantsLog.categoryCGMG5, type: .info, resetRxMessage.status)
bluetoothTransmitterDelegate.reset(successful: false)
bluetoothTransmitterDelegate.reset(for: self, successful: false)
}
} else {
trace("resetRxMessage is nil", log: log, category: ConstantsLog.categoryCGMG5, type: .error)

View File

@ -23,7 +23,7 @@ class CGMG6Transmitter: CGMG5Transmitter {
}
override func cgmTransmitterType() -> CGMTransmitterType? {
override func cgmTransmitterType() -> CGMTransmitterType {
return .dexcomG6
}

View File

@ -17,9 +17,7 @@ protocol CGMTransmitter:AnyObject {
func setWebOOPSiteAndToken(oopWebSite: String, oopWebToken: String)
/// get cgmTransmitterType
///
/// return value optional because watlaa also conforms to protocol CGMTransmitter although it's not really a CGMTransmitter
func cgmTransmitterType() -> CGMTransmitterType?
func cgmTransmitterType() -> CGMTransmitterType
}

View File

@ -93,7 +93,7 @@ class CGMBluconTransmitter: BluetoothTransmitter {
rxBuffer = Data()
// initialize
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_BluconService)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_Blucon, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_Blucon, startScanningAfterInit: CGMTransmitterType.Blucon.startScanningAfterInit(), bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_BluconService)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_Blucon, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_Blucon, startScanningAfterInit: true, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
//assign CGMTransmitterDelegate
cgmTransmitterDelegate = cGMTransmitterDelegate
@ -533,7 +533,7 @@ extension CGMBluconTransmitter: CGMTransmitter {
/// this transmitter does not support oop web
func setWebOOPSiteAndToken(oopWebSite: String, oopWebToken: String) {}
func cgmTransmitterType() -> CGMTransmitterType? {
func cgmTransmitterType() -> CGMTransmitterType {
return .Blucon
}

View File

@ -41,7 +41,7 @@ class CGMBlueReaderTransmitter:BluetoothTransmitter, CGMTransmitter {
// assign CGMTransmitterDelegate
cgmTransmitterDelegate = cGMTransmitterDelegate
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_BlueReader)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_BlueReader, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_BlueReader, startScanningAfterInit: CGMTransmitterType.blueReader.startScanningAfterInit(), bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_BlueReader)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_BlueReader, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_BlueReader, startScanningAfterInit: false, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
}
@ -124,7 +124,7 @@ class CGMBlueReaderTransmitter:BluetoothTransmitter, CGMTransmitter {
/// this transmitter does not support oop web
func setWebOOPSiteAndToken(oopWebSite: String, oopWebToken: String) {}
func cgmTransmitterType() -> CGMTransmitterType? {
func cgmTransmitterType() -> CGMTransmitterType {
return .blueReader
}

View File

@ -89,7 +89,7 @@ class CGMBubbleTransmitter:BluetoothTransmitter, CGMTransmitter {
self.oopWebToken = oopWebToken
self.oopWebSite = oopWebSite
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_Bubble)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_Bubble, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_Bubble, startScanningAfterInit: CGMTransmitterType.Bubble.startScanningAfterInit(), bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_Bubble)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_Bubble, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_Bubble, startScanningAfterInit: false, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
}
@ -215,7 +215,7 @@ class CGMBubbleTransmitter:BluetoothTransmitter, CGMTransmitter {
self.oopWebSite = oopWebSite
}
func cgmTransmitterType() -> CGMTransmitterType? {
func cgmTransmitterType() -> CGMTransmitterType {
return .Bubble
}

View File

@ -41,7 +41,7 @@ class CGMDroplet1Transmitter:BluetoothTransmitter, CGMTransmitter {
// assign CGMTransmitterDelegate
self.cgmTransmitterDelegate = cGMTransmitterDelegate
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_Droplet)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_Droplet, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_Droplet, startScanningAfterInit: CGMTransmitterType.Droplet1.startScanningAfterInit(), bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_Droplet)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_Droplet, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_Droplet, startScanningAfterInit: false, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
}
@ -127,7 +127,7 @@ class CGMDroplet1Transmitter:BluetoothTransmitter, CGMTransmitter {
/// this transmitter does not support oop web
func setWebOOPSiteAndToken(oopWebSite: String, oopWebToken: String) {}
func cgmTransmitterType() -> CGMTransmitterType? {
func cgmTransmitterType() -> CGMTransmitterType {
return .Droplet1
}

View File

@ -107,7 +107,7 @@ class CGMGNSEntryTransmitter:BluetoothTransmitter, CGMTransmitter {
self.timeStampLastBgReadingInMinutes = timeStampLastBgReading.toMillisecondsAsDouble()/1000/60
// initialize
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_GNWService), CBUUID(string: CBUUID_BatteryService), CBUUID(string: CBUUID_DeviceInformationService)], CBUUID_ReceiveCharacteristic: CBUUID_Characteristic_UUID.CBUUID_GNW_Notify.rawValue, CBUUID_WriteCharacteristic: CBUUID_Characteristic_UUID.CBUUID_GNW_Write.rawValue, startScanningAfterInit: CGMTransmitterType.GNSentry.startScanningAfterInit(), bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_GNWService), CBUUID(string: CBUUID_BatteryService), CBUUID(string: CBUUID_DeviceInformationService)], CBUUID_ReceiveCharacteristic: CBUUID_Characteristic_UUID.CBUUID_GNW_Notify.rawValue, CBUUID_WriteCharacteristic: CBUUID_Characteristic_UUID.CBUUID_GNW_Write.rawValue, startScanningAfterInit: false, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
//assign CGMTransmitterDelegate
self.cgmTransmitterDelegate = cGMTransmitterDelegate
@ -247,7 +247,7 @@ class CGMGNSEntryTransmitter:BluetoothTransmitter, CGMTransmitter {
/// this transmitter does not support oop web
func setWebOOPSiteAndToken(oopWebSite: String, oopWebToken: String) {}
func cgmTransmitterType() -> CGMTransmitterType? {
func cgmTransmitterType() -> CGMTransmitterType {
return .GNSentry
}

View File

@ -87,7 +87,7 @@ class CGMMiaoMiaoTransmitter:BluetoothTransmitter, CGMTransmitter {
self.oopWebToken = oopWebToken
self.oopWebSite = oopWebSite
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_MiaoMiao)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_MiaoMiao, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_MiaoMiao, startScanningAfterInit: CGMTransmitterType.miaomiao.startScanningAfterInit(), bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
super.init(addressAndName: newAddressAndName, CBUUID_Advertisement: nil, servicesCBUUIDs: [CBUUID(string: CBUUID_Service_MiaoMiao)], CBUUID_ReceiveCharacteristic: CBUUID_ReceiveCharacteristic_MiaoMiao, CBUUID_WriteCharacteristic: CBUUID_WriteCharacteristic_MiaoMiao, startScanningAfterInit: false, bluetoothTransmitterDelegate: bluetoothTransmitterDelegate)
}
@ -232,7 +232,7 @@ class CGMMiaoMiaoTransmitter:BluetoothTransmitter, CGMTransmitter {
self.oopWebSite = oopWebSite
}
func cgmTransmitterType() -> CGMTransmitterType? {
func cgmTransmitterType() -> CGMTransmitterType {
return .miaomiao
}

View File

@ -519,15 +519,7 @@ class BluetoothTransmitter: NSObject, CBCentralManagerDelegate, CBPeripheralDele
///
/// to be overriden. For transmitter types that don't need pairing, or that don't need pairing initiated by user/view controller, this function does not need to be overriden
func initiatePairing() {return}
// MARK: methods to get address and name
/// read device name
func name() -> String? {
return deviceName
}
// MARK: - helpers
private func initialize() {

View File

@ -27,7 +27,7 @@ protocol BluetoothTransmitterDelegate: AnyObject {
func pairingFailed()
/// transmitter reset result
func reset(successful: Bool)
func reset(for bluetoothTransmitter: BluetoothTransmitter, successful: Bool)
/// to pass some text error message, delegate can decide to show to user, log, ...
func error(message: String)

View File

@ -2,7 +2,7 @@ import Foundation
extension WatlaaBluetoothTransmitterMaster: CGMTransmitter {
func reset(requested: Bool) {
func reset(for bluetoothTransmitter: BluetoothTransmitter, successful: Bool) {
// no reset need for watlaa
}
@ -14,8 +14,8 @@ extension WatlaaBluetoothTransmitterMaster: CGMTransmitter {
// no web oop for watlaa as sensorid detection not supported
}
func cgmTransmitterType() -> CGMTransmitterType? {
return nil
func cgmTransmitterType() -> CGMTransmitterType {
return .watlaa
}
}

View File

@ -328,3 +328,4 @@ final class WatlaaBluetoothTransmitterMaster: BluetoothTransmitter {
}
}

View File

@ -17,6 +17,7 @@ public class BLEPeripheral: NSManagedObject {
self.shouldconnect = true
self.alias = alias
self.parameterUpdateNeededAtNextConnect = false
self.resetrequired = false
}

View File

@ -16,6 +16,9 @@ extension BLEPeripheral {
/// should app try to connect to the device yes or no
@NSManaged public var shouldconnect: Bool
/// is a reset require or not (only applicable to transmitters for which reset is supported, like DexcomG5)
@NSManaged public var resetrequired: Bool
/// alias chosen by user, to recognize the device or to distinguish two devices that have the same name
@NSManaged public var alias: String?

View File

@ -42,6 +42,7 @@
<attribute name="alias" optional="YES" attributeType="String"/>
<attribute name="name" attributeType="String"/>
<attribute name="parameterUpdateNeededAtNextConnect" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="resetrequired" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="shouldconnect" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="transmitterId" optional="YES" attributeType="String"/>
<relationship name="dexcomG5" optional="YES" maxCount="1" deletionRule="Deny" destinationEntity="DexcomG5" inverseName="blePeripheral" inverseEntity="DexcomG5"/>
@ -95,7 +96,7 @@
<element name="AlertEntry" positionX="-648" positionY="189" width="128" height="105"/>
<element name="AlertType" positionX="-657" positionY="180" width="128" height="165"/>
<element name="BgReading" positionX="-285.87109375" positionY="31.9921875" width="128" height="330"/>
<element name="BLEPeripheral" positionX="-630" positionY="216" width="128" height="178"/>
<element name="BLEPeripheral" positionX="-630" positionY="216" width="128" height="193"/>
<element name="Calibration" positionX="-859.21484375" positionY="46.21484375" width="128" height="285"/>
<element name="DexcomG5" positionX="-648" positionY="198" width="128" height="73"/>
<element name="M5Stack" positionX="-657" positionY="180" width="128" height="163"/>

View File

@ -26,8 +26,6 @@ extension UserDefaults {
/// transmitter type
case transmitterTypeAsString = "transmitterTypeAsString"
/// transmitterid
case transmitterId = "transmitterId"
/// is web OOP enabled or not
case webOOPEnabled = "webOOPEnabled"
/// if webOOP enabled, what site to use
@ -145,14 +143,6 @@ extension UserDefaults {
// Other Settings (not user configurable)
// cgm Transmitter
/// active transmitter address
case cgmTransmitterDeviceAddress = "cgmTransmitterDeviceAddress"
/// active transmitter name
case cgmTransmitterDeviceName = "cgmTransmitterDeviceName"
/// timestamp of last bluetooth disconnect to transmitter
case lastdisConnectTimestamp = "lastdisConnectTimestamp"
// Nightscout
/// timestamp lastest reading uploaded to NightScout
case timeStampLatestNSUploadedBgReadingToNightScout = "timeStampLatestUploadedBgReading"
@ -160,8 +150,6 @@ extension UserDefaults {
// Transmitter
/// Transmitter Battery Level
case transmitterBatteryInfo = "transmitterbatteryinfo"
/// Dexcom transmitter reset required
case transmitterResetRequired = "transmitterResetRequired"
// HealthKit
/// did user authorize the storage of readings in healthkit or not
@ -323,7 +311,7 @@ extension UserDefaults {
// MARK: Transmitter Settings
/// setting a new transmittertype will also set the transmitterid to nil
/// cgm ransmittertype currently active
var transmitterType:CGMTransmitterType? {
get {
if let transmitterTypeAsString = transmitterTypeAsString {
@ -343,21 +331,20 @@ extension UserDefaults {
// if transmittertype has changed then also reset the transmitter id to nil
// this is also a check to see if transmitterTypeAsString has really changed, because just calling a set without a new value may cause a transmittertype reset in other parts of the call (inclusive stopping sensor etc.)
if newValue != string(forKey: Key.transmitterTypeAsString.rawValue) {
set(nil, forKey: Key.transmitterId.rawValue)
set(newValue, forKey: Key.transmitterTypeAsString.rawValue)
}
}
}
/// transmitter id
@objc dynamic var transmitterId:String? {
/// NOT USED ANYMORE transmitter id
/*@objc dynamic var transmitterId:String? {
get {
return string(forKey: Key.transmitterId.rawValue)
}
set {
set(newValue, forKey: Key.transmitterId.rawValue)
}
}
}*/
/// web oop enabled
@objc dynamic var webOOPEnabled: Bool {
@ -788,33 +775,6 @@ extension UserDefaults {
// MARK: - ===== Other Settings ======
var cgmTransmitterDeviceAddress: String? {
get {
return string(forKey: Key.cgmTransmitterDeviceAddress.rawValue)
}
set {
set(newValue, forKey: Key.cgmTransmitterDeviceAddress.rawValue)
}
}
var cgmTransmitterDeviceName: String? {
get {
return string(forKey: Key.cgmTransmitterDeviceName.rawValue)
}
set {
set(newValue, forKey: Key.cgmTransmitterDeviceName.rawValue)
}
}
var lastdisConnectTimestamp:Date? {
get {
return object(forKey: Key.lastdisConnectTimestamp.rawValue) as? Date
}
set {
set(newValue, forKey: Key.lastdisConnectTimestamp.rawValue)
}
}
/// timestamp lastest reading uploaded to NightScout
var timeStampLatestNightScoutUploadedBgReading:Date? {
get {
@ -825,7 +785,7 @@ extension UserDefaults {
}
}
/// transmitterBatteryInfo
/// transmitterBatteryInfo, this should be the transmitter battery info of the latest active cgmTransmitter
var transmitterBatteryInfo:TransmitterBatteryInfo? {
get {
if let data = object(forKey: Key.transmitterBatteryInfo.rawValue) as? Data {
@ -844,16 +804,6 @@ extension UserDefaults {
}
}
/// is transmitter reset required or not
@objc dynamic var transmitterResetRequired: Bool {
get {
return bool(forKey: Key.transmitterResetRequired.rawValue)
}
set {
set(newValue, forKey: Key.transmitterResetRequired.rawValue)
}
}
/// did user authorize the storage of readings in healthkit or not - this setting is actually only used to allow the HealthKitManager to listen for changes in the authorization status
var storeReadingsInHealthkitAuthorized:Bool {
get {

View File

@ -1,8 +0,0 @@
import Foundation
/// unit to be used in alert entry - eg mgdl (not mmol because mmol is just mgdl converted), or minutes
enum AlertUnit {
case mgdl
case minutes
}

View File

@ -4,7 +4,7 @@ import AVFoundation
import AudioToolbox
extension BluetoothPeripheralManager: BluetoothTransmitterDelegate {
/// because extension dont allow var's, this is a workaround as explained here https://medium.com/@valv0/computed-properties-and-extensions-a-pure-swift-approach-64733768112c
private struct PropertyHolder {
@ -14,11 +14,11 @@ extension BluetoothPeripheralManager: BluetoothTransmitterDelegate {
/// timer used when asking the transmitter to initiate pairing. The user is waiting for the response, if the response from the transmitter doesn't come within a few seconds, then we'll inform the user
static var transmitterPairingResponseTimer:Timer?
/// constant for key in ApplicationManager.shared.addClosureToRunWhenAppWillEnterForeground - initiate pairing
static let applicationManagerKeyInitiatePairing = "RootViewController-InitiatePairing"
}
/// constant for key in ApplicationManager.shared.addClosureToRunWhenAppWillEnterForeground - initiate pairing
static let applicationManagerKeyInitiatePairing = "RootViewController-InitiatePairing"
/// Transmitter is calling this delegate function to indicate that bluetooth pairing is needed. If the app is in the background, the user will be informed, after opening the app a pairing request will be initiated. if the app is in the foreground, the pairing request will be initiated immediately
func transmitterNeedsPairing(bluetoothTransmitter: BluetoothTransmitter) {
@ -70,10 +70,10 @@ extension BluetoothPeripheralManager: BluetoothTransmitterDelegate {
// we will not just count on it that the user will click the notification to open the app (assuming the app is in the background, if the app is in the foreground, then we come in another flow)
// whenever app comes from-back to foreground, updateLabelsAndChart needs to be called
ApplicationManager.shared.addClosureToRunWhenAppWillEnterForeground(key: PropertyHolder.applicationManagerKeyInitiatePairing, closure: {
ApplicationManager.shared.addClosureToRunWhenAppWillEnterForeground(key: BluetoothPeripheralManager.applicationManagerKeyInitiatePairing, closure: {
// first of all reremove from application key manager
ApplicationManager.shared.removeClosureToRunWhenAppWillEnterForeground(key: PropertyHolder.applicationManagerKeyInitiatePairing)
ApplicationManager.shared.removeClosureToRunWhenAppWillEnterForeground(key: BluetoothPeripheralManager.applicationManagerKeyInitiatePairing)
// first remove existing notification if any
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [ConstantsNotifications.NotificationIdentifierForTransmitterNeedsPairing.transmitterNeedsPairing])
@ -93,6 +93,9 @@ extension BluetoothPeripheralManager: BluetoothTransmitterDelegate {
})
// need to temporary store the bluetooth transmitter that needs the pairing, user will now open the app, pairing will then be initiated
bluetoothTransmitterThatNeedsPairing = bluetoothTransmitter
}
func successfullyPaired() {
@ -121,10 +124,10 @@ extension BluetoothPeripheralManager: BluetoothTransmitterDelegate {
}
}
func reset(successful: Bool) {
func reset(for bluetoothTransmitter: BluetoothTransmitter, successful: Bool) {
// reset setting to false
UserDefaults.standard.transmitterResetRequired = false
// set resetrequired to false in coredata, there's no need to reset as it's just been done
getBluetoothPeripheral(for: bluetoothTransmitter).blePeripheral.resetrequired = false
// Create Notification Content to give info about reset result of reset attempt
let notificationContent = UNMutableNotificationContent()

View File

@ -29,6 +29,9 @@ class BluetoothPeripheralManager: NSObject {
/// will be used to present alerts, for example pairing failed
public let uIViewController: UIViewController
/// bluetoothtransmitter may need pairing, but app is in background. Notification will be sent to user, user will open the app, at that moment pairing can happen. variable bluetoothTransmitterThatNeedsPairing will temporary store the BluetoothTransmitter that needs the pairing
public var bluetoothTransmitterThatNeedsPairing: BluetoothTransmitter?
// MARK: - private properties
/// CoreDataManager to use
@ -624,6 +627,15 @@ extension BluetoothPeripheralManager: BluetoothPeripheralManaging {
}
}
func initiatePairing() {
bluetoothTransmitterThatNeedsPairing?.initiatePairing()
/// remove applicationManagerKeyInitiatePairing from application key manager - there's no need to initiate the pairing via this closure
ApplicationManager.shared.removeClosureToRunWhenAppWillEnterForeground(key: BluetoothPeripheralManager.applicationManagerKeyInitiatePairing)
}
}

View File

@ -40,4 +40,7 @@ func startScanningForNewDevice(type: BluetoothPeripheralType, transmitterId: Str
/// bluetoothtransmitter for this bluetoothperiheral will be deleted, as a result this will also disconnect the bluetoothtransmitter
func setBluetoothTransmitterToNil(forBluetoothPeripheral bluetoothPeripheral: BluetoothPeripheral)
/// bluetoothtransmitter may need pairing, but app is in background. Notification will be sent to user, user will open the app, at that moment initiatePairing will be called
func initiatePairing()
}

View File

@ -29,7 +29,7 @@
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<state key="normal" title="Transmitter"/>
<connections>
<action selector="transmitterButtonAction:" destination="9pv-A4-QxB" eventType="touchUpInside" id="iJp-CH-PZa"/>
<action selector="sensorButtonAction:" destination="9pv-A4-QxB" eventType="touchUpInside" id="iJp-CH-PZa"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fSY-nc-amN">
@ -102,7 +102,7 @@
<outlet property="diffLabelOutlet" destination="7Wo-wd-80o" id="nnn-w9-1sX"/>
<outlet property="minutesLabelOutlet" destination="uyn-2k-K74" id="XXm-rq-Suy"/>
<outlet property="preSnoozeButtonOutlet" destination="fSY-nc-amN" id="T25-Z1-3Ad"/>
<outlet property="transmitterButtonOutlet" destination="zWo-AR-qJE" id="uuB-WI-JKe"/>
<outlet property="sensorButtonOutlet" destination="zWo-AR-qJE" id="uuB-WI-JKe"/>
<outlet property="valueLabelOutlet" destination="We3-bN-ffR" id="wtY-sZ-mev"/>
</connections>
</viewController>

View File

@ -1,5 +1,5 @@
"presnooze" = "Snooze";
"transmitter" = "Transmitter";
"sensor" = "Sensor";
"calibrate" = "Calibrate";
"statusactiontitle" = "Status";
"scanbluetoothdeviceactiontitle" = "Scan for Transmitter";

View File

@ -8,8 +8,8 @@ enum Texts_HomeView {
return NSLocalizedString("presnooze", tableName: filename, bundle: Bundle.main, value: "Snooze", comment: "Text in button on home screen")
}()
static let transmitter:String = {
return NSLocalizedString("transmitter", tableName: filename, bundle: Bundle.main, value: "Transmitter", comment: "Literally 'Transmitter', used as name in the button in the home screen, but also in text in pop ups")
static let sensor:String = {
return NSLocalizedString("sensor", tableName: filename, bundle: Bundle.main, value: "Sensor", comment: "Literally 'Sensor', used as name in the button in the home screen, but also in text in pop ups")
}()
static let calibrationButton:String = {

View File

@ -789,10 +789,10 @@ extension BluetoothPeripheralViewController: BluetoothTransmitterDelegate {
}
func reset(successful: Bool) {
func reset(for bluetoothTransmitter: BluetoothTransmitter, successful: Bool) {
// need to inform also other delegates
previouslyAssignedBluetoothTransmitterDelegate?.reset(successful: successful)
previouslyAssignedBluetoothTransmitterDelegate?.reset(for: bluetoothTransmitter, successful: successful)
// handled in BluetoothPeripheralManager

View File

@ -47,11 +47,7 @@ extension DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
guard let cGMG5Transmitter = bluetoothTransmitter as? CGMG5Transmitter else {fatalError("DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel, reAssignBluetoothTransmitterDelegateToOriginal, not a WatlaaBluetoothTransmitterMaster")}
guard let previouslyAssignedcGMG5TransmitterDelegate = previouslyAssignedcGMG5TransmitterDelegate else {
fatalError("DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel, reAssignBluetoothTransmitterDelegateToOriginal, previouslyAssignedcGMG5TransmitterDelegate is nil")
return
}
guard let previouslyAssignedcGMG5TransmitterDelegate = previouslyAssignedcGMG5TransmitterDelegate else {fatalError("DexcomG5BluetoothPeripheralViewModel: BluetoothPeripheralViewModel, reAssignBluetoothTransmitterDelegateToOriginal, previouslyAssignedcGMG5TransmitterDelegate is nil")}
cGMG5Transmitter.cGMG5TransmitterDelegate = previouslyAssignedcGMG5TransmitterDelegate

View File

@ -607,11 +607,7 @@ extension M5StackBluetoothPeripheralViewModel: BluetoothPeripheralViewModel {
guard let m5StackBluetoothTransmitter = bluetoothTransmitter as? M5StackBluetoothTransmitter else {fatalError("M5StackBluetoothPeripheralViewModel: BluetoothPeripheralViewModel, reAssignBluetoothTransmitterDelegateToOriginal, not a m5StackBluetoothTransmitter")}
guard let previouslyAssignedM5StackBluetoothTransmitter = previouslyAssignedM5StackBluetoothTransmitterDelegate else {
fatalError("M5StackBluetoothPeripheralViewModel: BluetoothPeripheralViewModel, reAssignBluetoothTransmitterDelegateToOriginal, previouslyAssignedM5StackBluetoothTransmitter is nil")
return
}
guard let previouslyAssignedM5StackBluetoothTransmitter = previouslyAssignedM5StackBluetoothTransmitterDelegate else {fatalError("M5StackBluetoothPeripheralViewModel: BluetoothPeripheralViewModel, reAssignBluetoothTransmitterDelegateToOriginal, previouslyAssignedM5StackBluetoothTransmitter is nil")}
m5StackBluetoothTransmitter.m5StackBluetoothTransmitterDelegate = previouslyAssignedM5StackBluetoothTransmitter

View File

@ -45,11 +45,7 @@ extension WatlaaMasterBluetoothPeripheralViewModel: BluetoothPeripheralViewModel
guard let watlaaBluetoothTransmitter = bluetoothTransmitter as? WatlaaBluetoothTransmitterMaster else {fatalError("WatlaaMasterBluetoothPeripheralViewModel: BluetoothPeripheralViewModel, reAssignBluetoothTransmitterDelegateToOriginal, not a WatlaaBluetoothTransmitterMaster")}
guard let previouslyAssignedWatlaaBluetoothTransmitterDelegate = previouslyAssignedWatlaaBluetoothTransmitterDelegate else {
fatalError("WatlaaMasterBluetoothPeripheralViewModel: BluetoothPeripheralViewModel, reAssignBluetoothTransmitterDelegateToOriginal, previouslyAssignedWatlaaBluetoothTransmitterDelegate is nil")
return
}
guard let previouslyAssignedWatlaaBluetoothTransmitterDelegate = previouslyAssignedWatlaaBluetoothTransmitterDelegate else {fatalError("WatlaaMasterBluetoothPeripheralViewModel: BluetoothPeripheralViewModel, reAssignBluetoothTransmitterDelegateToOriginal, previouslyAssignedWatlaaBluetoothTransmitterDelegate is nil")}
watlaaBluetoothTransmitter.watlaaBluetoothTransmitterDelegate = previouslyAssignedWatlaaBluetoothTransmitterDelegate

View File

@ -271,10 +271,10 @@ extension BluetoothPeripheralsViewController: BluetoothTransmitterDelegate {
}
func reset(successful: Bool) {
func reset(for bluetoothTransmitter: BluetoothTransmitter, successful: Bool) {
// need to inform also other delegates
previouslyAssignedBluetoothTransmitterDelegate?.reset(successful: successful)
previouslyAssignedBluetoothTransmitterDelegate?.reset(for: bluetoothTransmitter, successful: successful)
// handled in BluetoothPeripheralManager
}

View File

@ -15,7 +15,7 @@ final class RootViewController: UIViewController {
@IBAction func calibrateButtonAction(_ sender: UIButton) {
if let transmitterType = UserDefaults.standard.transmitterType, transmitterType.canWebOOP(), UserDefaults.standard.webOOPEnabled {
if let cgmTransmitter = cgmTransmitter, cgmTransmitter.cgmTransmitterType().canWebOOP(), UserDefaults.standard.webOOPEnabled {
let alert = UIAlertController(title: Texts_Common.warning, message: Texts_HomeView.calibrationNotNecessary, actionHandler: nil)
@ -27,10 +27,10 @@ final class RootViewController: UIViewController {
}
@IBOutlet weak var transmitterButtonOutlet: UIButton!
@IBOutlet weak var sensorButtonOutlet: UIButton!
@IBAction func transmitterButtonAction(_ sender: UIButton) {
createAndPresentTransmitterButtonActionSheet()
@IBAction func sensorButtonAction(_ sender: UIButton) {
createAndPresentSensorButtonActionSheet()
}
@IBOutlet weak var preSnoozeButtonOutlet: UIButton!
@ -248,9 +248,6 @@ final class RootViewController: UIViewController {
// update label texts, minutes ago, diff and value
self.updateLabelsAndChart(overrideApplicationState: true)
// create transmitter based on UserDefaults
self.initializeCGMTransmitter()
// if licenseinfo not yet accepted, show license info with only ok button
if !UserDefaults.standard.licenseInfoAccepted {
@ -276,15 +273,10 @@ final class RootViewController: UIViewController {
setupView()
// observe setting changes
// when user changes transmitter type or transmitter id, theThat's why observer for these settings is required
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.transmitterTypeAsString.rawValue, options: .new, context: nil)
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.transmitterId.rawValue, options: .new, context: nil)
// changing from follower to master or vice versa requires transmitter setup
// changing from follower to master or vice versa
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.isMaster.rawValue, options: .new
, context: nil)
// need to prepare transmitter reset
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.transmitterResetRequired.rawValue, options: .new
, context: nil)
// web oop
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.webOOPEnabled.rawValue, options: .new
, context: nil)
@ -411,7 +403,24 @@ final class RootViewController: UIViewController {
bluetoothPeripheralManager = BluetoothPeripheralManager(coreDataManager: coreDataManager, cgmTransmitterDelegate: self, uIViewController: self, onCGMTransmitterCreation: {
(cgmTransmitter: CGMTransmitter?) in
// reinitialize cgmTransmitter, possibily we assign cgmTransmitter to nil here (in case user deletes the active cgmTransmitter)
self.cgmTransmitter = cgmTransmitter
//if cgmTransmitter not nil
if let cgmTransmitter = cgmTransmitter {
// reassign calibrator
self.calibrator = RootViewController.getCalibrator(transmitterType: cgmTransmitter.cgmTransmitterType(), webOOPEnabled: UserDefaults.standard.webOOPEnabled)
UserDefaults.standard.transmitterTypeAsString = cgmTransmitter.cgmTransmitterType().rawValue
} else {
UserDefaults.standard.transmitterTypeAsString = nil
}
})
@ -427,13 +436,14 @@ final class RootViewController: UIViewController {
private func processNewGlucoseData(glucoseData: inout [GlucoseData], sensorTimeInMinutes: Int?) {
// check that calibrations and coredata manager is not nil
guard let calibrationsAccessor = calibrationsAccessor, let coreDataManager = coreDataManager else {
fatalError("in processNewCGMInfo, calibrations or coreDataManager is nil")
guard let calibrationsAccessor = calibrationsAccessor, let coreDataManager = coreDataManager, let cgmTransmitter = cgmTransmitter else {
fatalError("in processNewCGMInfo, calibrations or coreDataManager or cgmTransmitter is nil")
}
if activeSensor == nil {
if let sensorTimeInMinutes = sensorTimeInMinutes, UserDefaults.standard.transmitterType?.canDetectNewSensor() ?? false {
if let sensorTimeInMinutes = sensorTimeInMinutes, cgmTransmitter.cgmTransmitterType().canDetectNewSensor() {
activeSensor = Sensor(startDate: Date(timeInterval: -Double(sensorTimeInMinutes * 60), since: Date()),nsManagedObjectContext: coreDataManager.mainManagedObjectContext)
if let activeSensor = activeSensor {
trace("created sensor with id : %{public}@ and startdate %{public}@", log: log, category: ConstantsLog.categoryRootView, type: .info, activeSensor.id, activeSensor.startDate.description)
@ -469,7 +479,7 @@ final class RootViewController: UIViewController {
for (_, glucose) in glucoseData.enumerated().reversed() {
if glucose.timeStamp > timeStampLastBgReading {
_ = calibrator.createNewBgReading(rawData: (Double)(glucose.glucoseLevelRaw), filteredData: (Double)(glucose.glucoseLevelRaw), timeStamp: glucose.timeStamp, sensor: activeSensor, last3Readings: &latest3BgReadings, lastCalibrationsForActiveSensorInLastXDays: &lastCalibrationsForActiveSensorInLastXDays, firstCalibration: firstCalibrationForActiveSensor, lastCalibration: lastCalibrationForActiveSensor, deviceName: UserDefaults.standard.cgmTransmitterDeviceName, nsManagedObjectContext: coreDataManager.mainManagedObjectContext)
_ = calibrator.createNewBgReading(rawData: (Double)(glucose.glucoseLevelRaw), filteredData: (Double)(glucose.glucoseLevelRaw), timeStamp: glucose.timeStamp, sensor: activeSensor, last3Readings: &latest3BgReadings, lastCalibrationsForActiveSensorInLastXDays: &lastCalibrationsForActiveSensorInLastXDays, firstCalibration: firstCalibrationForActiveSensor, lastCalibration: lastCalibrationForActiveSensor, deviceName: getCGMTransmitterDeviceName(for: cgmTransmitter), nsManagedObjectContext: coreDataManager.mainManagedObjectContext)
// save the newly created bgreading permenantly in coredata
coreDataManager.saveChanges()
@ -530,29 +540,11 @@ final class RootViewController: UIViewController {
switch keyPathEnum {
// for these three settings, a forgetdevice can be done and reinitialize cgmTransmitter. In case of switching from master to follower, initializeCGMTransmitter will not initialize a cgmTransmitter, so it's ok to call that function
case UserDefaults.Key.transmitterTypeAsString, UserDefaults.Key.transmitterId, UserDefaults.Key.isMaster :
// transmittertype change triggered by user, should not be done within 200 ms
if (keyValueObserverTimeKeeper.verifyKey(forKey: keyPathEnum.rawValue, withMinimumDelayMilliSeconds: 200)) {
// there's no need to stop the sensor here, maybe the user is just switching from xdrip a to xdrip b
// except if moving to follower
if !UserDefaults.standard.isMaster {
stopSensor()
}
// forget current device
forgetDevice()
// set up na transmitter
initializeCGMTransmitter()
}
case UserDefaults.Key.transmitterResetRequired :
if (keyValueObserverTimeKeeper.verifyKey(forKey: keyPathEnum.rawValue, withMinimumDelayMilliSeconds: 200)) {
cgmTransmitter?.reset(requested: UserDefaults.standard.transmitterResetRequired)
case UserDefaults.Key.isMaster :
// if switching to follower mode, then stop the sensor
if !UserDefaults.standard.isMaster {
stopSensor()
}
case UserDefaults.Key.webOOPEnabled:
@ -567,8 +559,8 @@ final class RootViewController: UIViewController {
// reinitialize calibrator
// calling initializeCGMTransmitter is not a good idea here because that would mean set cgmTransmitter to nil, for some type of transmitters that would mean the user needs to scan again
if let selectedTransmitterType = UserDefaults.standard.transmitterType {
calibrator = RootViewController.getCalibrator(transmitterType: selectedTransmitterType, webOOPEnabled: UserDefaults.standard.webOOPEnabled)
if let cgmTransmitter = cgmTransmitter {
calibrator = RootViewController.getCalibrator(transmitterType: cgmTransmitter.cgmTransmitterType(), webOOPEnabled: UserDefaults.standard.webOOPEnabled)
}
}
@ -604,7 +596,7 @@ final class RootViewController: UIViewController {
// set texts for buttons on top
calibrateButtonOutlet.setTitle(Texts_HomeView.calibrationButton, for: .normal)
preSnoozeButtonOutlet.setTitle(Texts_HomeView.snoozeButton, for: .normal)
transmitterButtonOutlet.setTitle(Texts_HomeView.transmitter, for: .normal)
sensorButtonOutlet.setTitle(Texts_HomeView.sensor, for: .normal)
chartLongPressGestureRecognizerOutlet.delegate = self
chartPanGestureRecognizerOutlet.delegate = self
@ -662,10 +654,10 @@ final class RootViewController: UIViewController {
private func requestCalibration(userRequested:Bool) {
// check that calibrationsAccessor is not nil
guard let calibrationsAccessor = calibrationsAccessor else {
fatalError("in requestCalibration, calibrationsAccessor is nil")
guard let calibrationsAccessor = calibrationsAccessor, let cgmTransmitter = cgmTransmitter, let bluetoothTransmitter = cgmTransmitter as? BluetoothTransmitter else {
fatalError("in requestCalibration, calibrationsAccessor or cgmTransmitter is nil")
}
// check if sensor active and if not don't continue
guard let activeSensor = activeSensor else {
@ -713,12 +705,12 @@ final class RootViewController: UIViewController {
if let calibrator = self.calibrator {
if latestCalibrations.count == 0 {
// calling initialCalibration will create two calibrations, they are returned also but we don't need them
_ = calibrator.initialCalibration(firstCalibrationBgValue: valueAsDoubleConvertedToMgDl, firstCalibrationTimeStamp: Date(timeInterval: -(5*60), since: Date()), secondCalibrationBgValue: valueAsDoubleConvertedToMgDl, sensor: activeSensor, lastBgReadingsWithCalculatedValue0AndForSensor: &latestReadings, deviceName: UserDefaults.standard.cgmTransmitterDeviceName, nsManagedObjectContext: coreDataManager.mainManagedObjectContext)
_ = calibrator.initialCalibration(firstCalibrationBgValue: valueAsDoubleConvertedToMgDl, firstCalibrationTimeStamp: Date(timeInterval: -(5*60), since: Date()), secondCalibrationBgValue: valueAsDoubleConvertedToMgDl, sensor: activeSensor, lastBgReadingsWithCalculatedValue0AndForSensor: &latestReadings, deviceName: self.getCGMTransmitterDeviceName(for: cgmTransmitter), nsManagedObjectContext: coreDataManager.mainManagedObjectContext)
} else {
// it's not the first calibration
if let firstCalibrationForActiveSensor = calibrationsAccessor.firstCalibrationForActiveSensor(withActivesensor: activeSensor) {
// calling createNewCalibration will create a new calibrations, it is returned but we don't need it
_ = calibrator.createNewCalibration(bgValue: valueAsDoubleConvertedToMgDl, lastBgReading: latestReadings[0], sensor: activeSensor, lastCalibrationsForActiveSensorInLastXDays: &latestCalibrations, firstCalibration: firstCalibrationForActiveSensor, deviceName: UserDefaults.standard.cgmTransmitterDeviceName, nsManagedObjectContext: coreDataManager.mainManagedObjectContext)
_ = calibrator.createNewCalibration(bgValue: valueAsDoubleConvertedToMgDl, lastBgReading: latestReadings[0], sensor: activeSensor, lastCalibrationsForActiveSensorInLastXDays: &latestCalibrations, firstCalibration: firstCalibrationForActiveSensor, deviceName: bluetoothTransmitter.deviceName, nsManagedObjectContext: coreDataManager.mainManagedObjectContext)
}
}
@ -756,77 +748,6 @@ final class RootViewController: UIViewController {
self.present(alert, animated: true)
}
/// will set first cgmTransmitter to nil, reads transmittertype from userdefaults, if applicable also transmitterid and if available creates the property cgmTransmitter - if follower mode then cgmTransmitter is set to nil
///
/// depending on transmitter type, scanning will automatically start as soon as cgmTransmitter is created
private func initializeCGMTransmitter() {
// setting cgmTransmitter to nil, if currently cgmTransmitter is not nil, by assign to nil the deinit function of the currently used cgmTransmitter will be called, which will deconnect the device
// setting to nil is also done in other places, doing it again just to be 100% sure
cgmTransmitter = nil
// if transmitter type is set and device is master
if let selectedTransmitterType = UserDefaults.standard.transmitterType, UserDefaults.standard.isMaster {
// first create transmitter
switch selectedTransmitterType {
case .dexcomG4:
if let currentTransmitterId = UserDefaults.standard.transmitterId {
cgmTransmitter = CGMG4xDripTransmitter(address: UserDefaults.standard.cgmTransmitterDeviceAddress, name: UserDefaults.standard.cgmTransmitterDeviceName, transmitterID: currentTransmitterId)
}
case .dexcomG5:
if let currentTransmitterId = UserDefaults.standard.transmitterId {
cgmTransmitter = CGMG5Transmitter(address: UserDefaults.standard.cgmTransmitterDeviceAddress, name: UserDefaults.standard.cgmTransmitterDeviceName, transmitterID: currentTransmitterId, bluetoothTransmitterDelegate: self, cGMTransmitterDelegate: self)
}
case .dexcomG6:
if let currentTransmitterId = UserDefaults.standard.transmitterId {
cgmTransmitter = CGMG6Transmitter(address: UserDefaults.standard.cgmTransmitterDeviceAddress, name: UserDefaults.standard.cgmTransmitterDeviceName, transmitterID: currentTransmitterId, bluetoothTransmitterDelegate: self, cGMTransmitterDelegate: self)
}
case .miaomiao:
cgmTransmitter = CGMMiaoMiaoTransmitter(address: UserDefaults.standard.cgmTransmitterDeviceAddress, name: UserDefaults.standard.cgmTransmitterDeviceName, bluetoothTransmitterDelegate: <#BluetoothTransmitterDelegate#>, timeStampLastBgReading: Date(timeIntervalSince1970: 0), webOOPEnabled: UserDefaults.standard.webOOPEnabled, oopWebSite: UserDefaults.standard.webOOPSite ?? ConstantsLibreOOP.site, oopWebToken: UserDefaults.standard.webOOPtoken ?? ConstantsLibreOOP.token)
case .Bubble:
cgmTransmitter = CGMBubbleTransmitter(address: UserDefaults.standard.cgmTransmitterDeviceAddress, name: UserDefaults.standard.cgmTransmitterDeviceName, bluetoothTransmitterDelegate: <#BluetoothTransmitterDelegate#>, timeStampLastBgReading: Date(timeIntervalSince1970: 0), sensorSerialNumber: UserDefaults.standard.sensorSerialNumber, webOOPEnabled: UserDefaults.standard.webOOPEnabled, oopWebSite: UserDefaults.standard.webOOPSite ?? ConstantsLibreOOP.site, oopWebToken: UserDefaults.standard.webOOPtoken ?? ConstantsLibreOOP.token)
case .GNSentry:
cgmTransmitter = CGMGNSEntryTransmitter(address: UserDefaults.standard.cgmTransmitterDeviceAddress, name: UserDefaults.standard.cgmTransmitterDeviceName, bluetoothTransmitterDelegate: <#BluetoothTransmitterDelegate#>, timeStampLastBgReading: Date(timeIntervalSince1970: 0))
case .Blucon:
if let currentTransmitterId = UserDefaults.standard.transmitterId {
cgmTransmitter = CGMBluconTransmitter(address: UserDefaults.standard.cgmTransmitterDeviceAddress, name: UserDefaults.standard.cgmTransmitterDeviceName, transmitterID: currentTransmitterId, bluetoothTransmitterDelegate: <#BluetoothTransmitterDelegate#>, timeStampLastBgReading: Date(timeIntervalSince1970: 0), sensorSerialNumber: UserDefaults.standard.sensorSerialNumber)
}
case .Droplet1:
cgmTransmitter = CGMDroplet1Transmitter(address: UserDefaults.standard.cgmTransmitterDeviceAddress, name: UserDefaults.standard.cgmTransmitterDeviceName)
case .blueReader:
cgmTransmitter = CGMBlueReaderTransmitter(address: UserDefaults.standard.cgmTransmitterDeviceAddress, name: UserDefaults.standard.cgmTransmitterDeviceName, delegate: self)
case .watlaa:
// watlaa transmitter needs to be set through bluetooth devices tab
cgmTransmitter = nil
}
// assign calibrator
switch selectedTransmitterType {
case .dexcomG4, .dexcomG5, .dexcomG6:
calibrator = DexcomCalibrator()
case .miaomiao, .GNSentry, .Blucon, .Bubble, .Droplet1, .blueReader, .watlaa:
// for all transmitters used with Libre1, calibrator is either NoCalibrator or Libre1Calibrator, depending if oopWeb is supported by the transmitter and on value of webOOPEnabled in settings
calibrator = RootViewController.getCalibrator(transmitterType: selectedTransmitterType, webOOPEnabled: UserDefaults.standard.webOOPEnabled)
}
}
//reset UserDefaults.standard.transmitterResetRequired to false, might have been set to true.
UserDefaults.standard.transmitterResetRequired = false
}
/// if transmitterType.canWebOOP and UserDefaults.standard.webOOPEnabled then returns an instance of NoCalibrator otherwise returns an instance of Libre1Calibrator
///
/// this is just some functionality which is used frequently
@ -1087,33 +1008,17 @@ final class RootViewController: UIViewController {
}
/// when user clicks transmitter button, this will create and present the actionsheet, contents depend on type of transmitter and sensor status
private func createAndPresentTransmitterButtonActionSheet() {
private func createAndPresentSensorButtonActionSheet() {
// initialize list of actions
var listOfActions = [String : ((UIAlertAction) -> Void)]()
// first action is to show the status
listOfActions[Texts_HomeView.statusActionTitle] = {(UIAlertAction) in self.showStatus()}
// next action is scan device or forget device, can also be omitted depending on type of device
if cgmTransmitter != nil {
// cgmTransmitter is setup, means user has set transmittertype and transmitter id
// transmitterType should be not nil but we need to unwrap anyway
if let transmitterType = UserDefaults.standard.transmitterType {
if !transmitterType.startScanningAfterInit() {
// it's a transmitter for which user needs to initiate the scanning
// see if bluetoothDeviceAddress is known, results determines next action to add
if UserDefaults.standard.cgmTransmitterDeviceAddress == nil {
listOfActions[Texts_HomeView.scanBluetoothDeviceActionTitle] = {(UIAlertAction) in self.userInitiatesStartScanning()}
} else {
listOfActions[Texts_HomeView.forgetBluetoothDeviceActionTitle] = {(UIAlertAction) in self.forgetDevice()}
}
}
}
}
// next action is to start or stop the sensor, can also be omitted depending on type of device - also not applicable for follower mode
if let transmitterType = UserDefaults.standard.transmitterType {
if transmitterType.allowManualSensorStart() && UserDefaults.standard.isMaster {
if let cgmTransmitter = cgmTransmitter {
if cgmTransmitter.cgmTransmitterType().allowManualSensorStart() && UserDefaults.standard.isMaster {
// user needs to start and stop the sensor manually
if activeSensor != nil {
listOfActions[Texts_HomeView.stopSensorActionTitle] = {(UIAlertAction) in self.stopSensor()}
@ -1151,31 +1056,6 @@ final class RootViewController: UIViewController {
// add 2 newlines
textToShow += "\r\n\r\n"
// add transmitter info
// first the name
textToShow += Texts_HomeView.transmitter + " : "
if let deviceName = UserDefaults.standard.cgmTransmitterDeviceName {
textToShow += deviceName
} else {
textToShow += Texts_HomeView.notKnown
}
// add 1 newline with last connection timestamp
textToShow += "\r\n\r\n"
// check if connected, if not add last connection timestamp
if let connectionStatus = cgmTransmitter?.getConnectionStatus(), connectionStatus == CBPeripheralState.connected {
textToShow += Texts_HomeView.connected + "\r\n\r\n"
} else {
if let lastDisconnectTimestamp = UserDefaults.standard.lastdisConnectTimestamp {
textToShow += Texts_HomeView.lastConnection + " : " + lastDisconnectTimestamp.description(with: .current)
// add 1 newline with last connection timestamp
textToShow += "\r\n\r\n"
} else {
textToShow += Texts_HomeView.neverConnected + "\r\n\r\n"
}
}
// add transmitterBatteryInfo if known
if let transmitterBatteryInfo = UserDefaults.standard.transmitterBatteryInfo {
textToShow += Texts_HomeView.transmitterBatteryLevel + " : " + transmitterBatteryInfo.description
@ -1190,72 +1070,6 @@ final class RootViewController: UIViewController {
}
/// user clicked start scanning action, this function will check if bluetooth is on (?) and if not yet scanning, start the scanning
private func userInitiatesStartScanning() {
// start the scanning, result of the startscanning will be in startScanningResult - this is not the result of the scanning itself. Scanning may have started successfully but maybe the peripheral is not yet connected, maybe it is
if let startScanningResult = cgmTransmitter?.startScanning() {
trace("in userInitiatesStartScanning, startScanningResult = %{public}@", log: log, category: ConstantsLog.categoryRootView, type: .info, startScanningResult.description())
switch startScanningResult {
case .success:
// success : could be useful to display that scanning has started, however in most cases the connection will immediately happen, causing a second pop up to say that the transmitter is connected, let's not create to many pop ups
// we do mark that the user initiated the scanning. If connection is setup, we'll inform the user, see cgmTransmitterDidConnect
userDidInitiateScanning = true
break
case .alreadyConnected, .connecting:
// alreadyConnected : should not happen because that would mean we gave the user the option to start scanning, although there is already a connection
// connecting : same as for alreadyConnected
break
case .alreadyScanning:
// probably user started scanning two times, let's show a pop up that scanning is ongoing
let alert = UIAlertController(title: Texts_HomeView.scanBluetoothDeviceActionTitle, message: Texts_HomeView.scanBluetoothDeviceOngoing, actionHandler: nil)
self.present(alert, animated: true, completion: nil)
case .bluetoothNotPoweredOn( _):
// bluetooth is not on, user should switch it on
let alert = UIAlertController(title: Texts_HomeView.scanBluetoothDeviceActionTitle, message: Texts_HomeView.bluetoothIsNotOn, actionHandler: nil)
self.present(alert, animated: true, completion: nil)
case .other(let reason):
// other unknown error occured
let alert = UIAlertController(title: Texts_HomeView.scanBluetoothDeviceActionTitle, message: "Error while starting scanning. Reason : " + reason, actionHandler: nil)
self.present(alert, animated: true, completion: nil)
}
}
}
/// - cgmTransmitter to nil, this disconnects also the existing transmitter
/// - UserDefaults.standard.transmitterBatteryInfo to nil
/// - UserDefaults.standard.lastdisConnectTimestamp to nil
/// - UserDefaults.standard.bluetoothDeviceAddress to nil
/// - UserDefaults.standard.bluetoothDeviceName to nil
/// -
/// - calls also initializeCGMTransmitter which recreated the cgmTransmitter property, depending on settings
private func forgetDevice() {
// set device address and name to nil in userdefaults
UserDefaults.standard.cgmTransmitterDeviceAddress = nil
UserDefaults.standard.cgmTransmitterDeviceName = nil
// setting cgmTransmitter to nil, the deinit function of the currently used cgmTransmitter will be called, which will disconnect the device
// set cgmTransmitter to nil, this will call the deinit function which will disconnect first
cgmTransmitter = nil
// by calling initializeCGMTransmitter, a new cgmTransmitter will be created, assuming it's not follower mode, and transmittertype is selected and if applicable transmitter id is set
initializeCGMTransmitter()
// reset also UserDefaults.standard.transmitterBatteryInfo
UserDefaults.standard.transmitterBatteryInfo = nil
// set lastdisconnecttimestamp to nil
UserDefaults.standard.lastdisConnectTimestamp = nil
}
// stops the active sensor and sets sensorSerialNumber in UserDefaults to nil
private func stopSensor() {
@ -1323,12 +1137,22 @@ final class RootViewController: UIViewController {
}
}
private func getCGMTransmitterDeviceName(for cgmTransmitter: CGMTransmitter) -> String? {
if let bluetoothTransmitter = cgmTransmitter as? BluetoothTransmitter {
return bluetoothTransmitter.deviceName
}
return nil
}
}
// MARK: - conform to CGMTransmitter protocol
/// conform to CGMTransmitterDelegate
extension RootViewController:CGMTransmitterDelegate {
extension RootViewController: CGMTransmitterDelegate {
func getCGMTransmitter() -> CGMTransmitter? {
return cgmTransmitter
@ -1425,10 +1249,8 @@ extension RootViewController: UITabBarControllerDelegate {
}
// MARK: - conform to UNUserNotificationCenterDelegate protocol
/// conform to UNUserNotificationCenterDelegate, for notifications
extension RootViewController:UNUserNotificationCenterDelegate {
extension RootViewController: UNUserNotificationCenterDelegate {
// called when notification created while app is in foreground
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
@ -1457,10 +1279,8 @@ extension RootViewController:UNUserNotificationCenterDelegate {
// so actually the app was in the foreground, at the moment the Transmitter Class called the cgmTransmitterNeedsPairing function, there's no need to show the notification, we can immediately call back the cgmTransmitter initiatePairing function
completionHandler([])
cgmTransmitter?.initiatePairing()
/// remove applicationManagerKeyInitiatePairing from application key manager - there's no need to initiate the pairing via this closure
ApplicationManager.shared.removeClosureToRunWhenAppWillEnterForeground(key: self.applicationManagerKeyInitiatePairing)
bluetoothPeripheralManager?.initiatePairing()
} else {

View File

@ -1,18 +1,16 @@
import UIKit
fileprivate enum Setting:Int, CaseIterable {
/// transmittertype
case transmitterType = 0
/// transmitterid
case transmitterId = 1
/// is transmitter reset required or not (only applicable to Dexcom G5 and later also G6)
case resetRequired = 2
/// is webOOP enabled or not
case webOOP = 3
case webOOP = 0
/// if webOOP enabled, what site to use
case webOOPsite = 4
case webOOPsite = 1
/// if webOOP enabled, value of the token
case webOOPtoken = 5
case webOOPtoken = 2
}
/// conforms to SettingsViewModelProtocol for all transmitter settings in the first sections screen
@ -24,7 +22,7 @@ struct SettingsViewTransmitterSettingsViewModel:SettingsViewModelProtocol {
func isEnabled(index: Int) -> Bool {
// in follower mode, all transmitter settings can be disabled
if UserDefaults.standard.isMaster {
if UserDefaults.standard.isMaster && UserDefaults.standard.transmitterType?.canWebOOP() ?? false {
return true
} else {
return false
@ -36,60 +34,6 @@ struct SettingsViewTransmitterSettingsViewModel:SettingsViewModelProtocol {
switch setting {
case .transmitterId:
return SettingsSelectedRowAction.askText(title: Texts_SettingsView.labelTransmitterId, message: Texts_SettingsView.labelGiveTransmitterId, keyboardType: UIKeyboardType.alphabet, text: UserDefaults.standard.transmitterId, placeHolder: "00000", actionTitle: nil, cancelTitle: nil, actionHandler: {(transmitterId:String) in
// convert to uppercase
let transmitterIdUpper = transmitterId.uppercased()
// if changed then store new value
if let currentTransmitterId = UserDefaults.standard.transmitterId {
if currentTransmitterId != transmitterIdUpper {
self.setTransmitterIdAndDexcomShareSerialNumber(id: transmitterIdUpper)
}
} else {
self.setTransmitterIdAndDexcomShareSerialNumber(id: transmitterIdUpper)
}
}, cancelHandler: nil, inputValidator: { (transmitterId) in
if transmitterId.count >= 2 {
// convert to upper
let transmitterIdUpper = transmitterId.uppercased()
if transmitterIdUpper.compare("8G") == .orderedAscending {
return nil
} else {
return Texts_SettingsView.transmitterId8OrHigherNotSupported
}
}
// more checks can be added later , like length of transmitter id
return nil
})
case .transmitterType:
var data = [String]()
for transmitterType in CGMTransmitterType.allCases {
data.append(transmitterType.rawValue)
}
//find index for transmitter type currently stored in userdefaults
var selectedRow:Int?
if let transmitterType = UserDefaults.standard.transmitterType?.rawValue {
selectedRow = data.firstIndex(of:transmitterType)
}
return SettingsSelectedRowAction.selectFromList(title: Texts_SettingsView.labelTransmitterId, data: data, selectedRow: selectedRow, actionTitle: nil, cancelTitle: nil, actionHandler: {(index:Int) in
if index != selectedRow {
UserDefaults.standard.transmitterTypeAsString = data[index]
}
}, cancelHandler: nil, didSelectRowHandler: nil)
case .resetRequired:
return SettingsSelectedRowAction.callFunction(function: {UserDefaults.standard.transmitterResetRequired ? (UserDefaults.standard.transmitterResetRequired) = false : (UserDefaults.standard.transmitterResetRequired = true)})
case .webOOP:
return SettingsSelectedRowAction.nothing
@ -112,37 +56,9 @@ struct SettingsViewTransmitterSettingsViewModel:SettingsViewModelProtocol {
// follower mode, no need to show all settings
return 1
}
return Setting.allCases.count
if let transmitterType = UserDefaults.standard.transmitterType {
// if transmitter doesn't need transmitterid (like MiaoMiao) then the settings row that asks for transmitterid doesn't need to be shown. That row is the second row - also reset transmitter not necessary in that case
// if ever there would be a transmitter that doesn't need a transmitter id but that supports reset transmitter, then some recoding will be necessary here
var count = 0
if transmitterType.needsTransmitterId() {
if transmitterType.resetPossible() {
count = 3
} else {
count = 2
}
} else {
count = 1
}
// for now WebOOP is only for transmitters that don't need transmitterId and no reset possible.
// So for those transmitters, if canWebOOP and if enabled, then amount of rows = 4 (enable weboop, weboop site and weboop token. If webOOP not enabled, then only show setting to enabled weboop
// Needs adaptation in case we would enable webOOP for transmitters with transmitterId, like Blucon
if transmitterType.canWebOOP() {
if UserDefaults.standard.webOOPEnabled {
count = 4
} else {
count = 2
}
}
return count
} else {
// transmitterType nil, means this is initial setup, no need to show transmitter id field
return 1
}
}
func settingsRowText(index: Int) -> String {
@ -150,15 +66,6 @@ struct SettingsViewTransmitterSettingsViewModel:SettingsViewModelProtocol {
switch (setting) {
case .transmitterId:
return Texts_SettingsView.labelTransmitterId
case .transmitterType:
return Texts_SettingsView.labelTransmitterType
case .resetRequired:
return Texts_SettingsView.labelResetTransmitter
case .webOOP:
return Texts_SettingsView.labelWebOOPTransmitter
@ -175,12 +82,6 @@ struct SettingsViewTransmitterSettingsViewModel:SettingsViewModelProtocol {
switch setting {
case .transmitterType:
return UITableViewCell.AccessoryType.disclosureIndicator
case .transmitterId:
return UITableViewCell.AccessoryType.disclosureIndicator
case .resetRequired:
return UITableViewCell.AccessoryType.none
case .webOOP:
return UITableViewCell.AccessoryType.none
case .webOOPsite:
@ -196,12 +97,6 @@ struct SettingsViewTransmitterSettingsViewModel:SettingsViewModelProtocol {
switch (setting) {
case .transmitterId:
return UserDefaults.standard.transmitterId
case .transmitterType:
return UserDefaults.standard.transmitterType?.rawValue
case .resetRequired:
return UserDefaults.standard.transmitterResetRequired ? Texts_Common.yes:Texts_Common.no
case .webOOP:
return nil
case .webOOPsite:
@ -247,33 +142,4 @@ struct SettingsViewTransmitterSettingsViewModel:SettingsViewModelProtocol {
return index
}
/// sets UserDefaults.standard.transmitterId with valud of id
///
/// if transmitterType is G5 or G6, then sets UserDefaults.standard.dexcomShareSerialNumber = UserDefaults.standard.transmitterId - otherwise dexcomShareSerialNumber is not changed
///
/// - parameters:
/// - id : new value for transmitterId and possibly also dexcomShareSerialNumber. If length is 0, then transmitterId gets value nil (and possibly also dexcomShareSerialNumber)
private func setTransmitterIdAndDexcomShareSerialNumber(id:String) {
// if length of id 0 , then set transmitterId to nil
if id.count == 0 {
UserDefaults.standard.transmitterId = nil
} else {
UserDefaults.standard.transmitterId = id
}
if let transmitterType = UserDefaults.standard.transmitterType {
switch transmitterType {
case .dexcomG5, .dexcomG6:
UserDefaults.standard.dexcomShareSerialNumber = UserDefaults.standard.transmitterId
default:
break
}
}
}
}