RS onConnectionStateChangeSynchronized

This commit is contained in:
Milos Kozak 2018-07-23 16:33:51 +02:00
parent d7b29db626
commit 130fca4c2a

View file

@ -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;