Comments (4)
Hello, thank you for using the library.
If I understood you correctly you find it difficult to use two concurrent services of your peripheral. If that's the case this wiki page should help you.
from rxandroidble.
Hello! Thanks for the quick response! oh ya i forget about share, in this use case i can create some cache like
HashMap<Rx Device,RxConnection> and provide to my code..
Is it correct if i will write like this?
val cache = HashMap<RxBleDevice, Observable<RxBleConnection>>()
fun getConnection(device: RxBleDevice): Observable<RxBleConnection> {
if (cache.contains(device)) return cache.get(device)
val connection = device.establishConnection(false).compose(ReplayingShare.instance())
.doOnError {
//clean cache/etc
cache.remove(device)
}
cache.put(device, connection)
return connection
}
fun startVoiceService(device: RxBleDevice) {
val disposable1 = getConnection(device).flatMap { connection ->
//notification
connection.setupNotification(UUID.randomUUID()).flatMap { observables ->
//request like get voice codec etc
connection.writeCharacteristic(
UUID.randomUUID(),
byteArrayOf()
).flatMapObservable {
Observable.just(observables)
}
}.flatMap { it }
.flatMap {
//some logic
if (it[0] == 0x0.toByte()) {
Observable.just(1)
} else Observable.just(2)
}
}
}
fun startUpdateCheck(device: RxBleDevice) {
val disposable2 = getConnection(device).flatMapSingle { connection ->
//get sw version ect
connection.readCharacteristic(UUID.fromString("00002a28-0000-1000-8000-00805f9b34fb"))
.flatMap {
if (it.littleEndianConversion() > 80) {
//logic to find update
Single.just(1)
} else {
Single.just(2)
}
}
}
}
So, if disposable 2 is finished (because we was take info and do logic to find update its faster then wait user input as hid event) disposable 1 will still work?
from rxandroidble.
Yes. It should still work
from rxandroidble.
Thank you for cool library!
from rxandroidble.
Related Issues (20)
- Permission for connection with sample-kotlin HOT 2
- Wrong permission checked in sample-kotlin app
- Strange unresolved methods HOT 1
- Does RxAndroidBle support the use of Bluetooth Gatt's connect method? HOT 4
- Building fork help HOT 6
- It is not possible to disconnect the Bluetooth while it is in the process of connecting. HOT 1
- BleGattCharacteristicException while readCharacteristic HOT 12
- scanResult.bleDevice.name not showing Ble updated name HOT 1
- BLUETOOTH_SCAN set usesPermissionFlags="neverForLocation",Is there a problem? HOT 2
- GenericFailure<CharacteristicValueUpdateError> HOT 11
- Send long bytes twice HOT 2
- Write request is not processed in the random order HOT 2
- Long Bytes Send HOT 8
- Creating a Fork HOT 2
- Set Preferred PHY / Read PHY HOT 2
- Is the library still maintained? HOT 3
- Android 14 breaking change HOT 15
- Google Pixel 5 loses bonding info after BT adapter cycle HOT 4
- Metode readcharacteristic not stream HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxandroidble.