Skip to content

Commit

Permalink
major changes
Browse files Browse the repository at this point in the history
- added demo application GUI
- changed Bluetooth toggle from power to enable
  • Loading branch information
michaeldorner committed Jan 1, 2017
1 parent 73286f4 commit 90644e0
Show file tree
Hide file tree
Showing 21 changed files with 580 additions and 117 deletions.
4 changes: 1 addition & 3 deletions BeeTee Demo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*/

import UIKit
import CoreLocation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
Expand All @@ -36,7 +36,5 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

6 changes: 6 additions & 0 deletions BeeTee Demo/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
23 changes: 23 additions & 0 deletions BeeTee Demo/Assets.xcassets/DeviceListing.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "noun_18353-2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "noun_18353-1.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "noun_18353.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions BeeTee Demo/Assets.xcassets/MissionControl.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "noun_655374_cc-2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "noun_655374_cc-1.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "noun_655374_cc.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
258 changes: 221 additions & 37 deletions BeeTee Demo/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion BeeTee Demo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>3.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
43 changes: 43 additions & 0 deletions BeeTee Demo/MissionControlViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
This file is part of BeeTee Project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/michaeldorner/BeeTee/blob/master/LICENSE. No part of BeeTee Project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.
*/

import UIKit


class MissionControlViewController: UITableViewController, BeeTeeDelegate {

private let beeTeeModel = BeeTeeModel.sharedInstance

@IBOutlet weak var bluetoothPowerSwitch: UISwitch!
@IBOutlet weak var bluetoothScanSwitch: UISwitch!

override func viewDidLoad() {
super.viewDidLoad()
beeTeeModel.subscribe(subscriber: self)
bluetoothPowerSwitch.setOn(beeTeeModel.bluetoothIsOn(), animated: false)
bluetoothScanSwitch.setOn(beeTeeModel.isScanning(), animated: false)
}

@IBAction func switchBluetoothPower() {
if beeTeeModel.bluetoothIsOn() {
beeTeeModel.turnBluetoothOff()
} else {
beeTeeModel.turnBluetoothOn()
}
}

@IBAction func switchBluetoothScanStatus() {
if beeTeeModel.isScanning() {
beeTeeModel.stopScan()
} else {
beeTeeModel.startScanForDevices()
}
}

func receivedBeeTeeNotification(notification: BeeTeeNotification) {
tableView.reloadData()
bluetoothPowerSwitch.setOn(beeTeeModel.bluetoothIsOn(), animated: true)
bluetoothScanSwitch.setOn(beeTeeModel.isScanning(), animated: true)
}
}
43 changes: 0 additions & 43 deletions BeeTee Demo/ViewController.swift

This file was deleted.

