node-poweredup 7.1.0 → 8.0.0

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.
Files changed (124) hide show
  1. package/README.md +40 -40
  2. package/dist/browser/poweredup.js +1 -1
  3. package/dist/browser/poweredup.js.map +1 -1
  4. package/dist/node/consts.d.ts +41 -24
  5. package/dist/node/consts.js +41 -24
  6. package/dist/node/consts.js.map +1 -1
  7. package/dist/node/devices/colordistancesensor.d.ts +11 -0
  8. package/dist/node/devices/colordistancesensor.js +93 -1
  9. package/dist/node/devices/colordistancesensor.js.map +1 -1
  10. package/dist/node/devices/device.js +2 -0
  11. package/dist/node/devices/device.js.map +1 -1
  12. package/dist/node/devices/technicmediumhubtiltsensor.d.ts +25 -1
  13. package/dist/node/devices/technicmediumhubtiltsensor.js +70 -2
  14. package/dist/node/devices/technicmediumhubtiltsensor.js.map +1 -1
  15. package/dist/node/hubs/lpf2hub.js +5 -4
  16. package/dist/node/hubs/lpf2hub.js.map +1 -1
  17. package/dist/node/poweredup-node.js +24 -1
  18. package/dist/node/poweredup-node.js.map +1 -1
  19. package/docs/AbsoluteMotor.html +1 -1
  20. package/docs/BaseHub.html +1 -1
  21. package/docs/BasicMotor.html +1 -1
  22. package/docs/ColorDistanceSensor.html +841 -53
  23. package/docs/CurrentSensor.html +1 -1
  24. package/docs/Device.html +1 -1
  25. package/docs/DuploTrainBase.html +1 -1
  26. package/docs/DuploTrainBaseColorSensor.html +1 -1
  27. package/docs/DuploTrainBaseMotor.html +1 -1
  28. package/docs/DuploTrainBaseSpeaker.html +1 -1
  29. package/docs/DuploTraniBaseSpeedometer.html +1 -1
  30. package/docs/Hub.html +1 -1
  31. package/docs/HubLED.html +1 -1
  32. package/docs/LPF2Hub.html +1 -1
  33. package/docs/Light.html +1 -1
  34. package/docs/Mario.html +1 -1
  35. package/docs/MarioAccelerometer.html +1 -1
  36. package/docs/MarioBarcodeSensor.html +1 -1
  37. package/docs/MarioPantsSensor.html +1 -1
  38. package/docs/MediumLinearMotor.html +1 -1
  39. package/docs/MotionSensor.html +1 -1
  40. package/docs/MoveHub.html +1 -1
  41. package/docs/MoveHubMediumLinearMotor.html +1 -1
  42. package/docs/MoveHubTiltSensor.html +1 -1
  43. package/docs/PiezoBuzzer.html +1 -1
  44. package/docs/PoweredUP.html +23 -23
  45. package/docs/RemoteControl.html +1 -1
  46. package/docs/RemoteControlButton.html +1 -1
  47. package/docs/SimpleMediumLinearMotor.html +1 -1
  48. package/docs/TachoMotor.html +1 -1
  49. package/docs/Technic3x3ColorLightMatrix.html +1 -1
  50. package/docs/TechnicColorSensor.html +1 -1
  51. package/docs/TechnicDistanceSensor.html +1 -1
  52. package/docs/TechnicForceSensor.html +1 -1
  53. package/docs/TechnicLargeAngularMotor.html +1 -1
  54. package/docs/TechnicLargeLinearMotor.html +1 -1
  55. package/docs/TechnicMediumAngularMotor.html +1 -1
  56. package/docs/TechnicMediumHub.html +1 -1
  57. package/docs/TechnicMediumHubAccelerometerSensor.html +1 -1
  58. package/docs/TechnicMediumHubGyroSensor.html +1 -1
  59. package/docs/TechnicMediumHubTiltSensor.html +590 -2
  60. package/docs/TechnicSmallAngularMotor.html +1 -1
  61. package/docs/TechnicXLargeLinearMotor.html +1 -1
  62. package/docs/TiltSensor.html +1 -1
  63. package/docs/TrainMotor.html +1 -1
  64. package/docs/VoltageSensor.html +1 -1
  65. package/docs/WeDo2SmartHub.html +1 -1
  66. package/docs/consts.js.html +42 -25
  67. package/docs/devices_absolutemotor.js.html +1 -1
  68. package/docs/devices_basicmotor.js.html +1 -1
  69. package/docs/devices_colordistancesensor.js.html +94 -2
  70. package/docs/devices_currentsensor.js.html +1 -1
  71. package/docs/devices_device.js.html +3 -1
  72. package/docs/devices_duplotrainbasecolorsensor.js.html +1 -1
  73. package/docs/devices_duplotrainbasemotor.js.html +1 -1
  74. package/docs/devices_duplotrainbasespeaker.js.html +1 -1
  75. package/docs/devices_duplotrainbasespeedometer.js.html +1 -1
  76. package/docs/devices_hubled.js.html +1 -1
  77. package/docs/devices_light.js.html +1 -1
  78. package/docs/devices_marioaccelerometer.js.html +1 -1
  79. package/docs/devices_mariobarcodesensor.js.html +1 -1
  80. package/docs/devices_mariopantssensor.js.html +1 -1
  81. package/docs/devices_mediumlinearmotor.js.html +1 -1
  82. package/docs/devices_motionsensor.js.html +1 -1
  83. package/docs/devices_movehubmediumlinearmotor.js.html +1 -1
  84. package/docs/devices_movehubtiltsensor.js.html +1 -1
  85. package/docs/devices_piezobuzzer.js.html +1 -1
  86. package/docs/devices_remotecontrolbutton.js.html +1 -1
  87. package/docs/devices_simplemediumlinearmotor.js.html +1 -1
  88. package/docs/devices_tachomotor.js.html +1 -1
  89. package/docs/devices_technic3x3colorlightmatrix.js.html +1 -1
  90. package/docs/devices_techniccolorsensor.js.html +1 -1
  91. package/docs/devices_technicdistancesensor.js.html +1 -1
  92. package/docs/devices_technicforcesensor.js.html +1 -1
  93. package/docs/devices_techniclargeangularmotor.js.html +1 -1
  94. package/docs/devices_techniclargelinearmotor.js.html +1 -1
  95. package/docs/devices_technicmediumangularmotor.js.html +1 -1
  96. package/docs/devices_technicmediumhubaccelerometersensor.js.html +1 -1
  97. package/docs/devices_technicmediumhubgyrosensor.js.html +1 -1
  98. package/docs/devices_technicmediumhubtiltsensor.js.html +71 -3
  99. package/docs/devices_technicsmallangularmotor.js.html +1 -1
  100. package/docs/devices_technicxlargelinearmotor.js.html +1 -1
  101. package/docs/devices_tiltsensor.js.html +1 -1
  102. package/docs/devices_trainmotor.js.html +1 -1
  103. package/docs/devices_voltagesensor.js.html +1 -1
  104. package/docs/global.html +541 -48
  105. package/docs/hubs_basehub.js.html +1 -1
  106. package/docs/hubs_duplotrainbase.js.html +1 -1
  107. package/docs/hubs_hub.js.html +1 -1
  108. package/docs/hubs_lpf2hub.js.html +6 -5
  109. package/docs/hubs_mario.js.html +1 -1
  110. package/docs/hubs_movehub.js.html +1 -1
  111. package/docs/hubs_remotecontrol.js.html +1 -1
  112. package/docs/hubs_technicmediumhub.js.html +1 -1
  113. package/docs/hubs_technicsmallhub.js.html +1 -1
  114. package/docs/hubs_wedo2smarthub.js.html +1 -1
  115. package/docs/index.html +35 -35
  116. package/docs/poweredup-browser.js.html +1 -1
  117. package/docs/poweredup-node.js.html +25 -2
  118. package/package.json +12 -12
  119. package/src/consts.ts +41 -24
  120. package/src/devices/colordistancesensor.ts +96 -2
  121. package/src/devices/device.ts +1 -0
  122. package/src/devices/technicmediumhubtiltsensor.ts +75 -3
  123. package/src/hubs/lpf2hub.ts +5 -6
  124. package/src/poweredup-node.ts +4 -1
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 v8.0+ required.
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.