fixes:
- closeGatt on stopConnecting - fix stopBolus
This commit is contained in:
parent
f9aa967b46
commit
bf7ad8e697
|
@ -78,6 +78,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
commandQueue: CommandQueueProvider
|
||||
) : PumpPluginBase(pluginDescription, injector, aapsLogger, resourceHelper, commandQueue), Pump {
|
||||
@Volatile var bolusCanceled = false
|
||||
@Volatile var bolusDeliveryInProgress = false
|
||||
|
||||
private val handler: Handler = Handler(Looper.getMainLooper())
|
||||
private lateinit var statusChecker: Runnable
|
||||
var nextPodWarningCheck: Long = 0
|
||||
|
@ -232,12 +234,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
override fun disconnect(reason: String) {
|
||||
aapsLogger.info(LTag.PUMP, "disconnect reason=$reason")
|
||||
stopConnecting?.let { it.countDown() }
|
||||
omnipodManager.disconnect()
|
||||
omnipodManager.disconnect(false)
|
||||
}
|
||||
|
||||
override fun stopConnecting() {
|
||||
aapsLogger.info(LTag.PUMP, "stopConnecting")
|
||||
stopConnecting?.let { it.countDown() }
|
||||
omnipodManager.disconnect(true)
|
||||
}
|
||||
|
||||
override fun getPumpStatus(reason: String) {
|
||||
|
@ -476,6 +479,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
try {
|
||||
bolusDeliveryInProgress = true
|
||||
aapsLogger.info(LTag.PUMP, "Delivering treatment: $detailedBolusInfo $bolusCanceled")
|
||||
val beepsConfigurationKey = if (detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB)
|
||||
R.string.key_omnipod_common_smb_beeps_enabled
|
||||
|
@ -563,6 +567,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
return ret
|
||||
} finally {
|
||||
bolusCanceled = false
|
||||
bolusDeliveryInProgress = false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -697,7 +702,9 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
|
||||
override fun stopBolusDelivering() {
|
||||
aapsLogger.info(LTag.PUMP, "stopBolusDelivering called")
|
||||
bolusCanceled = true
|
||||
if (bolusDeliveryInProgress) {
|
||||
bolusCanceled = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun setTempBasalAbsolute(
|
||||
|
|
|
@ -41,7 +41,7 @@ interface OmnipodDashManager {
|
|||
|
||||
fun deactivatePod(): Observable<PodEvent>
|
||||
|
||||
fun disconnect()
|
||||
fun disconnect(closeGatt: Boolean=false)
|
||||
|
||||
fun connect(stop: CountDownLatch): Observable<PodEvent>
|
||||
}
|
||||
|
|
|
@ -78,8 +78,8 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun disconnect() {
|
||||
bleManager.disconnect()
|
||||
override fun disconnect(closeGatt: Boolean) {
|
||||
bleManager.disconnect(closeGatt)
|
||||
}
|
||||
|
||||
override fun connect(stop: CountDownLatch): Observable<PodEvent> {
|
||||
|
|
|
@ -23,5 +23,5 @@ interface OmnipodDashBleManager {
|
|||
|
||||
fun pairNewPod(): Observable<PodEvent>
|
||||
|
||||
fun disconnect()
|
||||
fun disconnect(closeGatt: Boolean=false)
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
}
|
||||
emitter.onComplete()
|
||||
} catch (ex: Exception) {
|
||||
disconnect()
|
||||
disconnect(false)
|
||||
emitter.tryOnError(ex)
|
||||
} finally {
|
||||
busy.set(false)
|
||||
|
@ -142,7 +142,7 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
|
||||
emitter.onComplete()
|
||||
} catch (ex: Exception) {
|
||||
disconnect()
|
||||
disconnect(false)
|
||||
emitter.tryOnError(ex)
|
||||
} finally {
|
||||
busy.set(false)
|
||||
|
@ -226,15 +226,15 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
emitter.onNext(PodEvent.Connected)
|
||||
emitter.onComplete()
|
||||
} catch (ex: Exception) {
|
||||
disconnect()
|
||||
disconnect(false)
|
||||
emitter.tryOnError(ex)
|
||||
} finally {
|
||||
busy.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun disconnect() {
|
||||
connection?.disconnect()
|
||||
override fun disconnect(closeGatt: Boolean) {
|
||||
connection?.disconnect(closeGatt)
|
||||
?: aapsLogger.info(LTag.PUMPBTCOMM, "Trying to disconnect a null connection")
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@ class BleCommCallbacks(
|
|||
if (newState == BluetoothProfile.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) {
|
||||
connected.countDown()
|
||||
}
|
||||
if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
||||
if (newState == BluetoothProfile.STATE_DISCONNECTED && status != BluetoothGatt.GATT_SUCCESS ) {
|
||||
// If status == SUCCESS, it means that we initiated the disconnect.
|
||||
disconnectHandler.onConnectionLost(status)
|
||||
}
|
||||
}
|
||||
|
@ -54,12 +55,13 @@ class BleCommCallbacks(
|
|||
}
|
||||
|
||||
fun waitForConnection(timeoutMs: Long): Boolean {
|
||||
val latch = connected
|
||||
try {
|
||||
connected.await(timeoutMs, TimeUnit.MILLISECONDS)
|
||||
latch.await(timeoutMs, TimeUnit.MILLISECONDS)
|
||||
} catch (e: InterruptedException) {
|
||||
aapsLogger.warn(LTag.PUMPBTCOMM, "Interrupted while waiting for Connection")
|
||||
}
|
||||
return connected.count == 0L
|
||||
return latch.count == 0L
|
||||
}
|
||||
|
||||
fun startServiceDiscovery() {
|
||||
|
@ -67,12 +69,13 @@ class BleCommCallbacks(
|
|||
}
|
||||
|
||||
fun waitForServiceDiscovery(timeoutMs: Long): Boolean {
|
||||
val latch = serviceDiscoveryComplete
|
||||
try {
|
||||
serviceDiscoveryComplete.await(timeoutMs, TimeUnit.MILLISECONDS)
|
||||
latch.await(timeoutMs, TimeUnit.MILLISECONDS)
|
||||
} catch (e: InterruptedException) {
|
||||
aapsLogger.warn(LTag.PUMPBTCOMM, "Interrupted while waiting for ServiceDiscovery")
|
||||
}
|
||||
return serviceDiscoveryComplete.count == 0L
|
||||
return latch.count == 0L
|
||||
}
|
||||
|
||||
fun confirmWrite(expectedPayload: ByteArray, expectedUUID: String, timeoutMs: Long): WriteConfirmation {
|
||||
|
@ -208,6 +211,8 @@ class BleCommCallbacks(
|
|||
|
||||
fun resetConnection() {
|
||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Reset connection")
|
||||
connected?.countDown()
|
||||
serviceDiscoveryComplete?.countDown()
|
||||
connected = CountDownLatch(1)
|
||||
serviceDiscoveryComplete = CountDownLatch(1)
|
||||
flushConfirmationQueue()
|
||||
|
|
|
@ -63,7 +63,7 @@ class Connection(
|
|||
var msgIO: MessageIO? = null
|
||||
|
||||
fun connect(connectionWaitCond: ConnectionWaitCondition) {
|
||||
aapsLogger.debug("Connecting")
|
||||
aapsLogger.debug("Connecting connectionWaitCond=$connectionWaitCond")
|
||||
|
||||
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING
|
||||
val autoConnect = false
|
||||
|
@ -115,11 +115,15 @@ class Connection(
|
|||
dataBleIO.readyToRead()
|
||||
}
|
||||
|
||||
fun disconnect() {
|
||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Disconnecting")
|
||||
fun disconnect(closeGatt: Boolean) {
|
||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Disconnecting closeGatt=$closeGatt")
|
||||
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED
|
||||
|
||||
gattConnection?.disconnect()
|
||||
if (closeGatt) {
|
||||
gattConnection?.close()
|
||||
gattConnection = null
|
||||
} else {
|
||||
gattConnection?.disconnect()
|
||||
}
|
||||
bleCommCallbacks.resetConnection()
|
||||
session = null
|
||||
msgIO = null
|
||||
|
@ -186,7 +190,7 @@ class Connection(
|
|||
// This will be called from a different thread !!!
|
||||
override fun onConnectionLost(status: Int) {
|
||||
aapsLogger.info(LTag.PUMPBTCOMM, "Lost connection with status: $status")
|
||||
disconnect()
|
||||
disconnect(false)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
Loading…
Reference in a new issue