From 6a922bf535c08eec1e669f0935ced3d5e1e55f15 Mon Sep 17 00:00:00 2001 From: jbr7rr <> Date: Thu, 17 Aug 2023 09:06:25 +0200 Subject: [PATCH] Medtrum: Handle turning BLE off during connection --- .../pump/medtrum/services/MedtrumService.kt | 15 +++++++++++++-- .../ui/viewmodel/MedtrumOverviewViewModel.kt | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt index d90c51fa5a..75b36b0097 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt @@ -164,8 +164,19 @@ class MedtrumService : DaggerService(), BLECommCallback { if (currentState is IdleState) { medtrumPump.connectionState = ConnectionState.CONNECTING return bleComm.connect(from, medtrumPump.pumpSN) + } else if (currentState is ReadyState) { + aapsLogger.error(LTag.PUMPCOMM, "Connect attempt when in ReadyState from: $from") + if (isConnected) { + aapsLogger.debug(LTag.PUMP, "connect: already connected") + return true + } else { + aapsLogger.debug(LTag.PUMP, "connect: not connected, resetting state and trying to connect") + toState(IdleState()) + medtrumPump.connectionState = ConnectionState.CONNECTING + return bleComm.connect(from, medtrumPump.pumpSN) + } } else { - aapsLogger.error(LTag.PUMPCOMM, "Connect attempt when in non Idle state from: $from") + aapsLogger.error(LTag.PUMPCOMM, "Connect attempt when in state: $currentState from: $from") return false } } @@ -650,7 +661,7 @@ class MedtrumService : DaggerService(), BLECommCallback { result = currentState.waitForResponse(timeout) SystemClock.sleep(100) } else { - aapsLogger.error(LTag.PUMPCOMM, "Send packet attempt when in non Ready state") + aapsLogger.error(LTag.PUMPCOMM, "Send packet attempt when in state: $currentState") } return result } diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt index 1cd1de8a95..c1b170ad76 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt @@ -103,7 +103,7 @@ class MedtrumOverviewViewModel @Inject constructor( ConnectionState.DISCONNECTING -> { _bleStatus.postValue("{fa-bluetooth-b spin}") - _canDoRefresh.postValue(false) + _canDoRefresh.postValue(true) } } updateGUI()