node-poweredup 7.1.0 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -40
- package/dist/browser/poweredup.js +1 -1
- package/dist/browser/poweredup.js.map +1 -1
- package/dist/node/consts.d.ts +41 -24
- package/dist/node/consts.js +41 -24
- package/dist/node/consts.js.map +1 -1
- package/dist/node/devices/colordistancesensor.d.ts +11 -0
- package/dist/node/devices/colordistancesensor.js +93 -1
- package/dist/node/devices/colordistancesensor.js.map +1 -1
- package/dist/node/devices/device.js +2 -0
- package/dist/node/devices/device.js.map +1 -1
- package/dist/node/devices/technicmediumhubtiltsensor.d.ts +25 -1
- package/dist/node/devices/technicmediumhubtiltsensor.js +70 -2
- package/dist/node/devices/technicmediumhubtiltsensor.js.map +1 -1
- package/dist/node/hubs/basehub.d.ts +10 -0
- package/dist/node/hubs/basehub.js +14 -0
- package/dist/node/hubs/basehub.js.map +1 -1
- package/dist/node/hubs/lpf2hub.js +5 -4
- package/dist/node/hubs/lpf2hub.js.map +1 -1
- package/dist/node/nobleabstraction.js +2 -0
- package/dist/node/nobleabstraction.js.map +1 -1
- package/dist/node/poweredup-node.js +26 -1
- package/dist/node/poweredup-node.js.map +1 -1
- package/dist/node/webbleabstraction.js +1 -0
- package/dist/node/webbleabstraction.js.map +1 -1
- package/docs/AbsoluteMotor.html +1 -1
- package/docs/BaseHub.html +251 -9
- package/docs/BasicMotor.html +1 -1
- package/docs/ColorDistanceSensor.html +841 -53
- package/docs/CurrentSensor.html +1 -1
- package/docs/Device.html +1 -1
- package/docs/DuploTrainBase.html +269 -9
- package/docs/DuploTrainBaseColorSensor.html +1 -1
- package/docs/DuploTrainBaseMotor.html +1 -1
- package/docs/DuploTrainBaseSpeaker.html +1 -1
- package/docs/DuploTraniBaseSpeedometer.html +1 -1
- package/docs/Hub.html +658 -138
- package/docs/HubLED.html +1 -1
- package/docs/LPF2Hub.html +269 -9
- package/docs/Light.html +1 -1
- package/docs/Mario.html +269 -9
- package/docs/MarioAccelerometer.html +1 -1
- package/docs/MarioBarcodeSensor.html +1 -1
- package/docs/MarioPantsSensor.html +1 -1
- package/docs/MediumLinearMotor.html +1 -1
- package/docs/MotionSensor.html +1 -1
- package/docs/MoveHub.html +269 -9
- package/docs/MoveHubMediumLinearMotor.html +1 -1
- package/docs/MoveHubTiltSensor.html +1 -1
- package/docs/PiezoBuzzer.html +1 -1
- package/docs/PoweredUP.html +24 -24
- package/docs/RemoteControl.html +269 -9
- package/docs/RemoteControlButton.html +1 -1
- package/docs/SimpleMediumLinearMotor.html +1 -1
- package/docs/TachoMotor.html +1 -1
- package/docs/Technic3x3ColorLightMatrix.html +1 -1
- package/docs/TechnicColorSensor.html +1 -1
- package/docs/TechnicDistanceSensor.html +1 -1
- package/docs/TechnicForceSensor.html +1 -1
- package/docs/TechnicLargeAngularMotor.html +1 -1
- package/docs/TechnicLargeLinearMotor.html +1 -1
- package/docs/TechnicMediumAngularMotor.html +1 -1
- package/docs/TechnicMediumHub.html +269 -9
- package/docs/TechnicMediumHubAccelerometerSensor.html +1 -1
- package/docs/TechnicMediumHubGyroSensor.html +1 -1
- package/docs/TechnicMediumHubTiltSensor.html +590 -2
- package/docs/TechnicSmallAngularMotor.html +1 -1
- package/docs/TechnicXLargeLinearMotor.html +1 -1
- package/docs/TiltSensor.html +1 -1
- package/docs/TrainMotor.html +1 -1
- package/docs/VoltageSensor.html +1 -1
- package/docs/WeDo2SmartHub.html +269 -9
- package/docs/consts.js.html +42 -25
- package/docs/devices_absolutemotor.js.html +1 -1
- package/docs/devices_basicmotor.js.html +1 -1
- package/docs/devices_colordistancesensor.js.html +94 -2
- package/docs/devices_currentsensor.js.html +1 -1
- package/docs/devices_device.js.html +3 -1
- package/docs/devices_duplotrainbasecolorsensor.js.html +1 -1
- package/docs/devices_duplotrainbasemotor.js.html +1 -1
- package/docs/devices_duplotrainbasespeaker.js.html +1 -1
- package/docs/devices_duplotrainbasespeedometer.js.html +1 -1
- package/docs/devices_hubled.js.html +1 -1
- package/docs/devices_light.js.html +1 -1
- package/docs/devices_marioaccelerometer.js.html +1 -1
- package/docs/devices_mariobarcodesensor.js.html +1 -1
- package/docs/devices_mariopantssensor.js.html +1 -1
- package/docs/devices_mediumlinearmotor.js.html +1 -1
- package/docs/devices_motionsensor.js.html +1 -1
- package/docs/devices_movehubmediumlinearmotor.js.html +1 -1
- package/docs/devices_movehubtiltsensor.js.html +1 -1
- package/docs/devices_piezobuzzer.js.html +1 -1
- package/docs/devices_remotecontrolbutton.js.html +1 -1
- package/docs/devices_simplemediumlinearmotor.js.html +1 -1
- package/docs/devices_tachomotor.js.html +1 -1
- package/docs/devices_technic3x3colorlightmatrix.js.html +1 -1
- package/docs/devices_techniccolorsensor.js.html +1 -1
- package/docs/devices_technicdistancesensor.js.html +1 -1
- package/docs/devices_technicforcesensor.js.html +1 -1
- package/docs/devices_techniclargeangularmotor.js.html +1 -1
- package/docs/devices_techniclargelinearmotor.js.html +1 -1
- package/docs/devices_technicmediumangularmotor.js.html +1 -1
- package/docs/devices_technicmediumhubaccelerometersensor.js.html +1 -1
- package/docs/devices_technicmediumhubgyrosensor.js.html +1 -1
- package/docs/devices_technicmediumhubtiltsensor.js.html +71 -3
- package/docs/devices_technicsmallangularmotor.js.html +1 -1
- package/docs/devices_technicxlargelinearmotor.js.html +1 -1
- package/docs/devices_tiltsensor.js.html +1 -1
- package/docs/devices_trainmotor.js.html +1 -1
- package/docs/devices_voltagesensor.js.html +1 -1
- package/docs/global.html +541 -48
- package/docs/hubs_basehub.js.html +15 -1
- package/docs/hubs_duplotrainbase.js.html +1 -1
- package/docs/hubs_hub.js.html +1 -1
- package/docs/hubs_lpf2hub.js.html +6 -5
- package/docs/hubs_mario.js.html +1 -1
- package/docs/hubs_movehub.js.html +1 -1
- package/docs/hubs_remotecontrol.js.html +1 -1
- package/docs/hubs_technicmediumhub.js.html +1 -1
- package/docs/hubs_technicsmallhub.js.html +1 -1
- package/docs/hubs_wedo2smarthub.js.html +1 -1
- package/docs/index.html +35 -35
- package/docs/poweredup-browser.js.html +1 -1
- package/docs/poweredup-node.js.html +27 -2
- package/package.json +12 -12
- package/src/consts.ts +41 -24
- package/src/devices/colordistancesensor.ts +96 -2
- package/src/devices/device.ts +1 -0
- package/src/devices/technicmediumhubtiltsensor.ts +75 -3
- package/src/hubs/basehub.ts +18 -0
- package/src/hubs/lpf2hub.ts +5 -6
- package/src/nobleabstraction.ts +2 -0
- package/src/poweredup-node.ts +6 -1
- package/src/webbleabstraction.ts +1 -0
package/README.md
CHANGED
|
@@ -24,9 +24,48 @@ Other products that speak the Powered Up protocol include the Duplo App-Controll
|
|
|
24
24
|
|
|
25
25
|
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.
|
|
26
26
|
|
|
27
|
+
### Sample Usage
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
const PoweredUP = require("node-poweredup");
|
|
31
|
+
const poweredUP = new PoweredUP.PoweredUP();
|
|
32
|
+
|
|
33
|
+
poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
|
|
34
|
+
console.log(`Discovered ${hub.name}!`);
|
|
35
|
+
await hub.connect(); // Connect to the Hub
|
|
36
|
+
const motorA = await hub.waitForDeviceAtPort("A"); // Make sure a motor is plugged into port A
|
|
37
|
+
const motorB = await hub.waitForDeviceAtPort("B"); // Make sure a motor is plugged into port B
|
|
38
|
+
console.log("Connected");
|
|
39
|
+
|
|
40
|
+
while (true) { // Repeat indefinitely
|
|
41
|
+
console.log("Running motor B at speed 50");
|
|
42
|
+
motorB.setPower(50); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
|
|
43
|
+
console.log("Running motor A at speed 100 for 2 seconds");
|
|
44
|
+
motorA.setPower(100); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
|
|
45
|
+
await hub.sleep(2000);
|
|
46
|
+
motorA.brake();
|
|
47
|
+
await hub.sleep(1000); // Do nothing for 1 second
|
|
48
|
+
console.log("Running motor A at speed -30 for 1 second");
|
|
49
|
+
motorA.setPower(-30); // Run a motor attached to port A for 2 seconds at 1/2 speed in reverse (-50) then stop
|
|
50
|
+
await hub.sleep(2000);
|
|
51
|
+
motorA.brake();
|
|
52
|
+
await hub.sleep(1000); // Do nothing for 1 second
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
poweredUP.scan(); // Start scanning for Hubs
|
|
57
|
+
console.log("Scanning for Hubs...");
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
More examples are available in the "examples" directory.
|
|
61
|
+
|
|
62
|
+
### Documentation
|
|
63
|
+
|
|
64
|
+
[Full documentation is available here.](https://nathankellenicki.github.io/node-poweredup/)
|
|
65
|
+
|
|
27
66
|
### Node.js Installation
|
|
28
67
|
|
|
29
|
-
Node.js
|
|
68
|
+
Node.js v12.0+ required.
|
|
30
69
|
|
|
31
70
|
```javascript
|
|
32
71
|
npm install node-poweredup --save
|
|
@@ -83,45 +122,6 @@ In addition, the Hubs themselves have certain built-in features which this libra
|
|
|
83
122
|
|
|
84
123
|
* On most Unix systems, you need root permissions to access Bluetooth devices. You may want to [grant the node executable access to the Bluetooth adapter](https://github.com/abandonware/noble#running-without-rootsudo-linux-specific)
|
|
85
124
|
|
|
86
|
-
### Documentation
|
|
87
|
-
|
|
88
|
-
[Full documentation is available here.](https://nathankellenicki.github.io/node-poweredup/)
|
|
89
|
-
|
|
90
|
-
### Node.js Sample Usage
|
|
91
|
-
|
|
92
|
-
```javascript
|
|
93
|
-
const PoweredUP = require("node-poweredup");
|
|
94
|
-
const poweredUP = new PoweredUP.PoweredUP();
|
|
95
|
-
|
|
96
|
-
poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
|
|
97
|
-
console.log(`Discovered ${hub.name}!`);
|
|
98
|
-
await hub.connect(); // Connect to the Hub
|
|
99
|
-
const motorA = await hub.waitForDeviceAtPort("A"); // Make sure a motor is plugged into port A
|
|
100
|
-
const motorB = await hub.waitForDeviceAtPort("B"); // Make sure a motor is plugged into port B
|
|
101
|
-
console.log("Connected");
|
|
102
|
-
|
|
103
|
-
while (true) { // Repeat indefinitely
|
|
104
|
-
console.log("Running motor B at speed 50");
|
|
105
|
-
motorB.setPower(50); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
|
|
106
|
-
console.log("Running motor A at speed 100 for 2 seconds");
|
|
107
|
-
motorA.setPower(100); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
|
|
108
|
-
await hub.sleep(2000);
|
|
109
|
-
motorA.brake();
|
|
110
|
-
await hub.sleep(1000); // Do nothing for 1 second
|
|
111
|
-
console.log("Running motor A at speed -30 for 1 second");
|
|
112
|
-
motorA.setPower(-30); // Run a motor attached to port A for 2 seconds at 1/2 speed in reverse (-50) then stop
|
|
113
|
-
await hub.sleep(2000);
|
|
114
|
-
motorA.brake();
|
|
115
|
-
await hub.sleep(1000); // Do nothing for 1 second
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
poweredUP.scan(); // Start scanning for Hubs
|
|
120
|
-
console.log("Scanning for Hubs...");
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
More examples are available in the "examples" directory.
|
|
124
|
-
|
|
125
125
|
### Credits
|
|
126
126
|
|
|
127
127
|
Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian Raff ([@hobbyquaker](https://github.com/hobbyquaker)), Valentin Heun ([@vheun](https://github.com/vheun)), Johan Korten ([@jakorten](https://github.com/jakorten)), and Andrey Pokhilko ([@undera](https://github.com/undera)) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered Up protocols.
|