Only show reset alarms when it's needed
This commit is contained in:
parent
592a45612c
commit
b3a83a720d
3 changed files with 22 additions and 31 deletions
|
@ -225,7 +225,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
if (needLoadHistory) {
|
if (needLoadHistory) {
|
||||||
if (result) result = loadEvents()
|
if (result) result = loadEvents()
|
||||||
}
|
}
|
||||||
if (result) medtrumPump.needCheckTimeUpdate = false
|
if (result) medtrumPump.needCheckTimeUpdate = false
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,15 +238,18 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
medtrumPump.lastConnection = System.currentTimeMillis()
|
medtrumPump.lastConnection = System.currentTimeMillis()
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.error(LTag.PUMPCOMM, "Failed to load events")
|
aapsLogger.error(LTag.PUMPCOMM, "Failed to load events")
|
||||||
// TODO: remove me before release
|
|
||||||
fabricPrivacy.logMessage("Medtrum LoadEvents: Failed to load events")
|
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearAlarms(): Boolean {
|
fun clearAlarms(): Boolean {
|
||||||
var result = true
|
var result = true
|
||||||
if (medtrumPump.activeAlarms.isNotEmpty()) {
|
if (medtrumPump.pumpState in listOf(
|
||||||
|
MedtrumPumpState.PAUSED,
|
||||||
|
MedtrumPumpState.HMAX_SUSPENDED,
|
||||||
|
MedtrumPumpState.DMAX_SUSPENDED
|
||||||
|
)
|
||||||
|
) {
|
||||||
when (medtrumPump.pumpState) {
|
when (medtrumPump.pumpState) {
|
||||||
MedtrumPumpState.HMAX_SUSPENDED -> {
|
MedtrumPumpState.HMAX_SUSPENDED -> {
|
||||||
result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, ALARM_HOURLY_MAX_CLEAR_CODE))
|
result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, ALARM_HOURLY_MAX_CLEAR_CODE))
|
||||||
|
@ -257,26 +260,12 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
// TODO: Remove me before release!!!
|
// Nothing to reset
|
||||||
// Try to brute force the commands
|
|
||||||
aapsLogger.warn(LTag.PUMPCOMM, "Trying to clear alarms brutus!")
|
|
||||||
for (i in 0..100) {
|
|
||||||
result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, i))
|
|
||||||
if (result) {
|
|
||||||
aapsLogger.warn(LTag.PUMPCOMM, "Alarm cleared: $i")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
SystemClock.sleep(50)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// Resume suspended pump
|
||||||
// Resume suspended pump
|
|
||||||
if (medtrumPump.pumpState in listOf(MedtrumPumpState.LOWBG_SUSPENDED, MedtrumPumpState.PAUSED)) {
|
|
||||||
if (result) result = sendPacketAndGetResponse(ResumePumpPacket(injector))
|
if (result) result = sendPacketAndGetResponse(ResumePumpPacket(injector))
|
||||||
}
|
}
|
||||||
if (result) result = sendPacketAndGetResponse(ResumePumpPacket(injector))
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,7 +684,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
// Check if we have a supported pump
|
// Check if we have a supported pump
|
||||||
if (medtrumPump.pumpType() == PumpType.MEDTRUM_UNTESTED) {
|
if (medtrumPump.pumpType() == PumpType.MEDTRUM_UNTESTED) {
|
||||||
// Throw error
|
// Throw error
|
||||||
aapsLogger.error(LTag.PUMPCOMM, "Unsupported pump type")
|
aapsLogger.error(LTag.PUMPCOMM, "Unsupported pump type")
|
||||||
uiInteraction.addNotificationWithSound(
|
uiInteraction.addNotificationWithSound(
|
||||||
Notification.PUMP_ERROR,
|
Notification.PUMP_ERROR,
|
||||||
|
|
|
@ -107,11 +107,12 @@ class MedtrumOverviewViewModel @Inject constructor(
|
||||||
scope.launch {
|
scope.launch {
|
||||||
medtrumPump.pumpStateFlow.collect { state ->
|
medtrumPump.pumpStateFlow.collect { state ->
|
||||||
aapsLogger.debug(LTag.PUMP, "MedtrumViewModel pumpStateFlow: $state")
|
aapsLogger.debug(LTag.PUMP, "MedtrumViewModel pumpStateFlow: $state")
|
||||||
if (medtrumPump.pumpState > MedtrumPumpState.EJECTED && medtrumPump.pumpState < MedtrumPumpState.STOPPED) {
|
_canDoResetAlarms.postValue(
|
||||||
_canDoResetAlarms.postValue(true)
|
medtrumPump.pumpState in listOf(
|
||||||
} else {
|
MedtrumPumpState.PAUSED, MedtrumPumpState.HMAX_SUSPENDED, MedtrumPumpState.DMAX_SUSPENDED
|
||||||
_canDoResetAlarms.postValue(false)
|
)
|
||||||
}
|
)
|
||||||
|
|
||||||
updateGUI()
|
updateGUI()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,13 +162,10 @@ class MedtrumOverviewViewModel @Inject constructor(
|
||||||
// max 6h back
|
// max 6h back
|
||||||
_lastBolus.postValue(
|
_lastBolus.postValue(
|
||||||
dateUtil.timeString(medtrumPump.lastBolusTime) + " " + dateUtil.sinceString(medtrumPump.lastBolusTime, rh) + " " + rh.gs(
|
dateUtil.timeString(medtrumPump.lastBolusTime) + " " + dateUtil.sinceString(medtrumPump.lastBolusTime, rh) + " " + rh.gs(
|
||||||
info.nightscout.interfaces.R.string
|
info.nightscout.interfaces.R.string.format_insulin_units, medtrumPump.lastBolusAmount
|
||||||
.format_insulin_units, medtrumPump
|
|
||||||
.lastBolusAmount
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else
|
else _lastBolus.postValue("")
|
||||||
_lastBolus.postValue("")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val activeAlarmStrings = medtrumPump.activeAlarms.map { medtrumPump.alarmStateToString(it) }
|
val activeAlarmStrings = medtrumPump.activeAlarms.map { medtrumPump.alarmStateToString(it) }
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
<variable
|
<variable
|
||||||
name="viewmodel"
|
name="viewmodel"
|
||||||
type="info.nightscout.pump.medtrum.ui.viewmodel.MedtrumOverviewViewModel" />
|
type="info.nightscout.pump.medtrum.ui.viewmodel.MedtrumOverviewViewModel" />
|
||||||
|
|
||||||
|
<import type="android.view.View" />
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
@ -645,6 +648,7 @@
|
||||||
android:enabled="@{viewmodel.canDoResetAlarms}"
|
android:enabled="@{viewmodel.canDoResetAlarms}"
|
||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
android:text="@string/reset_alarms_label"
|
android:text="@string/reset_alarms_label"
|
||||||
|
android:visibility="@{viewmodel.canDoResetAlarms ? View.VISIBLE : View.GONE}"
|
||||||
app:onSafeClick="@{() -> viewmodel.onClickResetAlarms()}" />
|
app:onSafeClick="@{() -> viewmodel.onClickResetAlarms()}" />
|
||||||
|
|
||||||
<!-- Change Patch button -->
|
<!-- Change Patch button -->
|
||||||
|
|
Loading…
Reference in a new issue