0.4.6 • Published 2 months ago

rxpoweredup v0.4.6

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

rxPoweredUp

GitHub license CI Status NPM Version

A light-weight Typescript RxJS-based library for controlling LEGO Powered UP hubs & peripherals using Web Bluetooth API.

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.

Reactive

connectHub(navigator.bluetooth).pipe( // connect to the first available hub
    audit((hub) => hub.ports.onIoAttach(0)), // wait for the first device to be attached to port 0
    switchMap((hub) => concat(
        hub.motors.setSpeed(0, 100), // set motor speed to 100
        timer(1000), // wait for 1 second
        hub.motors.setSpeed(0, 0), // stop motor
        hub.disconnect() // disconnect from the hub
    ))
).subscribe();

Async

const hub = await firstValueFrom(connectHub(navigator.bluetooth));
await firstValueFrom(hub.ports.onIoAttach(0));
await lastValueFrom(hub.motors.setSpeed(0, 100));
await lastValueFrom(timer(1000));
await lastValueFrom(hub.motors.setSpeed(0, 0));
await lastValueFrom(hub.disconnect());

More examples can be found here

0.4.6

2 months ago

0.4.5

2 months ago

0.4.4

2 months ago

0.4.3

2 months ago

0.4.2

2 months ago

0.4.0

3 months ago

0.3.9

4 months ago

0.3.8

4 months ago

0.3.7-alpha

4 months ago

0.3.7

4 months ago

0.3.6-alpha

4 months ago

0.3.6

4 months ago

0.3.4

4 months ago

0.3.3

4 months ago

0.3.2

4 months ago

0.0.60

7 months ago

0.0.61

6 months ago

0.0.50

7 months ago

0.1.0

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.1.1

6 months ago

0.3.1

6 months ago

0.2.2

6 months ago

0.0.41

8 months ago

0.0.42

8 months ago

0.0.40

8 months ago

0.0.39

8 months ago

0.0.38

8 months ago

0.0.37

8 months ago

0.0.36

9 months ago