From 130fca4c2a1f0371b49a21908f407beb0beacb65 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 23 Jul 2018 16:33:51 +0200 Subject: [PATCH] RS onConnectionStateChangeSynchronized --- .../plugins/PumpDanaRS/services/BLEComm.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java index 50ecf7527e..e15f6f23c0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java @@ -187,17 +187,7 @@ public class BLEComm { private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { - log.debug("onConnectionStateChange"); - - if (newState == BluetoothProfile.STATE_CONNECTED) { - mBluetoothGatt.discoverServices(); - } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { - close(); - isConnected = false; - isConnecting = false; - MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED)); - log.debug("Device was disconnected " + gatt.getDevice().getName());//Device was disconnected - } + onConnectionStateChangeSynchronized(gatt, status, newState); // call it synchronized } public void onServicesDiscovered(BluetoothGatt gatt, int status) { @@ -325,6 +315,20 @@ public class BLEComm { } } + public synchronized void onConnectionStateChangeSynchronized(BluetoothGatt gatt, int status, int newState) { + log.debug("onConnectionStateChange"); + + if (newState == BluetoothProfile.STATE_CONNECTED) { + mBluetoothGatt.discoverServices(); + } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { + close(); + isConnected = false; + isConnecting = false; + MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED)); + log.debug("Device was disconnected " + gatt.getDevice().getName());//Device was disconnected + } + } + private final byte[] readBuffer = new byte[1024]; private int bufferLength = 0;