diff --git a/CGMBLEKit Example/AppDelegate.swift b/CGMBLEKit Example/AppDelegate.swift index 3f8028cc..e872997d 100644 --- a/CGMBLEKit Example/AppDelegate.swift +++ b/CGMBLEKit Example/AppDelegate.swift @@ -11,8 +11,8 @@ import xDripG5 import CoreBluetooth @UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate { - +class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate, TransmitterCommandSource { + var window: UIWindow? static var sharedDelegate: AppDelegate { @@ -28,14 +28,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate { ) transmitter?.stayConnected = UserDefaults.standard.stayConnected transmitter?.delegate = self + transmitter?.commandSource = self UserDefaults.standard.transmitterID = id } + glucose = nil } } var transmitter: Transmitter? + let commandQueue = CommandQueue() + + var glucose: Glucose? + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { transmitterID = UserDefaults.standard.transmitterID @@ -82,6 +88,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate { return dateFormatter }() + func dequeuePendingCommand(for transmitter: Transmitter) -> Command? { + return commandQueue.dequeue() + } + + func transmitter(_ transmitter: Transmitter, didFail command: Command, with error: Error) { + // TODO: implement + } + + func transmitter(_ transmitter: Transmitter, didComplete command: Command) { + // TODO: implement + } + func transmitter(_ transmitter: Transmitter, didError error: Error) { DispatchQueue.main.async { if let vc = self.window?.rootViewController as? TransmitterDelegate { @@ -91,6 +109,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate { } func transmitter(_ transmitter: Transmitter, didRead glucose: Glucose) { + self.glucose = glucose DispatchQueue.main.async { if let vc = self.window?.rootViewController as? TransmitterDelegate { vc.transmitter(transmitter, didRead: glucose) diff --git a/CGMBLEKit Example/Base.lproj/Main.storyboard b/CGMBLEKit Example/Base.lproj/Main.storyboard index 62b8b23b..be42d9a1 100644 --- a/CGMBLEKit Example/Base.lproj/Main.storyboard +++ b/CGMBLEKit Example/Base.lproj/Main.storyboard @@ -1,8 +1,11 @@ - - + + + + + - + @@ -10,31 +13,36 @@ - + - + + + + + @@ -59,13 +67,16 @@ + + @@ -73,26 +84,59 @@ + + - + + + + + + + + + + +