mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-29 02:59:57 +02:00
Delay the response handling in BLE with ~60 ms
Hopefully this avoids error 133 seen in #159. At least that's what https://android.jlelse.eu/lessons-for-first-time-android-bluetooth-le-developers-i-learned-the-hard-way-fee07646624 suggests.
This commit is contained in:
@@ -684,24 +684,32 @@ public abstract class BluetoothCommunication {
|
|||||||
setBtMachineState(BT_MACHINE_STATE.BT_INIT_STATE);
|
setBtMachineState(BT_MACHINE_STATE.BT_INIT_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void postDelayedHandleRequests() {
|
||||||
|
// Wait a short while before starting the next operation as suggested
|
||||||
|
// on the android.jlelse.eu link above.
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
synchronized (lock) {
|
||||||
|
openRequest = false;
|
||||||
|
handleRequests();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 60);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDescriptorWrite(BluetoothGatt gatt,
|
public void onDescriptorWrite(BluetoothGatt gatt,
|
||||||
BluetoothGattDescriptor descriptor,
|
BluetoothGattDescriptor descriptor,
|
||||||
int status) {
|
int status) {
|
||||||
synchronized (lock) {
|
postDelayedHandleRequests();
|
||||||
openRequest = false;
|
|
||||||
handleRequests();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicWrite(BluetoothGatt gatt,
|
public void onCharacteristicWrite(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic,
|
BluetoothGattCharacteristic characteristic,
|
||||||
int status) {
|
int status) {
|
||||||
synchronized (lock) {
|
postDelayedHandleRequests();
|
||||||
openRequest = false;
|
|
||||||
handleRequests();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -713,8 +721,7 @@ public abstract class BluetoothCommunication {
|
|||||||
|
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
onBluetoothDataRead(gatt, characteristic, status);
|
onBluetoothDataRead(gatt, characteristic, status);
|
||||||
openRequest = false;
|
postDelayedHandleRequests();
|
||||||
handleRequests();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -736,10 +743,7 @@ public abstract class BluetoothCommunication {
|
|||||||
Timber.d("onDescriptorRead %s (status=%d): %s",
|
Timber.d("onDescriptorRead %s (status=%d): %s",
|
||||||
descriptor.getUuid(), status, byteInHex(descriptor.getValue()));
|
descriptor.getUuid(), status, byteInHex(descriptor.getValue()));
|
||||||
|
|
||||||
synchronized (lock) {
|
postDelayedHandleRequests();
|
||||||
openRequest = false;
|
|
||||||
handleRequests();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user