From 7ae9ad1105fce3f84c913954381efdfa725cc301 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 7 Nov 2022 09:52:16 +0100 Subject: [PATCH] EOPatch2: log insulin change on activation --- .../general/overview/StatusLightHandler.kt | 20 +++-- .../androidaps/interfaces/PumpDescription.kt | 2 + .../plugins/pump/common/defs/PumpType.kt | 7 ++ .../plugins/pump/eopatch/AppConstant.kt | 1 - .../pump/eopatch/ble/PatchManagerImpl.java | 79 +++++++++++-------- 5 files changed, 66 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt index 954ff03ce8..c33faafdc5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt @@ -54,15 +54,19 @@ class StatusLightHandler @Inject constructor( } val insulinUnit = rh.gs(R.string.insulin_unit_shortname) - if (pump.model() == PumpType.OMNIPOD_EROS || pump.model() == PumpType.OMNIPOD_DASH) { - handlePatchReservoirLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit, - OmnipodConstants.MAX_RESERVOIR_READING) - } else if (pump.model() == PumpType.EOFLOW_EOPATCH2) { - handlePatchReservoirLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit, - AppConstant.MAX_RESERVOIR_READING) - } else { + if (pump.pumpDescription.isPatchPump) + handlePatchReservoirLevel( + careportal_reservoir_level, + R.string.key_statuslights_res_critical, + 10.0, + R.string.key_statuslights_res_warning, + 80.0, + pump.reservoirLevel, + insulinUnit, + pump.pumpDescription.maxResorvoirReading.toDouble() + ) + else handleLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit) - } if (!config.NSCLIENT) { if (bgSource.sensorBatteryLevel != -1) diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.kt index 4d8afe2a0e..6e703a11cf 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.kt @@ -39,6 +39,7 @@ class PumpDescription() { var needsManualTDDLoad = false var hasCustomUnreachableAlertCheck = false var isPatchPump = false + var maxResorvoirReading = 50 var useHardwareLink = false private fun resetSettings() { @@ -107,6 +108,7 @@ class PumpDescription() { is30minBasalRatesCapable = pumpCapability.hasCapability(PumpCapability.BasalRate30min) hasCustomUnreachableAlertCheck = pumpType.hasCustomUnreachableAlertCheck isPatchPump = pumpType.isPatchPump + maxResorvoirReading = pumpType.maxReservoirReading useHardwareLink = pumpType.useHardwareLink } diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.kt index 6d6e2da5f2..4d1688fa8c 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.kt @@ -213,6 +213,7 @@ enum class PumpType { pumpCapability = PumpCapability.OmnipodCapabilities, hasCustomUnreachableAlertCheck = true, isPatchPump = true, + maxReservoirReading = 50, useHardwareLink = true, supportBatteryLevel = false, source = Sources.OmnipodEros @@ -232,6 +233,7 @@ enum class PumpType { baseBasalStep = 0.05, baseBasalSpecialSteps = null, isPatchPump = true, + maxReservoirReading = 50, pumpCapability = PumpCapability.OmnipodCapabilities, hasCustomUnreachableAlertCheck = false, supportBatteryLevel = false @@ -392,6 +394,7 @@ enum class PumpType { baseBasalSpecialSteps = null, pumpCapability = PumpCapability.EopatchCapabilities, isPatchPump = true, + maxReservoirReading = 50, source = Sources.EOPatch2); val description: String @@ -435,6 +438,8 @@ enum class PumpType { private set var isPatchPump = false private set + var maxReservoirReading = 50 + private set var supportBatteryLevel = true private set var useHardwareLink = false @@ -510,6 +515,7 @@ enum class PumpType { pumpCapability: PumpCapability, hasCustomUnreachableAlertCheck: Boolean = false, isPatchPump: Boolean = false, + maxReservoirReading: Int = 50, supportBatteryLevel: Boolean = true, useHardwareLink: Boolean = false, source: Sources = Sources.VirtualPump @@ -530,6 +536,7 @@ enum class PumpType { this.pumpCapability = pumpCapability this.hasCustomUnreachableAlertCheck = hasCustomUnreachableAlertCheck this.isPatchPump = isPatchPump + this.maxReservoirReading = maxReservoirReading this.supportBatteryLevel = supportBatteryLevel this.useHardwareLink = useHardwareLink this.source = source diff --git a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/AppConstant.kt b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/AppConstant.kt index 67e61ba793..81087620ef 100644 --- a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/AppConstant.kt +++ b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/AppConstant.kt @@ -25,6 +25,5 @@ interface AppConstant { const val DAY_START_MINUTE = 0 * 60 const val DAY_END_MINUTE = 24 * 60 const val INSULIN_DURATION_MIN = 2.0f - const val MAX_RESERVOIR_READING = 50.0 } } \ No newline at end of file diff --git a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/PatchManagerImpl.java b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/PatchManagerImpl.java index 9254ef2358..ce1f5bf130 100644 --- a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/PatchManagerImpl.java +++ b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/PatchManagerImpl.java @@ -35,6 +35,7 @@ import javax.inject.Singleton; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.interfaces.PumpSync; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.eopatch.EoPatchRxBus; import info.nightscout.androidaps.plugins.pump.eopatch.alarm.AlarmCode; import info.nightscout.androidaps.plugins.pump.eopatch.ble.task.ActivateTask; @@ -104,7 +105,7 @@ import io.reactivex.rxjava3.functions.Consumer; import io.reactivex.rxjava3.schedulers.Schedulers; @Singleton -public class PatchManagerImpl{ +public class PatchManagerImpl { @Inject IPreferenceManager pm; @Inject Context context; @Inject SP sp; @@ -154,27 +155,27 @@ public class PatchManagerImpl{ Observable dateTimeChanged = RxBroadcastReceiver.Companion.create(context, filter); compositeDisposable.add( - Observable.combineLatest(patch.observeConnected(), pm.observePatchLifeCycle(), - (connected, lifeCycle) -> (connected && lifeCycle.isActivated())) - .subscribeOn(aapsSchedulers.getIo()) - .filter(ok -> ok) - .observeOn(aapsSchedulers.getIo()) - .doOnNext(v -> TaskBase.enqueue(TaskFunc.UPDATE_CONNECTION)) - .retry() - .subscribe()); + Observable.combineLatest(patch.observeConnected(), pm.observePatchLifeCycle(), + (connected, lifeCycle) -> (connected && lifeCycle.isActivated())) + .subscribeOn(aapsSchedulers.getIo()) + .filter(ok -> ok) + .observeOn(aapsSchedulers.getIo()) + .doOnNext(v -> TaskBase.enqueue(TaskFunc.UPDATE_CONNECTION)) + .retry() + .subscribe()); compositeDisposable.add( - Observable.combineLatest(patch.observeConnected(), - pm.observePatchLifeCycle().distinctUntilChanged(), - dateTimeChanged.startWith(Observable.just(new Intent())), - (connected, lifeCycle, value) -> (connected && lifeCycle.isActivated())) - .subscribeOn(aapsSchedulers.getIo()) - .doOnNext(v -> aapsLogger.debug(LTag.PUMP,"Has the date or time changed? "+v)) - .filter(ok -> ok) - .doOnNext(v -> TaskBase.enqueue(TaskFunc.SET_GLOBAL_TIME)) - .doOnError(e -> aapsLogger.error(LTag.PUMP, "Failed to set EOPatch time.")) - .retry() - .subscribe()); + Observable.combineLatest(patch.observeConnected(), + pm.observePatchLifeCycle().distinctUntilChanged(), + dateTimeChanged.startWith(Observable.just(new Intent())), + (connected, lifeCycle, value) -> (connected && lifeCycle.isActivated())) + .subscribeOn(aapsSchedulers.getIo()) + .doOnNext(v -> aapsLogger.debug(LTag.PUMP, "Has the date or time changed? " + v)) + .filter(ok -> ok) + .doOnNext(v -> TaskBase.enqueue(TaskFunc.SET_GLOBAL_TIME)) + .doOnError(e -> aapsLogger.error(LTag.PUMP, "Failed to set EOPatch time.")) + .retry() + .subscribe()); compositeDisposable.add( patch.observeConnected() @@ -233,7 +234,7 @@ public class PatchManagerImpl{ } }) .flatMap(integer -> { - if(pc.getLowReservoirAlertAmount() != doseUnit || pc.getPatchExpireAlertTime() != hours) { + if (pc.getLowReservoirAlertAmount() != doseUnit || pc.getPatchExpireAlertTime() != hours) { return setLowReservoir(doseUnit, hours) .doOnSuccess(patchBooleanResponse -> { pc.setLowReservoirAlertAmount(doseUnit); @@ -244,7 +245,7 @@ public class PatchManagerImpl{ return Single.just(true); }) .flatMap(ret -> { - if(pc.getInfoReminder() != buzzer) { + if (pc.getInfoReminder() != buzzer) { return infoReminderSet(buzzer) .doOnSuccess(patchBooleanResponse -> { pc.setInfoReminder(buzzer); @@ -256,7 +257,7 @@ public class PatchManagerImpl{ .subscribe()); } - if(!connected && activated){ + if (!connected && activated) { pm.getPatchConfig().updatetDisconnectedTime(); } } @@ -304,7 +305,7 @@ public class PatchManagerImpl{ NormalBasal normalBasal = pm.getNormalBasalManager().getNormalBasal(); - if(normalBasal.updateNormalBasalIndex()) { + if (normalBasal.updateNormalBasalIndex()) { pm.flushNormalBasalManager(); } } @@ -319,7 +320,7 @@ public class PatchManagerImpl{ /** * getPatchConnection() 을 사용해야 한다. * 아직 Life Cycle 이 Activated 가 아님. - * + *

* Activation Process task #1 Get Patch Information from Patch * Fragment: fragment_patch_connect_new */ @@ -348,7 +349,7 @@ public class PatchManagerImpl{ public Single getTemperature() { return TEMPERATURE_GET.get() - .timeout(DEFAULT_API_TIME_OUT, TimeUnit.SECONDS); + .timeout(DEFAULT_API_TIME_OUT, TimeUnit.SECONDS); } public Observable startPriming(long timeout, long count) { @@ -382,6 +383,13 @@ public class PatchManagerImpl{ TaskBase.enqueue(TaskFunc.LOW_RESERVOIR); TaskBase.enqueue(TaskFunc.INFO_REMINDER); pumpSync.connectNewPump(true); + pumpSync.insertTherapyEventIfNewWithTimestamp( + System.currentTimeMillis(), + DetailedBolusInfo.EventType.INSULIN_CHANGE, + null, + null, + PumpType.EOFLOW_EOPATCH2, + null); } }); } @@ -482,7 +490,7 @@ public class PatchManagerImpl{ return stopExtBolusTask.stop().timeout(DEFAULT_API_TIME_OUT, TimeUnit.SECONDS); } - public Single stopComboBolus(){ + public Single stopComboBolus() { return stopComboBolusTask.stop().timeout(DEFAULT_API_TIME_OUT, TimeUnit.SECONDS); } @@ -524,6 +532,7 @@ public class PatchManagerImpl{ @Inject DeactivateTask deactivateTask; + // Patch Activation Tasks public Single deactivate(long timeout, boolean force) { return deactivateTask.run(force, timeout); @@ -538,12 +547,14 @@ public class PatchManagerImpl{ @Inject SetLowReservoirTask setLowReservoirTask; + public Single setLowReservoir(int doseUnit, int hours) { return setLowReservoirTask.set(doseUnit, hours).timeout(DEFAULT_API_TIME_OUT, TimeUnit.SECONDS); } @Inject UpdateConnectionTask updateConnectionTask; + public Single updateConnection() { return updateConnectionTask.update(); } @@ -566,7 +577,7 @@ public class PatchManagerImpl{ patchStateManager.updatePatchState(PatchState.create(notification.patchState, System.currentTimeMillis())); if (pm.getPatchConfig().isActivated()) { - if(!patch.isSeqReady()){ + if (!patch.isSeqReady()) { getSequence().subscribe(); } updateBasal(); @@ -601,11 +612,11 @@ public class PatchManagerImpl{ public Single sharedKey() { return genKeyPair().flatMap(keyPair -> ECPublicToRawBytes(keyPair) - .flatMap(bytes -> PUBLIC_KEY_SET.send(bytes) - .map(KeyResponse::getPublicKey) - .map(bytes2 -> rawToEncodedECPublicKey(SECP256R1, bytes2)) - .map(publicKey -> generateSharedSecret(keyPair.getPrivate(), publicKey)) - .doOnSuccess(this::saveShared).map(v2 -> true))) + .flatMap(bytes -> PUBLIC_KEY_SET.send(bytes) + .map(KeyResponse::getPublicKey) + .map(bytes2 -> rawToEncodedECPublicKey(SECP256R1, bytes2)) + .map(publicKey -> generateSharedSecret(keyPair.getPrivate(), publicKey)) + .doOnSuccess(this::saveShared).map(v2 -> true))) .doOnError(e -> aapsLogger.error(LTag.PUMP, "sharedKey error")); } @@ -731,7 +742,7 @@ public class PatchManagerImpl{ return patch.observeConnectionState(); } - public void updateMacAddress(String mac, boolean b){ + public void updateMacAddress(String mac, boolean b) { patch.updateMacAddress(mac, b); } }