Rescan when connection is lost during connecting
This commit is contained in:
parent
5a6d5b41d4
commit
d8427c6d56
1 changed files with 10 additions and 2 deletions
|
@ -195,14 +195,15 @@ class BLEComm @Inject internal constructor(
|
||||||
}
|
}
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from")
|
||||||
if (isConnecting) {
|
if (isConnecting) {
|
||||||
|
isConnecting = false
|
||||||
stopScan()
|
stopScan()
|
||||||
}
|
SystemClock.sleep(100)
|
||||||
|
}
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
mBluetoothGatt?.disconnect()
|
mBluetoothGatt?.disconnect()
|
||||||
} else {
|
} else {
|
||||||
close()
|
close()
|
||||||
isConnected = false
|
isConnected = false
|
||||||
isConnecting = false
|
|
||||||
mCallback?.onBLEDisconnected()
|
mCallback?.onBLEDisconnected()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -391,6 +392,13 @@ class BLEComm @Inject internal constructor(
|
||||||
isConnecting = false
|
isConnecting = false
|
||||||
mBluetoothGatt?.discoverServices()
|
mBluetoothGatt?.discoverServices()
|
||||||
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
||||||
|
if (isConnecting) {
|
||||||
|
// When we are disconnected during connecting, we reset the device address to force a new scan
|
||||||
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Disconnected while connecting! Reset device address")
|
||||||
|
mDevice = null
|
||||||
|
// Wait a bit before retrying
|
||||||
|
SystemClock.sleep(2000)
|
||||||
|
}
|
||||||
close()
|
close()
|
||||||
isConnected = false
|
isConnected = false
|
||||||
isConnecting = false
|
isConnecting = false
|
||||||
|
|
Loading…
Reference in a new issue