mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-22 00:06:48 +02:00
removed Bluetooth delays
This commit is contained in:
@@ -35,7 +35,6 @@ import com.polidea.rxandroidble2.scan.ScanSettings;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
@@ -70,7 +69,6 @@ public abstract class BluetoothCommunication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final int BT_RETRY_TIMES_ON_ERROR = 3;
|
private final int BT_RETRY_TIMES_ON_ERROR = 3;
|
||||||
private final int BT_DELAY = 50; // MS
|
|
||||||
|
|
||||||
protected Context context;
|
protected Context context;
|
||||||
|
|
||||||
@@ -297,7 +295,6 @@ public abstract class BluetoothCommunication {
|
|||||||
*/
|
*/
|
||||||
protected void writeBytes(UUID characteristic, byte[] bytes) {
|
protected void writeBytes(UUID characteristic, byte[] bytes) {
|
||||||
final Disposable disposable = connectionObservable
|
final Disposable disposable = connectionObservable
|
||||||
.delay(BT_DELAY, TimeUnit.MILLISECONDS)
|
|
||||||
.flatMapSingle(rxBleConnection -> rxBleConnection.writeCharacteristic(characteristic, bytes))
|
.flatMapSingle(rxBleConnection -> rxBleConnection.writeCharacteristic(characteristic, bytes))
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.retry(BT_RETRY_TIMES_ON_ERROR)
|
.retry(BT_RETRY_TIMES_ON_ERROR)
|
||||||
@@ -322,7 +319,6 @@ public abstract class BluetoothCommunication {
|
|||||||
*/
|
*/
|
||||||
protected void readBytes(UUID characteristic) {
|
protected void readBytes(UUID characteristic) {
|
||||||
final Disposable disposable = connectionObservable
|
final Disposable disposable = connectionObservable
|
||||||
.delay(BT_DELAY, TimeUnit.MILLISECONDS)
|
|
||||||
.firstOrError()
|
.firstOrError()
|
||||||
.flatMap(rxBleConnection -> rxBleConnection.readCharacteristic(characteristic))
|
.flatMap(rxBleConnection -> rxBleConnection.readCharacteristic(characteristic))
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
@@ -344,7 +340,6 @@ public abstract class BluetoothCommunication {
|
|||||||
*/
|
*/
|
||||||
protected void setIndicationOn(UUID characteristic) {
|
protected void setIndicationOn(UUID characteristic) {
|
||||||
final Disposable disposable = connectionObservable
|
final Disposable disposable = connectionObservable
|
||||||
.delay(BT_DELAY, TimeUnit.MILLISECONDS)
|
|
||||||
.flatMap(rxBleConnection -> rxBleConnection.setupIndication(characteristic))
|
.flatMap(rxBleConnection -> rxBleConnection.setupIndication(characteristic))
|
||||||
.doOnNext(notificationObservable -> {
|
.doOnNext(notificationObservable -> {
|
||||||
Timber.d("Successful set indication on for %s", BluetoothGattUuid.prettyPrint(characteristic));
|
Timber.d("Successful set indication on for %s", BluetoothGattUuid.prettyPrint(characteristic));
|
||||||
@@ -375,7 +370,6 @@ public abstract class BluetoothCommunication {
|
|||||||
*/
|
*/
|
||||||
protected void setNotificationOn(UUID characteristic) {
|
protected void setNotificationOn(UUID characteristic) {
|
||||||
final Disposable disposable = connectionObservable
|
final Disposable disposable = connectionObservable
|
||||||
.delay(BT_DELAY, TimeUnit.MILLISECONDS)
|
|
||||||
.flatMap(rxBleConnection -> rxBleConnection.setupNotification(characteristic))
|
.flatMap(rxBleConnection -> rxBleConnection.setupNotification(characteristic))
|
||||||
.doOnNext(notificationObservable -> {
|
.doOnNext(notificationObservable -> {
|
||||||
Timber.d("Successful set notification on for %s", BluetoothGattUuid.prettyPrint(characteristic));
|
Timber.d("Successful set notification on for %s", BluetoothGattUuid.prettyPrint(characteristic));
|
||||||
@@ -401,7 +395,6 @@ public abstract class BluetoothCommunication {
|
|||||||
|
|
||||||
public void doBluetoothDiscoverServices() {
|
public void doBluetoothDiscoverServices() {
|
||||||
final Disposable connectionDisposable = connectionObservable
|
final Disposable connectionDisposable = connectionObservable
|
||||||
.delay(BT_DELAY, TimeUnit.MILLISECONDS)
|
|
||||||
.flatMapSingle(RxBleConnection::discoverServices)
|
.flatMapSingle(RxBleConnection::discoverServices)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.retry(BT_RETRY_TIMES_ON_ERROR)
|
.retry(BT_RETRY_TIMES_ON_ERROR)
|
||||||
@@ -528,7 +521,6 @@ public abstract class BluetoothCommunication {
|
|||||||
|
|
||||||
connectionObservable = bleDevice
|
connectionObservable = bleDevice
|
||||||
.establishConnection(false)
|
.establishConnection(false)
|
||||||
.delay(BT_DELAY, TimeUnit.MILLISECONDS)
|
|
||||||
.takeUntil(disconnectTriggerSubject)
|
.takeUntil(disconnectTriggerSubject)
|
||||||
.doOnError(throwable -> setBtStatus(BT_STATUS_CODE.BT_CONNECTION_RETRYING))
|
.doOnError(throwable -> setBtStatus(BT_STATUS_CODE.BT_CONNECTION_RETRYING))
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
Reference in New Issue
Block a user