combov2: Consider pump as uninitialized for a while after an error occurred
Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
parent
b39f5a3672
commit
6b989ec7aa
3 changed files with 57 additions and 2 deletions
|
@ -41,6 +41,7 @@ class ComboV2Fragment : DaggerFragment() {
|
||||||
|
|
||||||
binding.combov2RefreshButton.setOnClickListener {
|
binding.combov2RefreshButton.setOnClickListener {
|
||||||
binding.combov2RefreshButton.isEnabled = false
|
binding.combov2RefreshButton.isEnabled = false
|
||||||
|
combov2Plugin.clearPumpErrorObservedFlag()
|
||||||
commandQueue.readStatus(rh.gs(info.nightscout.core.ui.R.string.user_request), null)
|
commandQueue.readStatus(rh.gs(info.nightscout.core.ui.R.string.user_request), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,8 @@ import info.nightscout.comboctl.base.Tbr as ComboCtlTbr
|
||||||
import info.nightscout.comboctl.main.Pump as ComboCtlPump
|
import info.nightscout.comboctl.main.Pump as ComboCtlPump
|
||||||
import info.nightscout.comboctl.main.PumpManager as ComboCtlPumpManager
|
import info.nightscout.comboctl.main.PumpManager as ComboCtlPumpManager
|
||||||
|
|
||||||
|
internal const val PUMP_ERROR_TIMEOUT_INTERVAL_MSECS = 1000L * 60 * 5
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ComboV2Plugin @Inject constructor (
|
class ComboV2Plugin @Inject constructor (
|
||||||
injector: HasAndroidInjector,
|
injector: HasAndroidInjector,
|
||||||
|
@ -161,6 +163,13 @@ class ComboV2Plugin @Inject constructor (
|
||||||
private var lastConnectionTimestamp = 0L
|
private var lastConnectionTimestamp = 0L
|
||||||
private var lastComboAlert: AlertScreenContent? = null
|
private var lastComboAlert: AlertScreenContent? = null
|
||||||
|
|
||||||
|
// States for when the pump reports an error. We then want isInitialized()
|
||||||
|
// to return false until either the user presses the Refresh button or the
|
||||||
|
// pumpErrorTimeoutJob expires. That way, the loop won't run until then,
|
||||||
|
// giving the user a chance to handle the error.
|
||||||
|
private var pumpErrorObserved = false
|
||||||
|
private var pumpErrorTimeoutJob: Job? = null
|
||||||
|
|
||||||
// Set to true if a disconnect request came in while the driver
|
// Set to true if a disconnect request came in while the driver
|
||||||
// was in the Connecting, CheckingPump, or ExecutingCommand
|
// was in the Connecting, CheckingPump, or ExecutingCommand
|
||||||
// state (in other words, while isBusy() was returning true).
|
// state (in other words, while isBusy() was returning true).
|
||||||
|
@ -183,7 +192,7 @@ class ComboV2Plugin @Inject constructor (
|
||||||
private var activeBasalProfile: BasalProfile? = null
|
private var activeBasalProfile: BasalProfile? = null
|
||||||
// This is used for checking that the correct basal profile is
|
// This is used for checking that the correct basal profile is
|
||||||
// active in the Combo. If not, loop invocation is disallowed.
|
// active in the Combo. If not, loop invocation is disallowed.
|
||||||
// This is _not_ reset by disconect(). That's on purpose; it
|
// This is _not_ reset by disconnect(). That's on purpose; it
|
||||||
// is read by isLoopInvocationAllowed(), which is called even
|
// is read by isLoopInvocationAllowed(), which is called even
|
||||||
// if the pump is not connected.
|
// if the pump is not connected.
|
||||||
private var lastActiveBasalProfileNumber: Int? = null
|
private var lastActiveBasalProfileNumber: Int? = null
|
||||||
|
@ -381,7 +390,7 @@ class ComboV2Plugin @Inject constructor (
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isInitialized(): Boolean =
|
override fun isInitialized(): Boolean =
|
||||||
isPaired() && (driverStateFlow.value != DriverState.NotInitialized)
|
isPaired() && (driverStateFlow.value != DriverState.NotInitialized) && !pumpErrorObserved
|
||||||
|
|
||||||
override fun isSuspended(): Boolean =
|
override fun isSuspended(): Boolean =
|
||||||
when (driverStateUIFlow.value) {
|
when (driverStateUIFlow.value) {
|
||||||
|
@ -432,6 +441,16 @@ class ComboV2Plugin @Inject constructor (
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pumpErrorObserved) {
|
||||||
|
aapsLogger.debug(LTag.PUMP, "Aborting connect attempt since the pumpErrorObserved flag is set")
|
||||||
|
uiInteraction.addNotification(
|
||||||
|
Notification.COMBO_PUMP_ALARM,
|
||||||
|
text = rh.gs(R.string.combov2_cannot_connect_pump_error_observed),
|
||||||
|
level = Notification.NORMAL
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
when (driverStateFlow.value) {
|
when (driverStateFlow.value) {
|
||||||
DriverState.Connecting,
|
DriverState.Connecting,
|
||||||
DriverState.CheckingPump,
|
DriverState.CheckingPump,
|
||||||
|
@ -1398,6 +1417,14 @@ class ComboV2Plugin @Inject constructor (
|
||||||
commandQueue.readStatus(reason, null)
|
commandQueue.readStatus(reason, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clearPumpErrorObservedFlag() {
|
||||||
|
stopPumpErrorTimeout()
|
||||||
|
if (pumpErrorObserved) {
|
||||||
|
aapsLogger.info(LTag.PUMP, "Clearing pumpErrorObserved flag")
|
||||||
|
pumpErrorObserved = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*** Loop constraints ***/
|
/*** Loop constraints ***/
|
||||||
// These restrict the function of the loop in case of an event
|
// These restrict the function of the loop in case of an event
|
||||||
// that makes running a loop too risky, for example because something
|
// that makes running a loop too risky, for example because something
|
||||||
|
@ -1550,6 +1577,8 @@ class ComboV2Plugin @Inject constructor (
|
||||||
_serialNumberUIFlow.value = ""
|
_serialNumberUIFlow.value = ""
|
||||||
_bluetoothAddressUIFlow.value = ""
|
_bluetoothAddressUIFlow.value = ""
|
||||||
|
|
||||||
|
clearPumpErrorObservedFlag()
|
||||||
|
|
||||||
// The unpairing variable is set to false in
|
// The unpairing variable is set to false in
|
||||||
// the PumpManager onPumpUnpaired callback.
|
// the PumpManager onPumpUnpaired callback.
|
||||||
}
|
}
|
||||||
|
@ -1748,6 +1777,23 @@ class ComboV2Plugin @Inject constructor (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun startPumpErrorTimeout() {
|
||||||
|
if (pumpErrorTimeoutJob != null)
|
||||||
|
return
|
||||||
|
|
||||||
|
pumpErrorTimeoutJob = pumpCoroutineScope.launch {
|
||||||
|
delay(PUMP_ERROR_TIMEOUT_INTERVAL_MSECS)
|
||||||
|
aapsLogger.info(LTag.PUMP, "Clearing pumpErrorObserved flag after timeout was reached")
|
||||||
|
pumpErrorObserved = false
|
||||||
|
commandQueue.readStatus(rh.gs(R.string.combov2_refresh_pump_status_after_error), null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopPumpErrorTimeout() {
|
||||||
|
pumpErrorTimeoutJob?.cancel()
|
||||||
|
pumpErrorTimeoutJob = null
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateBaseBasalRateUI() {
|
private fun updateBaseBasalRateUI() {
|
||||||
val currentHour = DateTime().hourOfDay().get()
|
val currentHour = DateTime().hourOfDay().get()
|
||||||
// This sets value to null if no profile is set,
|
// This sets value to null if no profile is set,
|
||||||
|
@ -2142,6 +2188,12 @@ class ComboV2Plugin @Inject constructor (
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notifyAboutComboAlert(alert: AlertScreenContent) {
|
private fun notifyAboutComboAlert(alert: AlertScreenContent) {
|
||||||
|
if (alert is AlertScreenContent.Error) {
|
||||||
|
aapsLogger.info(LTag.PUMP, "Error screen observed - setting pumpErrorObserved flag")
|
||||||
|
pumpErrorObserved = true
|
||||||
|
startPumpErrorTimeout()
|
||||||
|
}
|
||||||
|
|
||||||
uiInteraction.addNotification(
|
uiInteraction.addNotification(
|
||||||
Notification.COMBO_PUMP_ALARM,
|
Notification.COMBO_PUMP_ALARM,
|
||||||
text = "${rh.gs(R.string.combov2_combo_alert)}: ${getAlertDescription(alert)}",
|
text = "${rh.gs(R.string.combov2_combo_alert)}: ${getAlertDescription(alert)}",
|
||||||
|
|
|
@ -135,4 +135,6 @@ buttons at the same time to cancel pairing)\n
|
||||||
<string name="combov2_datetime_changed">Date and/or time changed</string>
|
<string name="combov2_datetime_changed">Date and/or time changed</string>
|
||||||
<string name="combov2_dst_started">Daylight savings time (DST) started</string>
|
<string name="combov2_dst_started">Daylight savings time (DST) started</string>
|
||||||
<string name="combov2_dst_ended">Daylight savings time (DST) ended</string>
|
<string name="combov2_dst_ended">Daylight savings time (DST) ended</string>
|
||||||
|
<string name="combov2_cannot_connect_pump_error_observed">Cannot connect to pump because the pump reported an error. User must handle the error and then either wait 5 minutes or press the Refresh button in the driver tab.</string>
|
||||||
|
<string name="combov2_refresh_pump_status_after_error">Refreshing pump status after the pump reported an error</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue