RS pairing improvement

This commit is contained in:
Milos Kozak 2021-03-05 21:19:53 +01:00
parent 04f074caf9
commit 65770ecbf6
3 changed files with 12 additions and 6 deletions

View file

@ -177,6 +177,7 @@
<!-- BlePreCheck-->
<string name="ble_not_supported">Bluetooth Low Energy not supported.</string>
<string name="ble_not_supported_or_not_paired">Bluetooth Low Energy not supported or device not paired.</string>
<string name="ble_not_enabled">Bluetooth not enabled.</string>
<string name="location_not_found_title">Location Is Not Enabled</string>
<string name="location_not_found_message">For Bluetooth discovery to work on newer devices, location must be enabled. AAPS does not track your location and it can be disabled after pairing is successful.</string>

View file

@ -137,7 +137,7 @@ class DanaRSPlugin @Inject constructor(
aapsLogger.debug(LTag.PUMP, "RS connect from: $reason")
if (danaRSService != null && mDeviceAddress != "" && mDeviceName != "") {
val success = danaRSService?.connect(reason, mDeviceAddress) ?: false
if (!success) ToastUtils.showToastInUiThread(context, resourceHelper.gs(R.string.ble_not_supported))
if (!success) ToastUtils.showToastInUiThread(context, resourceHelper.gs(R.string.ble_not_supported_or_not_paired))
}
}

View file

@ -105,16 +105,21 @@ class BLEComm @Inject internal constructor(
return false
}
isConnected = false
v3Encryption = false
encryptedDataRead = false
encryptedCommandSent = false
isConnecting = true
val device = bluetoothAdapter?.getRemoteDevice(address)
if (device == null) {
aapsLogger.error("Device not found. Unable to connect from: $from")
return false
}
if (device.bondState == BluetoothDevice.BOND_NONE) {
device.createBond()
SystemClock.sleep(10000)
return false
}
isConnected = false
v3Encryption = false
encryptedDataRead = false
encryptedCommandSent = false
isConnecting = true
aapsLogger.debug(LTag.PUMPBTCOMM, "Trying to create a new connection from: $from")
connectDeviceName = device.name
bluetoothGatt = device.connectGatt(context, false, mGattCallback)