Medtrum: Add active bolus to overview

This commit is contained in:
jbr7rr 2023-08-29 20:46:30 +02:00
parent a7d330e87f
commit ccda05e71c
5 changed files with 67 additions and 0 deletions

View file

@ -222,12 +222,16 @@ class MedtrumPump @Inject constructor(
var patchAge = 0L // Time in seconds?! // As reported by pump, not used (yet)
// bolus status
var bolusStartTime = 0L // Time in ms!
var bolusingTreatment: EventOverviewBolusProgress.Treatment? = null // actually delivered treatment
var bolusAmountToBeDelivered = 0.0 // amount to be delivered
var bolusProgressLastTimeStamp: Long = 0 // timestamp of last bolus progress message
var bolusStopped = false // bolus stopped by user
var bolusDone = false // Bolus completed or stopped on pump
private val _bolusAmountDelivered = MutableStateFlow(0.0)
val bolusAmountDeliveredFlow: StateFlow<Double> = _bolusAmountDelivered
// Last basal status update (from pump)
private var _lastBasalSequence = 0
val lastBasalSequence: Int
@ -358,6 +362,7 @@ class MedtrumPump @Inject constructor(
fun handleBolusStatusUpdate(bolusType: Int, bolusCompleted: Boolean, amountDelivered: Double) {
aapsLogger.debug(LTag.PUMP, "handleBolusStatusUpdate: bolusType: $bolusType bolusCompleted: $bolusCompleted amountDelivered: $amountDelivered")
bolusProgressLastTimeStamp = dateUtil.now()
_bolusAmountDelivered.value = amountDelivered
bolusingTreatment?.insulin = amountDelivered
bolusDone = bolusCompleted
}

View file

@ -333,6 +333,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
medtrumPump.bolusAmountToBeDelivered = insulin
medtrumPump.bolusStopped = false
medtrumPump.bolusProgressLastTimeStamp = bolusStart
medtrumPump.bolusStartTime = bolusStart
detailedBolusInfo.timestamp = bolusStart // Make sure the timestamp is set to the start of the bolus
detailedBolusInfoStorage.add(detailedBolusInfo) // will be picked up on reading history

View file

@ -77,6 +77,10 @@ class MedtrumOverviewViewModel @Inject constructor(
val patchExpiry: LiveData<String>
get() = _patchExpiry
private val _activeBolusStatus = SingleLiveEvent<String>()
val activeBolusStatus: LiveData<String>
get() = _activeBolusStatus
init {
scope.launch {
medtrumPump.connectionStateFlow.collect { state ->
@ -121,6 +125,19 @@ class MedtrumOverviewViewModel @Inject constructor(
updateGUI()
}
}
scope.launch {
medtrumPump.bolusAmountDeliveredFlow.collect { bolusAmount ->
aapsLogger.debug(LTag.PUMP, "MedtrumViewModel bolusAmountDeliveredFlow: $bolusAmount")
if (!medtrumPump.bolusDone) {
_activeBolusStatus.postValue(
dateUtil.timeString(medtrumPump.bolusStartTime) + " " + dateUtil.sinceString(medtrumPump.bolusStartTime, rh)
+ " " + rh.gs(info.nightscout.interfaces.R.string.format_insulin_units, bolusAmount) + " / " + rh.gs(
info.nightscout.interfaces.R.string.format_insulin_units, medtrumPump.bolusAmountToBeDelivered
)
)
}
}
}
// Periodically update gui
scope.launch {
while (true) {
@ -172,6 +189,9 @@ class MedtrumOverviewViewModel @Inject constructor(
)
else _lastBolus.postValue("")
}
if (medtrumPump.bolusDone) {
_activeBolusStatus.postValue("")
}
val activeAlarmStrings = medtrumPump.activeAlarms.map { medtrumPump.alarmStateToString(it) }
_activeAlarms.postValue(activeAlarmStrings.joinToString("\n"))

View file

@ -290,6 +290,46 @@
android:textSize="14sp" />
</LinearLayout>
<!-- Active Bolus -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="3dp"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:gravity="end"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text="@string/active_bolus_label"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingStart="2dp"
android:paddingEnd="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/active_bolus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text='@{viewmodel.activeBolusStatus}'
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"

View file

@ -37,6 +37,7 @@
<!-- overview fragment -->
<string name="ble_status_label">BLE Status</string>
<string name="last_connection_label">Last connected</string>
<string name="active_bolus_label">Active bolus</string>
<string name="pump_state_label">Pump state</string>
<string name="active_alarms_label">Active alarms</string>
<string name="reservoir_level"> %.2f U</string>