Medtrum: Handle turning BLE off during connection

This commit is contained in:
jbr7rr 2023-08-17 09:06:25 +02:00
parent 0c38967c00
commit 6a922bf535
2 changed files with 14 additions and 3 deletions

View file

@ -164,8 +164,19 @@ class MedtrumService : DaggerService(), BLECommCallback {
if (currentState is IdleState) { if (currentState is IdleState) {
medtrumPump.connectionState = ConnectionState.CONNECTING medtrumPump.connectionState = ConnectionState.CONNECTING
return bleComm.connect(from, medtrumPump.pumpSN) 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 { } 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 return false
} }
} }
@ -650,7 +661,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
result = currentState.waitForResponse(timeout) result = currentState.waitForResponse(timeout)
SystemClock.sleep(100) SystemClock.sleep(100)
} else { } 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 return result
} }

View file

@ -103,7 +103,7 @@ class MedtrumOverviewViewModel @Inject constructor(
ConnectionState.DISCONNECTING -> { ConnectionState.DISCONNECTING -> {
_bleStatus.postValue("{fa-bluetooth-b spin}") _bleStatus.postValue("{fa-bluetooth-b spin}")
_canDoRefresh.postValue(false) _canDoRefresh.postValue(true)
} }
} }
updateGUI() updateGUI()