From d8427c6d566fd9d001e2bbe1171be358985b625a Mon Sep 17 00:00:00 2001 From: jbr7rr <> Date: Sun, 28 May 2023 10:27:13 +0200 Subject: [PATCH] Rescan when connection is lost during connecting --- .../info/nightscout/pump/medtrum/services/BLEComm.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/BLEComm.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/BLEComm.kt index 7a70987256..3ff7d00acb 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/BLEComm.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/BLEComm.kt @@ -195,14 +195,15 @@ class BLEComm @Inject internal constructor( } aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from") if (isConnecting) { + isConnecting = false stopScan() - } + SystemClock.sleep(100) + } if (isConnected) { mBluetoothGatt?.disconnect() } else { close() isConnected = false - isConnecting = false mCallback?.onBLEDisconnected() } } @@ -391,6 +392,13 @@ class BLEComm @Inject internal constructor( isConnecting = false mBluetoothGatt?.discoverServices() } 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() isConnected = false isConnecting = false