Git Product home page Git Product logo

Comments (4)

dariuszseweryn avatar dariuszseweryn commented on June 16, 2024

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.

morkovkin avatar morkovkin commented on June 16, 2024

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.

dariuszseweryn avatar dariuszseweryn commented on June 16, 2024

Yes. It should still work

from rxandroidble.

morkovkin avatar morkovkin commented on June 16, 2024

Thank you for cool library!

from rxandroidble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.