From fe9be2bbfae32b73ef91a922d9194d5fb70c75a9 Mon Sep 17 00:00:00 2001 From: jbr7rr <> Date: Fri, 4 Aug 2023 10:47:52 +0200 Subject: [PATCH] Only do connectNewPump() on sn change, only allow sn change when no patch is activated --- .../java/info/nightscout/pump/medtrum/MedtrumPlugin.kt | 8 ++++++++ .../pump/medtrum/comm/packets/ActivatePacket.kt | 4 ---- .../nightscout/pump/medtrum/services/MedtrumService.kt | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt index 903dd7728d..d1017ef425 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt @@ -6,6 +6,8 @@ import android.content.Intent import android.content.ServiceConnection import android.os.IBinder import android.text.format.DateFormat +import androidx.preference.EditTextPreference +import androidx.preference.PreferenceFragmentCompat import dagger.android.HasAndroidInjector import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.utils.fabric.FabricPrivacy @@ -118,6 +120,12 @@ import kotlin.math.abs return medtrumService } + override fun preprocessPreferences(preferenceFragment: PreferenceFragmentCompat) { + super.preprocessPreferences(preferenceFragment) + val serialSetting = preferenceFragment.findPreference(rh.gs(R.string.key_sn_input)) as EditTextPreference? + serialSetting?.isEnabled = !isInitialized() + } + override fun isInitialized(): Boolean { return medtrumPump.pumpState > MedtrumPumpState.EJECTED && medtrumPump.pumpState < MedtrumPumpState.STOPPED } diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/ActivatePacket.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/ActivatePacket.kt index 377f9240df..838fff9727 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/ActivatePacket.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/ActivatePacket.kt @@ -75,10 +75,6 @@ class ActivatePacket(injector: HasAndroidInjector, private val basalProfile: Byt val dailyMaxInsulin: Int = round(medtrumPump.desiredDailyMaxInsulin / 0.05).toInt() val currentTDD: Double = tddCalculator.calculateToday()?.totalAmount?.div(0.05) ?: 0.0 - // Update the pump in the database, technically this is not a new pump only new patch, but still TBR's etc need to be cannceled - // Do it here, to make sure TBR's are cancelled by AAPS before new information comes in from the pump - pumpSync.connectNewPump() - return byteArrayOf(opCode) + autoSuspendEnable + autoSuspendTime + patchExpiration + alarmSetting + lowSuspend + predictiveLowSuspend + predictiveLowSuspendRange + hourlyMaxInsulin.toByteArray( 2 ) + dailyMaxInsulin.toByteArray(2) + currentTDD.toInt().toByteArray(2) + 1.toByte() + basalProfile diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt index d70fcc31f3..8ebb41c72c 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt @@ -110,7 +110,10 @@ class MedtrumService : DaggerService(), BLECommCallback { .observeOn(aapsSchedulers.io) .subscribe({ event -> if (event.isChanged(rh.gs(R.string.key_sn_input))) { + aapsLogger.debug(LTag.PUMPCOMM, "Serial number changed, reporting new pump!") + pumpSync.connectNewPump() medtrumPump.loadUserSettingsFromSP() + medtrumPump.setFakeTBRIfNeeded() } if (event.isChanged(rh.gs(R.string.key_alarm_setting)) || event.isChanged(rh.gs(R.string.key_patch_expiration))