Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option, to enable scanning on connection errors #3381

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import android.os.SystemClock
import androidx.core.app.ActivityCompat
import app.aaps.core.interfaces.logging.AAPSLogger
import app.aaps.core.interfaces.logging.LTag
import app.aaps.core.interfaces.sharedPreferences.SP
import app.aaps.core.ui.toast.ToastUtils
import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.comm.ManufacturerData
import info.nightscout.pump.medtrum.comm.ReadDataPacket
import info.nightscout.pump.medtrum.comm.WriteCommandPackets
Expand All @@ -46,7 +48,8 @@ interface BLECommCallback {
@Singleton
class BLEComm @Inject internal constructor(
private val aapsLogger: AAPSLogger,
private val context: Context
private val context: Context,
private val sp: SP
) {

companion object {
Expand Down Expand Up @@ -383,7 +386,12 @@ class BLEComm @Inject internal constructor(
mBluetoothGatt?.discoverServices()
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
if (isConnecting) {
aapsLogger.warn(LTag.PUMPBTCOMM, "Disconnected while connecting!")
val resetDevice = sp.getBoolean(R.string.key_scan_on_connection_error, true)
if (resetDevice) {
// When we are disconnected during connecting, we reset the device address to force a new scan
aapsLogger.warn(LTag.PUMPBTCOMM, "Disconnected while connecting! Reset device address")
mDeviceAddress = null
}
// Wait a bit before retrying
SystemClock.sleep(2000)
}
Expand Down
3 changes: 3 additions & 0 deletions pump/medtrum/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<string name="key_pump_warning_expiry_hour" translatable="false">pump_expiry_warning_hour</string>
<string name="key_hourly_max_insulin" translatable="false">hourly_max_insulin</string>
<string name="key_daily_max_insulin" translatable="false">daily_max_insulin</string>
<string name="key_scan_on_connection_error" translatable="false">scan_on_connection_error</string>

<string name="key_medtrum_pump_settings" translatable="false">medtrum_pump_setting</string>
<string name="key_pump_state" translatable="false">pump_state</string>
Expand Down Expand Up @@ -156,6 +157,8 @@
<string name="hourly_max_insulin_summary">Specify the maximum units of insulin allowed per hour. If exceeded, the pump will suspend.</string>
<string name="daily_max_insulin_title">Daily Maximum Insulin [Units]</string>
<string name="daily_max_insulin_summary">Specify the maximum units of insulin allowed per day. If exceeded, the pump will suspend.</string>
<string name="scan_on_connection_error_title">Scan on connection error</string>
<string name="scan_on_connection_error_summary">WARNING: Only enable if you have connection problems. If enabled the driver scans for the pump again before trying to reconnect to the pump. Make sure you have Location permission set to "Always allow" </string>

<!-- treatment state-->
<string name="getting_pump_status">Getting pump status</string>
Expand Down
12 changes: 12 additions & 0 deletions pump/medtrum/src/main/res/xml/pref_medtrum_pump.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@
validate:minNumber="20"
validate:testType="numericRange" />

<androidx.preference.PreferenceScreen
android:key="medtrum_advanced_settings"
android:title="@string/advanced_settings_title">

<SwitchPreference
android:defaultValue="false"
android:key="@string/key_scan_on_connection_error"
android:title="@string/scan_on_connection_error_title"
android:summary="@string/scan_on_connection_error_summary" />

</androidx.preference.PreferenceScreen>

</PreferenceCategory>

</androidx.preference.PreferenceScreen>