renamed M5StackManaging to BluetoothPeripheralManaging and M5StackManager to BluetoothPeripheralManager

This commit is contained in:
Johan Degraeve 2019-11-26 21:47:58 +01:00
parent 5653de5161
commit cd8850b2d2
9 changed files with 90 additions and 90 deletions

View File

@ -55,6 +55,8 @@
F821CF9522ADB0D7005C1E43 /* HealthKitManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF9422ADB0D7005C1E43 /* HealthKitManager.swift */; };
F821CF9722AE589E005C1E43 /* HealthKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F821CF9622AE589E005C1E43 /* HealthKit.framework */; };
F821CF9D22AEF483005C1E43 /* BGReadingSpeaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F821CF9C22AEF483005C1E43 /* BGReadingSpeaker.swift */; };
F8297F45238DC4AC00D74D66 /* BluetoothPerpheralManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8297F43238DC4AC00D74D66 /* BluetoothPerpheralManager.swift */; };
F8297F46238DC4AC00D74D66 /* BluetoothPeripheralManaging.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8297F44238DC4AC00D74D66 /* BluetoothPeripheralManaging.swift */; };
F856CE5B22EDC8E50083E436 /* ConstantsBluetoothPairing.swift in Sources */ = {isa = PBXBuildFile; fileRef = F856CE5A22EDC8E50083E436 /* ConstantsBluetoothPairing.swift */; };
F85C4A9A2336CE8E00D6A86F /* M5StacksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F85C4A992336CE8E00D6A86F /* M5StacksViewController.swift */; };
F85C4A9D2336D05100D6A86F /* M5StackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F85C4A9C2336D05100D6A86F /* M5StackViewController.swift */; };
@ -234,8 +236,6 @@
F8EEDD5422FF685400D2D610 /* NSMutableURLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8EEDD5322FF685400D2D610 /* NSMutableURLRequest.swift */; };
F8EEDD552300136F00D2D610 /* DexcomShareTestResult.strings in Resources */ = {isa = PBXBuildFile; fileRef = F8EEDD572300136F00D2D610 /* DexcomShareTestResult.strings */; };
F8EEDD6423020FAD00D2D610 /* NoCalibrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8EEDD6323020FAD00D2D610 /* NoCalibrator.swift */; };
F8F6226C233A85CE00BE8796 /* M5StackManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8F6226B233A85CE00BE8796 /* M5StackManager.swift */; };
F8F6226E233A86EA00BE8796 /* M5StackManaging.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8F6226D233A86EA00BE8796 /* M5StackManaging.swift */; };
F8F62270233AA3B200BE8796 /* M5StackAccessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8F6226F233AA3B200BE8796 /* M5StackAccessor.swift */; };
F8F62276233D1CE600BE8796 /* TextsM5StacksView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8F62275233D1CE600BE8796 /* TextsM5StacksView.swift */; };
F8F62278233D1CED00BE8796 /* TextsM5StackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8F62277233D1CED00BE8796 /* TextsM5StackView.swift */; };
@ -295,6 +295,8 @@
F821CF9822AE589E005C1E43 /* xdrip.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = xdrip.entitlements; sourceTree = "<group>"; };
F821CF9C22AEF483005C1E43 /* BGReadingSpeaker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BGReadingSpeaker.swift; sourceTree = "<group>"; };
F8297F41238C3A6400D74D66 /* xdrip v5.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "xdrip v5.xcdatamodel"; sourceTree = "<group>"; };
F8297F43238DC4AC00D74D66 /* BluetoothPerpheralManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BluetoothPerpheralManager.swift; sourceTree = "<group>"; };
F8297F44238DC4AC00D74D66 /* BluetoothPeripheralManaging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BluetoothPeripheralManaging.swift; sourceTree = "<group>"; };
F846CDD523046BAC00DCF016 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/SettingsViews.strings"; sourceTree = "<group>"; };
F846CDD623046BAE00DCF016 /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/SettingsViews.strings; sourceTree = "<group>"; };
F856CE5A22EDC8E50083E436 /* ConstantsBluetoothPairing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsBluetoothPairing.swift; sourceTree = "<group>"; };
@ -655,8 +657,6 @@
F8EEDD612300139800D2D610 /* zh */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = zh; path = zh.lproj/DexcomShareTestResult.strings; sourceTree = "<group>"; };
F8EEDD622300139A00D2D610 /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/DexcomShareTestResult.strings; sourceTree = "<group>"; };
F8EEDD6323020FAD00D2D610 /* NoCalibrator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoCalibrator.swift; sourceTree = "<group>"; };
F8F6226B233A85CE00BE8796 /* M5StackManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = M5StackManager.swift; sourceTree = "<group>"; };
F8F6226D233A86EA00BE8796 /* M5StackManaging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = M5StackManaging.swift; sourceTree = "<group>"; };
F8F6226F233AA3B200BE8796 /* M5StackAccessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = M5StackAccessor.swift; sourceTree = "<group>"; };
F8F62275233D1CE600BE8796 /* TextsM5StacksView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextsM5StacksView.swift; sourceTree = "<group>"; };
F8F62277233D1CED00BE8796 /* TextsM5StackView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextsM5StackView.swift; sourceTree = "<group>"; };
@ -866,6 +866,15 @@
path = Speak;
sourceTree = "<group>";
};
F8297F42238DC4AC00D74D66 /* BluetoothPeripheral */ = {
isa = PBXGroup;
children = (
F8297F43238DC4AC00D74D66 /* BluetoothPerpheralManager.swift */,
F8297F44238DC4AC00D74D66 /* BluetoothPeripheralManaging.swift */,
);
path = BluetoothPeripheral;
sourceTree = "<group>";
};
F85C4A982336CE0400D6A86F /* M5StacksViewController */ = {
isa = PBXGroup;
children = (
@ -893,8 +902,8 @@
F85DC2F621D25E3A00B9F74A /* Managers */ = {
isa = PBXGroup;
children = (
F8297F42238DC4AC00D74D66 /* BluetoothPeripheral */,
F8BECB03235CE5970060DAE1 /* Charts */,
F8F6226A233A85A700BE8796 /* M5Stack */,
F81D6D4622BD5F43005EFAE2 /* DexcomShare */,
F821CF9922AEF2DF005C1E43 /* Speak */,
F821CF9122ADB064005C1E43 /* HealthKit */,
@ -1473,15 +1482,6 @@
path = Calibration;
sourceTree = "<group>";
};
F8F6226A233A85A700BE8796 /* M5Stack */ = {
isa = PBXGroup;
children = (
F8F6226B233A85CE00BE8796 /* M5StackManager.swift */,
F8F6226D233A86EA00BE8796 /* M5StackManaging.swift */,
);
path = M5Stack;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -1715,6 +1715,7 @@
F80859292364D61B00F3829D /* UserDefaults+charts.swift in Sources */,
F8A389C3231F1A4B0010F405 /* M5StackReadBlePassWordTxMessage.swift in Sources */,
F8B3A7B2226A0878004BA588 /* TextsAlerts.swift in Sources */,
F8297F46238DC4AC00D74D66 /* BluetoothPeripheralManaging.swift in Sources */,
F8A54B0022D9179100934E7A /* LibreDataParser.swift in Sources */,
F8025E5421EE8D2100ECF0C0 /* Libre1Calibrator.swift in Sources */,
F81FA00A228F53680028C70F /* TextsHomeView.swift in Sources */,
@ -1752,6 +1753,7 @@
F8A1587322EDC893007F5B5D /* ConstantsDexcomShare.swift in Sources */,
F8A1586F22EDC7EE007F5B5D /* ConstantsSuspensionPrevention.swift in Sources */,
F8A54AB822D9111900934E7A /* TransmitterBatteryInfo.swift in Sources */,
F8297F45238DC4AC00D74D66 /* BluetoothPerpheralManager.swift in Sources */,
F8B3A82D227F07D6004BA588 /* SettingsNavigationController.swift in Sources */,
F8A54AB722D9111900934E7A /* CGMTransmitter.swift in Sources */,
F80ED2EC236F68F90005C035 /* SettingsViewM5StackBluetoothSettingsViewModel.swift in Sources */,
@ -1818,7 +1820,6 @@
F8B3A79522635A25004BA588 /* AlertType+CoreDataProperties.swift in Sources */,
F8A389BC231713580010F405 /* M5StackTransmitterOpCode.swift in Sources */,
F8B3A84C227F090E004BA588 /* SettingsViewController.swift in Sources */,
F8F6226E233A86EA00BE8796 /* M5StackManaging.swift in Sources */,
F8EEDD5222FECE3800D2D610 /* ConstantsLibreOOP.swift in Sources */,
F8AC426021ADEBD60078C348 /* RootViewController.swift in Sources */,
F8B3A78B225D473D004BA588 /* UIAlertController.swift in Sources */,
@ -1831,7 +1832,6 @@
F8B3A7DF226E48C1004BA588 /* SoundPlayer.swift in Sources */,
F8B3A820227DEC92004BA588 /* AlertTypesAccessor.swift in Sources */,
F8B3A81E227DEC92004BA588 /* BgReadingsAccessor.swift in Sources */,
F8F6226C233A85CE00BE8796 /* M5StackManager.swift in Sources */,
F8A389C6231FBA110010F405 /* M5StackPacket.swift in Sources */,
F8B3A846227F090E004BA588 /* SettingsViewTransmitterSettingsViewModel.swift in Sources */,
F80ED2F32379C6CD0005C035 /* M5StackBluetoothDelegate.swift in Sources */,

View File

@ -91,8 +91,8 @@ enum ConstantsLog {
/// for use in M5Stack
static let categoryM5StackBluetoothTransmitter = "categoryM5StackBluetoothTransmitter"
/// M5Stack manager logging
static let categoryM5StackManager = "categoryM5StackManager"
/// BluetoothPeripheralManager logging
static let categoryBluetoothPeripheralManager = "categoryBluetoothPeripheralManager"
/// StatusChartsManager logging
static let categoryGlucoseChartManager = "categoryGlucoseChartManager"

View File

@ -1,7 +1,7 @@
import Foundation
/// used by M5Stack UI view controllers - it's the glue between M5StackManager and UIViewControllers - defines functions to scan for devices, connect/disconnect, delete an M5 stack, change the username, etc.
protocol M5StackManaging: AnyObject {
/// used by M5Stack UI view controllers - it's the glue between BluetoothPeripheralManager and UIViewControllers - defines functions to scan for devices, connect/disconnect, delete an M5 stack, change the username, etc.
protocol BluetoothPeripheralManaging: AnyObject {
/// to scan for a new M5SStack - callback will be called when a new M5Stack is found and connected
func startScanningForNewDevice(callback: @escaping (M5Stack) -> Void)
@ -21,7 +21,7 @@ protocol M5StackManaging: AnyObject {
/// deletes the M5Stack in coredata, and also the corresponding M5StackBluetoothTransmitter if there is one will be deleted
func deleteM5Stack(m5Stack: M5Stack)
/// - returns: the M5Stack's managed by this M5StackManager
/// - returns: the M5Stack's managed by this BluetoothPeripheralManager
func m5Stacks() -> [M5Stack]
/// sets flag m5StacksParameterUpdateNeeded for m5Stack to true

View File

@ -2,7 +2,7 @@ import Foundation
import os
import CoreBluetooth
class M5StackManager: NSObject {
class BluetoothPeripheralManager: NSObject {
// MARK: - private properties
@ -10,7 +10,7 @@ class M5StackManager: NSObject {
private let coreDataManager:CoreDataManager
/// for logging
private var log = OSLog(subsystem: ConstantsLog.subSystem, category: ConstantsLog.categoryM5StackManager)
private var log = OSLog(subsystem: ConstantsLog.subSystem, category: ConstantsLog.categoryBluetoothPeripheralManager)
/// dictionary with key = an instance of M5Stack, and value an instance of M5StackBluetoothTransmitter. Value can be nil in which case we found an M5Stack in the coredata but shouldconnect == false so we don't instanstiate an M5StackBluetoothTransmitter
private var m5StacksBlueToothTransmitters = [M5Stack : M5StackBluetoothTransmitter?]()
@ -282,9 +282,9 @@ class M5StackManager: NSObject {
// MARK: - extensions
// MARK: extension M5StackManaging
// MARK: extension BluetoothPeripheralManaging
extension M5StackManager: M5StackManaging {
extension BluetoothPeripheralManager: BluetoothPeripheralManaging {
/// to scan for a new M5SStack - callback will be called when a new M5Stack is found and connected
func startScanningForNewDevice(callback: @escaping (M5Stack) -> Void) {
@ -376,7 +376,7 @@ extension M5StackManager: M5StackManaging {
}
/// - returns: the M5Stack's managed by this M5StackManager
/// - returns: the M5Stack's managed by this BluetoothPeripheralManager
func m5Stacks() -> [M5Stack] {
return Array(m5StacksBlueToothTransmitters.keys)
}
@ -396,7 +396,7 @@ extension M5StackManager: M5StackManaging {
// MARK: extensions M5StackBluetoothDelegate
extension M5StackManager: M5StackBluetoothDelegate {
extension BluetoothPeripheralManager: M5StackBluetoothDelegate {
/// m5Stack is asking for an update of all parameters, send them
func isAskingForAllParameters(m5Stack: M5Stack) {
@ -411,7 +411,7 @@ extension M5StackManager: M5StackBluetoothDelegate {
}
/// will be called if M5Stack is connected, and authentication was successful, M5StackManager can start sending data like parameter updates or bgreadings
/// will be called if M5Stack is connected, and authentication was successful, BluetoothPeripheralManager can start sending data like parameter updates or bgreadings
func isReadyToReceiveData(m5Stack : M5Stack) {
// if the M5Stack needs new parameters, then send them

View File

@ -11,7 +11,7 @@ final class M5StackBluetoothTransmitter: BluetoothTransmitter, BluetoothTransmit
/// will be used to pass data back
///
/// there's two delegates, one public, one private. The private one will be assigned during object creation. There's two because two other classes want to receive feedback : M5StackManager and UIViewControllers. There's only one instance of M5StackManager and it's always the same. An instance will be assigned to m5StackBluetoothTransmitterDelegateFixed. There can be different UIViewController' and they can change, an instance will be assigned to m5StackBluetoothTransmitterDelegateVariable
/// there's two delegates, one public, one private. The private one will be assigned during object creation. There's two because two other classes want to receive feedback : BluetoothPeripheralManager and UIViewControllers. There's only one instance of BluetoothPeripheralManager and it's always the same. An instance will be assigned to m5StackBluetoothTransmitterDelegateFixed. There can be different UIViewController' and they can change, an instance will be assigned to m5StackBluetoothTransmitterDelegateVariable
public weak var m5StackBluetoothTransmitterDelegateVariable: M5StackBluetoothDelegate?
// MARK: - private properties
@ -36,7 +36,7 @@ final class M5StackBluetoothTransmitter: BluetoothTransmitter, BluetoothTransmit
/// will be used to pass data back
///
/// there's two delegates, one public, one private. The private one will be assigned during object creation. There's two because two other classes want to receive feedback : M5StackManager and UIViewControllers. There's only one instance of M5StackManager and it's always the same. An instance will be assigned to m5StackBluetoothTransmitterDelegateFixed. There can be different UIViewController' and they can change, an instance will be assigned to m5StackBluetoothTransmitterDelegateVariable
/// there's two delegates, one public, one private. The private one will be assigned during object creation. There's two because two other classes want to receive feedback : BluetoothPeripheralManager and UIViewControllers. There's only one instance of BluetoothPeripheralManager and it's always the same. An instance will be assigned to m5StackBluetoothTransmitterDelegateFixed. There can be different UIViewController' and they can change, an instance will be assigned to m5StackBluetoothTransmitterDelegateVariable
private weak var m5StackBluetoothTransmitterDelegateFixed:M5StackBluetoothDelegate!
/// is the transmitter ready to receive data like parameter updates or reading values
@ -49,7 +49,7 @@ final class M5StackBluetoothTransmitter: BluetoothTransmitter, BluetoothTransmit
/// - parameters:
/// - m5Stack : an instance of M5Stack, if nil then this instance is created to scan for a new M5Stack, address and name not yet known, so not possible yet to create an M5Stack instance
/// - delegateFixed : there's two delegates, one public, one private. The private one will be assigned during object creation. There's two because two other classes want to receive feedback : M5StackManager and UIViewControllers. There's only one instance of M5StackManager and it's always the same. An instance will be assigned to m5StackBluetoothTransmitterDelegateFixed. There can be different UIViewController' and they can change, an instance will be assigned to m5StackBluetoothTransmitterDelegateVariable
/// - delegateFixed : there's two delegates, one public, one private. The private one will be assigned during object creation. There's two because two other classes want to receive feedback : BluetoothPeripheralManager and UIViewControllers. There's only one instance of BluetoothPeripheralManager and it's always the same. An instance will be assigned to m5StackBluetoothTransmitterDelegateFixed. There can be different UIViewController' and they can change, an instance will be assigned to m5StackBluetoothTransmitterDelegateVariable
/// - blePassword : optional. If nil then xdrip will send a M5StackReadBlePassWordTxMessage to the M5Stack, so this would be a case where the M5Stack (all M5Stacks managed by xdrip) do not have a fixed blepassword
/// The blepassword in the M5Stack object gets priority over the blePassword in the parameter list
init(m5Stack: M5Stack?, delegateFixed: M5StackBluetoothDelegate, blePassword: String?) {

View File

@ -7,17 +7,17 @@ final class M5StackNavigationController: UINavigationController {
/// reference to coreDataManager
private var coreDataManager:CoreDataManager?
/// an m5stackManager
private weak var m5StackManager: M5StackManaging?
/// a bluetoothPeripheralManager
private weak var bluetoothPeripheralManager: BluetoothPeripheralManaging?
// MARK:- public functions
/// configure
public func configure(coreDataManager: CoreDataManager, m5StackManager: M5StackManaging) {
public func configure(coreDataManager: CoreDataManager, bluetoothPeripheralManager: BluetoothPeripheralManaging) {
// initalize private properties
self.coreDataManager = coreDataManager
self.m5StackManager = m5StackManager
self.bluetoothPeripheralManager = bluetoothPeripheralManager
}
@ -34,8 +34,8 @@ final class M5StackNavigationController: UINavigationController {
extension M5StackNavigationController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
if let m5StacksViewController = viewController as? M5StacksViewController, let coreDataManager = coreDataManager, let m5StackManager = m5StackManager {
m5StacksViewController.configure(coreDataManager: coreDataManager, m5StackManager: m5StackManager)
if let m5StacksViewController = viewController as? M5StacksViewController, let coreDataManager = coreDataManager, let bluetoothPeripheralManager = bluetoothPeripheralManager {
m5StacksViewController.configure(coreDataManager: coreDataManager, bluetoothPeripheralManager: bluetoothPeripheralManager)
}
}
}

View File

@ -92,8 +92,8 @@ final class M5StackViewController: UIViewController {
/// reference to coreDataManager
private var coreDataManager:CoreDataManager?
/// an m5stackManager
private weak var m5StackManager: M5StackManaging?
/// a BluetoothPeripheralManager
private weak var bluetoothPeripheralManager: BluetoothPeripheralManaging?
/// name given by user as alias , to easier recognize different M5Stacks
///
@ -132,17 +132,17 @@ final class M5StackViewController: UIViewController {
// MARK:- public functions
/// configure the viewController
public func configure(m5Stack: M5Stack?, coreDataManager: CoreDataManager, m5StackManager: M5StackManaging) {
public func configure(m5Stack: M5Stack?, coreDataManager: CoreDataManager, bluetoothPeripheralManager: BluetoothPeripheralManaging) {
self.m5StackAsNSObject = m5Stack
self.coreDataManager = coreDataManager
self.m5StackNameAccessor = M5StackNameAccessor(coreDataManager: coreDataManager)
self.m5StackManager = m5StackManager
self.bluetoothPeripheralManager = bluetoothPeripheralManager
if let m5StackAsNSObject = m5StackAsNSObject {
// set self as delegate in bluetoothTransmitter
if let bluetoothTransmitter = m5StackManager.m5StackBluetoothTransmitter(forM5stack: m5StackAsNSObject, createANewOneIfNecesssary: false) {
if let bluetoothTransmitter = bluetoothPeripheralManager.m5StackBluetoothTransmitter(forM5stack: m5StackAsNSObject, createANewOneIfNecesssary: false) {
bluetoothTransmitter.m5StackBluetoothTransmitterDelegateVariable = self
}
@ -195,7 +195,7 @@ final class M5StackViewController: UIViewController {
case M5StackViewController.UnwindSegueIdentifiers.M5StackToM5StacksUnWindSegueIdentifier:
if deleteM5StackWhenClosingViewController, let m5StackAsNSObject = m5StackAsNSObject {
m5StackManager?.deleteM5Stack(m5Stack: m5StackAsNSObject)
bluetoothPeripheralManager?.deleteM5Stack(m5Stack: m5StackAsNSObject)
}
}
}
@ -255,7 +255,7 @@ final class M5StackViewController: UIViewController {
if let m5StackAsNSObject = m5StackAsNSObject, let coreDataManager = coreDataManager, let m5StackNameAccessor = m5StackNameAccessor {
// set variable delegate in m5StackAsNSObject to nil, no need anymore to receive info
m5StackManager?.m5StackBluetoothTransmitter(forM5stack: m5StackAsNSObject, createANewOneIfNecesssary: false)?.m5StackBluetoothTransmitterDelegateVariable = nil
bluetoothPeripheralManager?.m5StackBluetoothTransmitter(forM5stack: m5StackAsNSObject, createANewOneIfNecesssary: false)?.m5StackBluetoothTransmitterDelegateVariable = nil
// if user has set or changed a userDefinedName, stored it, or delete it if userDefinedName is set to nil
if let m5StackName = m5StackAsNSObject.m5StackName {
@ -308,10 +308,10 @@ final class M5StackViewController: UIViewController {
private func scanButtonAction() {
// if m5StackAsNSObject is not nil, then there's already an M5stack for which scanning has started or which is already known from a previous scan (either connected or not connected) (m5StackAsNSObject should be nil because if it is not, the scanbutton should not even be enabled, anyway let's check).
// Also check m5StackManager not nil
guard m5StackAsNSObject == nil, let m5StackManager = m5StackManager else {return}
// Also check BluetoothPeripheralManager not nil
guard m5StackAsNSObject == nil, let bluetoothPeripheralManager = bluetoothPeripheralManager else {return}
m5StackManager.startScanningForNewDevice(callback: { (m5Stack) in
bluetoothPeripheralManager.startScanningForNewDevice(callback: { (m5Stack) in
// assign internal m5StackAsNSObject to new m5Stack
self.m5StackAsNSObject = m5Stack
@ -341,7 +341,7 @@ final class M5StackViewController: UIViewController {
self.deleteM5StackWhenClosingViewController = true
// set self as delegate in the bluetoothTransmitter
self.m5StackManager?.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false)?.m5StackBluetoothTransmitterDelegateVariable = self
self.bluetoothPeripheralManager?.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false)?.m5StackBluetoothTransmitterDelegateVariable = self
})
@ -365,7 +365,7 @@ final class M5StackViewController: UIViewController {
let alert = UIAlertController(title: Texts_M5StackView.confirmDeletionM5Stack + " " + textToAdd + "?", message: nil, actionHandler: {
// delete
self.m5StackManager?.deleteM5Stack(m5Stack: m5StackAsNSObject)
self.bluetoothPeripheralManager?.deleteM5Stack(m5Stack: m5StackAsNSObject)
// as the M5Stack is already deleted, there's no need to call delete again, when prepareForSegue
self.deleteM5StackWhenClosingViewController = false
@ -395,13 +395,13 @@ final class M5StackViewController: UIViewController {
setConnectButtonLabelText()
// normally there should be a bluetoothTransmitter
if let bluetoothTransmitter = m5StackManager?.m5StackBluetoothTransmitter(forM5stack: m5StackAsNSObject, createANewOneIfNecesssary: false) {
if let bluetoothTransmitter = bluetoothPeripheralManager?.m5StackBluetoothTransmitter(forM5stack: m5StackAsNSObject, createANewOneIfNecesssary: false) {
// set delegate in bluetoothtransmitter to nil, as we're going to disconnect permenantly, so not interested anymore to receive info
bluetoothTransmitter.m5StackBluetoothTransmitterDelegateVariable = nil
// this will also set bluetoothTransmitter to nil and also disconnect the M5Stack
m5StackManager?.setBluetoothTransmitterToNil(forM5Stack: m5StackAsNSObject)
bluetoothPeripheralManager?.setBluetoothTransmitterToNil(forM5Stack: m5StackAsNSObject)
}
@ -412,7 +412,7 @@ final class M5StackViewController: UIViewController {
coreDataManager?.saveChanges()
// get bluetoothTransmitter
if let bluetoothTransmitter = m5StackManager?.m5StackBluetoothTransmitter(forM5stack: m5StackAsNSObject, createANewOneIfNecesssary: true) {
if let bluetoothTransmitter = bluetoothPeripheralManager?.m5StackBluetoothTransmitter(forM5stack: m5StackAsNSObject, createANewOneIfNecesssary: true) {
// set delegate
bluetoothTransmitter.m5StackBluetoothTransmitterDelegateVariable = self
@ -435,7 +435,7 @@ final class M5StackViewController: UIViewController {
guard let m5StackAsNSObject = m5StackAsNSObject else {return false}
guard let connectionStatus = m5StackManager?.m5StackBluetoothTransmitter(forM5stack: m5StackAsNSObject, createANewOneIfNecesssary: false)?.getConnectionStatus() else {return false}
guard let connectionStatus = bluetoothPeripheralManager?.m5StackBluetoothTransmitter(forM5stack: m5StackAsNSObject, createANewOneIfNecesssary: false)?.getConnectionStatus() else {return false}
return connectionStatus == CBPeripheralState.connected
@ -461,7 +461,7 @@ final class M5StackViewController: UIViewController {
private func cancelButtonAction() {
// just in case scanning for a new device is still ongoing, call stopscanning
m5StackManager?.stopScanningForNewDevice()
bluetoothPeripheralManager?.stopScanningForNewDevice()
// return to M5StacksViewController
performSegue(withIdentifier: UnwindSegueIdentifiers.M5StackToM5StacksUnWindSegueIdentifier.rawValue, sender: self)
@ -668,11 +668,11 @@ extension M5StackViewController: UITableViewDataSource, UITableViewDelegate {
self.textColorTemporaryValue = colors[index]
// send value to M5Stack, if that would fail then set updateNeeded for that m5Stack
if let m5Stack = self.m5StackAsNSObject, let m5StackManager = self.m5StackManager {
if let textColor = self.textColorTemporaryValue, let blueToothTransmitter = m5StackManager.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false), blueToothTransmitter.writeTextColor(textColor: textColor) {
if let m5Stack = self.m5StackAsNSObject, let bluetoothPeripheralManager = self.bluetoothPeripheralManager {
if let textColor = self.textColorTemporaryValue, let blueToothTransmitter = bluetoothPeripheralManager.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false), blueToothTransmitter.writeTextColor(textColor: textColor) {
// do nothing, textColor successfully written to m5Stack - although it's not yet 100% sure because
} else {
m5StackManager.updateNeeded(forM5Stack: m5Stack)
bluetoothPeripheralManager.updateNeeded(forM5Stack: m5Stack)
}
}
@ -715,11 +715,11 @@ extension M5StackViewController: UITableViewDataSource, UITableViewDelegate {
self.backGroundColorTemporaryValue = colors[index]
// send value to M5Stack, if that would fail then set updateNeeded for that m5Stack
if let m5Stack = self.m5StackAsNSObject, let m5StackManager = self.m5StackManager {
if let backGroundColor = self.backGroundColorTemporaryValue, let blueToothTransmitter = m5StackManager.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false), blueToothTransmitter.writeBackGroundColor(backGroundColor: backGroundColor) {
if let m5Stack = self.m5StackAsNSObject, let bluetoothPeripheralManager = self.bluetoothPeripheralManager {
if let backGroundColor = self.backGroundColorTemporaryValue, let blueToothTransmitter = bluetoothPeripheralManager.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false), blueToothTransmitter.writeBackGroundColor(backGroundColor: backGroundColor) {
// do nothing, backGroundColor successfully written to m5Stack - although it's not yet 100% sure because write returns true without waiting for response from bluetooth peripheral
} else {
m5StackManager.updateNeeded(forM5Stack: m5Stack)
bluetoothPeripheralManager.updateNeeded(forM5Stack: m5Stack)
}
}
@ -754,11 +754,11 @@ extension M5StackViewController: UITableViewDataSource, UITableViewDelegate {
self.rotationTempValue = UInt16(index)
// send value to M5Stack, if that would fail then set updateNeeded for that m5Stack
if let m5Stack = self.m5StackAsNSObject, let m5StackManager = self.m5StackManager {
if let blueToothTransmitter = m5StackManager.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false), blueToothTransmitter.writeRotation(rotation: index) {
if let m5Stack = self.m5StackAsNSObject, let bluetoothPeripheralManager = self.bluetoothPeripheralManager {
if let blueToothTransmitter = bluetoothPeripheralManager.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false), blueToothTransmitter.writeRotation(rotation: index) {
// do nothing, rotation successfully written to m5Stack - although it's not yet 100% sure because write returns true without waiting for response from bluetooth peripheral
} else {
m5StackManager.updateNeeded(forM5Stack: m5Stack)
bluetoothPeripheralManager.updateNeeded(forM5Stack: m5Stack)
}
}
@ -796,11 +796,11 @@ extension M5StackViewController: UITableViewDataSource, UITableViewDelegate {
self.brightnessTemporaryValue = index * 10
// send value to M5Stack, if that would fail then set updateNeeded for that m5Stack
if let m5Stack = self.m5StackAsNSObject, let m5StackManager = self.m5StackManager {
if let blueToothTransmitter = m5StackManager.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false), blueToothTransmitter.writeBrightness(brightness: index * 10) {
if let m5Stack = self.m5StackAsNSObject, let bluetoothPeripheralManager = self.bluetoothPeripheralManager {
if let blueToothTransmitter = bluetoothPeripheralManager.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false), blueToothTransmitter.writeBrightness(brightness: index * 10) {
// do nothing, brightness successfully written to m5Stack - although it's not yet 100% sure because write returns true without waiting for response from bluetooth peripheral
} else {
m5StackManager.updateNeeded(forM5Stack: m5Stack)
bluetoothPeripheralManager.updateNeeded(forM5Stack: m5Stack)
}
}
@ -837,7 +837,7 @@ extension M5StackViewController: M5StackBluetoothDelegate {
func newBlePassWord(newBlePassword: String, forM5Stack m5Stack: M5Stack) {
// blePassword is also saved in M5StackManager, tant pis
// blePassword is also saved in BluetoothPeripheralManager, tant pis
m5StackAsNSObject?.blepassword = newBlePassword
tableView.reloadRows(at: [IndexPath(row: Setting.blePassword.rawValue, section: 0)], with: .none)
@ -851,7 +851,7 @@ extension M5StackViewController: M5StackBluetoothDelegate {
// show warning, inform that user should set password or reset M5Stack
let alert = UIAlertController(title: Texts_Common.warning, message: Texts_M5StackView.authenticationFailureWarning + " " + Texts_M5StackView.alwaysConnect, actionHandler: {
// by the time user clicks 'ok', the M5stack will be disconnected by the M5StackManager (see authentication in M5StackManager)
// by the time user clicks 'ok', the M5stack will be disconnected by the BluetoothPeripheralManager (see authentication in BluetoothPeripheralManager)
self.setShouldConnectToFalse(forM5Stack: m5Stack)
})
@ -865,7 +865,7 @@ extension M5StackViewController: M5StackBluetoothDelegate {
// show warning, inform that user should set password
let alert = UIAlertController(title: Texts_Common.warning, message: Texts_M5StackView.authenticationFailureWarning + " " + Texts_M5StackView.alwaysConnect, actionHandler: {
// by the time user clicks 'ok', the M5stack will be disconnected by the M5StackManager (see authentication in M5StackManager)
// by the time user clicks 'ok', the M5stack will be disconnected by the BluetoothPeripheralManager (see authentication in BluetoothPeripheralManager)
self.setShouldConnectToFalse(forM5Stack: m5Stack)
})
@ -879,7 +879,7 @@ extension M5StackViewController: M5StackBluetoothDelegate {
// show warning, inform that user should reset M5Stack
let alert = UIAlertController(title: Texts_Common.warning, message: Texts_M5StackView.m5StackResetRequiredWarning + " " + Texts_M5StackView.alwaysConnect, actionHandler: {
// by the time user clicks 'ok', the M5stack will be disconnected by the M5StackManager (see authentication in M5StackManager)
// by the time user clicks 'ok', the M5stack will be disconnected by the BluetoothPeripheralManager (see authentication in BluetoothPeripheralManager)
self.setShouldConnectToFalse(forM5Stack: m5Stack)
})

View File

@ -26,8 +26,8 @@ final class M5StacksViewController: UIViewController {
/// reference to coreDataManager
private var coreDataManager:CoreDataManager?
/// an m5stackManager
private weak var m5StackManager: M5StackManaging?
/// a bluetoothPeripheralManager
private weak var bluetoothPeripheralManager: BluetoothPeripheralManaging?
/// list of M5Stack's
private var m5Stacks: [M5Stack] = []
@ -35,11 +35,11 @@ final class M5StacksViewController: UIViewController {
// MARK: public functions
/// configure
public func configure(coreDataManager: CoreDataManager, m5StackManager: M5StackManaging) {
public func configure(coreDataManager: CoreDataManager, bluetoothPeripheralManager: BluetoothPeripheralManaging) {
// initalize private properties
self.coreDataManager = coreDataManager
self.m5StackManager = m5StackManager
self.bluetoothPeripheralManager = bluetoothPeripheralManager
initializeM5Stacks()
}
@ -68,11 +68,11 @@ final class M5StacksViewController: UIViewController {
switch segueIdentifierAsCase {
case M5StackViewController.SegueIdentifiers.M5StacksToM5StackSegueIdentifier:
guard let vc = segue.destination as? M5StackViewController, let coreDataManager = coreDataManager, let m5StackManager = m5StackManager else {
fatalError("In M5StacksViewController, prepare for segue, viewcontroller is not M5StackViewController or coreDataManager is nil or m5StackManager is nil" )
guard let vc = segue.destination as? M5StackViewController, let coreDataManager = coreDataManager, let bluetoothPeripheralManager = bluetoothPeripheralManager else {
fatalError("In M5StacksViewController, prepare for segue, viewcontroller is not M5StackViewController or coreDataManager is nil or bluetoothPeripheralManager is nil" )
}
vc.configure(m5Stack: sender as? M5Stack, coreDataManager: coreDataManager, m5StackManager: m5StackManager)
vc.configure(m5Stack: sender as? M5Stack, coreDataManager: coreDataManager, bluetoothPeripheralManager: bluetoothPeripheralManager)
}
}
@ -121,11 +121,11 @@ final class M5StacksViewController: UIViewController {
/// initializes m5Stacks array
private func initializeM5Stacks() {
if let m5StackManager = m5StackManager {
m5Stacks = m5StackManager.m5Stacks()
if let bluetoothPeripheralManager = bluetoothPeripheralManager {
m5Stacks = bluetoothPeripheralManager.m5Stacks()
for m5Stack in m5Stacks {
m5StackManager.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false)?.m5StackBluetoothTransmitterDelegateVariable = self
bluetoothPeripheralManager.m5StackBluetoothTransmitter(forM5stack: m5Stack, createANewOneIfNecesssary: false)?.m5StackBluetoothTransmitterDelegateVariable = self
}
} else {// should never happen or it would be a coding error, but let's assign to empty string
@ -169,7 +169,7 @@ extension M5StacksViewController: UITableViewDataSource, UITableViewDelegate {
// detail is the connection status
cell.detailTextLabel?.text = Texts_M5StackView.notConnected // start with not connected
if let bluetoothTransmitter = m5StackManager?.m5StackBluetoothTransmitter(forM5stack: m5Stacks[indexPath.row], createANewOneIfNecesssary: false) {
if let bluetoothTransmitter = bluetoothPeripheralManager?.m5StackBluetoothTransmitter(forM5stack: m5Stacks[indexPath.row], createANewOneIfNecesssary: false) {
if let connectionStatus = bluetoothTransmitter.getConnectionStatus(), connectionStatus == CBPeripheralState.connected {
cell.detailTextLabel?.text = Texts_M5StackView.connected
@ -223,7 +223,7 @@ extension M5StacksViewController: M5StackBluetoothDelegate {
func newBlePassWord(newBlePassword: String, forM5Stack m5Stack: M5Stack) {
// blePassword is also saved in M5StackManager, tant pis
// blePassword is also saved in BluetoothPerpheralManager, tant pis
m5Stack.blepassword = newBlePassword
}

View File

@ -190,7 +190,7 @@ final class RootViewController: UIViewController {
private var timeStampLastNotificationForPairing:Date?
/// manages m5Stacks that this app knows
private var m5StackManager: M5StackManager?
private var bluetoothPeripheralManager: BluetoothPeripheralManager?
/// manage glucose chart
private var glucoseChartManager: GlucoseChartManager!
@ -332,7 +332,7 @@ final class RootViewController: UIViewController {
}
}
// creates activeSensor, bgreadingsAccessor, calibrationsAccessor, NightScoutUploadManager, soundPlayer, dexcomShareUploadManager, nightScoutFollowManager, alertManager, healthKitManager, bgReadingSpeaker, m5StackManager
// creates activeSensor, bgreadingsAccessor, calibrationsAccessor, NightScoutUploadManager, soundPlayer, dexcomShareUploadManager, nightScoutFollowManager, alertManager, healthKitManager, bgReadingSpeaker, bluetoothPeripheralManager
private func setupApplicationData() {
// if coreDataManager is nil then there's no reason to continue
@ -388,8 +388,8 @@ final class RootViewController: UIViewController {
})
// setup m5StackManager
m5StackManager = M5StackManager(coreDataManager: coreDataManager)
// setup bluetoothPeripheralManager
bluetoothPeripheralManager = BluetoothPeripheralManager(coreDataManager: coreDataManager)
}
@ -484,7 +484,7 @@ final class RootViewController: UIViewController {
dexcomShareUploadManager?.upload()
m5StackManager?.sendLatestReading()
bluetoothPeripheralManager?.sendLatestReading()
}
}
@ -1495,9 +1495,9 @@ extension RootViewController: UITabBarControllerDelegate {
navigationController.configure(coreDataManager: coreDataManager, soundPlayer: soundPlayer)
} else if let navigationController = viewController as? M5StackNavigationController, let m5StackManager = m5StackManager, let coreDataManager = coreDataManager {
} else if let navigationController = viewController as? M5StackNavigationController, let bluetoothPeripheralManager = bluetoothPeripheralManager, let coreDataManager = coreDataManager {
navigationController.configure(coreDataManager: coreDataManager, m5StackManager: m5StackManager)
navigationController.configure(coreDataManager: coreDataManager, bluetoothPeripheralManager: bluetoothPeripheralManager)
}
}
@ -1656,7 +1656,7 @@ extension RootViewController:NightScoutFollowerDelegate {
bgReadingSpeaker.speakNewReading()
}
m5StackManager?.sendLatestReading()
bluetoothPeripheralManager?.sendLatestReading()
}
}