0.0.36 • Published 1 year ago
@nvsukhanov/rxpoweredup v0.0.36
rxPoweredUP
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
1 year ago
0.0.31
1 year ago
0.0.32
1 year ago
0.0.33
1 year ago
0.0.34
1 year ago
0.0.35
1 year ago
0.0.36
1 year ago
0.0.29
1 year ago
0.0.28
1 year ago
0.0.27
2 years ago
0.0.26
2 years ago
0.0.25
2 years ago
0.0.24
2 years ago
0.0.23
2 years ago
0.0.22
2 years ago
0.0.21
2 years ago
0.0.20
2 years ago
0.0.19
2 years ago
0.0.18
2 years ago
0.0.17
2 years ago
0.0.16
2 years ago
0.0.15
2 years ago