Skip to content

Commit

Permalink
Update Connection.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
jgslade authored Jun 28, 2023
1 parent 77de1af commit 313f0d6
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class Connection(
connectionWaitCond.timeoutMs = newTimeout
}
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTED
_connectionWaitCond = null

val discoverer = ServiceDiscoverer(aapsLogger, gatt, bleCommCallbacks, this)
val discovered = discoverer.discoverServices(connectionWaitCond)
Expand All @@ -122,21 +121,24 @@ class Connection(
cmdBleIO.hello()
cmdBleIO.readyToRead()
dataBleIO.readyToRead()
_connectionWaitCond = null
}

@Synchronized
fun disconnect(closeGatt: Boolean) {
aapsLogger.debug(LTag.PUMPBTCOMM, "Disconnecting closeGatt=$closeGatt")
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED
if (closeGatt) {
if (closeGatt == false && gattConnection != null) {
// Disconnect first, then close gatt
gattConnection?.disconnect()
} else {
// Call with closeGatt=true only when ble is already disconnected or there is no connection
gattConnection?.close()
bleCommCallbacks.resetConnection()
gattConnection = null
} else {
gattConnection?.disconnect()
session = null
msgIO = null
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED
}
bleCommCallbacks.resetConnection()
session = null
msgIO = null
}

private fun waitForConnection(connectionWaitCond: ConnectionWaitCondition): ConnectionState {
Expand Down

0 comments on commit 313f0d6

Please sign in to comment.