diff --git a/.gitignore b/.gitignore index 2bd1cb9a..e23c67fc 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ profile DerivedData *.hmap *.ipa +project.xcworkspace # Bundler .bundle @@ -32,3 +33,4 @@ Carthage # Pods/ + diff --git a/.travis.yml b/.travis.yml index 0b3983d9..3b0aa6a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode9 +osx_image: xcode9.3 # cache: cocoapods # podfile: Example/Podfile @@ -12,5 +12,7 @@ script: # Build cocoapods example project # - set -o pipefail && xcodebuild -workspace Example/xDripG5.xcworkspace -scheme xDripG5-Example -sdk iphonesimulator -destination name="iPhone SE" ONLY_ACTIVE_ARCH=NO | xcpretty # Build Travis project and run tests -- xcodebuild -project xDripG5.xcodeproj -scheme xDripG5 -sdk iphonesimulator11.0 build -destination name="iPhone SE" test +- xcodebuild -project CGMBLEKit.xcodeproj -scheme CGMBLEKit build -destination name="iPhone SE" test +- xcodebuild -project CGMBLEKit.xcodeproj -scheme "CGMBLEKit Example" build -destination name="iPhone SE" +- xcodebuild -project CGMBLEKit.xcodeproj -scheme ResetTransmitter build -destination name="iPhone SE" # - pod lib lint diff --git a/Example/xDripG5/AppDelegate.swift b/CGMBLEKit Example/AppDelegate.swift similarity index 63% rename from Example/xDripG5/AppDelegate.swift rename to CGMBLEKit Example/AppDelegate.swift index f230f6d9..70125e67 100644 --- a/Example/xDripG5/AppDelegate.swift +++ b/CGMBLEKit Example/AppDelegate.swift @@ -7,11 +7,11 @@ // import UIKit -import xDripG5 +import CGMBLEKit import CoreBluetooth @UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate { +class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate, TransmitterCommandSource { var window: UIWindow? @@ -19,16 +19,32 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate { return UIApplication.shared.delegate as! AppDelegate } + var transmitterID: String? { + didSet { + if let id = transmitterID { + transmitter = Transmitter( + id: id, + passiveModeEnabled: UserDefaults.standard.passiveModeEnabled + ) + 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 { - transmitter = Transmitter( - ID: UserDefaults.standard.transmitterID, - passiveModeEnabled: UserDefaults.standard.passiveModeEnabled - ) - transmitter?.stayConnected = UserDefaults.standard.stayConnected - transmitter?.delegate = self + transmitterID = UserDefaults.standard.transmitterID return true } @@ -42,7 +58,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - if let transmitter = transmitter , !transmitter.stayConnected { + if let transmitter = transmitter, !transmitter.stayConnected { transmitter.stopScanning() } } @@ -72,27 +88,48 @@ 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) { - if let vc = window?.rootViewController as? TransmitterDelegate { - DispatchQueue.main.async { + DispatchQueue.main.async { + if let vc = self.window?.rootViewController as? TransmitterDelegate { vc.transmitter(transmitter, didError: error) } } } func transmitter(_ transmitter: Transmitter, didRead glucose: Glucose) { - if let vc = window?.rootViewController as? TransmitterDelegate { - DispatchQueue.main.async { + self.glucose = glucose + DispatchQueue.main.async { + if let vc = self.window?.rootViewController as? TransmitterDelegate { vc.transmitter(transmitter, didRead: glucose) } } } func transmitter(_ transmitter: Transmitter, didReadUnknownData data: Data) { - if let vc = window?.rootViewController as? TransmitterDelegate { - DispatchQueue.main.async { + DispatchQueue.main.async { + if let vc = self.window?.rootViewController as? TransmitterDelegate { vc.transmitter(transmitter, didReadUnknownData: data) } } } + + func transmitter(_ transmitter: Transmitter, didReadBackfill glucose: [Glucose]) { + DispatchQueue.main.async { + if let vc = self.window?.rootViewController as? TransmitterDelegate { + vc.transmitter(transmitter, didReadBackfill: glucose) + } + } + } } diff --git a/Example/xDripG5/Assets.xcassets/AppIcon.appiconset/Contents.json b/CGMBLEKit Example/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 73% rename from Example/xDripG5/Assets.xcassets/AppIcon.appiconset/Contents.json rename to CGMBLEKit Example/Assets.xcassets/AppIcon.appiconset/Contents.json index eeea76c2..d8db8d65 100644 --- a/Example/xDripG5/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/CGMBLEKit Example/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -64,6 +84,11 @@ "idiom" : "ipad", "size" : "83.5x83.5", "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/Example/xDripG5/Base.lproj/LaunchScreen.storyboard b/CGMBLEKit Example/Base.lproj/LaunchScreen.storyboard similarity index 58% rename from Example/xDripG5/Base.lproj/LaunchScreen.storyboard rename to CGMBLEKit Example/Base.lproj/LaunchScreen.storyboard index 78686cd0..f83f6fd5 100644 --- a/Example/xDripG5/Base.lproj/LaunchScreen.storyboard +++ b/CGMBLEKit Example/Base.lproj/LaunchScreen.storyboard @@ -1,22 +1,20 @@ - + - - + + + - - - - - + - + + diff --git a/Example/xDripG5/Base.lproj/Main.storyboard b/CGMBLEKit Example/Base.lproj/Main.storyboard similarity index 72% rename from Example/xDripG5/Base.lproj/Main.storyboard rename to CGMBLEKit Example/Base.lproj/Main.storyboard index 62b8b23b..be42d9a1 100644 --- a/Example/xDripG5/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 @@ + + - + + + + + + + + + + +