0.0.36 • Published 9 months ago

@nvsukhanov/rxpoweredup v0.0.36

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

rxPoweredUP

GitHub license CI Status NPM Version

A Typescript RxJS-based library for controlling LEGO Powered UP MOCs.

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 NodeJS, however, it is may by 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();
0.0.30

11 months ago

0.0.31

10 months ago

0.0.32

10 months ago

0.0.33

10 months ago

0.0.34

9 months ago

0.0.35

9 months ago

0.0.36

9 months ago

0.0.29

11 months ago

0.0.28

11 months ago

0.0.27

11 months ago

0.0.26

11 months ago

0.0.25

11 months ago

0.0.24

12 months ago

0.0.23

12 months ago

0.0.22

12 months ago

0.0.21

12 months ago

0.0.20

12 months ago

0.0.19

12 months ago

0.0.18

12 months ago

0.0.17

12 months ago

0.0.16

12 months ago

0.0.15

12 months ago