Merge pull request #2662 from jbr7rr/medtrum-improvements
Medtrum improvements
This commit is contained in:
commit
2666197fc0
7 changed files with 98 additions and 54 deletions
|
@ -7,6 +7,7 @@ import android.content.ServiceConnection
|
|||
import android.os.IBinder
|
||||
import android.text.format.DateFormat
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.core.ui.toast.ToastUtils
|
||||
|
@ -122,8 +123,29 @@ import kotlin.math.abs
|
|||
|
||||
override fun preprocessPreferences(preferenceFragment: PreferenceFragmentCompat) {
|
||||
super.preprocessPreferences(preferenceFragment)
|
||||
val serialSetting = preferenceFragment.findPreference(rh.gs(R.string.key_sn_input)) as EditTextPreference?
|
||||
serialSetting?.isEnabled = !isInitialized()
|
||||
preferenceFragment.findPreference<EditTextPreference>(rh.gs(R.string.key_sn_input))?.isEnabled = !isInitialized()
|
||||
|
||||
val alarmSetting = preferenceFragment.findPreference<ListPreference>(rh.gs(R.string.key_alarm_setting))
|
||||
val allAlarmEntries = preferenceFragment.resources.getStringArray(R.array.alarmSettings)
|
||||
val allAlarmValues = preferenceFragment.resources.getStringArray(R.array.alarmSettingsValues)
|
||||
|
||||
if (allAlarmEntries.size < 8 || allAlarmValues.size < 8) {
|
||||
aapsLogger.error(LTag.PUMP, "Alarm settings array is not complete")
|
||||
return
|
||||
}
|
||||
|
||||
when (medtrumPump.pumpType()) {
|
||||
PumpType.MEDTRUM_NANO -> {
|
||||
alarmSetting?.entries = arrayOf(allAlarmEntries[6], allAlarmEntries[7]) // "Beep", "Silent"
|
||||
alarmSetting?.entryValues = arrayOf(allAlarmValues[6], allAlarmValues[7]) // "6", "7"
|
||||
}
|
||||
|
||||
else -> {
|
||||
// Use Nano settings for unknown pumps
|
||||
alarmSetting?.entries = arrayOf(allAlarmEntries[6], allAlarmEntries[7]) // "Beep", "Silent"
|
||||
alarmSetting?.entryValues = arrayOf(allAlarmValues[6], allAlarmValues[7]) // "6", "7"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun isInitialized(): Boolean {
|
||||
|
|
|
@ -459,11 +459,9 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
|||
private fun syncRecords(): Boolean {
|
||||
aapsLogger.debug(LTag.PUMP, "syncRecords: called!, syncedSequenceNumber: ${medtrumPump.syncedSequenceNumber}, currentSequenceNumber: ${medtrumPump.currentSequenceNumber}")
|
||||
var result = true
|
||||
// Note: medtrum app fetches all records when they sync?
|
||||
if (medtrumPump.syncedSequenceNumber < medtrumPump.currentSequenceNumber) {
|
||||
for (sequence in (medtrumPump.syncedSequenceNumber + 1)..medtrumPump.currentSequenceNumber) {
|
||||
result = sendPacketAndGetResponse(GetRecordPacket(injector, sequence), COMMAND_SYNC_TIMEOUT_SEC)
|
||||
SystemClock.sleep(100)
|
||||
if (result == false) break
|
||||
}
|
||||
}
|
||||
|
@ -644,6 +642,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
|||
mPacket = packet
|
||||
mPacket?.getRequest()?.let { bleComm.sendMessage(it) }
|
||||
result = currentState.waitForResponse(timeout)
|
||||
SystemClock.sleep(100)
|
||||
} else {
|
||||
aapsLogger.error(LTag.PUMPCOMM, "Send packet attempt when in non Ready state")
|
||||
}
|
||||
|
|
|
@ -43,14 +43,22 @@ class MedtrumActivity : MedtrumBaseActivity<ActivityMedtrumBinding>() {
|
|||
PatchStep.ATTACH_PATCH -> setupViewFragment(MedtrumAttachPatchFragment.newInstance())
|
||||
PatchStep.ACTIVATE -> setupViewFragment(MedtrumActivateFragment.newInstance())
|
||||
PatchStep.ACTIVATE_COMPLETE -> setupViewFragment(MedtrumActivateCompleteFragment.newInstance())
|
||||
PatchStep.CANCEL,
|
||||
PatchStep.COMPLETE -> this@MedtrumActivity.finish()
|
||||
PatchStep.ERROR -> Unit // Do nothing, let activity handle this
|
||||
PatchStep.RETRY_ACTIVATION -> setupViewFragment(MedtrumRetryActivationFragment.newInstance())
|
||||
PatchStep.RETRY_ACTIVATION_CONNECT -> setupViewFragment(MedtrumRetryActivationConnectFragment.newInstance())
|
||||
PatchStep.START_DEACTIVATION -> setupViewFragment(MedtrumStartDeactivationFragment.newInstance())
|
||||
PatchStep.DEACTIVATE -> setupViewFragment(MedtrumDeactivatePatchFragment.newInstance())
|
||||
|
||||
PatchStep.CANCEL -> {
|
||||
handleCancel()
|
||||
this@MedtrumActivity.finish()
|
||||
}
|
||||
|
||||
PatchStep.COMPLETE -> {
|
||||
handleComplete()
|
||||
this@MedtrumActivity.finish()
|
||||
}
|
||||
|
||||
PatchStep.FORCE_DEACTIVATION -> {
|
||||
medtrumPump.pumpState = MedtrumPumpState.STOPPED
|
||||
moveStep(PatchStep.DEACTIVATION_COMPLETE)
|
||||
|
|
|
@ -34,6 +34,7 @@ class MedtrumRetryActivationConnectFragment : MedtrumBaseFragment<FragmentMedtru
|
|||
viewModel?.apply {
|
||||
|
||||
setupStep.observe(viewLifecycleOwner) {
|
||||
if (patchStep.value != PatchStep.CANCEL) {
|
||||
when (it) {
|
||||
MedtrumViewModel.SetupStep.INITIAL -> Unit // Nothing to do here
|
||||
MedtrumViewModel.SetupStep.FILLED -> forceMoveStep(PatchStep.PRIME)
|
||||
|
@ -46,6 +47,7 @@ class MedtrumRetryActivationConnectFragment : MedtrumBaseFragment<FragmentMedtru
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
retryActivationConnect()
|
||||
}
|
||||
btnNegative.setOnClickListener {
|
||||
|
|
|
@ -47,6 +47,7 @@ class MedtrumViewModel @Inject constructor(
|
|||
val eventHandler: LiveData<UIEvent<EventType>>
|
||||
get() = _eventHandler
|
||||
|
||||
private var oldPatchStep: PatchStep? = null
|
||||
private var mInitPatchStep: PatchStep? = null
|
||||
private var connectRetryCounter = 0
|
||||
|
||||
|
@ -135,52 +136,41 @@ class MedtrumViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
fun moveStep(newPatchStep: PatchStep) {
|
||||
val oldPatchStep = patchStep.value
|
||||
oldPatchStep = patchStep.value
|
||||
|
||||
if (oldPatchStep != newPatchStep) {
|
||||
when (newPatchStep) {
|
||||
PatchStep.CANCEL -> {
|
||||
if (oldPatchStep !in listOf(
|
||||
PatchStep.PREPARE_PATCH,
|
||||
PatchStep.START_DEACTIVATION,
|
||||
PatchStep.DEACTIVATE,
|
||||
PatchStep.FORCE_DEACTIVATION,
|
||||
PatchStep.DEACTIVATION_COMPLETE
|
||||
)
|
||||
) {
|
||||
medtrumService?.disconnect("Cancel")
|
||||
}
|
||||
}
|
||||
|
||||
PatchStep.COMPLETE -> {
|
||||
medtrumService?.disconnect("Complete")
|
||||
}
|
||||
|
||||
PatchStep.CANCEL,
|
||||
PatchStep.COMPLETE,
|
||||
PatchStep.ACTIVATE_COMPLETE,
|
||||
PatchStep.ERROR,
|
||||
PatchStep.START_DEACTIVATION,
|
||||
PatchStep.DEACTIVATE,
|
||||
PatchStep.FORCE_DEACTIVATION,
|
||||
PatchStep.DEACTIVATION_COMPLETE,
|
||||
PatchStep.PREPARE_PATCH,
|
||||
PatchStep.RETRY_ACTIVATION,
|
||||
PatchStep.RETRY_ACTIVATION_CONNECT -> {
|
||||
// Do nothing, deactivation uses commandQueue to control connection
|
||||
PatchStep.RETRY_ACTIVATION -> {
|
||||
// Do nothing, these steps don't require a connection
|
||||
}
|
||||
|
||||
PatchStep.RETRY_ACTIVATION_CONNECT,
|
||||
PatchStep.PREPARE_PATCH_CONNECT -> {
|
||||
// Make sure we are disconnected, else dont move step
|
||||
if (medtrumService?.isConnected == true) {
|
||||
aapsLogger.info(LTag.PUMP, "moveStep: connected, not moving step")
|
||||
return
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
PatchStep.PRIME,
|
||||
PatchStep.PRIMING,
|
||||
PatchStep.PRIME_COMPLETE,
|
||||
PatchStep.ATTACH_PATCH,
|
||||
PatchStep.ACTIVATE -> {
|
||||
// Make sure we are connected, else dont move step
|
||||
if (medtrumService?.isConnected == false) {
|
||||
aapsLogger.info(LTag.PUMP, "moveStep: not connected, not moving step")
|
||||
return
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -198,6 +188,30 @@ class MedtrumViewModel @Inject constructor(
|
|||
aapsLogger.info(LTag.PUMP, "forceMoveStep: $oldPatchStep -> $newPatchStep")
|
||||
}
|
||||
|
||||
fun handleCancel() {
|
||||
if (oldPatchStep !in listOf(
|
||||
PatchStep.PREPARE_PATCH,
|
||||
PatchStep.START_DEACTIVATION,
|
||||
PatchStep.DEACTIVATE,
|
||||
PatchStep.FORCE_DEACTIVATION,
|
||||
PatchStep.DEACTIVATION_COMPLETE
|
||||
)
|
||||
) {
|
||||
medtrumService?.disconnect("Cancel")
|
||||
}
|
||||
if (oldPatchStep == PatchStep.RETRY_ACTIVATION_CONNECT) {
|
||||
while (medtrumService?.isConnecting == true || medtrumService?.isConnected == true) {
|
||||
SystemClock.sleep(100)
|
||||
}
|
||||
// Set pump state to FILLED, so user will be able to retry activation again
|
||||
medtrumPump.pumpState = MedtrumPumpState.FILLED
|
||||
}
|
||||
}
|
||||
|
||||
fun handleComplete() {
|
||||
medtrumService?.disconnect("Complete")
|
||||
}
|
||||
|
||||
fun initializePatchStep(step: PatchStep) {
|
||||
mInitPatchStep = prepareStep(step)
|
||||
}
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
<resources>
|
||||
<string-array name="alarmSettings">
|
||||
<!-- Nano doesnt have lights, other patches not yet supported -->
|
||||
<!-- <item>Light, vibrate and beep</item> -->
|
||||
<!-- <item>Light and vibrate</item> -->
|
||||
<!-- <item>Light and beep</item> -->
|
||||
<!-- <item>Light only</item> -->
|
||||
<item>Light, vibrate and beep</item>
|
||||
<item>Light and vibrate</item>
|
||||
<item>Light and beep</item>
|
||||
<item>Light</item>
|
||||
<item>Vibrate and beep</item>
|
||||
<item>Vibrate only</item>
|
||||
<item>Beep only</item>
|
||||
<item>None</item>
|
||||
<item>Vibrate</item>
|
||||
<item>Beep</item>
|
||||
<item>Silent</item>
|
||||
</string-array>
|
||||
<string-array name="alarmSettingsValues" translatable="false">
|
||||
<!-- <item>0</item> -->
|
||||
<!-- <item>1</item> -->
|
||||
<!-- <item>2</item> -->
|
||||
<!-- <item>3</item> -->
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
<item>6</item>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
android:summary="@string/patch_expiration_summary" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="4"
|
||||
android:defaultValue="6"
|
||||
android:key="@string/key_alarm_setting"
|
||||
android:title="@string/alarm_setting_title"
|
||||
android:dialogTitle="@string/alarm_setting_summary"
|
||||
|
@ -28,7 +28,7 @@
|
|||
android:entryValues="@array/alarmSettingsValues" />
|
||||
|
||||
<info.nightscout.core.validators.ValidatingEditTextPreference
|
||||
android:defaultValue="30"
|
||||
android:defaultValue="25"
|
||||
android:inputType="number"
|
||||
android:key="@string/key_hourly_max_insulin"
|
||||
android:title="@string/hourly_max_insulin_title"
|
||||
|
@ -38,7 +38,7 @@
|
|||
validate:testType="numericRange" />
|
||||
|
||||
<info.nightscout.core.validators.ValidatingEditTextPreference
|
||||
android:defaultValue="100"
|
||||
android:defaultValue="80"
|
||||
android:inputType="number"
|
||||
android:key="@string/key_daily_max_insulin"
|
||||
android:title="@string/daily_max_insulin_title"
|
||||
|
|
Loading…
Reference in a new issue