diff --git a/BluefruitPlayground-SimulatedBluetooth-Info.plist b/BluefruitPlayground-SimulatedBluetooth-Info.plist index 8eac424..b94dfcf 100644 --- a/BluefruitPlayground-SimulatedBluetooth-Info.plist +++ b/BluefruitPlayground-SimulatedBluetooth-Info.plist @@ -28,6 +28,8 @@ This app needs access to Bluetooth to connect to Circuit Playground Bluefruit devices NSBluetoothPeripheralUsageDescription This app needs access to Bluetooth to connect to Circuit Playground Bluefruit devices + NSCameraUsageDescription + Puppet module requires access to the camera UILaunchStoryboardName LaunchScreen UIMainStoryboardFile diff --git a/BluefruitPlayground.xcodeproj/project.pbxproj b/BluefruitPlayground.xcodeproj/project.pbxproj index bc36463..3642e4f 100644 --- a/BluefruitPlayground.xcodeproj/project.pbxproj +++ b/BluefruitPlayground.xcodeproj/project.pbxproj @@ -1347,7 +1347,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 13; DEVELOPMENT_TEAM = 2X94RM7457; INFOPLIST_FILE = BluefruitPlayground/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; @@ -1372,7 +1372,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 13; DEVELOPMENT_TEAM = 2X94RM7457; INFOPLIST_FILE = BluefruitPlayground/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; @@ -1436,7 +1436,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 13; DEVELOPMENT_TEAM = 2X94RM7457; INFOPLIST_FILE = "BluefruitPlayground-SimulatedBluetooth-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; @@ -1446,7 +1446,7 @@ ); MARKETING_VERSION = 1.2.0; OTHER_SWIFT_FLAGS = "$(inherited) -D COCOAPODS -D SIMULATEBLUETOOTH"; - PRODUCT_BUNDLE_IDENTIFIER = com.adafruit.BluefruitPlayground; + PRODUCT_BUNDLE_IDENTIFIER = com.adafruit.BluefruitPlayground.simulated; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "BluefruitPlayground/BluefruitPlayground-SimulateBluetooth-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -1462,7 +1462,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 13; DEVELOPMENT_TEAM = 2X94RM7457; INFOPLIST_FILE = "BluefruitPlayground-SimulatedBluetooth-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; @@ -1472,7 +1472,7 @@ ); MARKETING_VERSION = 1.2.0; OTHER_SWIFT_FLAGS = "$(inherited) -D COCOAPODS -D SIMULATEBLUETOOTH"; - PRODUCT_BUNDLE_IDENTIFIER = com.adafruit.BluefruitPlayground; + PRODUCT_BUNDLE_IDENTIFIER = com.adafruit.BluefruitPlayground.simulated; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "BluefruitPlayground/BluefruitPlayground-SimulateBluetooth-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/BluefruitPlayground/AdafruitKit/Ble/BleCentralMode/BleManager.swift b/BluefruitPlayground/AdafruitKit/Ble/BleCentralMode/BleManager.swift index 8addc22..c5515b8 100644 --- a/BluefruitPlayground/AdafruitKit/Ble/BleCentralMode/BleManager.swift +++ b/BluefruitPlayground/AdafruitKit/Ble/BleCentralMode/BleManager.swift @@ -38,7 +38,7 @@ class BleManager: NSObject { internal var scanningStartTime: TimeInterval? // Time when the scanning started. nil if stopped private var scanningServicesFilter: [CBUUID]? internal var peripheralsFound = [UUID: BlePeripheral]() - private var peripheralsFoundLock = NSLock() + internal var peripheralsFoundLock = NSLock() // Connecting private var connectionTimeoutTimers = [UUID: MSWeakTimer]() @@ -353,6 +353,10 @@ extension BleManager: CBCentralManagerDelegate { func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) { DLog("didFailToConnect") + // Clean + peripheralsFound[peripheral.identifier]?.reset() + + // Notify NotificationCenter.default.post(name: .didDisconnectFromPeripheral, object: nil, userInfo: [NotificationUserInfoKey.uuid.rawValue: peripheral.identifier]) } diff --git a/BluefruitPlayground/AdafruitKit/Ble/BleCentralMode/BlePeripheral.swift b/BluefruitPlayground/AdafruitKit/Ble/BleCentralMode/BlePeripheral.swift index 9de31b4..cbf8ae1 100644 --- a/BluefruitPlayground/AdafruitKit/Ble/BleCentralMode/BlePeripheral.swift +++ b/BluefruitPlayground/AdafruitKit/Ble/BleCentralMode/BlePeripheral.swift @@ -337,7 +337,7 @@ class BlePeripheral: NSObject { } // MARK: - Command Queue - private class BleCommand: Equatable { + internal class BleCommand: Equatable { enum CommandType { case discoverService case discoverCharacteristic @@ -404,7 +404,7 @@ class BlePeripheral: NSObject { return "\(descriptor.characteristic.service.uuid.uuidString)-\(descriptor.characteristic.uuid.uuidString)-\(descriptor.uuid.uuidString)" } - private func finishedExecutingCommand(error: Error?) { + internal func finishedExecutingCommand(error: Error?) { //DLog("finishedExecutingCommand") // Result Callback @@ -523,7 +523,7 @@ class BlePeripheral: NSObject { peripheral.readValue(for: descriptor) } - private func disconnect(with command: BleCommand) { + internal func disconnect(with command: BleCommand) { let centralManager = command.parameters!.first as! CBCentralManager centralManager.cancelPeripheralConnection(self.peripheral) finishedExecutingCommand(error: nil) diff --git a/BluefruitPlayground/AdafruitKit/Ble/Tests/BleManagerSimulated.swift b/BluefruitPlayground/AdafruitKit/Ble/Tests/BleManagerSimulated.swift index fb35ded..530836f 100644 --- a/BluefruitPlayground/AdafruitKit/Ble/Tests/BleManagerSimulated.swift +++ b/BluefruitPlayground/AdafruitKit/Ble/Tests/BleManagerSimulated.swift @@ -19,6 +19,7 @@ class BleManagerSimulated: BleManager { } + // MARK: - Scanning override func startScan(withServices services: [CBUUID]? = nil) { scanningStartTime = CACurrentMediaTime() @@ -31,8 +32,12 @@ class BleManagerSimulated: BleManager { override func stopScan() { } + // MARK: - Connect override func connect(to peripheral: BlePeripheral, timeout: TimeInterval? = nil, shouldNotifyOnConnection: Bool = false, shouldNotifyOnDisconnection: Bool = false, shouldNotifyOnNotification: Bool = false) { + guard let blePeripheral = peripheral as? BlePeripheralSimulated else { return } + blePeripheral.simulateConnect() + // Send notification NotificationCenter.default.post(name: .didConnectToPeripheral, object: nil, userInfo: [NotificationUserInfoKey.uuid.rawValue: peripheral.identifier]) } @@ -40,4 +45,34 @@ class BleManagerSimulated: BleManager { override func reconnecToPeripherals(withIdentifiers identifiers: [UUID], withServices services: [CBUUID], timeout: Double? = nil) -> Bool { return false } + + // MARK: - Disconnect + override func disconnect(from peripheral: BlePeripheral, waitForQueuedCommands: Bool = false) { + guard let blePeripheral = peripheral as? BlePeripheralSimulated else { return } + + DLog("disconnect") + NotificationCenter.default.post(name: .willDisconnectFromPeripheral, object: nil, userInfo: [NotificationUserInfoKey.uuid.rawValue: peripheral.identifier]) + + if waitForQueuedCommands { + // Send the disconnection to the command queue, so all the previous command are executed before disconnecting + if let centralManager = centralManager { + blePeripheral.disconnect(centralManager: centralManager) + } + } + else { + didDisconnectPeripheral(blePeripheral: blePeripheral) + } + } + + func didDisconnectPeripheral(blePeripheral: BlePeripheralSimulated) { + DLog("didDisconnectPeripheral") + + // Clean + peripheralsFound[blePeripheral.identifier]?.reset() + + // Notify + NotificationCenter.default.post(name: .didDisconnectFromPeripheral, object: nil, userInfo: [NotificationUserInfoKey.uuid.rawValue: blePeripheral.identifier]) + + // Don't remove the peripheral from the peripheral list (so we can select again the simulated peripheral) + } } diff --git a/BluefruitPlayground/AdafruitKit/Ble/Tests/BlePeripheralSimulated.swift b/BluefruitPlayground/AdafruitKit/Ble/Tests/BlePeripheralSimulated.swift index 121e024..2302864 100644 --- a/BluefruitPlayground/AdafruitKit/Ble/Tests/BlePeripheralSimulated.swift +++ b/BluefruitPlayground/AdafruitKit/Ble/Tests/BlePeripheralSimulated.swift @@ -10,20 +10,19 @@ import Foundation import CoreBluetooth class BlePeripheralSimulated: BlePeripheral { - // Constants - private static let kSimulatedUUID = UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")! - // Data + private var simulatedIdentifier = UUID() override var identifier: UUID { - return BlePeripheralSimulated.kSimulatedUUID + return simulatedIdentifier } override var name: String? { return "Simulated Peripheral" } - + + private var simulatedState: CBPeripheralState = .disconnected override var state: CBPeripheralState { - return .connected + return simulatedState } // MARK: - Lifecycle @@ -46,5 +45,20 @@ class BlePeripheralSimulated: BlePeripheral { override func discover(serviceUuids: [CBUUID]?, completion: ((Error?) -> Void)?) { completion?(nil) } + + // MARK: - Connect + func simulateConnect() { + simulatedState = .connected + } + + // MARK: - Disconnect + override internal func disconnect(with command: BleCommand) { + // Simulate disconnection + simulatedState = .disconnected + BleManagerSimulated.simulated.didDisconnectPeripheral(blePeripheral: self) + + // Finished + finishedExecutingCommand(error: nil) + } } diff --git a/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand.png b/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand.png index a83c41b..9d7499c 100644 Binary files a/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand.png and b/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand.png differ diff --git a/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand@2x.png b/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand@2x.png index 63c7634..3b46162 100644 Binary files a/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand@2x.png and b/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand@2x.png differ diff --git a/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand@3x.png b/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand@3x.png index 7e514f6..9cb39e8 100644 Binary files a/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand@3x.png and b/BluefruitPlayground/Assets.xcassets/puppet/puppet_hand.imageset/puppet_hand@3x.png differ diff --git a/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/Contents.json b/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/Contents.json index 1f52187..6233972 100644 --- a/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/Contents.json +++ b/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/Contents.json @@ -12,6 +12,7 @@ }, { "idiom" : "universal", + "filename" : "scanproblems_powerup@3x.png", "scale" : "3x" } ], diff --git a/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup.png b/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup.png index 2e38487..c5ad969 100644 Binary files a/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup.png and b/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup.png differ diff --git a/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup@2x.png b/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup@2x.png index 99e046d..ca8a38c 100644 Binary files a/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup@2x.png and b/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup@2x.png differ diff --git a/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup@3x.png b/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup@3x.png new file mode 100644 index 0000000..d88f7a2 Binary files /dev/null and b/BluefruitPlayground/Assets.xcassets/scan_problems/scanproblems_powerup.imageset/scanproblems_powerup@3x.png differ diff --git a/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo.png b/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo.png index 3bc3303..1d787e0 100644 Binary files a/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo.png and b/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo.png differ diff --git a/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo@2x.png b/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo@2x.png index 3db9480..19ddd35 100644 Binary files a/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo@2x.png and b/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo@2x.png differ diff --git a/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo@3x.png b/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo@3x.png index 608460a..0058af7 100644 Binary files a/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo@3x.png and b/BluefruitPlayground/Assets.xcassets/splash/welcome_logo.imageset/welcome_logo@3x.png differ diff --git a/BluefruitPlayground/Base.lproj/Main.storyboard b/BluefruitPlayground/Base.lproj/Main.storyboard index 1e64a5b..934c058 100644 --- a/BluefruitPlayground/Base.lproj/Main.storyboard +++ b/BluefruitPlayground/Base.lproj/Main.storyboard @@ -1,6 +1,6 @@ - + @@ -18,16 +18,19 @@ - + + + + - + @@ -36,9 +39,10 @@ - - + + + @@ -194,10 +198,10 @@ - + @@ -1227,14 +1231,14 @@ - + - + - + @@ -1310,13 +1314,13 @@ - + - + - + - + - + @@ -1936,19 +1941,19 @@ @@ -2035,14 +2040,14 @@ - + - + - + - + - + - + - + @@ -2224,7 +2229,7 @@ - + @@ -2323,7 +2328,7 @@ - + @@ -2433,16 +2438,16 @@ - + - + - + - + - + - + - + @@ -2900,7 +2905,7 @@ - + @@ -2984,25 +2989,25 @@ - + - + - + - + - + @@ -3015,7 +3020,7 @@ - + - + - + @@ -3042,7 +3047,7 @@ - + - + - + @@ -3069,7 +3074,7 @@