50 changes: 43 additions & 7 deletions BeeTee.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
objects = {

/* Begin PBXBuildFile section */
5F0893721E17F82500197FAD /* MissionControlViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F0893711E17F82500197FAD /* MissionControlViewController.swift */; };
5F0893761E181C7B00197FAD /* BeeTeeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F0893751E181C7B00197FAD /* BeeTeeModel.swift */; };
5F08937D1E19021500197FAD /* DeviceListingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F08937C1E19021500197FAD /* DeviceListingViewController.swift */; };
5F08937F1E19071800197FAD /* DeviceDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F08937E1E19071800197FAD /* DeviceDetailViewController.swift */; };
5F1764F71E0EBFB0003F888A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F1764F61E0EBFB0003F888A /* AppDelegate.swift */; };
5F1764F91E0EBFBA003F888A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5F1764F81E0EBFBA003F888A /* Assets.xcassets */; };
5F1764FE1E0EBFC2003F888A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5F1764FA1E0EBFC2003F888A /* LaunchScreen.storyboard */; };
5F1764FF1E0EBFC2003F888A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5F1764FC1E0EBFC2003F888A /* Main.storyboard */; };
5F1765031E0EBFD2003F888A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F1765011E0EBFD2003F888A /* ViewController.swift */; };
5F2409071E0C0134004AF90F /* BeeTeeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F2409061E0C0134004AF90F /* BeeTeeTests.swift */; };
5F9F63371E0EB9300014A043 /* BeeTee.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F9F632F1E0EB9300014A043 /* BeeTee.swift */; };
5F9F63381E0EB9300014A043 /* BeeTeeDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F9F63301E0EB9300014A043 /* BeeTeeDevice.swift */; };
Expand All @@ -30,12 +33,15 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
5F0893711E17F82500197FAD /* MissionControlViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MissionControlViewController.swift; path = "BeeTee Demo/MissionControlViewController.swift"; sourceTree = SOURCE_ROOT; };
5F0893751E181C7B00197FAD /* BeeTeeModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BeeTeeModel.swift; sourceTree = "<group>"; };
5F08937C1E19021500197FAD /* DeviceListingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceListingViewController.swift; sourceTree = "<group>"; };
5F08937E1E19071800197FAD /* DeviceDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceDetailViewController.swift; sourceTree = "<group>"; };
5F1764F61E0EBFB0003F888A /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = "BeeTee Demo/AppDelegate.swift"; sourceTree = SOURCE_ROOT; };
5F1764F81E0EBFBA003F888A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = "BeeTee Demo/Assets.xcassets"; sourceTree = SOURCE_ROOT; };
5F1764FB1E0EBFC2003F888A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = "BeeTee Demo/Base.lproj/LaunchScreen.storyboard"; sourceTree = SOURCE_ROOT; };
5F1764FD1E0EBFC2003F888A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = "BeeTee Demo/Base.lproj/Main.storyboard"; sourceTree = SOURCE_ROOT; };
5F1765001E0EBFD2003F888A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = "BeeTee Demo/Info.plist"; sourceTree = SOURCE_ROOT; };
5F1765011E0EBFD2003F888A /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ViewController.swift; path = "BeeTee Demo/ViewController.swift"; sourceTree = SOURCE_ROOT; };
5F2408EE1E0C0134004AF90F /* BeeTee.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BeeTee.app; sourceTree = BUILT_PRODUCTS_DIR; };
5F2409021E0C0134004AF90F /* BeeTeeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BeeTeeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5F2409061E0C0134004AF90F /* BeeTeeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeeTeeTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -69,6 +75,34 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
5F0893791E18F95B00197FAD /* View */ = {
isa = PBXGroup;
children = (
5F1764F81E0EBFBA003F888A /* Assets.xcassets */,
5F1764FA1E0EBFC2003F888A /* LaunchScreen.storyboard */,
5F1764FC1E0EBFC2003F888A /* Main.storyboard */,
);
name = View;
sourceTree = "<group>";
};
5F08937A1E18F96900197FAD /* Controller */ = {
isa = PBXGroup;
children = (
5F0893711E17F82500197FAD /* MissionControlViewController.swift */,
5F08937C1E19021500197FAD /* DeviceListingViewController.swift */,
5F08937E1E19071800197FAD /* DeviceDetailViewController.swift */,
);
name = Controller;
sourceTree = "<group>";
};
5F08937B1E18F97000197FAD /* Model */ = {
isa = PBXGroup;
children = (
5F0893751E181C7B00197FAD /* BeeTeeModel.swift */,
);
name = Model;
sourceTree = "<group>";
};
5F2408E51E0C0134004AF90F = {
isa = PBXGroup;
children = (
Expand All @@ -92,11 +126,10 @@
isa = PBXGroup;
children = (
5F1765001E0EBFD2003F888A /* Info.plist */,
5F1765011E0EBFD2003F888A /* ViewController.swift */,
5F1764F61E0EBFB0003F888A /* AppDelegate.swift */,
5F1764F81E0EBFBA003F888A /* Assets.xcassets */,
5F1764FA1E0EBFC2003F888A /* LaunchScreen.storyboard */,
5F1764FC1E0EBFC2003F888A /* Main.storyboard */,
5F0893791E18F95B00197FAD /* View */,
5F08937A1E18F96900197FAD /* Controller */,
5F08937B1E18F97000197FAD /* Model */,
);
name = "BeeTee Demo";
path = BeeTee;
Expand Down Expand Up @@ -251,9 +284,12 @@
5F9F633A1E0EB9300014A043 /* BluetoothManagerHandler.m in Sources */,
5F9F63371E0EB9300014A043 /* BeeTee.swift in Sources */,
5F1764F71E0EBFB0003F888A /* AppDelegate.swift in Sources */,
5F1765031E0EBFD2003F888A /* ViewController.swift in Sources */,
5F08937D1E19021500197FAD /* DeviceListingViewController.swift in Sources */,
5F9F63381E0EB9300014A043 /* BeeTeeDevice.swift in Sources */,
5F08937F1E19071800197FAD /* DeviceDetailViewController.swift in Sources */,
5F0893761E181C7B00197FAD /* BeeTeeModel.swift in Sources */,
5F9F63391E0EB9300014A043 /* BluetoothDeviceHandler.m in Sources */,
5F0893721E17F82500197FAD /* MissionControlViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
56 changes: 30 additions & 26 deletions BeeTee/BeeTee.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,57 +33,55 @@ public class BeeTee {
public var delegate: BeeTeeDelegate? = nil
public var availableDevices: [BeeTeeDevice] {
get {
return Array(devices)
return Array(_availableDevices)
}
}

private let bluetoothManagerHandler = BluetoothManagerHandler.sharedInstance()!
private var devices = Set<BeeTeeDevice>()
private var observers = [NSObjectProtocol]()
private var _availableDevices = Set<BeeTeeDevice>()
private var tokenCache = [BeeTeeNotification: NSObjectProtocol]()

convenience init(delegate: BeeTeeDelegate) {
self.init()
self.delegate = delegate
}

init() {
public init() {

for beeTeeNotification in BeeTeeNotification.allNotifications {
print("registered \(beeTeeNotification)")
print("Registered \(beeTeeNotification)")

let observer = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: beeTeeNotification.rawValue), object: nil, queue: OperationQueue.main) { (notification) in
let notification = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: beeTeeNotification.rawValue), object: nil, queue: OperationQueue.main) { [unowned self] (notification) in
let beeTeeNotification = BeeTeeNotification.init(rawValue: notification.name.rawValue)!
switch beeTeeNotification {
case .DeviceDiscovered:
let beeTeeDevice = self.extractBeeTeeDevice(from: notification)
self.devices.insert(beeTeeDevice)
self._availableDevices.insert(beeTeeDevice)
case .DeviceRemoved:
let beeTeeDevice = self.extractBeeTeeDevice(from: notification)
self.devices.remove(beeTeeDevice)
self._availableDevices.remove(beeTeeDevice)
default:
break
}
print(beeTeeNotification)
self.delegate?.receivedBeeTeeNotification(notification: beeTeeNotification)
if (self.delegate != nil) {
self.delegate?.receivedBeeTeeNotification(notification: beeTeeNotification)
}
}
observers.append(observer)
self.tokenCache[beeTeeNotification] = notification
}
}

deinit {
for observer in observers {
NotificationCenter.default.removeObserver(observer)
for key in tokenCache.keys {
NotificationCenter.default.removeObserver(tokenCache[key]!)
}
}

public func turnBluetoothOn() {
bluetoothManagerHandler.setPower(true)
public func enableBluetooth() {
bluetoothManagerHandler.enable()
}

public func turnBluetoothOff() {
bluetoothManagerHandler.setPower(false)
public func disableBluetooth() {
bluetoothManagerHandler.disable()
}

public func bluetoothIsOn() -> Bool {
return bluetoothManagerHandler.powered()
public func bluetoothIsEnabled() -> Bool {
return bluetoothManagerHandler.enabled()
}

public func startScanForDevices() {
Expand All @@ -92,14 +90,15 @@ public class BeeTee {

public func stopScan() {
bluetoothManagerHandler.stopScan()
resetAvailableDevices()
}

public func isScanning() -> Bool {
return bluetoothManagerHandler.isScanning()
}

public func debugLowLevel() {
NSLog("This is a dirty C hack and only for demonstration and deep debugging, but not for production.") // credits to http://stackoverflow.com/a/3738387/1864294
public static func debugLowLevel() {
print("This is a dirty C hack and only for demonstration and deep debugging, but not for production.") // credits to http://stackoverflow.com/a/3738387/1864294
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
nil,
{ (_, observer, name, _, _) in
Expand All @@ -113,9 +112,14 @@ public class BeeTee {
.deliverImmediately)
}

private func resetAvailableDevices() {
_availableDevices.removeAll()
}

private func extractBeeTeeDevice(from notification: Notification) -> BeeTeeDevice {
let bluetoothDevice = BluetoothDeviceHandler(notification: notification)!
let beeTeeDevice = BeeTeeDevice(name: bluetoothDevice.name, address: bluetoothDevice.address, majorClass: bluetoothDevice.majorClass, minorClass: bluetoothDevice.minorClass, type: bluetoothDevice.type, supportsBatteryLevel: bluetoothDevice.supportsBatteryLevel, detectingDate: Date())
return beeTeeDevice
}
}

Loading

0 comments on commit 90644e0

Please sign in to comment.