Updated docs, readme, version
This commit is contained in:
parent
c0009f8f08
commit
e721e0f5bf
14
README.md
14
README.md
@ -5,13 +5,13 @@
|
||||
|
||||
### 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.
|
||||
|
||||
### Node.js Installation
|
||||
|
||||
Node.js v8.0 required.
|
||||
Node.js v8.0+ required.
|
||||
|
||||
```javascript
|
||||
npm install node-poweredup --save
|
||||
@ -19,7 +19,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).
|
||||
|
||||
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
|
||||
|
||||
@ -36,6 +36,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> |
|
||||
| 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> |
|
||||
| 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.
|
||||
|
||||
@ -56,6 +62,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.
|
||||
|
||||
* 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
|
||||
|
||||
[Full documentation is available here.](https://nathankellenicki.github.io/node-poweredup/)
|
||||
|
1413
docs/AbsoluteMotor.html
Normal file
1413
docs/AbsoluteMotor.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
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
1401
docs/Hub.html
1401
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
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
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
5235
docs/PUPHub.html
5235
docs/PUPHub.html
File diff suppressed because one or more lines are too long
3876
docs/PUPRemote.html
3876
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
File diff suppressed because one or more lines are too long
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
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
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
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
File diff suppressed because one or more lines are too long
48
package-lock.json
generated
48
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-poweredup",
|
||||
"version": "5.0.0",
|
||||
"version": "6.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -36,18 +36,18 @@
|
||||
}
|
||||
},
|
||||
"@babel/code-frame": {
|
||||
"version": "7.5.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz",
|
||||
"integrity": "sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==",
|
||||
"version": "7.8.3",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.8.3.tgz",
|
||||
"integrity": "sha512-a9gxpmdXtZEInkCSHUJDLHZVBgb1QS0jhss4cPP93EW7s+uC5bikET2twEF3KV+7rDblJcmNvTR7VJejqd2C2g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/highlight": "^7.0.0"
|
||||
"@babel/highlight": "^7.8.3"
|
||||
}
|
||||
},
|
||||
"@babel/highlight": {
|
||||
"version": "7.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.5.0.tgz",
|
||||
"integrity": "sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ==",
|
||||
"version": "7.8.3",
|
||||
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.8.3.tgz",
|
||||
"integrity": "sha512-PX4y5xQUvy0fnEVHrYOarRPXVWafSjTW9T0Hab8gVIawpl2Sj0ORyrygANq+KjcNlSSTw0YCLSNA8OyZ1I4yEg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chalk": "^2.0.0",
|
||||
@ -68,9 +68,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "13.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.1.5.tgz",
|
||||
"integrity": "sha512-wupvfmtbqRJzjCm1H2diy7wo31Gn1OzvqoxCfQuKM9eSecogzP0WTlrjdq7cf7jgSO2ZX6hxwgRPR8Wt7FA22g==",
|
||||
"version": "13.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.0.tgz",
|
||||
"integrity": "sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/web-bluetooth": {
|
||||
@ -1505,9 +1505,9 @@
|
||||
"optional": true
|
||||
},
|
||||
"diff": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.1.tgz",
|
||||
"integrity": "sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==",
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
||||
"dev": true
|
||||
},
|
||||
"diffie-hellman": {
|
||||
@ -4716,9 +4716,9 @@
|
||||
}
|
||||
},
|
||||
"resolve": {
|
||||
"version": "1.12.0",
|
||||
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz",
|
||||
"integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==",
|
||||
"version": "1.15.1",
|
||||
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz",
|
||||
"integrity": "sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"path-parse": "^1.0.6"
|
||||
@ -5546,9 +5546,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"tslint": {
|
||||
"version": "5.20.1",
|
||||
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.20.1.tgz",
|
||||
"integrity": "sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg==",
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/tslint/-/tslint-6.0.0.tgz",
|
||||
"integrity": "sha512-9nLya8GBtlFmmFMW7oXXwoXS1NkrccqTqAtwXzdPV9e2mqSEvCki6iHL/Fbzi5oqbugshzgGPk7KBb2qNP1DSA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.0.0",
|
||||
@ -5562,7 +5562,7 @@
|
||||
"mkdirp": "^0.5.1",
|
||||
"resolve": "^1.3.2",
|
||||
"semver": "^5.3.0",
|
||||
"tslib": "^1.8.0",
|
||||
"tslib": "^1.10.0",
|
||||
"tsutils": "^2.29.0"
|
||||
}
|
||||
},
|
||||
@ -5597,9 +5597,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.7.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz",
|
||||
"integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==",
|
||||
"version": "3.7.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz",
|
||||
"integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==",
|
||||
"dev": true
|
||||
},
|
||||
"typical": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-poweredup",
|
||||
"version": "5.0.0",
|
||||
"version": "6.0.0",
|
||||
"description": "A Javascript module to interface with LEGO Powered Up components.",
|
||||
"homepage": "https://github.com/nathankellenicki/node-poweredup/",
|
||||
"main": "dist/node/index-node.js",
|
||||
|
@ -5,6 +5,10 @@ import { IDeviceInterface } from "../interfaces";
|
||||
import * as Consts from "../consts";
|
||||
import { mapSpeed, normalizeAngle, roundAngleToNearest90 } from "../utils";
|
||||
|
||||
/**
|
||||
* @class AbsoluteMotor
|
||||
* @extends TachoMotor
|
||||
*/
|
||||
export class AbsoluteMotor extends TachoMotor {
|
||||
|
||||
constructor (hub: IDeviceInterface, portId: number, modeMap: {[event: string]: number} = {}, type: Consts.DeviceType = Consts.DeviceType.UNKNOWN) {
|
||||
@ -20,6 +24,7 @@ export class AbsoluteMotor extends TachoMotor {
|
||||
/**
|
||||
* Emits when a the motors absolute position is changed.
|
||||
* @event AbsoluteMotor#absolute
|
||||
* @type {object}
|
||||
* @param {number} absolute
|
||||
*/
|
||||
this.notify("absolute", { angle });
|
||||
|
@ -6,6 +6,10 @@ import * as Consts from "../consts";
|
||||
|
||||
import { calculateRamp, mapSpeed } from "../utils";
|
||||
|
||||
/**
|
||||
* @class BasicMotor
|
||||
* @extends Device
|
||||
*/
|
||||
export class BasicMotor extends Device {
|
||||
|
||||
|
||||
@ -18,7 +22,7 @@ export class BasicMotor extends Device {
|
||||
* Set the motor power.
|
||||
* @method BasicMotor#setPower
|
||||
* @param {number} power For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
|
||||
* @returns {Promise} Resolved upon successful completion of command.
|
||||
* @returns {Promise} Resolved upon successful issuance of the command.
|
||||
*/
|
||||
public setPower (power: number, interrupt: boolean = true) {
|
||||
if (interrupt) {
|
||||
@ -54,7 +58,7 @@ export class BasicMotor extends Device {
|
||||
/**
|
||||
* Stop the motor.
|
||||
* @method BasicMotor#stop
|
||||
* @returns {Promise} Resolved upon successful completion of command.
|
||||
* @returns {Promise} Resolved upon successful issuance of the command.
|
||||
*/
|
||||
public stop () {
|
||||
this.cancelEventTimer();
|
||||
@ -65,7 +69,7 @@ export class BasicMotor extends Device {
|
||||
/**
|
||||
* Brake the motor.
|
||||
* @method BasicMotor#brake
|
||||
* @returns {Promise} Resolved upon successful completion of command.
|
||||
* @returns {Promise} Resolved upon successful issuance of the command.
|
||||
*/
|
||||
public brake () {
|
||||
this.cancelEventTimer();
|
||||
|
@ -4,6 +4,10 @@ import { IDeviceInterface } from "../interfaces";
|
||||
|
||||
import * as Consts from "../consts";
|
||||
|
||||
/**
|
||||
* @class ColorDistanceSensor
|
||||
* @extends Device
|
||||
*/
|
||||
export class ColorDistanceSensor extends Device {
|
||||
|
||||
constructor (hub: IDeviceInterface, portId: number) {
|
||||
@ -21,6 +25,7 @@ export class ColorDistanceSensor extends Device {
|
||||
/**
|
||||
* Emits when a color sensor is activated.
|
||||
* @event ColorDistanceSensor#color
|
||||
* @type {object}
|
||||
* @param {Color} color
|
||||
*/
|
||||
this.notify("color", { color });
|
||||
@ -37,6 +42,7 @@ export class ColorDistanceSensor extends Device {
|
||||
/**
|
||||
* Emits when a distance sensor is activated.
|
||||
* @event ColorDistanceSensor#distance
|
||||
* @type {object}
|
||||
* @param {number} distance Distance, in millimeters.
|
||||
*/
|
||||
this.notify("distance", { distance });
|
||||
@ -60,6 +66,7 @@ export class ColorDistanceSensor extends Device {
|
||||
/**
|
||||
* A combined color and distance event, emits when the sensor is activated.
|
||||
* @event ColorDistanceSensor#colorAndDistance
|
||||
* @type {object}
|
||||
* @param {Color} color
|
||||
* @param {number} distance Distance, in millimeters.
|
||||
*/
|
||||
|
@ -4,6 +4,10 @@ import { IDeviceInterface } from "../interfaces";
|
||||
|
||||
import * as Consts from "../consts";
|
||||
|
||||
/**
|
||||
* @class CurrentSensor
|
||||
* @extends Device
|
||||
*/
|
||||
export class CurrentSensor extends Device {
|
||||
|
||||
constructor (hub: IDeviceInterface, portId: number) {
|
||||
@ -31,6 +35,7 @@ export class CurrentSensor extends Device {
|
||||
/**
|
||||
* Emits when a current change is detected.
|
||||
* @event CurrentSensor#current
|
||||
* @type {object}
|
||||
* @param {number} current
|
||||
*/
|
||||
this.notify("current", { current });
|
||||
|
@ -4,6 +4,10 @@ import { IDeviceInterface } from "../interfaces";
|
||||
|
||||
import * as Consts from "../consts";
|
||||
|
||||
/**
|
||||
* @class Device
|
||||
* @extends EventEmitter
|
||||
*/
|
||||
export class Device extends EventEmitter {
|
||||
|
||||
public autoSubscribe: boolean = true;
|
||||
@ -62,10 +66,18 @@ export class Device extends EventEmitter {
|
||||
this.hub.on("detach", deviceDetachListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {boolean} connected Check if the device is still attached.
|
||||
*/
|
||||
public get connected () {
|
||||
return this._connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {Hub} hub The Hub the device is attached to.
|
||||
*/
|
||||
public get hub () {
|
||||
return this._hub;
|
||||
}
|
||||
@ -74,10 +86,18 @@ export class Device extends EventEmitter {
|
||||
return this._portId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {string} portName The port the device is attached to.
|
||||
*/
|
||||
public get portName () {
|
||||
return this.hub.getPortNameForPortId(this.portId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {number} type The type of the device
|
||||
*/
|
||||
public get type () {
|
||||
return this._type;
|
||||
}
|
||||
@ -86,6 +106,10 @@ export class Device extends EventEmitter {
|
||||
return Consts.DeviceTypeNames[this.type];
|
||||
}
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {number} mode The mode the device is currently in
|
||||
*/
|
||||
public get mode () {
|
||||
return this._mode;
|
||||
}
|
||||
@ -94,6 +118,10 @@ export class Device extends EventEmitter {
|
||||
return this._isWeDo2SmartHub;
|
||||
}
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @property {boolean} isVirtualPort Is this device attached to a virtual port (ie. a combined device)
|
||||
*/
|
||||
protected get isVirtualPort () {
|
||||
return this._isVirtualPort;
|
||||
}
|
||||
|
@ -4,6 +4,10 @@ import { IDeviceInterface } from "../interfaces";
|
||||
|
||||
import * as Consts from "../consts";
|
||||
|
||||
/**
|
||||
* @class DuploTrainBaseColorSensor
|
||||
* @extends Device
|
||||
*/
|
||||
export class DuploTrainBaseColorSensor extends Device {
|
||||
|
||||
constructor (hub: IDeviceInterface, portId: number) {
|
||||
@ -21,6 +25,7 @@ export class DuploTrainBaseColorSensor extends Device {
|
||||
/**
|
||||
* Emits when a color sensor is activated.
|
||||
* @event DuploTrainBaseColorSensor#color
|
||||
* @type {object}
|
||||
* @param {Color} color
|
||||
*/
|
||||
this.notify("color", { color });
|
||||
|
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