Skip to content

twyatt/RxIoio

Repository files navigation

RxIoio

Reactive APIs for IOIO. Designed to work alongside the standard IOIOLooper paradigm.

Inspired by libraries such as RxBinding and Rx Preferences.

Usage

// ...
@Override
public IOIOLooper createIOIOLooper(String connectionType, Object extra) {
    return new IOIOLooper() {
        @Override
        public void setup(IOIO ioio) throws ConnectionLostException, InterruptedException {
            RxIoio rxIoio = RxIoio.create(ioio);
            // ...
        }

        @Override
        public void disconnected() {
            disposable.dispose();
        }

        // ...
    }
}
// ...

Input

// ...
RxIoio rxIoio = RxIoio.create(ioio);
disposable = rxIoio
    .digitalInput(BUTTON_INPUT_PIN)
    .subscribeWith(new DisposableSubscriber<Boolean>() {
        @Override
        public void onNext(Boolean aBoolean) {
            System.out.println("Button pressed: " + aBoolean);
        }
        // ...
    }
// ...

Output

// ...
RxIoio rxIoio = RxIoio.create(ioio);

disposable = rxFlowable // Whereas rxFlowable provides a stream of Boolean objects.
    .lift(rxIoio.digitalOutput(STAT_LED_PIN))
    .subscribeWith(new DisposableSubscriber<Boolean>() {
        @Override
        public void onNext(Boolean aBoolean) {
            System.out.println("Setting stat LED pin to: " + aBoolean);
        }
        // ...
    }
// ...

See Android example or Desktop example for more details.