Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import app.aaps.core.utils.toHex
import app.aaps.pump.omnipod.dash.driver.comm.io.CharacteristicType.Companion.byValue
import app.aaps.pump.omnipod.dash.driver.comm.io.IncomingPackets
import app.aaps.pump.omnipod.dash.driver.comm.session.DisconnectHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.util.UUID
import java.util.concurrent.BlockingQueue
import java.util.concurrent.CountDownLatch
Expand Down Expand Up @@ -38,7 +42,14 @@ class BleCommCallbacks(
aapsLogger.debug(LTag.PUMPBTCOMM, "OnConnectionStateChange with status/state: $status/$newState")
super.onConnectionStateChange(gatt, status, newState)
if (newState == BluetoothProfile.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) {
connected.countDown()
aapsLogger.debug(LTag.PUMPBTCOMM, "OnConnectionStateChange delaying gattConnected event by $SLEEP_AFTER_CONNECT_GATT ms")
CoroutineScope(Dispatchers.IO).launch {
// give GATT a chance to configure encryption, race condition bt stack.
delay(SLEEP_AFTER_CONNECT_GATT)
aapsLogger.debug(LTag.PUMPBTCOMM, "OnConnectionStateChange now delivering gattConnected")

connected.countDown()
}
}
if (newState == BluetoothProfile.STATE_DISCONNECTED) {
// If status == SUCCESS, it means that we initiated the disconnect.
Expand Down Expand Up @@ -225,5 +236,7 @@ class BleCommCallbacks(
companion object {

private const val WRITE_CONFIRM_TIMEOUT_MS = 10 // the confirmation queue should be empty anyway

const val SLEEP_AFTER_CONNECT_GATT = 1000L
}
}