Only do connectNewPump() on sn change, only allow sn change when no patch is activated

This commit is contained in:
jbr7rr 2023-08-04 10:47:52 +02:00
parent c738b1001f
commit fe9be2bbfa
3 changed files with 11 additions and 4 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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))