Merge branch 'avereha/alarms' into avereha/bolus
This commit is contained in:
commit
18735540fd
|
@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class OmnipodDashPumpPlugin @Inject constructor(
|
class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
|
@ -136,6 +137,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
podStateManager.updateActiveCommand()
|
podStateManager.updateActiveCommand()
|
||||||
.map { handleCommandConfirmation(it) }
|
.map { handleCommandConfirmation(it) }
|
||||||
.ignoreElement(),
|
.ignoreElement(),
|
||||||
|
checkPodKaput()
|
||||||
)
|
)
|
||||||
).blockingGet()
|
).blockingGet()
|
||||||
if (throwable != null) {
|
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 {
|
override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
|
||||||
val basalProgram = mapProfileToBasalProgram(profile)
|
val basalProgram = mapProfileToBasalProgram(profile)
|
||||||
return executeProgrammingCommand(
|
return executeProgrammingCommand(
|
||||||
|
@ -224,7 +245,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
val date = Date()
|
val date = Date()
|
||||||
val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0
|
val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0
|
||||||
aapsLogger.info(LTag.PUMP, "baseBasalRate: %ret at $date}")
|
aapsLogger.info(LTag.PUMP, "baseBasalRate: %ret at $date}")
|
||||||
return ret
|
return if (podStateManager.alarmType != null) {
|
||||||
|
0.0
|
||||||
|
} else
|
||||||
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
override val reservoirLevel: Double
|
override val reservoirLevel: Double
|
||||||
|
|
|
@ -28,6 +28,7 @@ interface OmnipodDashPodStateManager {
|
||||||
val isActivationCompleted: Boolean
|
val isActivationCompleted: Boolean
|
||||||
val isSuspended: Boolean
|
val isSuspended: Boolean
|
||||||
val isPodRunning: Boolean
|
val isPodRunning: Boolean
|
||||||
|
val isPodKaput: Boolean
|
||||||
var bluetoothConnectionState: BluetoothConnectionState
|
var bluetoothConnectionState: BluetoothConnectionState
|
||||||
|
|
||||||
val lastUpdatedSystem: Long // System.currentTimeMillis()
|
val lastUpdatedSystem: Long // System.currentTimeMillis()
|
||||||
|
@ -57,6 +58,7 @@ interface OmnipodDashPodStateManager {
|
||||||
val deliveryStatus: DeliveryStatus?
|
val deliveryStatus: DeliveryStatus?
|
||||||
val minutesSinceActivation: Short?
|
val minutesSinceActivation: Short?
|
||||||
val activeAlerts: EnumSet<AlertType>?
|
val activeAlerts: EnumSet<AlertType>?
|
||||||
|
val alarmType: AlarmType?
|
||||||
|
|
||||||
var tempBasal: TempBasal?
|
var tempBasal: TempBasal?
|
||||||
val tempBasalActive: Boolean
|
val tempBasalActive: Boolean
|
||||||
|
|
|
@ -55,6 +55,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
get() = podState.deliveryStatus?.equals(DeliveryStatus.SUSPENDED)
|
get() = podState.deliveryStatus?.equals(DeliveryStatus.SUSPENDED)
|
||||||
?: false
|
?: false
|
||||||
|
|
||||||
|
override val isPodKaput: Boolean
|
||||||
|
get() = podState.podStatus in arrayOf(PodStatus.ALARM, PodStatus.DEACTIVATED)
|
||||||
|
|
||||||
override val isPodRunning: Boolean
|
override val isPodRunning: Boolean
|
||||||
get() = podState.podStatus?.isRunning() ?: false
|
get() = podState.podStatus?.isRunning() ?: false
|
||||||
|
|
||||||
|
@ -137,6 +140,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
override val activeAlerts: EnumSet<AlertType>?
|
override val activeAlerts: EnumSet<AlertType>?
|
||||||
get() = podState.activeAlerts
|
get() = podState.activeAlerts
|
||||||
|
|
||||||
|
override val alarmType: AlarmType?
|
||||||
|
get() = podState.alarmType
|
||||||
|
|
||||||
override var tempBasal: OmnipodDashPodStateManager.TempBasal?
|
override var tempBasal: OmnipodDashPodStateManager.TempBasal?
|
||||||
get() = podState.tempBasal
|
get() = podState.tempBasal
|
||||||
set(tempBasal) {
|
set(tempBasal) {
|
||||||
|
@ -317,6 +323,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateFromDefaultStatusResponse(response: DefaultStatusResponse) {
|
override fun updateFromDefaultStatusResponse(response: DefaultStatusResponse) {
|
||||||
|
logger.debug(LTag.PUMPBTCOMM, "Default status reponse :$response")
|
||||||
podState.deliveryStatus = response.deliveryStatus
|
podState.deliveryStatus = response.deliveryStatus
|
||||||
podState.podStatus = response.podStatus
|
podState.podStatus = response.podStatus
|
||||||
podState.pulsesDelivered = response.totalPulsesDelivered
|
podState.pulsesDelivered = response.totalPulsesDelivered
|
||||||
|
@ -383,15 +390,24 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateFromAlarmStatusResponse(response: AlarmStatusResponse) {
|
override fun updateFromAlarmStatusResponse(response: AlarmStatusResponse) {
|
||||||
// TODO
|
|
||||||
logger.error(
|
|
||||||
LTag.PUMP,
|
|
||||||
"Not implemented: OmnipodDashPodStateManagerImpl.updateFromAlarmStatusResponse(AlarmStatusResponse)"
|
|
||||||
)
|
|
||||||
logger.info(
|
logger.info(
|
||||||
LTag.PUMP,
|
LTag.PUMP,
|
||||||
"Received AlarmStatusReponse: $response"
|
"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()
|
store()
|
||||||
rxBus.send(EventOmnipodDashPumpValuesChanged())
|
rxBus.send(EventOmnipodDashPumpValuesChanged())
|
||||||
}
|
}
|
||||||
|
@ -463,6 +479,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
var deliveryStatus: DeliveryStatus? = null
|
var deliveryStatus: DeliveryStatus? = null
|
||||||
var minutesSinceActivation: Short? = null
|
var minutesSinceActivation: Short? = null
|
||||||
var activeAlerts: EnumSet<AlertType>? = null
|
var activeAlerts: EnumSet<AlertType>? = null
|
||||||
|
var alarmType: AlarmType? = null
|
||||||
|
|
||||||
var basalProgram: BasalProgram? = null
|
var basalProgram: BasalProgram? = null
|
||||||
var tempBasal: OmnipodDashPodStateManager.TempBasal? = null
|
var tempBasal: OmnipodDashPodStateManager.TempBasal? = null
|
||||||
|
|
|
@ -212,7 +212,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateUi() {
|
private fun updateUi() {
|
||||||
// TODO update bluetooth status
|
|
||||||
updateBluetoothStatus()
|
updateBluetoothStatus()
|
||||||
updateOmnipodStatus()
|
updateOmnipodStatus()
|
||||||
updatePodActionButtons()
|
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))
|
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
|
// base basal rate
|
||||||
podInfoBinding.baseBasalRate.text = if (podStateManager.basalProgram != null && !podStateManager.isSuspended) {
|
podInfoBinding.baseBasalRate.text = if (podStateManager.basalProgram != null && !podStateManager.isSuspended) {
|
||||||
|
|
Loading…
Reference in a new issue