Merge branch 'feature/devices'
This commit is contained in:
commit
91a0c02972
33
README.md
33
README.md
@ -3,15 +3,19 @@
|
|||||||
|
|
||||||
# **node-poweredup** - A Javascript module to interface with LEGO Powered Up components.
|
# **node-poweredup** - A Javascript module to interface with LEGO Powered Up components.
|
||||||
|
|
||||||
|
### Announcements
|
||||||
|
|
||||||
|
*Important*: v6.0.0 is a complete re-architecting of this library. Improvements include proper device and mode support through an external Device object, correct handling of firmware features, and promise-based functionality for interfacing with device attachments. Although many new features were added, existing code will almost surely break upon upgrade.
|
||||||
|
|
||||||
### Introduction
|
### Introduction
|
||||||
|
|
||||||
LEGO Powered Up is the successor to Power Functions, the system for adding electronics to LEGO models. Powered Up is a collection of ranges - starting with LEGO WeDo 2.0 released in 2016, LEGO Boost released in 2017, LEGO Powered Up released in 2018, and LEGO Technic CONTROL+ released in 2019. It also includes the 2018 Duplo App-Controlled Train sets.
|
LEGO Powered Up is the successor to Power Functions, the system for adding electronics to LEGO models. Powered Up is a collection of ranges - starting with LEGO Education WeDo 2.0 released in 2016, LEGO Boost released in 2017, LEGO Powered Up released in 2018, LEGO Technic CONTROL+ released in 2019, and LEGO Education SPIKE Prime released in 2020. It also includes the 2018 Duplo App-Controlled Train sets.
|
||||||
|
|
||||||
This library allows communication and control of Powered Up devices and peripherals via Javascript, both from Node.js and from the browser using Web Bluetooth.
|
This library allows communication and control of Powered Up devices and peripherals via Javascript, both from Node.js and from the browser using Web Bluetooth.
|
||||||
|
|
||||||
### Node.js Installation
|
### Node.js Installation
|
||||||
|
|
||||||
Node.js v8.0 required.
|
Node.js v8.0+ required.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
npm install node-poweredup --save
|
npm install node-poweredup --save
|
||||||
@ -19,7 +23,7 @@ npm install node-poweredup --save
|
|||||||
|
|
||||||
node-poweredup uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are [certain dependencies which may need installed first](https://github.com/noble/noble#prerequisites).
|
node-poweredup uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are [certain dependencies which may need installed first](https://github.com/noble/noble#prerequisites).
|
||||||
|
|
||||||
Note: node-poweredup has been tested on macOS 10.13 and Debian/Raspbian on the Raspberry Pi 3 Model B.
|
Note: node-poweredup has been tested on macOS 10.15 and Debian/Raspbian on the Raspberry Pi 3 Model B.
|
||||||
|
|
||||||
### Compatibility
|
### Compatibility
|
||||||
|
|
||||||
@ -36,6 +40,12 @@ While most Powered Up components and Hubs are compatible with each other, there
|
|||||||
| Powered Up LED Lights | <a href="https://brickset.com/sets/88005-1/">88005</a> | Light | Yes | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> |
|
| Powered Up LED Lights | <a href="https://brickset.com/sets/88005-1/">88005</a> | Light | Yes | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> |
|
||||||
| Control+ Large Motor | 22169 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a> |
|
| Control+ Large Motor | 22169 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a> |
|
||||||
| Control+ XLarge Motor | 22172 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a> |
|
| Control+ XLarge Motor | 22172 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a> |
|
||||||
|
| SPIKE Prime Medium Motor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
|
||||||
|
| SPIKE Prime Large Motor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
|
||||||
|
| SPIKE Prime Color Sensor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
|
||||||
|
| SPIKE Prime Distance Sensor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
|
||||||
|
| SPIKE Prime Force Sensor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
|
||||||
|
|
||||||
|
|
||||||
In addition, the Hubs themselves have certain built-in features which this library exposes.
|
In addition, the Hubs themselves have certain built-in features which this library exposes.
|
||||||
|
|
||||||
@ -56,6 +66,8 @@ In addition, the Hubs themselves have certain built-in features which this libra
|
|||||||
|
|
||||||
* When used with the Boost Move Hub, the Control+ Motors do not currently accept commands.
|
* When used with the Boost Move Hub, the Control+ Motors do not currently accept commands.
|
||||||
|
|
||||||
|
* The SPIKE Prime Hub does not use Bluetooth Low Energy, so is not supported via this library. It is recommended you use MicroPython and Bluetooth Classic to develop for this Hub.
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
||||||
[Full documentation is available here.](https://nathankellenicki.github.io/node-poweredup/)
|
[Full documentation is available here.](https://nathankellenicki.github.io/node-poweredup/)
|
||||||
@ -69,17 +81,22 @@ const poweredUP = new PoweredUP.PoweredUP();
|
|||||||
poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
|
poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
|
||||||
console.log(`Discovered ${hub.name}!`);
|
console.log(`Discovered ${hub.name}!`);
|
||||||
await hub.connect(); // Connect to the Hub
|
await hub.connect(); // Connect to the Hub
|
||||||
|
const motorA = hub.waitForDeviceAtPort("A"); // Make sure a motor is plugged into port A
|
||||||
|
const motorB = hub.waitForDeviceAtPort("B"); // Make sure a motor is plugged into port B
|
||||||
console.log("Connected");
|
console.log("Connected");
|
||||||
await hub.sleep(3000); // Sleep for 3 seconds before starting
|
|
||||||
|
|
||||||
while (true) { // Repeat indefinitely
|
while (true) { // Repeat indefinitely
|
||||||
console.log("Running motor B at speed 75");
|
console.log("Running motor B at speed 75");
|
||||||
hub.setMotorSpeed("B", 75); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
|
motorB.setPower("B", 75); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
|
||||||
console.log("Running motor A at speed 100 for 2 seconds");
|
console.log("Running motor A at speed 100 for 2 seconds");
|
||||||
await hub.setMotorSpeed("A", 100, 2000); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
|
motorA.setPower("A", 100); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
|
||||||
|
await hub.sleep(2000);
|
||||||
|
motorA.setPower("A", 0);
|
||||||
await hub.sleep(1000); // Do nothing for 1 second
|
await hub.sleep(1000); // Do nothing for 1 second
|
||||||
console.log("Running motor A at speed -50 for 1 seconds");
|
console.log("Running motor A at speed -50 for 1 second");
|
||||||
await hub.setMotorSpeed("A", -50, 1000); // Run a motor attached to port A for 1 second at 1/2 speed in reverse (-50) then stop
|
motorA.setPower("A", -50); // Run a motor attached to port A for 1 second at 1/2 speed in reverse (-50) then stop
|
||||||
|
hub.sleep(1000);
|
||||||
|
motorA.setPower("A", 0);
|
||||||
await hub.sleep(1000); // Do nothing for 1 second
|
await hub.sleep(1000); // Do nothing for 1 second
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
1413
docs/AbsoluteMotor.html
Normal file
1413
docs/AbsoluteMotor.html
Normal file
File diff suppressed because one or more lines are too long
1419
docs/BaseHub.html
Normal file
1419
docs/BaseHub.html
Normal file
File diff suppressed because one or more lines are too long
1716
docs/BasicMotor.html
Normal file
1716
docs/BasicMotor.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1576
docs/ColorDistanceSensor.html
Normal file
1576
docs/ColorDistanceSensor.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1264
docs/CurrentSensor.html
Normal file
1264
docs/CurrentSensor.html
Normal file
File diff suppressed because one or more lines are too long
1062
docs/Device.html
Normal file
1062
docs/Device.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1264
docs/DuploTrainBaseColorSensor.html
Normal file
1264
docs/DuploTrainBaseColorSensor.html
Normal file
File diff suppressed because one or more lines are too long
1752
docs/DuploTrainBaseMotor.html
Normal file
1752
docs/DuploTrainBaseMotor.html
Normal file
File diff suppressed because one or more lines are too long
1282
docs/DuploTrainBaseSpeaker.html
Normal file
1282
docs/DuploTrainBaseSpeaker.html
Normal file
File diff suppressed because one or more lines are too long
1116
docs/DuploTraniBaseSpeedometer.html
Normal file
1116
docs/DuploTraniBaseSpeedometer.html
Normal file
File diff suppressed because one or more lines are too long
2470
docs/Hub.html
2470
docs/Hub.html
File diff suppressed because one or more lines are too long
1492
docs/HubLED.html
Normal file
1492
docs/HubLED.html
Normal file
File diff suppressed because one or more lines are too long
3789
docs/LPF2Hub.html
3789
docs/LPF2Hub.html
File diff suppressed because one or more lines are too long
1492
docs/Light.html
Normal file
1492
docs/Light.html
Normal file
File diff suppressed because one or more lines are too long
1051
docs/MediumLinearMotor.html
Normal file
1051
docs/MediumLinearMotor.html
Normal file
File diff suppressed because one or more lines are too long
1264
docs/MotionSensor.html
Normal file
1264
docs/MotionSensor.html
Normal file
File diff suppressed because one or more lines are too long
2218
docs/MoveHub.html
Normal file
2218
docs/MoveHub.html
Normal file
File diff suppressed because one or more lines are too long
1051
docs/MoveHubMediumLinearMotor.html
Normal file
1051
docs/MoveHubMediumLinearMotor.html
Normal file
File diff suppressed because one or more lines are too long
1288
docs/MoveHubTiltSensor.html
Normal file
1288
docs/MoveHubTiltSensor.html
Normal file
File diff suppressed because one or more lines are too long
4920
docs/PUPHub.html
4920
docs/PUPHub.html
File diff suppressed because one or more lines are too long
3561
docs/PUPRemote.html
3561
docs/PUPRemote.html
File diff suppressed because one or more lines are too long
1306
docs/PiezoBuzzer.html
Normal file
1306
docs/PiezoBuzzer.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2218
docs/RemoteControl.html
Normal file
2218
docs/RemoteControl.html
Normal file
File diff suppressed because one or more lines are too long
1264
docs/RemoteControlButton.html
Normal file
1264
docs/RemoteControlButton.html
Normal file
File diff suppressed because one or more lines are too long
1116
docs/SimpleMediumLinearMotor.html
Normal file
1116
docs/SimpleMediumLinearMotor.html
Normal file
File diff suppressed because one or more lines are too long
2419
docs/TachoMotor.html
Normal file
2419
docs/TachoMotor.html
Normal file
File diff suppressed because one or more lines are too long
1552
docs/TechnicColorSensor.html
Normal file
1552
docs/TechnicColorSensor.html
Normal file
File diff suppressed because one or more lines are too long
1646
docs/TechnicDistanceSensor.html
Normal file
1646
docs/TechnicDistanceSensor.html
Normal file
File diff suppressed because one or more lines are too long
1552
docs/TechnicForceSensor.html
Normal file
1552
docs/TechnicForceSensor.html
Normal file
File diff suppressed because one or more lines are too long
1431
docs/TechnicLargeAngularMotor.html
Normal file
1431
docs/TechnicLargeAngularMotor.html
Normal file
File diff suppressed because one or more lines are too long
1431
docs/TechnicLargeLinearMotor.html
Normal file
1431
docs/TechnicLargeLinearMotor.html
Normal file
File diff suppressed because one or more lines are too long
1431
docs/TechnicMediumAngularMotor.html
Normal file
1431
docs/TechnicMediumAngularMotor.html
Normal file
File diff suppressed because one or more lines are too long
2218
docs/TechnicMediumHub.html
Normal file
2218
docs/TechnicMediumHub.html
Normal file
File diff suppressed because one or more lines are too long
1312
docs/TechnicMediumHubAccelerometerSensor.html
Normal file
1312
docs/TechnicMediumHubAccelerometerSensor.html
Normal file
File diff suppressed because one or more lines are too long
1312
docs/TechnicMediumHubGyroSensor.html
Normal file
1312
docs/TechnicMediumHubGyroSensor.html
Normal file
File diff suppressed because one or more lines are too long
1312
docs/TechnicMediumHubTiltSensor.html
Normal file
1312
docs/TechnicMediumHubTiltSensor.html
Normal file
File diff suppressed because one or more lines are too long
1431
docs/TechnicXLargeLinearMotor.html
Normal file
1431
docs/TechnicXLargeLinearMotor.html
Normal file
File diff suppressed because one or more lines are too long
1288
docs/TiltSensor.html
Normal file
1288
docs/TiltSensor.html
Normal file
File diff suppressed because one or more lines are too long
1752
docs/TrainMotor.html
Normal file
1752
docs/TrainMotor.html
Normal file
File diff suppressed because one or more lines are too long
1264
docs/VoltageSensor.html
Normal file
1264
docs/VoltageSensor.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
14820
docs/classes.list.html
14820
docs/classes.list.html
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
301
docs/devices_absolutemotor.js.html
Normal file
301
docs/devices_absolutemotor.js.html
Normal file
File diff suppressed because one or more lines are too long
289
docs/devices_basicmotor.js.html
Normal file
289
docs/devices_basicmotor.js.html
Normal file
File diff suppressed because one or more lines are too long
302
docs/devices_colordistancesensor.js.html
Normal file
302
docs/devices_colordistancesensor.js.html
Normal file
File diff suppressed because one or more lines are too long
280
docs/devices_currentsensor.js.html
Normal file
280
docs/devices_currentsensor.js.html
Normal file
File diff suppressed because one or more lines are too long
379
docs/devices_device.js.html
Normal file
379
docs/devices_device.js.html
Normal file
File diff suppressed because one or more lines are too long
261
docs/devices_duplotrainbasecolorsensor.js.html
Normal file
261
docs/devices_duplotrainbasecolorsensor.js.html
Normal file
File diff suppressed because one or more lines are too long
237
docs/devices_duplotrainbasemotor.js.html
Normal file
237
docs/devices_duplotrainbasemotor.js.html
Normal file
File diff suppressed because one or more lines are too long
254
docs/devices_duplotrainbasespeaker.js.html
Normal file
254
docs/devices_duplotrainbasespeaker.js.html
Normal file
File diff suppressed because one or more lines are too long
259
docs/devices_duplotrainbasespeedometer.js.html
Normal file
259
docs/devices_duplotrainbasespeedometer.js.html
Normal file
File diff suppressed because one or more lines are too long
285
docs/devices_hubled.js.html
Normal file
285
docs/devices_hubled.js.html
Normal file
File diff suppressed because one or more lines are too long
271
docs/devices_light.js.html
Normal file
271
docs/devices_light.js.html
Normal file
File diff suppressed because one or more lines are too long
237
docs/devices_mediumlinearmotor.js.html
Normal file
237
docs/devices_mediumlinearmotor.js.html
Normal file
File diff suppressed because one or more lines are too long
263
docs/devices_motionsensor.js.html
Normal file
263
docs/devices_motionsensor.js.html
Normal file
File diff suppressed because one or more lines are too long
237
docs/devices_movehubmediumlinearmotor.js.html
Normal file
237
docs/devices_movehubmediumlinearmotor.js.html
Normal file
File diff suppressed because one or more lines are too long
261
docs/devices_movehubtiltsensor.js.html
Normal file
261
docs/devices_movehubtiltsensor.js.html
Normal file
File diff suppressed because one or more lines are too long
253
docs/devices_piezobuzzer.js.html
Normal file
253
docs/devices_piezobuzzer.js.html
Normal file
File diff suppressed because one or more lines are too long
265
docs/devices_remotecontrolbutton.js.html
Normal file
265
docs/devices_remotecontrolbutton.js.html
Normal file
File diff suppressed because one or more lines are too long
237
docs/devices_simplemediumlinearmotor.js.html
Normal file
237
docs/devices_simplemediumlinearmotor.js.html
Normal file
File diff suppressed because one or more lines are too long
348
docs/devices_tachomotor.js.html
Normal file
348
docs/devices_tachomotor.js.html
Normal file
File diff suppressed because one or more lines are too long
285
docs/devices_techniccolorsensor.js.html
Normal file
285
docs/devices_techniccolorsensor.js.html
Normal file
File diff suppressed because one or more lines are too long
283
docs/devices_technicdistancesensor.js.html
Normal file
283
docs/devices_technicdistancesensor.js.html
Normal file
File diff suppressed because one or more lines are too long
283
docs/devices_technicforcesensor.js.html
Normal file
283
docs/devices_technicforcesensor.js.html
Normal file
File diff suppressed because one or more lines are too long
237
docs/devices_techniclargeangularmotor.js.html
Normal file
237
docs/devices_techniclargeangularmotor.js.html
Normal file
File diff suppressed because one or more lines are too long
237
docs/devices_techniclargelinearmotor.js.html
Normal file
237
docs/devices_techniclargelinearmotor.js.html
Normal file
File diff suppressed because one or more lines are too long
237
docs/devices_technicmediumangularmotor.js.html
Normal file
237
docs/devices_technicmediumangularmotor.js.html
Normal file
File diff suppressed because one or more lines are too long
263
docs/devices_technicmediumhubaccelerometersensor.js.html
Normal file
263
docs/devices_technicmediumhubaccelerometersensor.js.html
Normal file
File diff suppressed because one or more lines are too long
263
docs/devices_technicmediumhubgyrosensor.js.html
Normal file
263
docs/devices_technicmediumhubgyrosensor.js.html
Normal file
File diff suppressed because one or more lines are too long
263
docs/devices_technicmediumhubtiltsensor.js.html
Normal file
263
docs/devices_technicmediumhubtiltsensor.js.html
Normal file
File diff suppressed because one or more lines are too long
237
docs/devices_technicxlargelinearmotor.js.html
Normal file
237
docs/devices_technicxlargelinearmotor.js.html
Normal file
File diff suppressed because one or more lines are too long
261
docs/devices_tiltsensor.js.html
Normal file
261
docs/devices_tiltsensor.js.html
Normal file
File diff suppressed because one or more lines are too long
237
docs/devices_trainmotor.js.html
Normal file
237
docs/devices_trainmotor.js.html
Normal file
File diff suppressed because one or more lines are too long
284
docs/devices_voltagesensor.js.html
Normal file
284
docs/devices_voltagesensor.js.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
480
docs/global.html
480
docs/global.html
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
576
docs/hubs_basehub.js.html
Normal file
576
docs/hubs_basehub.js.html
Normal file
File diff suppressed because one or more lines are too long
276
docs/hubs_boostmovehub.js.html
Normal file
276
docs/hubs_boostmovehub.js.html
Normal file
File diff suppressed because one or more lines are too long
273
docs/hubs_controlplushub.js.html
Normal file
273
docs/hubs_controlplushub.js.html
Normal file
File diff suppressed because one or more lines are too long
263
docs/hubs_duplotrainbase.js.html
Normal file
263
docs/hubs_duplotrainbase.js.html
Normal file
File diff suppressed because one or more lines are too long
275
docs/hubs_hub.js.html
Normal file
275
docs/hubs_hub.js.html
Normal file
File diff suppressed because one or more lines are too long
561
docs/hubs_lpf2hub.js.html
Normal file
561
docs/hubs_lpf2hub.js.html
Normal file
File diff suppressed because one or more lines are too long
277
docs/hubs_movehub.js.html
Normal file
277
docs/hubs_movehub.js.html
Normal file
File diff suppressed because one or more lines are too long
273
docs/hubs_puphub.js.html
Normal file
273
docs/hubs_puphub.js.html
Normal file
File diff suppressed because one or more lines are too long
266
docs/hubs_pupremote.js.html
Normal file
266
docs/hubs_pupremote.js.html
Normal file
File diff suppressed because one or more lines are too long
265
docs/hubs_remotecontrol.js.html
Normal file
265
docs/hubs_remotecontrol.js.html
Normal file
File diff suppressed because one or more lines are too long
271
docs/hubs_technicmediumhub.js.html
Normal file
271
docs/hubs_technicmediumhub.js.html
Normal file
File diff suppressed because one or more lines are too long
417
docs/hubs_wedo2smarthub.js.html
Normal file
417
docs/hubs_wedo2smarthub.js.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user