switch pumps properly

This commit is contained in:
Milos Kozak 2020-03-27 21:48:42 +01:00
parent 5ce8b998d9
commit 75cd9bccdc
5 changed files with 16 additions and 6 deletions

View file

@ -103,8 +103,10 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
if (event.isChanged(getResourceHelper(), R.string.key_danar_bt_name))
if (event.isChanged(getResourceHelper(), R.string.key_danar_bt_name)) {
danaRPump.setLastConnection(0);
danaRPump.setLastSettingsRead(0);
getCommandQueue().readStatus("DeviceChanged", null); }
})
);
}

View file

@ -171,7 +171,7 @@ class DanaRFragment : DaggerFragment() {
// GUI functions
@Synchronized
internal fun updateGUI() {
fun updateGUI() {
if (danar_dailyunits == null) return
val pump = danaRPump
val plugin: PumpInterface = activePlugin.activePump

View file

@ -166,9 +166,9 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
disposable.add(rxBus
.toObservable(EventDanaRSDeviceChange.class)
.observeOn(Schedulers.io())
.subscribe(event -> loadAddress(), fabricPrivacy::logException)
.subscribe(event -> changePump(), fabricPrivacy::logException)
);
loadAddress(); // load device name
changePump(); // load device name
super.onStart();
}
@ -194,10 +194,12 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
}
};
private void loadAddress() {
public void changePump() {
mDeviceAddress = sp.getString(R.string.key_danars_address, "");
mDeviceName = sp.getString(R.string.key_danars_name, "");
danaRPump.setLastConnection(0);
danaRPump.setLastSettingsRead(0);
getCommandQueue().readStatus("DeviceChanged", null);
}
@Override

View file

@ -96,6 +96,9 @@ class BLEComm @Inject internal constructor(
return false
}
isConnected = false
v3Encryption = false
encryptedDataRead = false
isConnecting = true
val device = bluetoothAdapter?.getRemoteDevice(address)
if (device == null) {
@ -118,13 +121,14 @@ class BLEComm @Inject internal constructor(
fun disconnect(from: String) {
aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from")
if (!encryptedDataRead) {
if (!encryptedDataRead && v3Encryption) {
// there was no response from pump after started encryption
// assume pairing keys are invalid
sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName)
sp.remove(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName)
sp.remove(resourceHelper.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName)
ToastUtils.showToastInUiThread(context, R.string.invalidpairing)
danaRSPlugin.changePump()
}
// cancel previous scheduled disconnection to prevent closing upcoming connection
scheduledDisconnection?.cancel(false)

View file

@ -374,12 +374,14 @@ class CommandQueue @Inject constructor(
callback?.result(PumpEnactResult(injector).success(true).enacted(false))?.run()
return false
}
/* this is breaking setting of profile at all if not engineering mode
if (!buildHelper.isEngineeringModeOrRelease()) {
val notification = Notification(Notification.NOT_ENG_MODE_OR_RELEASE, resourceHelper.gs(R.string.not_eng_mode_or_release), Notification.URGENT)
rxBus.send(EventNewNotification(notification))
callback?.result(PumpEnactResult(injector).success(false).enacted(false).comment(resourceHelper.gs(R.string.not_eng_mode_or_release)))?.run()
return false
}
*/
// Compare with pump limits
val basalValues = profile.basalValues
for (basalValue in basalValues) {