JSPM

  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q37017F
  • License MIT

A Typescript RxJS-based library for controlling LEGO Powered hubs & peripherals.

Package Exports

  • rxpoweredup
  • rxpoweredup/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rxpoweredup) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

rxPoweredUP

GitHub license CI Status NPM Version

A Typescript RxJS-based library for controlling LEGO Powered hubs & peripherals.

Documentation can be found here

Disclaimer

LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this application.

Examples

Following examples use experimental navigator.bluetooth browser API to connect to Bluetooth devices, which is not yet fully supported by all browsers. Web Bluetooth API is not available in Node.js, however, it may be possible to use libraries which provide similar API.

Async

async function test(): Promise<void> {
    const hub = await firstValueFrom(connectHub(navigator.bluetooth));
    await firstValueFrom(hub.ports.onIoAttach({
        ports: [ 0 ],
        ioTypes: [ IOType.largeTechnicMotor ]
    }));
    await lastValueFrom(hub.motors.setSpeed(0, 100));
    await lastValueFrom(timer(1000));
    await lastValueFrom(hub.motors.setSpeed(0, 0));
    await lastValueFrom(hub.disconnect());
}

document.addEventListener('click', () => test());

Reactive

function test(): Observable<unknown> {
    return connectHub(navigator.bluetooth).pipe(
        audit((hub) => hub.ports.onIoAttach({
            ports: [ 0 ],
            ioTypes: [ IOType.largeTechnicMotor ]
        })),
        switchMap((hub) => concat(
            hub.motors.setSpeed(0, 100),
            timer(1000),
            hub.motors.setSpeed(0, 0),
            hub.disconnect()
        )),
    );
}

fromEvent(document, 'click').pipe(
    exhaustMap(() => test())
).subscribe();