Reactive APIs for IOIO. Designed to work alongside the standard IOIOLooper paradigm.
Inspired by libraries such as RxBinding and Rx Preferences.
// ...
@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();
}
// ...
}
}
// ...
// ...
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);
}
// ...
}
// ...
// ...
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.