Merge pull request #2718 from jbr7rr/medtrum-improvements

Medtrum: Add active bolus to overview
This commit is contained in:
Milos Kozak 2023-08-29 21:01:22 +02:00 committed by GitHub
commit 6e3a8b3869
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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) var patchAge = 0L // Time in seconds?! // As reported by pump, not used (yet)
// bolus status // bolus status
var bolusStartTime = 0L // Time in ms!
var bolusingTreatment: EventOverviewBolusProgress.Treatment? = null // actually delivered treatment var bolusingTreatment: EventOverviewBolusProgress.Treatment? = null // actually delivered treatment
var bolusAmountToBeDelivered = 0.0 // amount to be delivered var bolusAmountToBeDelivered = 0.0 // amount to be delivered
var bolusProgressLastTimeStamp: Long = 0 // timestamp of last bolus progress message var bolusProgressLastTimeStamp: Long = 0 // timestamp of last bolus progress message
var bolusStopped = false // bolus stopped by user var bolusStopped = false // bolus stopped by user
var bolusDone = false // Bolus completed or stopped on pump 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) // Last basal status update (from pump)
private var _lastBasalSequence = 0 private var _lastBasalSequence = 0
val lastBasalSequence: Int val lastBasalSequence: Int
@ -358,6 +362,7 @@ class MedtrumPump @Inject constructor(
fun handleBolusStatusUpdate(bolusType: Int, bolusCompleted: Boolean, amountDelivered: Double) { fun handleBolusStatusUpdate(bolusType: Int, bolusCompleted: Boolean, amountDelivered: Double) {
aapsLogger.debug(LTag.PUMP, "handleBolusStatusUpdate: bolusType: $bolusType bolusCompleted: $bolusCompleted amountDelivered: $amountDelivered") aapsLogger.debug(LTag.PUMP, "handleBolusStatusUpdate: bolusType: $bolusType bolusCompleted: $bolusCompleted amountDelivered: $amountDelivered")
bolusProgressLastTimeStamp = dateUtil.now() bolusProgressLastTimeStamp = dateUtil.now()
_bolusAmountDelivered.value = amountDelivered
bolusingTreatment?.insulin = amountDelivered bolusingTreatment?.insulin = amountDelivered
bolusDone = bolusCompleted bolusDone = bolusCompleted
} }

View file

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

View file

@ -77,6 +77,10 @@ class MedtrumOverviewViewModel @Inject constructor(
val patchExpiry: LiveData<String> val patchExpiry: LiveData<String>
get() = _patchExpiry get() = _patchExpiry
private val _activeBolusStatus = SingleLiveEvent<String>()
val activeBolusStatus: LiveData<String>
get() = _activeBolusStatus
init { init {
scope.launch { scope.launch {
medtrumPump.connectionStateFlow.collect { state -> medtrumPump.connectionStateFlow.collect { state ->
@ -121,6 +125,19 @@ class MedtrumOverviewViewModel @Inject constructor(
updateGUI() 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 // Periodically update gui
scope.launch { scope.launch {
while (true) { while (true) {
@ -172,6 +189,9 @@ class MedtrumOverviewViewModel @Inject constructor(
) )
else _lastBolus.postValue("") else _lastBolus.postValue("")
} }
if (medtrumPump.bolusDone) {
_activeBolusStatus.postValue("")
}
val activeAlarmStrings = medtrumPump.activeAlarms.map { medtrumPump.alarmStateToString(it) } val activeAlarmStrings = medtrumPump.activeAlarms.map { medtrumPump.alarmStateToString(it) }
_activeAlarms.postValue(activeAlarmStrings.joinToString("\n")) _activeAlarms.postValue(activeAlarmStrings.joinToString("\n"))

View file

@ -290,6 +290,46 @@
android:textSize="14sp" /> android:textSize="14sp" />
</LinearLayout> </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 <View
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="2dip" android:layout_height="2dip"

View file

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