Merge branch 'avereha/alarms' into avereha/bolus
This commit is contained in:
commit
18735540fd
4 changed files with 58 additions and 7 deletions
|
@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit
|
|||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlin.math.ceil
|
||||
import kotlin.random.Random
|
||||
|
||||
@Singleton
|
||||
class OmnipodDashPumpPlugin @Inject constructor(
|
||||
|
@ -136,6 +137,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
podStateManager.updateActiveCommand()
|
||||
.map { handleCommandConfirmation(it) }
|
||||
.ignoreElement(),
|
||||
checkPodKaput()
|
||||
)
|
||||
).blockingGet()
|
||||
if (throwable != null) {
|
||||
|
@ -145,6 +147,25 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun checkPodKaput(): Completable = Completable.defer {
|
||||
val tbr = pumpSync.expectedPumpState().temporaryBasal
|
||||
if (podStateManager.isPodKaput &&
|
||||
(tbr == null || tbr.rate != 0.0)
|
||||
) {
|
||||
pumpSync.syncTemporaryBasalWithPumpId(
|
||||
timestamp = System.currentTimeMillis(),
|
||||
rate = 0.0,
|
||||
duration = T.mins(PodConstants.MAX_POD_LIFETIME.standardMinutes).msecs(),
|
||||
isAbsolute = true,
|
||||
type = PumpSync.TemporaryBasalType.PUMP_SUSPEND,
|
||||
pumpId = Random.Default.nextLong(), // we don't use this, just make sure it's unique
|
||||
pumpType = PumpType.OMNIPOD_DASH,
|
||||
pumpSerial = serialNumber()
|
||||
)
|
||||
}
|
||||
Completable.complete()
|
||||
}
|
||||
|
||||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
|
||||
val basalProgram = mapProfileToBasalProgram(profile)
|
||||
return executeProgrammingCommand(
|
||||
|
@ -224,7 +245,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
val date = Date()
|
||||
val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0
|
||||
aapsLogger.info(LTag.PUMP, "baseBasalRate: %ret at $date}")
|
||||
return ret
|
||||
return if (podStateManager.alarmType != null) {
|
||||
0.0
|
||||
} else
|
||||
ret
|
||||
}
|
||||
|
||||
override val reservoirLevel: Double
|
||||
|
|
|
@ -28,6 +28,7 @@ interface OmnipodDashPodStateManager {
|
|||
val isActivationCompleted: Boolean
|
||||
val isSuspended: Boolean
|
||||
val isPodRunning: Boolean
|
||||
val isPodKaput: Boolean
|
||||
var bluetoothConnectionState: BluetoothConnectionState
|
||||
|
||||
val lastUpdatedSystem: Long // System.currentTimeMillis()
|
||||
|
@ -57,6 +58,7 @@ interface OmnipodDashPodStateManager {
|
|||
val deliveryStatus: DeliveryStatus?
|
||||
val minutesSinceActivation: Short?
|
||||
val activeAlerts: EnumSet<AlertType>?
|
||||
val alarmType: AlarmType?
|
||||
|
||||
var tempBasal: TempBasal?
|
||||
val tempBasalActive: Boolean
|
||||
|
|
|
@ -55,6 +55,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
get() = podState.deliveryStatus?.equals(DeliveryStatus.SUSPENDED)
|
||||
?: false
|
||||
|
||||
override val isPodKaput: Boolean
|
||||
get() = podState.podStatus in arrayOf(PodStatus.ALARM, PodStatus.DEACTIVATED)
|
||||
|
||||
override val isPodRunning: Boolean
|
||||
get() = podState.podStatus?.isRunning() ?: false
|
||||
|
||||
|
@ -137,6 +140,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
override val activeAlerts: EnumSet<AlertType>?
|
||||
get() = podState.activeAlerts
|
||||
|
||||
override val alarmType: AlarmType?
|
||||
get() = podState.alarmType
|
||||
|
||||
override var tempBasal: OmnipodDashPodStateManager.TempBasal?
|
||||
get() = podState.tempBasal
|
||||
set(tempBasal) {
|
||||
|
@ -317,6 +323,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
}
|
||||
|
||||
override fun updateFromDefaultStatusResponse(response: DefaultStatusResponse) {
|
||||
logger.debug(LTag.PUMPBTCOMM, "Default status reponse :$response")
|
||||
podState.deliveryStatus = response.deliveryStatus
|
||||
podState.podStatus = response.podStatus
|
||||
podState.pulsesDelivered = response.totalPulsesDelivered
|
||||
|
@ -383,15 +390,24 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
}
|
||||
|
||||
override fun updateFromAlarmStatusResponse(response: AlarmStatusResponse) {
|
||||
// TODO
|
||||
logger.error(
|
||||
LTag.PUMP,
|
||||
"Not implemented: OmnipodDashPodStateManagerImpl.updateFromAlarmStatusResponse(AlarmStatusResponse)"
|
||||
)
|
||||
logger.info(
|
||||
LTag.PUMP,
|
||||
"Received AlarmStatusReponse: $response"
|
||||
)
|
||||
podState.deliveryStatus = response.deliveryStatus
|
||||
podState.podStatus = response.podStatus
|
||||
podState.pulsesDelivered = response.totalPulsesDelivered
|
||||
if (response.reservoirPulsesRemaining < 1023) {
|
||||
podState.pulsesRemaining = response.reservoirPulsesRemaining
|
||||
}
|
||||
podState.sequenceNumberOfLastProgrammingCommand = response.sequenceNumberOfLastProgrammingCommand
|
||||
podState.minutesSinceActivation = response.minutesSinceActivation
|
||||
podState.activeAlerts = response.activeAlerts
|
||||
podState.alarmType = response.alarmType
|
||||
|
||||
podState.lastUpdatedSystem = System.currentTimeMillis()
|
||||
podState.lastStatusResponseReceived = SystemClock.elapsedRealtime()
|
||||
|
||||
store()
|
||||
rxBus.send(EventOmnipodDashPumpValuesChanged())
|
||||
}
|
||||
|
@ -463,6 +479,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
var deliveryStatus: DeliveryStatus? = null
|
||||
var minutesSinceActivation: Short? = null
|
||||
var activeAlerts: EnumSet<AlertType>? = null
|
||||
var alarmType: AlarmType? = null
|
||||
|
||||
var basalProgram: BasalProgram? = null
|
||||
var tempBasal: OmnipodDashPodStateManager.TempBasal? = null
|
||||
|
|
|
@ -212,7 +212,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
private fun updateUi() {
|
||||
// TODO update bluetooth status
|
||||
updateBluetoothStatus()
|
||||
updateOmnipodStatus()
|
||||
updatePodActionButtons()
|
||||
|
@ -296,6 +295,15 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
errors.add(resourceHelper.gs(R.string.omnipod_common_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name))
|
||||
}
|
||||
*/
|
||||
podStateManager.alarmType?.let {
|
||||
errors.add(
|
||||
resourceHelper.gs(
|
||||
R.string.omnipod_common_pod_status_pod_fault_description,
|
||||
it.value,
|
||||
it.toString()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// base basal rate
|
||||
podInfoBinding.baseBasalRate.text = if (podStateManager.basalProgram != null && !podStateManager.isSuspended) {
|
||||
|
|
Loading…
Reference in a new issue