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 d050e82476..cb20bc17ec 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 @@ -135,6 +135,7 @@ class OmnipodDashManagerImpl @Inject constructor( private fun observeProgramBasalCommand(basalProgram: BasalProgram): Observable { return Observable.defer { + logger.debug(LTag.PUMPCOMM, "Programming basal. basalProgram={}", basalProgram) bleManager.sendCommand( ProgramBasalCommand.Builder() .setUniqueId(podStateManager.uniqueId!!.toInt()) @@ -219,7 +220,10 @@ class OmnipodDashManagerImpl @Inject constructor( } if (podStateManager.activationProgress.isBefore(ActivationProgress.PRIMING)) { observables.add( - Observable.timer(PRIME_BOLUS_DURATION_SECONDS, TimeUnit.SECONDS).flatMap { Observable.empty() }) + Observable.defer { + Observable.timer(podStateManager.firstPrimeBolusVolume!!.toLong(), TimeUnit.SECONDS) + .flatMap { Observable.empty() } + }) observables.add( Observable.defer { bleManager.sendCommand( @@ -317,8 +321,10 @@ class OmnipodDashManagerImpl @Inject constructor( } if (podStateManager.activationProgress.isBefore(ActivationProgress.INSERTING_CANNULA)) { observables.add( - Observable.timer(CANNULA_INSERTION_BOLUS_DURATION_SECONDS, TimeUnit.SECONDS) - .flatMap { Observable.empty() }) + Observable.defer { + Observable.timer(podStateManager.secondPrimeBolusVolume!!.toLong(), TimeUnit.SECONDS) + .flatMap { Observable.empty() } + }) observables.add( observeSendProgramBolusCommand( podStateManager.secondPrimeBolusVolume!! * 0.05, diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/PodAlarmException.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/PodAlarmException.kt index 4d6cd067b9..8abd3386b3 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/PodAlarmException.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/PodAlarmException.kt @@ -1,5 +1,13 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.AlarmStatusResponse +import java.util.* -class PodAlarmException(val response: AlarmStatusResponse) : Exception("Pod is in alarm: ${response.alarmType.value} ${response.alarmType.name}") \ No newline at end of file +class PodAlarmException(val response: AlarmStatusResponse) : Exception( + String.format( + Locale.getDefault(), + "Pod is in alarm: %03d %s", + response.alarmType.value.toInt() and 0xff, + response.alarmType.name + ) +) \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/event/PodEvent.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/event/PodEvent.kt index 367393292e..18b8d7fb71 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/event/PodEvent.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/event/PodEvent.kt @@ -7,18 +7,53 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response. sealed class PodEvent { /* BT connection events */ - class AlreadyConnected(val bluetoothAddress: String) : PodEvent() + class AlreadyConnected(val bluetoothAddress: String) : PodEvent() { + + override fun toString(): String { + return "AlreadyConnected(bluetoothAddress='$bluetoothAddress')" + } + } + object AlreadyPaired : PodEvent() object Scanning : PodEvent() object BluetoothConnecting : PodEvent() - class BluetoothConnected(val bluetoothAddress: String) : PodEvent() + class BluetoothConnected(val bluetoothAddress: String) : PodEvent() { + + override fun toString(): String { + return "BluetoothConnected(bluetoothAddress='$bluetoothAddress')" + } + } + object Pairing : PodEvent() - class Paired(val uniqueId: Id) : PodEvent() + class Paired(val uniqueId: Id) : PodEvent() { + + override fun toString(): String { + return "Paired(uniqueId=$uniqueId)" + } + } + object EstablishingSession : PodEvent() object Connected : PodEvent() /* Message exchange events */ - class CommandSending(val command: Command) : PodEvent() - class CommandSent(val command: Command) : PodEvent() - class ResponseReceived(val response: Response) : PodEvent() + class CommandSending(val command: Command) : PodEvent() { + + override fun toString(): String { + return "CommandSending(command=$command)" + } + } + + class CommandSent(val command: Command) : PodEvent() { + + override fun toString(): String { + return "CommandSent(command=$command)" + } + } + + class ResponseReceived(val response: Response) : PodEvent() { + + override fun toString(): String { + return "ResponseReceived(response=$response)" + } + } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt index cf0cc52d6f..5372a6967f 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt @@ -32,7 +32,14 @@ class DashInsertCannulaViewModel @Inject constructor( if (profile == null) { source.onError(IllegalStateException("No profile set")) } else { - val disposable = omnipodManager.activatePodPart2(mapProfileToBasalProgram(profile)).subscribeBy( + val basalProgram = mapProfileToBasalProgram(profile) + logger.debug( + LTag.PUMPCOMM, + "Mapped profile to basal program. profile={}, basalProgram={}", + profile, + basalProgram + ) + val disposable = omnipodManager.activatePodPart2(basalProgram).subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/Functions.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/Functions.kt index baa0ecf7c9..8b1e08848e 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/Functions.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/Functions.kt @@ -41,7 +41,7 @@ fun mapProfileToBasalProgram(profile: Profile): BasalProgram { } if (entries.size == 0 && basalValue.timeAsSeconds != 0) { - throw java.lang.IllegalArgumentException("First basal segment start time should be 0") + throw IllegalArgumentException("First basal segment start time should be 0") } if (entries.size > 0 && entries[entries.size - 1].endSlotIndex != startSlotIndex) {