Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Example/xDripG5.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
06C991A3D94948120AD2A278 /* Pods_xDripG5_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42011659993839B43D24C553 /* Pods_xDripG5_Example.framework */; };
439FCA211C332AA4007DE84C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 439FCA1F1C332AA4007DE84C /* LaunchScreen.storyboard */; };
439FCA231C332AE5007DE84C /* NSUserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439FCA221C332AE5007DE84C /* NSUserDefaults.swift */; };
43E3979F1D569B340028E321 /* HKUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43E3979E1D569B340028E321 /* HKUnit.swift */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
Expand All @@ -20,6 +21,7 @@
42011659993839B43D24C553 /* Pods_xDripG5_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_xDripG5_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
439FCA201C332AA4007DE84C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
439FCA221C332AE5007DE84C /* NSUserDefaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSUserDefaults.swift; sourceTree = "<group>"; };
43E3979E1D569B340028E321 /* HKUnit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HKUnit.swift; path = ../../xDripG5/HKUnit.swift; sourceTree = "<group>"; };
598554A3C216FA3B8F8CD6BE /* xDripG5.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = xDripG5.podspec; path = ../xDripG5.podspec; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* xDripG5_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = xDripG5_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -76,6 +78,7 @@
isa = PBXGroup;
children = (
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
43E3979E1D569B340028E321 /* HKUnit.swift */,
439FCA221C332AE5007DE84C /* NSUserDefaults.swift */,
607FACD71AFB9204008FA782 /* ViewController.swift */,
607FACDC1AFB9204008FA782 /* Assets.xcassets */,
Expand Down Expand Up @@ -243,6 +246,7 @@
files = (
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
43E3979F1D569B340028E321 /* HKUnit.swift in Sources */,
439FCA231C332AE5007DE84C /* NSUserDefaults.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
13 changes: 2 additions & 11 deletions Example/xDripG5/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate {

transmitter = Transmitter(
ID: NSUserDefaults.standardUserDefaults().transmitterID,
startTimeInterval: NSUserDefaults.standardUserDefaults().startTimeInterval,
passiveModeEnabled: NSUserDefaults.standardUserDefaults().passiveModeEnabled
)
transmitter?.stayConnected = NSUserDefaults.standardUserDefaults().stayConnected
Expand Down Expand Up @@ -81,19 +80,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate {
}
}

func transmitter(transmitter: Transmitter, didReadGlucose glucose: GlucoseRxMessage) {

if let startTime = transmitter.startTimeInterval {
NSUserDefaults.standardUserDefaults().startTimeInterval = startTime
}

func transmitter(transmitter: Transmitter, didRead glucose: Glucose) {
if let vc = window?.rootViewController as? TransmitterDelegate {
dispatch_async(dispatch_get_main_queue()) {
vc.transmitter(transmitter, didReadGlucose: glucose)
vc.transmitter(transmitter, didRead: glucose)
}
}
}
}



15 changes: 0 additions & 15 deletions Example/xDripG5/NSUserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,6 @@ extension NSUserDefaults {
}
}

var startTimeInterval: NSTimeInterval? {
get {
let value = doubleForKey("startTimeInterval")

return value > 0 ? value : nil
}
set {
if let value = newValue {
setDouble(value, forKey: "startTimeInterval")
} else {
setObject(nil, forKey: "startTimeInterval")
}
}
}

var stayConnected: Bool {
get {
return boolForKey("stayConnected") ?? true
Expand Down
18 changes: 9 additions & 9 deletions Example/xDripG5/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import HealthKit
import xDripG5

class ViewController: UIViewController, TransmitterDelegate, UITextFieldDelegate {
Expand Down Expand Up @@ -106,19 +107,18 @@ class ViewController: UIViewController, TransmitterDelegate, UITextFieldDelegate
subtitleLabel.text = "\(error)"
}

func transmitter(transmitter: Transmitter, didReadGlucose glucose: GlucoseRxMessage) {
titleLabel.text = NSNumberFormatter.localizedStringFromNumber(NSNumber(short: Int16(glucose.glucose)), numberStyle: .NoStyle)

if let startTime = transmitter.startTimeInterval {
let date = NSDate(timeIntervalSince1970: startTime).dateByAddingTimeInterval(NSTimeInterval(glucose.timestamp))

subtitleLabel.text = NSDateFormatter.localizedStringFromDate(date, dateStyle: .NoStyle, timeStyle: .LongStyle)
func transmitter(transmitter: Transmitter, didRead glucose: Glucose) {
let unit = HKUnit.milligramsPerDeciliter()
if let value = glucose.glucose?.doubleValueForUnit(unit) {
titleLabel.text = "\(value) \(unit.unitString)"
} else {
subtitleLabel.text = "Unknown time"
titleLabel.text = String(glucose.state)
}

}

let date = glucose.readDate
subtitleLabel.text = NSDateFormatter.localizedStringFromDate(date, dateStyle: .NoStyle, timeStyle: .LongStyle)
}
}


Expand Down
2 changes: 1 addition & 1 deletion xDripG5.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "xDripG5"
s.version = "0.5.0"
s.version = "0.6.0"
s.summary = "An interface for communicating with the G5 glucose transmitter over Bluetooth."

s.description = <<-DESC
Expand Down
36 changes: 28 additions & 8 deletions xDripG5.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
43CE7CDC1CA77468003CC1B0 /* TransmitterStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43CE7CDB1CA77468003CC1B0 /* TransmitterStatus.swift */; };
43DC87C01C8B509B005BC30D /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43DC87BF1C8B509B005BC30D /* NSData.swift */; };
43DC87C21C8B520F005BC30D /* GlucoseRxMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43DC87C11C8B520F005BC30D /* GlucoseRxMessageTests.swift */; };
43E3978B1D5668BD0028E321 /* CalibrationState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43E3978A1D5668BD0028E321 /* CalibrationState.swift */; };
43E3978D1D566AEA0028E321 /* HealthKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43E3978C1D566AEA0028E321 /* HealthKit.framework */; };
43E3978F1D566B170028E321 /* Glucose.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43E3978E1D566B170028E321 /* Glucose.swift */; };
43E397911D5692080028E321 /* GlucoseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43E397901D5692080028E321 /* GlucoseTests.swift */; };
43E397931D56950C0028E321 /* HKUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43E397921D56950C0028E321 /* HKUnit.swift */; };
43EEA7111D14DC0800CBBDA0 /* AESCrypt.h in Headers */ = {isa = PBXBuildFile; fileRef = 43EEA70F1D14DC0800CBBDA0 /* AESCrypt.h */; settings = {ATTRIBUTES = (Public, ); }; };
43EEA7121D14DC0800CBBDA0 /* AESCrypt.m in Sources */ = {isa = PBXBuildFile; fileRef = 43EEA7101D14DC0800CBBDA0 /* AESCrypt.m */; };
43F82BCC1D035AA4006F5DD7 /* TransmitterTimeRxMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F82BCB1D035AA4006F5DD7 /* TransmitterTimeRxMessageTests.swift */; };
Expand Down Expand Up @@ -100,6 +105,11 @@
43CE7CDB1CA77468003CC1B0 /* TransmitterStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransmitterStatus.swift; sourceTree = "<group>"; };
43DC87BF1C8B509B005BC30D /* NSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = "<group>"; };
43DC87C11C8B520F005BC30D /* GlucoseRxMessageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlucoseRxMessageTests.swift; sourceTree = "<group>"; };
43E3978A1D5668BD0028E321 /* CalibrationState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalibrationState.swift; sourceTree = "<group>"; };
43E3978C1D566AEA0028E321 /* HealthKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HealthKit.framework; path = System/Library/Frameworks/HealthKit.framework; sourceTree = SDKROOT; };
43E3978E1D566B170028E321 /* Glucose.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Glucose.swift; sourceTree = "<group>"; };
43E397901D5692080028E321 /* GlucoseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlucoseTests.swift; sourceTree = "<group>"; };
43E397921D56950C0028E321 /* HKUnit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HKUnit.swift; sourceTree = "<group>"; };
43EEA70F1D14DC0800CBBDA0 /* AESCrypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AESCrypt.h; sourceTree = "<group>"; };
43EEA7101D14DC0800CBBDA0 /* AESCrypt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AESCrypt.m; sourceTree = "<group>"; };
43F82BCB1D035AA4006F5DD7 /* TransmitterTimeRxMessageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransmitterTimeRxMessageTests.swift; sourceTree = "<group>"; };
Expand All @@ -114,6 +124,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
43E3978D1D566AEA0028E321 /* HealthKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -131,6 +142,7 @@
43CABDE91C3506F100005705 = {
isa = PBXGroup;
children = (
43E3978C1D566AEA0028E321 /* HealthKit.framework */,
43CABDF51C3506F100005705 /* xDripG5 */,
43CABE011C3506F100005705 /* xDripG5Tests */,
43CABDF41C3506F100005705 /* Products */,
Expand All @@ -149,24 +161,28 @@
43CABDF51C3506F100005705 /* xDripG5 */ = {
isa = PBXGroup;
children = (
43CABDF61C3506F100005705 /* xDripG5.h */,
43CABDF81C3506F100005705 /* Info.plist */,
43EEA70F1D14DC0800CBBDA0 /* AESCrypt.h */,
43EEA7101D14DC0800CBBDA0 /* AESCrypt.m */,
43CABE0E1C350B2800005705 /* BluetoothManager.swift */,
43CABE0F1C350B2800005705 /* BluetoothServices.swift */,
43E3978A1D5668BD0028E321 /* CalibrationState.swift */,
43E3978E1D566B170028E321 /* Glucose.swift */,
43E397921D56950C0028E321 /* HKUnit.swift */,
43CABDF81C3506F100005705 /* Info.plist */,
43CABE101C350B2800005705 /* NSData.swift */,
430D64C41CB7846A00FCA750 /* NSData+CRC.swift */,
43CABE111C350B2800005705 /* Transmitter.swift */,
43CE7CDB1CA77468003CC1B0 /* TransmitterStatus.swift */,
43CABDF61C3506F100005705 /* xDripG5.h */,
43CABE161C350B2E00005705 /* Messages */,
43EEA70F1D14DC0800CBBDA0 /* AESCrypt.h */,
43EEA7101D14DC0800CBBDA0 /* AESCrypt.m */,
);
path = xDripG5;
sourceTree = "<group>";
};
43CABE011C3506F100005705 /* xDripG5Tests */ = {
isa = PBXGroup;
children = (
43E397901D5692080028E321 /* GlucoseTests.swift */,
43DC87C11C8B520F005BC30D /* GlucoseRxMessageTests.swift */,
43CABE041C3506F100005705 /* Info.plist */,
43DC87BF1C8B509B005BC30D /* NSData.swift */,
Expand Down Expand Up @@ -316,13 +332,15 @@
buildActionMask = 2147483647;
files = (
43CE7CCA1CA73B94003CC1B0 /* TransmitterVersionTxMessage.swift in Sources */,
43E3978B1D5668BD0028E321 /* CalibrationState.swift in Sources */,
43CABE2D1C350B3D00005705 /* TransmitterTimeRxMessage.swift in Sources */,
43CABE291C350B3D00005705 /* GlucoseRxMessage.swift in Sources */,
43CE7CDC1CA77468003CC1B0 /* TransmitterStatus.swift in Sources */,
43CABE271C350B3D00005705 /* BondRequestTxMessage.swift in Sources */,
43CABE231C350B3D00005705 /* AuthChallengeRxMessage.swift in Sources */,
43CABE261C350B3D00005705 /* AuthStatusRxMessage.swift in Sources */,
43CE7CD41CA73CE8003CC1B0 /* GlucoseHistoryTxMessage.swift in Sources */,
43E397931D56950C0028E321 /* HKUnit.swift in Sources */,
43CE7CD01CA73C57003CC1B0 /* SessionStopTxMessage.swift in Sources */,
43CABE2A1C350B3D00005705 /* GlucoseTxMessage.swift in Sources */,
43CE7CC81CA73AEB003CC1B0 /* FirmwareVersionTxMessage.swift in Sources */,
Expand All @@ -332,6 +350,7 @@
43CABE2E1C350B3D00005705 /* TransmitterTimeTxMessage.swift in Sources */,
43CABE2C1C350B3D00005705 /* TransmitterMessage.swift in Sources */,
43CABE131C350B2800005705 /* BluetoothServices.swift in Sources */,
43E3978F1D566B170028E321 /* Glucose.swift in Sources */,
43CABE151C350B2800005705 /* Transmitter.swift in Sources */,
43CABE281C350B3D00005705 /* DisconnectTxMessage.swift in Sources */,
43CABE141C350B2800005705 /* NSData.swift in Sources */,
Expand All @@ -354,6 +373,7 @@
43F82BD41D037227006F5DD7 /* SessionStartRxMessageTests.swift in Sources */,
43DC87C01C8B509B005BC30D /* NSData.swift in Sources */,
43F82BD21D037040006F5DD7 /* SessionStopRxMessageTests.swift in Sources */,
43E397911D5692080028E321 /* GlucoseTests.swift in Sources */,
43DC87C21C8B520F005BC30D /* GlucoseRxMessageTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -388,7 +408,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 11;
CURRENT_PROJECT_VERSION = 12;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -436,7 +456,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 11;
CURRENT_PROJECT_VERSION = 12;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -464,7 +484,7 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 11;
DYLIB_CURRENT_VERSION = 12;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = xDripG5/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -482,7 +502,7 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 11;
DYLIB_CURRENT_VERSION = 12;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = xDripG5/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand Down
35 changes: 23 additions & 12 deletions xDripG5/BluetoothManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,17 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate

private var manager: CBCentralManager! = nil

private var peripheral: CBPeripheral?
private var peripheral: CBPeripheral? {
didSet {
if let oldValue = oldValue {
oldValue.delegate = nil
}

if let newValue = peripheral {
newValue.delegate = self
}
}
}

// MARK: - GCD Management

Expand All @@ -91,12 +101,18 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
return
}

manager.scanForPeripheralsWithServices(
[
CBUUID(string: TransmitterServiceUUID.Advertisement.rawValue)
],
options: nil
)
if let peripheral = manager.retrieveConnectedPeripheralsWithServices([
CBUUID(string: TransmitterServiceUUID.Advertisement.rawValue),
CBUUID(string: TransmitterServiceUUID.CGMService.rawValue)
]).first where delegate == nil || delegate!.bluetoothManager(self, shouldConnectPeripheral: peripheral) {
self.peripheral = peripheral
} else {
manager.scanForPeripheralsWithServices([
CBUUID(string: TransmitterServiceUUID.Advertisement.rawValue)
],
options: nil
)
}

if let peripheral = self.peripheral {
self.manager.connectPeripheral(peripheral, options: nil)
Expand Down Expand Up @@ -313,17 +329,14 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
for peripheral in peripherals {
if delegate == nil || delegate!.bluetoothManager(self, shouldConnectPeripheral: peripheral) {
self.peripheral = peripheral
peripheral.delegate = self
}
}
}
}

func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {

if delegate == nil || delegate!.bluetoothManager(self, shouldConnectPeripheral: peripheral) {
self.peripheral = peripheral
peripheral.delegate = self

central.connectPeripheral(peripheral, options: nil)

Expand All @@ -348,14 +361,12 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
}

func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) {

if stayConnected {
scanAfterDelay()
}
}

func centralManager(central: CBCentralManager, didFailToConnectPeripheral peripheral: CBPeripheral, error: NSError?) {

if stayConnected {
scanAfterDelay()
}
Expand Down
Loading