Skip to content
Closed
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: 3 additions & 1 deletion Example/xDripG5/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

transmitter?.resumeScanning()
if let transmitter = transmitter , !transmitter.stayConnected {
transmitter.resumeScanning()
}
}

func applicationWillTerminate(_ application: UIApplication) {
Expand Down
2 changes: 1 addition & 1 deletion xDripG5/BluetoothManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class BluetoothManager: NSObject {
#endif

if let peripheralID = self.peripheral?.identifier, let peripheral = manager.retrievePeripherals(withIdentifiers: [peripheralID]).first {
log.info("Re-connecting to known peripheral %{public}@ in %zds", peripheral.identifier.uuidString, delay)
log.info("Re-connecting to known peripheral %{public}@ in %.1f s", peripheral.identifier.uuidString, delay)
self.peripheral = peripheral
self.manager.connect(peripheral, options: connectOptions)
} else if let peripheral = manager.retrieveConnectedPeripherals(withServices: [
Expand Down
6 changes: 4 additions & 2 deletions xDripG5/PeripheralManager+G5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ extension PeripheralManager {
peripheral.writeValue(value, for: characteristic, type: type)
}

guard let value = characteristic.value else {
let value = characteristic.value

guard !characteristic.isNotifying || value != nil else {
// TODO: This is an "unknown value" issue, not a timeout
throw PeripheralManagerError.timeout
}

return value
return value ?? Data()
}
}

Expand Down
14 changes: 2 additions & 12 deletions xDripG5/Transmitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,27 +247,17 @@ fileprivate extension PeripheralManager {
throw TransmitterError.authenticationError("Error writing keep-alive for bond: \(error)")
}

let data: Data
do {
// Wait for the OS dialog to pop-up before continuing.
_ = try writeValue(BondRequestTxMessage().data, for: .authentication)
data = try readValue(for: .authentication, timeout: 15, expectingFirstByte: AuthStatusRxMessage.opcode)
} catch let error {
throw TransmitterError.authenticationError("Error writing bond request: \(error)")
}

guard let response = AuthStatusRxMessage(data: data) else {
throw TransmitterError.authenticationError("Unable to parse auth status: \(data)")
}

guard response.bonded == 0x1 else {
throw TransmitterError.authenticationError("Transmitter failed to bond")
}
}

func control() throws -> Glucose {
do {
try setNotifyValue(true, for: .control)
// Wait for up to 15s for the user to respond to the pairing request.
try setNotifyValue(true, for: .control, timeout: 15)
} catch let error {
throw TransmitterError.controlError("Error enabling notification: \(error)")
}
Expand Down