RS onConnectionStateChangeSynchronized
This commit is contained in:
parent
d7b29db626
commit
130fca4c2a
1 changed files with 15 additions and 11 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue