Merge pull request #139 from vanelsberg/fixes-3refactored
Fixes-3 refactoring
This commit is contained in:
commit
9071068bad
5 changed files with 36 additions and 16 deletions
|
@ -510,7 +510,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
// Omnipod only reports reservoir level when there's < 1023 pulses left
|
// Omnipod only reports reservoir level when there's < 1023 pulses left
|
||||||
return podStateManager.pulsesRemaining?.let {
|
return podStateManager.pulsesRemaining?.let {
|
||||||
it * 0.05
|
it * PodConstants.POD_PULSE_BOLUS_UNITS
|
||||||
} ?: 75.0
|
} ?: 75.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -724,7 +724,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun estimateBolusDeliverySeconds(requestedBolusAmount: Double): Long {
|
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(
|
private fun pumpSyncBolusStart(
|
||||||
|
|
|
@ -9,6 +9,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.*
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.GetVersionCommand.Companion.DEFAULT_UNIQUE_ID
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.GetVersionCommand.Companion.DEFAULT_UNIQUE_ID
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.*
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.*
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.MAX_POD_LIFETIME
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.MAX_POD_LIFETIME
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_ALERT_HOURS_DURATION
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_IMMINENT_ALERT_HOURS
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_ALERT_HOURS
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.*
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.*
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
|
@ -278,7 +281,7 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
.setUniqueId(podStateManager.uniqueId!!.toInt())
|
.setUniqueId(podStateManager.uniqueId!!.toInt())
|
||||||
.setSequenceNumber(podStateManager.messageSequenceNumber)
|
.setSequenceNumber(podStateManager.messageSequenceNumber)
|
||||||
.setNonce(NONCE)
|
.setNonce(NONCE)
|
||||||
.setNumberOfUnits(podStateManager.firstPrimeBolusVolume!! * 0.05)
|
.setNumberOfUnits(podStateManager.firstPrimeBolusVolume!! * PodConstants.POD_PULSE_BOLUS_UNITS)
|
||||||
.setDelayBetweenPulsesInEighthSeconds(podStateManager.primePulseRate!!.toByte())
|
.setDelayBetweenPulsesInEighthSeconds(podStateManager.primePulseRate!!.toByte())
|
||||||
.setProgramReminder(ProgramReminder(atStart = false, atEnd = false, atInterval = 0))
|
.setProgramReminder(ProgramReminder(atStart = false, atEnd = false, atInterval = 0))
|
||||||
.build(),
|
.build(),
|
||||||
|
@ -380,7 +383,7 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
)
|
)
|
||||||
observables.add(
|
observables.add(
|
||||||
observeSendProgramBolusCommand(
|
observeSendProgramBolusCommand(
|
||||||
podStateManager.secondPrimeBolusVolume!! * 0.05,
|
podStateManager.secondPrimeBolusVolume!! * PodConstants.POD_PULSE_BOLUS_UNITS,
|
||||||
podStateManager.primePulseRate!!.toByte(),
|
podStateManager.primePulseRate!!.toByte(),
|
||||||
confirmationBeeps = false,
|
confirmationBeeps = false,
|
||||||
completionBeeps = false
|
completionBeeps = false
|
||||||
|
@ -394,10 +397,10 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
AlertConfiguration(
|
AlertConfiguration(
|
||||||
AlertType.EXPIRATION,
|
AlertType.EXPIRATION,
|
||||||
enabled = true,
|
enabled = true,
|
||||||
durationInMinutes = TimeUnit.HOURS.toMinutes(7).toShort(),
|
durationInMinutes = TimeUnit.HOURS.toMinutes(POD_EXPIRATION_ALERT_HOURS_DURATION).toShort(),
|
||||||
autoOff = false,
|
autoOff = false,
|
||||||
AlertTrigger.TimerTrigger(
|
AlertTrigger.TimerTrigger(
|
||||||
TimeUnit.HOURS.toMinutes(72).toShort()
|
TimeUnit.HOURS.toMinutes(POD_EXPIRATION_ALERT_HOURS).toShort()
|
||||||
), // FIXME use activation time
|
), // FIXME use activation time
|
||||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||||
BeepRepetitionType.XXX3
|
BeepRepetitionType.XXX3
|
||||||
|
@ -408,7 +411,7 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
durationInMinutes = 0,
|
durationInMinutes = 0,
|
||||||
autoOff = false,
|
autoOff = false,
|
||||||
AlertTrigger.TimerTrigger(
|
AlertTrigger.TimerTrigger(
|
||||||
TimeUnit.HOURS.toMinutes(79).toShort()
|
TimeUnit.HOURS.toMinutes(POD_EXPIRATION_IMMINENT_ALERT_HOURS).toShort()
|
||||||
), // FIXME use activation time
|
), // FIXME use activation time
|
||||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||||
BeepRepetitionType.XXX4
|
BeepRepetitionType.XXX4
|
||||||
|
|
|
@ -1,9 +1,23 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition
|
||||||
|
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class PodConstants {
|
class PodConstants {
|
||||||
companion object {
|
companion object {
|
||||||
val MAX_POD_LIFETIME = Duration.ofHours(80)
|
val MAX_POD_LIFETIME : Duration = Duration.ofHours(80)
|
||||||
|
|
||||||
|
// Expiration alert time in minutes since activation and duration in minutes
|
||||||
|
const val POD_EXPIRATION_ALERT_HOURS = 72L
|
||||||
|
const val POD_EXPIRATION_ALERT_HOURS_DURATION = 7L
|
||||||
|
|
||||||
|
// Expiration eminent alert time in minutes since activation
|
||||||
|
const val POD_EXPIRATION_IMMINENT_ALERT_HOURS = 79L
|
||||||
|
|
||||||
|
// Bolus & Priming units
|
||||||
|
const val POD_PULSE_BOLUS_UNITS = 0.05
|
||||||
|
|
||||||
|
// Reservoir units alert threshold
|
||||||
|
const val DEFAULT_MAX_RESERVOIR_ALERT_THRESHOLD : Short = 20
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,7 +311,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
|
|
||||||
private fun updateLastBolusFromResponse(bolusPulsesRemaining: Short) {
|
private fun updateLastBolusFromResponse(bolusPulsesRemaining: Short) {
|
||||||
podState.lastBolus?.run {
|
podState.lastBolus?.run {
|
||||||
val remainingUnits = bolusPulsesRemaining.toDouble() * 0.05
|
val remainingUnits = bolusPulsesRemaining.toDouble() * PodConstants.POD_PULSE_BOLUS_UNITS
|
||||||
this.bolusUnitsRemaining = remainingUnits
|
this.bolusUnitsRemaining = remainingUnits
|
||||||
if (remainingUnits == 0.0) {
|
if (remainingUnits == 0.0) {
|
||||||
this.deliveryComplete = true
|
this.deliveryComplete = true
|
||||||
|
@ -627,11 +627,14 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun connectionSuccessRatio(): Float {
|
override fun connectionSuccessRatio(): Float {
|
||||||
val attempts = connectionAttempts
|
if (connectionAttempts == 0) {
|
||||||
if (attempts == 0) {
|
|
||||||
return 0.0F
|
return 0.0F
|
||||||
}
|
}
|
||||||
return successfulConnections.toFloat() / attempts.toFloat()
|
else if (connectionAttempts <= successfulConnections) {
|
||||||
|
// Prevent bogus quality > 1 during initialisation
|
||||||
|
return 1.0F
|
||||||
|
}
|
||||||
|
return successfulConnections.toFloat() / connectionAttempts.toFloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reset() {
|
override fun reset() {
|
||||||
|
|
|
@ -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.ActivationProgress
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertType
|
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.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.Callback
|
||||||
import info.nightscout.androidaps.queue.events.EventQueueChanged
|
import info.nightscout.androidaps.queue.events.EventQueueChanged
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
@ -68,7 +69,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
@Inject lateinit var buildHelper: BuildHelper
|
@Inject lateinit var buildHelper: BuildHelper
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds
|
private const val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds
|
||||||
private const val PLACEHOLDER = "-"
|
private const val PLACEHOLDER = "-"
|
||||||
private const val MAX_TIME_DEVIATION_MINUTES = 10L
|
private const val MAX_TIME_DEVIATION_MINUTES = 10L
|
||||||
|
@ -372,7 +372,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
if (podStateManager.isActivationCompleted && podStateManager.pulsesDelivered != null) {
|
if (podStateManager.isActivationCompleted && podStateManager.pulsesDelivered != null) {
|
||||||
resourceHelper.gs(
|
resourceHelper.gs(
|
||||||
R.string.omnipod_common_overview_total_delivered_value,
|
R.string.omnipod_common_overview_total_delivered_value,
|
||||||
podStateManager.pulsesDelivered!! * 0.05
|
(podStateManager.pulsesDelivered!! * PodConstants.POD_PULSE_BOLUS_UNITS)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
PLACEHOLDER
|
PLACEHOLDER
|
||||||
|
@ -387,11 +387,11 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
// TODO
|
// TODO
|
||||||
// val lowReservoirThreshold = (omnipodAlertUtil.lowReservoirAlertUnits
|
// val lowReservoirThreshold = (omnipodAlertUtil.lowReservoirAlertUnits
|
||||||
// ?: OmnipodConstants.DEFAULT_MAX_RESERVOIR_ALERT_THRESHOLD).toDouble()
|
// ?: 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(
|
podInfoBinding.reservoir.text = resourceHelper.gs(
|
||||||
R.string.omnipod_common_overview_reservoir_value,
|
R.string.omnipod_common_overview_reservoir_value,
|
||||||
(podStateManager.pulsesRemaining!! * 0.05)
|
(podStateManager.pulsesRemaining!! * PodConstants.POD_PULSE_BOLUS_UNITS)
|
||||||
)
|
)
|
||||||
podInfoBinding.reservoir.setTextColor(
|
podInfoBinding.reservoir.setTextColor(
|
||||||
if (podStateManager.pulsesRemaining!! < lowReservoirThreshold) {
|
if (podStateManager.pulsesRemaining!! < lowReservoirThreshold) {
|
||||||
|
|
Loading…
Reference in a new issue