From 5ffe61d6c4b592a765cf2695b4b27d075561bdff Mon Sep 17 00:00:00 2001 From: Theo van Elsberg Date: Mon, 4 Oct 2021 22:38:37 +0200 Subject: [PATCH] Move fixed values to PodConstants --- .../plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt | 4 ++-- .../pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt | 4 ++-- .../omnipod/dash/driver/pod/definition/PodConstants.kt | 9 ++++++++- .../driver/pod/state/OmnipodDashPodStateManagerImpl.kt | 2 +- .../pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt | 8 ++++---- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index 9ac1b96278..364a138484 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -510,7 +510,7 @@ class OmnipodDashPumpPlugin @Inject constructor( // Omnipod only reports reservoir level when there's < 1023 pulses left return podStateManager.pulsesRemaining?.let { - it * 0.05 + it * PodConstants.POD_PULSE_BOLUS_UNITS } ?: 75.0 } @@ -724,7 +724,7 @@ class OmnipodDashPumpPlugin @Inject constructor( } private fun estimateBolusDeliverySeconds(requestedBolusAmount: Double): Long { - return ceil(requestedBolusAmount / 0.05).toLong() * 2 + 3 + return ceil(requestedBolusAmount / PodConstants.POD_PULSE_BOLUS_UNITS).toLong() * 2 + 3 } private fun pumpSyncBolusStart( diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt index d64ea2ef42..3e9c78ed4e 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt @@ -278,7 +278,7 @@ class OmnipodDashManagerImpl @Inject constructor( .setUniqueId(podStateManager.uniqueId!!.toInt()) .setSequenceNumber(podStateManager.messageSequenceNumber) .setNonce(NONCE) - .setNumberOfUnits(podStateManager.firstPrimeBolusVolume!! * 0.05) + .setNumberOfUnits(podStateManager.firstPrimeBolusVolume!! * PodConstants.POD_PRIMING_BOLUS_UNITS) .setDelayBetweenPulsesInEighthSeconds(podStateManager.primePulseRate!!.toByte()) .setProgramReminder(ProgramReminder(atStart = false, atEnd = false, atInterval = 0)) .build(), @@ -380,7 +380,7 @@ class OmnipodDashManagerImpl @Inject constructor( ) observables.add( observeSendProgramBolusCommand( - podStateManager.secondPrimeBolusVolume!! * 0.05, + podStateManager.secondPrimeBolusVolume!! * PodConstants.POD_CANNULA_INSERTION_BOLUS_UNITS, podStateManager.primePulseRate!!.toByte(), confirmationBeeps = false, completionBeeps = false diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/PodConstants.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/PodConstants.kt index 915c6b7bde..f6901d34d7 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/PodConstants.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/PodConstants.kt @@ -4,6 +4,13 @@ import java.time.Duration class PodConstants { companion object { - val MAX_POD_LIFETIME = Duration.ofHours(80) + val MAX_POD_LIFETIME : Duration = Duration.ofHours(80) + + const val POD_PULSE_BOLUS_UNITS = 0.05 + // Priming + const val POD_PRIMING_BOLUS_UNITS = 0.05 + const val POD_CANNULA_INSERTION_BOLUS_UNITS = 0.05 + // Reservoir + const val DEFAULT_MAX_RESERVOIR_ALERT_THRESHOLD : Short = 20 } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index e9368c2954..37798a8412 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -311,7 +311,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( private fun updateLastBolusFromResponse(bolusPulsesRemaining: Short) { podState.lastBolus?.run { - val remainingUnits = bolusPulsesRemaining.toDouble() * 0.05 + val remainingUnits = bolusPulsesRemaining.toDouble() * PodConstants.POD_PULSE_BOLUS_UNITS this.bolusUnitsRemaining = remainingUnits if (remainingUnits == 0.0) { this.deliveryComplete = true diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt index d0267f0589..fd0d3785e5 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt @@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.databinding.OmnipodD import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertType import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.events.EventQueueChanged import info.nightscout.androidaps.utils.DateUtil @@ -68,7 +69,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() { @Inject lateinit var buildHelper: BuildHelper companion object { - private const val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds private const val PLACEHOLDER = "-" private const val MAX_TIME_DEVIATION_MINUTES = 10L @@ -372,7 +372,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { if (podStateManager.isActivationCompleted && podStateManager.pulsesDelivered != null) { resourceHelper.gs( R.string.omnipod_common_overview_total_delivered_value, - podStateManager.pulsesDelivered!! * 0.05 + (podStateManager.pulsesDelivered!! * PodConstants.POD_PULSE_BOLUS_UNITS) ) } else { PLACEHOLDER @@ -387,11 +387,11 @@ class OmnipodDashOverviewFragment : DaggerFragment() { // TODO // val lowReservoirThreshold = (omnipodAlertUtil.lowReservoirAlertUnits // ?: OmnipodConstants.DEFAULT_MAX_RESERVOIR_ALERT_THRESHOLD).toDouble() - val lowReservoirThreshold: Short = 20 + val lowReservoirThreshold: Short = PodConstants.DEFAULT_MAX_RESERVOIR_ALERT_THRESHOLD podInfoBinding.reservoir.text = resourceHelper.gs( R.string.omnipod_common_overview_reservoir_value, - (podStateManager.pulsesRemaining!! * 0.05) + (podStateManager.pulsesRemaining!! * PodConstants.POD_PULSE_BOLUS_UNITS) ) podInfoBinding.reservoir.setTextColor( if (podStateManager.pulsesRemaining!! < lowReservoirThreshold) {