From c0009f8f08d8a81c94520e66a65a71c0f044dad3 Mon Sep 17 00:00:00 2001 From: Nathan Kellenicki Date: Fri, 7 Feb 2020 14:28:32 -0800 Subject: [PATCH] Updated vernie sample, added braking style --- README.md | 15 +- docs/BaseHub.html | 1419 ++ docs/DuploTrainBase.html | 4872 +----- docs/Hub.html | 1791 ++- docs/LPF2Hub.html | 3897 +---- docs/MoveHub.html | 2412 +++ docs/PoweredUP.html | 206 +- docs/RemoteControl.html | 2412 +++ docs/TechnicMediumHub.html | 2412 +++ docs/WeDo2SmartHub.html | 4365 +---- docs/classes.list.html | 13164 +++------------- docs/consts.js.html | 105 +- docs/devices_absolutemotor.js.html | 296 + docs/devices_basicmotor.js.html | 285 + docs/devices_colordistancesensor.js.html | 295 + docs/devices_currentsensor.js.html | 275 + .../devices_duplotrainbasecolorsensor.js.html | 256 + docs/devices_duplotrainbasespeaker.js.html | 250 + .../devices_duplotrainbasespeedometer.js.html | 254 + docs/devices_hubled.js.html | 281 + docs/devices_light.js.html | 267 + docs/devices_motionsensor.js.html | 258 + docs/devices_movehubtiltsensor.js.html | 256 + docs/devices_piezobuzzer.js.html | 249 + docs/devices_remotecontrolbutton.js.html | 260 + docs/devices_tachomotor.js.html | 336 + docs/devices_techniccolorsensor.js.html | 278 + docs/devices_technicdistancesensor.js.html | 277 + docs/devices_technicforcesensor.js.html | 276 + ...echnicmediumhubaccelerometersensor.js.html | 259 + ...devices_technicmediumhubgyrosensor.js.html | 258 + ...devices_technicmediumhubtiltsensor.js.html | 258 + docs/devices_tiltsensor.js.html | 256 + docs/devices_voltagesensor.js.html | 279 + docs/global.html | 480 +- docs/hubs_basehub.js.html | 543 + docs/hubs_duplotrainbase.js.html | 263 + docs/hubs_hub.js.html | 275 + docs/hubs_lpf2hub.js.html | 552 + docs/hubs_movehub.js.html | 277 + docs/hubs_remotecontrol.js.html | 265 + docs/hubs_technicmediumhub.js.html | 271 + docs/hubs_wedo2smarthub.js.html | 417 + docs/index.html | 28 +- docs/poweredup-node.js.html | 84 +- docs/quicksearch.html | 2 +- examples/vernie_remote.js | 52 +- package.json | 8 +- src/consts.ts | 11 + src/devices/absolutemotor.ts | 114 +- src/devices/basicmotor.ts | 2 +- src/devices/tachomotor.ts | 20 +- src/hubs/technicmediumhub.ts | 59 - 53 files changed, 22479 insertions(+), 24273 deletions(-) create mode 100644 docs/BaseHub.html create mode 100644 docs/MoveHub.html create mode 100644 docs/RemoteControl.html create mode 100644 docs/TechnicMediumHub.html create mode 100644 docs/devices_absolutemotor.js.html create mode 100644 docs/devices_basicmotor.js.html create mode 100644 docs/devices_colordistancesensor.js.html create mode 100644 docs/devices_currentsensor.js.html create mode 100644 docs/devices_duplotrainbasecolorsensor.js.html create mode 100644 docs/devices_duplotrainbasespeaker.js.html create mode 100644 docs/devices_duplotrainbasespeedometer.js.html create mode 100644 docs/devices_hubled.js.html create mode 100644 docs/devices_light.js.html create mode 100644 docs/devices_motionsensor.js.html create mode 100644 docs/devices_movehubtiltsensor.js.html create mode 100644 docs/devices_piezobuzzer.js.html create mode 100644 docs/devices_remotecontrolbutton.js.html create mode 100644 docs/devices_tachomotor.js.html create mode 100644 docs/devices_techniccolorsensor.js.html create mode 100644 docs/devices_technicdistancesensor.js.html create mode 100644 docs/devices_technicforcesensor.js.html create mode 100644 docs/devices_technicmediumhubaccelerometersensor.js.html create mode 100644 docs/devices_technicmediumhubgyrosensor.js.html create mode 100644 docs/devices_technicmediumhubtiltsensor.js.html create mode 100644 docs/devices_tiltsensor.js.html create mode 100644 docs/devices_voltagesensor.js.html create mode 100644 docs/hubs_basehub.js.html create mode 100644 docs/hubs_duplotrainbase.js.html create mode 100644 docs/hubs_hub.js.html create mode 100644 docs/hubs_lpf2hub.js.html create mode 100644 docs/hubs_movehub.js.html create mode 100644 docs/hubs_remotecontrol.js.html create mode 100644 docs/hubs_technicmediumhub.js.html create mode 100644 docs/hubs_wedo2smarthub.js.html diff --git a/README.md b/README.md index dbb1771..2c86c9a 100644 --- a/README.md +++ b/README.md @@ -69,17 +69,22 @@ const poweredUP = new PoweredUP.PoweredUP(); poweredUP.on("discover", async (hub) => { // Wait to discover a Hub console.log(`Discovered ${hub.name}!`); 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"); - await hub.sleep(3000); // Sleep for 3 seconds before starting while (true) { // Repeat indefinitely 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"); - 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 - console.log("Running motor A at speed -50 for 1 seconds"); - 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 + console.log("Running motor A at speed -50 for 1 second"); + 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 } }); diff --git a/docs/BaseHub.html b/docs/BaseHub.html new file mode 100644 index 0000000..b582d8f --- /dev/null +++ b/docs/BaseHub.html @@ -0,0 +1,1419 @@ + + + + + + + node-poweredup Class: BaseHub + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: BaseHub

+
+ +
+ +

+ BaseHub +

+ + +
+ + +
+
+ + +
+
+

new BaseHub()

+ + +
+
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + +
+ + +

Extends

+ + + + +
    +
  • EventEmitter
  • +
+ + + + + + + + + + + + + +

Members

+ +
+ +
+
+

<readonly> batteryLevel

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
batteryLevel + + +number + + + + +

Battery level of the hub (Percentage between 0-100)

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> firmwareVersion

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
firmwareVersion + + +string + + + + +

Firmware version of the hub

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> hardwareVersion

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
firmwareVersion + + +string + + + + +

Hardware version of the hub

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> name

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + +

Name of the hub

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> ports

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ports + + +Array.<string> + + + + +

Array of port names

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> primaryMACAddress

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
primaryMACAddress + + +string + + + + +

Primary MAC address of the hub

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> rssi

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rssi + + +number + + + + +

Signal strength of the hub

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> type

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + +

Hub type

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> uuid

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
uuid + + +string + + + + +

UUID of the hub

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ +
+ + + + + + + +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/DuploTrainBase.html b/docs/DuploTrainBase.html index b5f2e06..48883ed 100644 --- a/docs/DuploTrainBase.html +++ b/docs/DuploTrainBase.html @@ -33,21 +33,14 @@ - - @@ -152,8 +145,8 @@
@@ -194,7 +187,7 @@ @@ -290,17 +283,12 @@
- -
Overrides:
-
@@ -326,141 +314,8 @@
-
- - - - - - - - - - - - - - - -
-
-

<readonly> current

- - -
-
- - - - - -
- - -
Properties:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
current - - -number - - - - -

Current usage of the hub (Milliamps)

-
- - - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -556,17 +411,12 @@
- -
Overrides:
-
@@ -592,8 +442,8 @@
@@ -689,17 +539,12 @@
- -
Overrides:
-
@@ -725,8 +570,8 @@
@@ -822,17 +667,12 @@
- -
Overrides:
-
@@ -858,8 +698,136 @@
+
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> ports

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ports + + +Array.<string> + + + + +

Array of port names

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -955,17 +923,12 @@
- -
Overrides:
-
@@ -991,8 +954,8 @@
@@ -1088,17 +1051,12 @@
- -
Overrides:
-
@@ -1124,8 +1082,136 @@
+
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> type

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + +

Hub type

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -1221,17 +1307,12 @@
- -
Overrides:
-
@@ -1257,141 +1338,8 @@
-
- - - - - - - -
- - - -
- - - -
-
-

<readonly> voltage

- - -
-
- - - - - -
- - -
Properties:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
voltage - - -number - - - - -

Voltage of the hub (Volts)

-
- - - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -1416,1741 +1364,6 @@
-
-
-

brakeMotor(port)

- - -
-
- - -
-

Fully (hard) stop the motor on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful completion of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

connect()

- - -
-
- - -
-

Connect to the Hub.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful connect.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

disconnect()

- - -
-
- - -
-

Disconnect the Hub.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful disconnect.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

getHubType()

- - -
-
- - -
-

Get the hub type.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -HubType - - - -
-
- - - - - -
- - - -
-
-

getPortDeviceType(port)

- - -
-
- - -
-

Get the device type for a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -DeviceType - - - -
-
- - - - - -
- - - -
-
-

playSound(sound)

- - -
-
- - -
-

Play a built-in train sound.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
sound - - -DuploTrainBaseSound - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

rampMotorSpeed(port, fromSpeed, toSpeed, time)

- - -
-
- - -
-

Ramp the motor speed on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
fromSpeed - - -number - - - - -

For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.

toSpeed - - -number - - - - -

For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.

time - - -number - - - - -

How long the ramp should last (in milliseconds).

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful completion of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

setLEDColor(color)

- - -
-
- - -
-

Set the color of the LED on the Hub via a color value.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
color - - -Color - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

setLEDRGB(red, green, blue)

- - -
-
- - -
-

Set the color of the LED on the Hub via RGB values.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
red - - -number - - - - -
green - - -number - - - - -
blue - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

setMotorSpeed(port, speed [, time])

- - -
-
- - -
-

Set the motor speed on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeArgumentDescription
port - - -string - - - - - - - - - - -
speed - - -number -| - -Array.<number> - - - - - - - - - - -

For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds.

time - - -number - - - - - - - <optional>
- - - - - -

How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely.

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful completion of command. If time is specified, this is once the motor is finished.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - -

setName(name)

@@ -3266,8 +1479,8 @@
@@ -3387,8 +1600,8 @@
@@ -3439,756 +1652,6 @@ -
- - - -
-
-

sleep(delay)

- - -
-
- - -
-

Sleep a given amount of time.

-

This is a helper method to make it easier to add delays into a chain of commands.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
delay - - -number - - - - -

How long to sleep (in milliseconds).

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved after the delay is finished.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

subscribe(port [, mode])

- - -
-
- - -
-

Subscribe to sensor notifications on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeArgumentDescription
port - - -string - - - - - - - - - - -
mode - - -number - - - - - - - <optional>
- - - - - -

The sensor mode to activate. If no mode is provided, the default for that sensor will be chosen.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

unsubscribe(port)

- - -
-
- - -
-

Unsubscribe to sensor notifications on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

wait(commands)

- - -
-
- - -
-

Wait until a given list of concurrently running commands are complete.

-

This is a helper method to make it easier to wait for concurrent commands to complete.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
commands - - -Array.<Promise.<any>> - - - - -

Array of executing commands.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved after the commands are finished.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - -
@@ -4388,184 +1851,8 @@
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-

attach

- - -
-
- - -
-

Emits when a motor or sensor is attached to the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
type - - -DeviceType - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -4671,7 +1958,7 @@ -ButtonState +ButtonState @@ -4735,1531 +2022,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

color

- - -
-
- - -
-

Emits when a color sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

colorAndDistance

- - -
-
- - -
-

A combined color and distance event, emits when the sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

detach

- - -
-
- - -
-

Emits when an attached motor or sensor is detached from the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

disconnect

- - -
-
- - -
-

Emits when the hub is disconnected.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

distance

- - -
-
- - -
-

Emits when a distance sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

gyro

- - -
-
- - -
-

Emits when gyroscope detects movement. Measured in DPS - degrees per second.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
x - - -number - - - - -
y - - -number - - - - -
z - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

rotate

- - -
-
- - -
-

Emits when a rotation sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
rotation - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

speed

- - -
-
- - -
-

Emits on a speed change.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
speed - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

temp

- - -
-
- - -
-

Emits when a change is detected on a temperature sensor. Measured in degrees centigrade.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -

For Control+ Hubs, port will be "CPU" as the sensor reports CPU temperature.

temp - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -6333,30 +2097,6 @@ - - - port - - - - - -string - - - - - - - - - - -

If the event is fired from the Move Hub or Control+ Hub's in-built tilt sensor, the special port "TILT" is used.

- - - - x @@ -6404,30 +2144,6 @@ - - - - z - - - - - -number - - - - - - - - - - -

(Only available when using a Control+ Hub)

- - - @@ -6477,8 +2193,8 @@
@@ -6557,7 +2273,7 @@ Documentation generated by JSDoc 3.6.3 - on Tue Dec 3rd 2019 + on Fri Feb 7th 2020 using the DocStrap template. diff --git a/docs/Hub.html b/docs/Hub.html index 4326aed..1999914 100644 --- a/docs/Hub.html +++ b/docs/Hub.html @@ -33,21 +33,14 @@ - - @@ -105,6 +98,10 @@
+
+

The Hub is emitted if the discovered device is a Hub.

+
+ @@ -148,8 +145,8 @@
@@ -188,7 +185,9 @@ @@ -280,126 +279,16 @@ - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
+
Inherited From:
+
- - - - - -
- - - -
- - - -
-
-

<readonly> current

- - -
-
- - - - - -
- - -
Properties:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
current - - -number - - - - -

Current usage of the hub (Milliamps)

-
- - - - - - - - - @@ -425,8 +314,8 @@
@@ -518,6 +407,15 @@ +
Inherited From:
+
+ +
+ @@ -544,8 +442,8 @@
@@ -637,6 +535,15 @@ +
Inherited From:
+
+ +
+ @@ -663,8 +570,8 @@
@@ -756,6 +663,15 @@ +
Inherited From:
+
+ +
+ @@ -782,8 +698,136 @@
+
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> ports

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ports + + +Array.<string> + + + + +

Array of port names

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -875,6 +919,15 @@ +
Inherited From:
+
+ +
+ @@ -901,8 +954,8 @@
@@ -994,6 +1047,15 @@ +
Inherited From:
+
+ +
+ @@ -1020,8 +1082,136 @@
+
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> type

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + +

Hub type

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -1113,126 +1303,16 @@ - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
+
Inherited From:
+
- - - - - -
- - - -
- - - -
-
-

<readonly> voltage

- - -
-
- - - - - -
- - -
Properties:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
voltage - - -number - - - - -

Voltage of the hub (Volts)

-
- - - - - - - - - @@ -1258,8 +1338,8 @@
@@ -1340,8 +1420,8 @@
@@ -1452,8 +1532,8 @@
@@ -1510,7 +1590,7 @@
-

getHubType()

+

setName(name)

@@ -1518,115 +1598,7 @@
-

Get the hub type.

-
- - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -HubType - - - -
-
- - - - - -
- - - -
-
-

getPortDeviceType(port)

- - -
-
- - -
-

Get the device type for a given port.

+

Set the name of the Hub.

@@ -1661,7 +1633,7 @@ - port + name @@ -1678,7 +1650,7 @@ - +

New name of the hub (14 characters or less, ASCII only).

@@ -1696,6 +1668,15 @@ +
Inherited From:
+
+ +
+ @@ -1722,8 +1703,8 @@
@@ -1751,6 +1732,10 @@
Returns:
+
+

Resolved upon successful issuance of command.

+
+
@@ -1759,7 +1744,128 @@
-DeviceType +Promise + + + +
+
+ + + + + + + + + +
+
+

shutdown()

+ + +
+
+ + +
+

Shutdown the Hub.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

Resolved upon successful disconnect.

+
+ + + +
+
+ Type +
+
+ +Promise @@ -1881,8 +1987,8 @@
@@ -1933,374 +2039,6 @@ -
- - - -
-
-

subscribe(port [, mode])

- - -
-
- - -
-

Subscribe to sensor notifications on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeArgumentDescription
port - - -string - - - - - - - - - - -
mode - - -number - - - - - - - <optional>
- - - - - -

The sensor mode to activate. If no mode is provided, the default for that sensor will be chosen.

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

unsubscribe(port)

- - -
-
- - -
-

Unsubscribe to sensor notifications on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - -
@@ -2412,8 +2150,8 @@
@@ -2478,7 +2216,7 @@
-

attach

+

accel

@@ -2486,7 +2224,7 @@
-

Emits when a motor or sensor is attached to the Hub.

+

Emits when accelerometer detects movement. Measured in mG.

@@ -2545,13 +2283,61 @@ - type + x -DeviceType +number + + + + + + + + + + + + + + + + + + y + + + + + +number + + + + + + + + + + + + + + + + + + z + + + + + +number @@ -2580,6 +2366,15 @@ +
Inherited From:
+
+ +
+ @@ -2606,8 +2401,8 @@
@@ -2640,7 +2435,7 @@
-

detach

+

attach

@@ -2648,7 +2443,7 @@
-

Emits when an attached motor or sensor is detached from the Hub.

+

Emits when a device is attached to the Hub.

@@ -2683,13 +2478,13 @@ - port + device -string +Device @@ -2744,8 +2539,317 @@
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

attach

+ + +
+
+ + +
+

Emits when a device is detached from the Hub.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
device + + +Device + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

button

+ + +
+
+ + +
+

Emits when a button is pressed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
button + + +string + + + + +
state + + +ButtonState + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -2832,8 +2936,179 @@
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

tilt

+ + +
+
+ + +
+

Emits when a tilt sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +number + + + + +
y + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -2912,7 +3187,7 @@ Documentation generated by JSDoc 3.6.3 - on Tue Dec 3rd 2019 + on Fri Feb 7th 2020 using the DocStrap template. diff --git a/docs/LPF2Hub.html b/docs/LPF2Hub.html index 4a95752..9a8d0b4 100644 --- a/docs/LPF2Hub.html +++ b/docs/LPF2Hub.html @@ -33,21 +33,14 @@ - - @@ -148,8 +141,8 @@
@@ -188,7 +181,7 @@ @@ -284,7 +277,7 @@
@@ -315,136 +308,8 @@
-
- - - - - - - -
- - - -
- - - -
-
-

<readonly> current

- - -
-
- - - - - -
- - -
Properties:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
current - - -number - - - - -

Current usage of the hub (Milliamps)

-
- - - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -540,7 +405,7 @@
@@ -571,8 +436,8 @@
@@ -668,7 +533,7 @@
@@ -699,8 +564,8 @@
@@ -796,7 +661,7 @@
@@ -827,8 +692,136 @@
+
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> ports

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ports + + +Array.<string> + + + + +

Array of port names

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -924,7 +917,7 @@
@@ -955,8 +948,8 @@
@@ -1052,7 +1045,7 @@
@@ -1083,8 +1076,136 @@
+
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> type

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + +

Hub type

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -1180,7 +1301,7 @@
@@ -1211,136 +1332,8 @@
-
- - - - - - - -
- - - -
- - - -
-
-

<readonly> voltage

- - -
-
- - - - - -
- - -
Properties:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
voltage - - -number - - - - -

Voltage of the hub (Volts)

-
- - - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -1365,909 +1358,6 @@
-
-
-

connect()

- - -
-
- - -
-

Connect to the Hub.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful connect.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

disconnect()

- - -
-
- - -
-

Disconnect the Hub.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful disconnect.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

getHubType()

- - -
-
- - -
-

Get the hub type.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -HubType - - - -
-
- - - - - -
- - - -
-
-

getPortDeviceType(port)

- - -
-
- - -
-

Get the device type for a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -DeviceType - - - -
-
- - - - - -
- - - -
-
-

setLEDColor(color)

- - -
-
- - -
-

Set the color of the LED on the Hub via a color value.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
color - - -Color - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

setLEDRGB(red, green, blue)

- - -
-
- - -
-

Set the color of the LED on the Hub via RGB values.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
red - - -number - - - - -
green - - -number - - - - -
blue - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - -

setName(name)

@@ -2374,8 +1464,8 @@
@@ -2486,8 +1576,8 @@
@@ -2538,736 +1628,6 @@ -
- - - -
-
-

sleep(delay)

- - -
-
- - -
-

Sleep a given amount of time.

-

This is a helper method to make it easier to add delays into a chain of commands.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
delay - - -number - - - - -

How long to sleep (in milliseconds).

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved after the delay is finished.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

subscribe(port [, mode])

- - -
-
- - -
-

Subscribe to sensor notifications on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeArgumentDescription
port - - -string - - - - - - - - - - -
mode - - -number - - - - - - - <optional>
- - - - - -

The sensor mode to activate. If no mode is provided, the default for that sensor will be chosen.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

unsubscribe(port)

- - -
-
- - -
-

Unsubscribe to sensor notifications on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

wait(commands)

- - -
-
- - -
-

Wait until a given list of concurrently running commands are complete.

-

This is a helper method to make it easier to wait for concurrent commands to complete.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
commands - - -Array.<Promise.<any>> - - - - -

Array of executing commands.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved after the commands are finished.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - -
@@ -3458,179 +1818,8 @@
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-

attach

- - -
-
- - -
-

Emits when a motor or sensor is attached to the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
type - - -DeviceType - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -3736,7 +1925,7 @@ -ButtonState +ButtonState @@ -3791,1458 +1980,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

color

- - -
-
- - -
-

Emits when a color sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

colorAndDistance

- - -
-
- - -
-

A combined color and distance event, emits when the sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

detach

- - -
-
- - -
-

Emits when an attached motor or sensor is detached from the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

disconnect

- - -
-
- - -
-

Emits when the hub is disconnected.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

distance

- - -
-
- - -
-

Emits when a distance sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

gyro

- - -
-
- - -
-

Emits when gyroscope detects movement. Measured in DPS - degrees per second.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
x - - -number - - - - -
y - - -number - - - - -
z - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

rotate

- - -
-
- - -
-

Emits when a rotation sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
rotation - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

speed

- - -
-
- - -
-

Emits on a speed change.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
speed - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

temp

- - -
-
- - -
-

Emits when a change is detected on a temperature sensor. Measured in degrees centigrade.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -

For Control+ Hubs, port will be "CPU" as the sensor reports CPU temperature.

temp - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -5316,30 +2055,6 @@ - - - port - - - - - -string - - - - - - - - - - -

If the event is fired from the Move Hub or Control+ Hub's in-built tilt sensor, the special port "TILT" is used.

- - - - x @@ -5387,30 +2102,6 @@ - - - - z - - - - - -number - - - - - - - - - - -

(Only available when using a Control+ Hub)

- - - @@ -5451,8 +2142,8 @@
@@ -5531,7 +2222,7 @@ Documentation generated by JSDoc 3.6.3 - on Tue Dec 3rd 2019 + on Fri Feb 7th 2020 using the DocStrap template. diff --git a/docs/MoveHub.html b/docs/MoveHub.html new file mode 100644 index 0000000..1dc1a1f --- /dev/null +++ b/docs/MoveHub.html @@ -0,0 +1,2412 @@ + + + + + + + node-poweredup Class: MoveHub + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: MoveHub

+
+ +
+ +

+ MoveHub +

+ + +
+ + +
+
+ + +
+
+

new MoveHub()

+ + +
+
+ + +
+

The MoveHub is emitted if the discovered device is a Move Hub.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + +

Members

+ +
+ +
+
+

<readonly> batteryLevel

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
batteryLevel + + +number + + + + +

Battery level of the hub (Percentage between 0-100)

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> firmwareVersion

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
firmwareVersion + + +string + + + + +

Firmware version of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> hardwareVersion

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
firmwareVersion + + +string + + + + +

Hardware version of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> name

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + +

Name of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> ports

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ports + + +Array.<string> + + + + +

Array of port names

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> primaryMACAddress

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
primaryMACAddress + + +string + + + + +

Primary MAC address of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> rssi

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rssi + + +number + + + + +

Signal strength of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> type

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + +

Hub type

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> uuid

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
uuid + + +string + + + + +

UUID of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+
+

setName(name)

+ + +
+
+ + +
+

Set the name of the Hub.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + +

New name of the hub (14 characters or less, ASCII only).

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

Resolved upon successful issuance of command.

+
+ + + +
+
+ Type +
+
+ +Promise + + + +
+
+ + + + + +
+ + + +
+
+

shutdown()

+ + +
+
+ + +
+

Shutdown the Hub.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

Resolved upon successful disconnect.

+
+ + + +
+
+ Type +
+
+ +Promise + + + +
+
+ + + + + +
+ +
+ + + + + +

Events

+ +
+ +
+
+

accel

+ + +
+
+ + +
+

Emits when accelerometer detects movement. Measured in mG.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
x + + +number + + + + +
y + + +number + + + + +
z + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

button

+ + +
+
+ + +
+

Emits when a button is pressed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
button + + +string + + + + +
state + + +ButtonState + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

tilt

+ + +
+
+ + +
+

Emits when a tilt sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +number + + + + +
y + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/PoweredUP.html b/docs/PoweredUP.html index 03923a7..d9f67de 100644 --- a/docs/PoweredUP.html +++ b/docs/PoweredUP.html @@ -33,14 +33,14 @@ @@ -211,7 +211,7 @@
-

getConnectedHubByPrimaryMACAddress(address)

+

getHubByPrimaryMACAddress(address)

@@ -316,7 +316,7 @@
@@ -352,7 +352,7 @@
-Hub +BaseHub @@ -369,7 +369,7 @@
-

getConnectedHubByUUID(uuid)

+

getHubByUUID(uuid)

@@ -474,7 +474,7 @@ @@ -510,7 +510,7 @@
-Hub +BaseHub | null @@ -530,7 +530,7 @@
-

getConnectedHubs()

+

getHubs()

@@ -585,7 +585,7 @@ @@ -621,7 +621,7 @@
-Array.<Hub> +Array.<BaseHub> @@ -638,7 +638,7 @@
-

getConnectedHubsByName(name)

+

getHubsByName(name)

@@ -743,7 +743,7 @@ @@ -779,7 +779,165 @@
-Array.<Hub> +Array.<BaseHub> + + + +
+ + + + + + + + + + +
+
+

getHubsByType(name)

+ + +
+
+ + +
+

Retrieve a list of Powered UP Hub by type.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<BaseHub> @@ -851,7 +1009,7 @@
@@ -939,7 +1097,7 @@
@@ -1029,22 +1187,22 @@ -WeDo2SmartHub +WeDo2SmartHub | -BoostMoveHub +MoveHub | -ControlPlusHub +TechnicMediumHub | -PUPHub +Hub | -PUPRemote +RemoteControl | -DuploTrainBase +DuploTrainBase @@ -1100,7 +1258,7 @@ @@ -1179,7 +1337,7 @@ Documentation generated by JSDoc 3.6.3 - on Tue Dec 3rd 2019 + on Fri Feb 7th 2020 using the DocStrap template. diff --git a/docs/RemoteControl.html b/docs/RemoteControl.html new file mode 100644 index 0000000..21f65a4 --- /dev/null +++ b/docs/RemoteControl.html @@ -0,0 +1,2412 @@ + + + + + + + node-poweredup Class: RemoteControl + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: RemoteControl

+
+ +
+ +

+ RemoteControl +

+ + +
+ + +
+
+ + +
+
+

new RemoteControl()

+ + +
+
+ + +
+

The RemoteControl is emitted if the discovered device is a Remote Control.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + +

Members

+ +
+ +
+
+

<readonly> batteryLevel

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
batteryLevel + + +number + + + + +

Battery level of the hub (Percentage between 0-100)

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> firmwareVersion

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
firmwareVersion + + +string + + + + +

Firmware version of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> hardwareVersion

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
firmwareVersion + + +string + + + + +

Hardware version of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> name

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + +

Name of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> ports

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ports + + +Array.<string> + + + + +

Array of port names

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> primaryMACAddress

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
primaryMACAddress + + +string + + + + +

Primary MAC address of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> rssi

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rssi + + +number + + + + +

Signal strength of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> type

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + +

Hub type

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> uuid

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
uuid + + +string + + + + +

UUID of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+
+

setName(name)

+ + +
+
+ + +
+

Set the name of the Hub.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + +

New name of the hub (14 characters or less, ASCII only).

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

Resolved upon successful issuance of command.

+
+ + + +
+
+ Type +
+
+ +Promise + + + +
+
+ + + + + +
+ + + +
+
+

shutdown()

+ + +
+
+ + +
+

Shutdown the Hub.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

Resolved upon successful disconnect.

+
+ + + +
+
+ Type +
+
+ +Promise + + + +
+
+ + + + + +
+ +
+ + + + + +

Events

+ +
+ +
+
+

accel

+ + +
+
+ + +
+

Emits when accelerometer detects movement. Measured in mG.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
x + + +number + + + + +
y + + +number + + + + +
z + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

button

+ + +
+
+ + +
+

Emits when a button is pressed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
button + + +string + + + + +
state + + +ButtonState + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

tilt

+ + +
+
+ + +
+

Emits when a tilt sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +number + + + + +
y + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/TechnicMediumHub.html b/docs/TechnicMediumHub.html new file mode 100644 index 0000000..9c221df --- /dev/null +++ b/docs/TechnicMediumHub.html @@ -0,0 +1,2412 @@ + + + + + + + node-poweredup Class: TechnicMediumHub + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: TechnicMediumHub

+
+ +
+ +

+ TechnicMediumHub +

+ + +
+ + +
+
+ + +
+
+

new TechnicMediumHub()

+ + +
+
+ + +
+

The TechnicMediumHub is emitted if the discovered device is a Technic Medium Hub.

+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + +

Members

+ +
+ +
+
+

<readonly> batteryLevel

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
batteryLevel + + +number + + + + +

Battery level of the hub (Percentage between 0-100)

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> firmwareVersion

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
firmwareVersion + + +string + + + + +

Firmware version of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> hardwareVersion

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
firmwareVersion + + +string + + + + +

Hardware version of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> name

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + +

Name of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> ports

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ports + + +Array.<string> + + + + +

Array of port names

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> primaryMACAddress

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
primaryMACAddress + + +string + + + + +

Primary MAC address of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> rssi

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rssi + + +number + + + + +

Signal strength of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> type

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + +

Hub type

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> uuid

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
uuid + + +string + + + + +

UUID of the hub

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+
+

setName(name)

+ + +
+
+ + +
+

Set the name of the Hub.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + +

New name of the hub (14 characters or less, ASCII only).

+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

Resolved upon successful issuance of command.

+
+ + + +
+
+ Type +
+
+ +Promise + + + +
+
+ + + + + +
+ + + +
+
+

shutdown()

+ + +
+
+ + +
+

Shutdown the Hub.

+
+ + + + + + + + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

Resolved upon successful disconnect.

+
+ + + +
+
+ Type +
+
+ +Promise + + + +
+
+ + + + + +
+ +
+ + + + + +

Events

+ +
+ +
+
+

accel

+ + +
+
+ + +
+

Emits when accelerometer detects movement. Measured in mG.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
x + + +number + + + + +
y + + +number + + + + +
z + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

button

+ + +
+
+ + +
+

Emits when a button is pressed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
button + + +string + + + + +
state + + +ButtonState + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

tilt

+ + +
+
+ + +
+

Emits when a tilt sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +number + + + + +
y + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/WeDo2SmartHub.html b/docs/WeDo2SmartHub.html index 2b9db75..5479d68 100644 --- a/docs/WeDo2SmartHub.html +++ b/docs/WeDo2SmartHub.html @@ -33,21 +33,14 @@ - - @@ -152,8 +145,8 @@
@@ -192,7 +185,7 @@ @@ -288,7 +281,7 @@
@@ -319,136 +312,8 @@
-
- - - - - - - - - - - - - - - -
-
-

<readonly> current

- - -
-
- - - - - -
- - -
Properties:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
current - - -number - - - - -

Current usage of the hub (Milliamps)

-
- - - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -544,7 +409,7 @@
@@ -575,8 +440,8 @@
@@ -672,7 +537,7 @@
@@ -703,8 +568,8 @@
@@ -800,7 +665,7 @@
@@ -831,8 +696,136 @@
+
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> ports

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ports + + +Array.<string> + + + + +

Array of port names

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -928,7 +921,7 @@
@@ -959,8 +952,8 @@
@@ -1056,7 +1049,7 @@
@@ -1087,8 +1080,136 @@
+
+ + + + + + + +
+ + + +
+ + + +
+
+

<readonly> type

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +string + + + + +

Hub type

+
+ + + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -1184,7 +1305,7 @@
@@ -1215,136 +1336,8 @@
-
- - - - - - - -
- - - -
- - - -
-
-

<readonly> voltage

- - -
-
- - - - - -
- - -
Properties:
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
voltage - - -number - - - - -

Voltage of the hub (Volts)

-
- - - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -1369,1967 +1362,6 @@
-
-
-

brakeMotor(port)

- - -
-
- - -
-

Fully (hard) stop the motor on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful completion of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

connect()

- - -
-
- - -
-

Connect to the Hub.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful connect.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

disconnect()

- - -
-
- - -
-

Disconnect the Hub.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful disconnect.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

getHubType()

- - -
-
- - -
-

Get the hub type.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -HubType - - - -
-
- - - - - -
- - - -
-
-

getPortDeviceType(port)

- - -
-
- - -
-

Get the device type for a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -DeviceType - - - -
-
- - - - - -
- - - -
-
-

playTone(frequency, time)

- - -
-
- - -
-

Play a tone on the Hub's in-built buzzer

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
frequency - - -number - - - - -
time - - -number - - - - -

How long the tone should play for (in milliseconds).

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful completion of command (ie. once the tone has finished playing).

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

rampMotorSpeed(port, fromSpeed, toSpeed, time)

- - -
-
- - -
-

Ramp the motor speed on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
fromSpeed - - -number - - - - -

For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.

toSpeed - - -number - - - - -

For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.

time - - -number - - - - -

How long the ramp should last (in milliseconds).

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful completion of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

setLEDColor(color)

- - -
-
- - -
-

Set the color of the LED on the Hub via a color value.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
color - - -Color - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

setLEDRGB(red, green, blue)

- - -
-
- - -
-

Set the color of the LED on the Hub via RGB values.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
red - - -number - - - - -
green - - -number - - - - -
blue - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

setLightBrightness(port, brightness [, time])

- - -
-
- - -
-

Set the light brightness on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeArgumentDescription
port - - -string - - - - - - - - - - -
brightness - - -number - - - - - - - - - - -

Brightness value between 0-100 (0 is off)

time - - -number - - - - - - - <optional>
- - - - - -

How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely.

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful completion of command. If time is specified, this is once the light is turned off.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

setMotorSpeed(port, speed [, time])

- - -
-
- - -
-

Set the motor speed on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeArgumentDescription
port - - -string - - - - - - - - - - -
speed - - -number - - - - - - - - - - -

For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.

time - - -number - - - - - - - <optional>
- - - - - -

How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely.

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful completion of command. If time is specified, this is once the motor is finished.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - -

setName(name)

@@ -3436,8 +1468,8 @@
@@ -3548,8 +1580,8 @@
@@ -3600,736 +1632,6 @@ -
- - - -
-
-

sleep(delay)

- - -
-
- - -
-

Sleep a given amount of time.

-

This is a helper method to make it easier to add delays into a chain of commands.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
delay - - -number - - - - -

How long to sleep (in milliseconds).

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved after the delay is finished.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

subscribe(port [, mode])

- - -
-
- - -
-

Subscribe to sensor notifications on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeArgumentDescription
port - - -string - - - - - - - - - - -
mode - - -number - - - - - - - <optional>
- - - - - -

The sensor mode to activate. If no mode is provided, the default for that sensor will be chosen.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

unsubscribe(port)

- - -
-
- - -
-

Unsubscribe to sensor notifications on a given port.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved upon successful issuance of command.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - - -
- - - -
-
-

wait(commands)

- - -
-
- - -
-

Wait until a given list of concurrently running commands are complete.

-

This is a helper method to make it easier to wait for concurrent commands to complete.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
commands - - -Array.<Promise.<any>> - - - - -

Array of executing commands.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - -
Returns:
- - -
-

Resolved after the commands are finished.

-
- - - -
-
- Type -
-
- -Promise - - - -
-
- - - - -
@@ -4342,177 +1644,6 @@
-
-
-

attach

- - -
-
- - -
-

Emits when a motor or sensor is attached to the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
type - - -DeviceType - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - -

button

@@ -4588,7 +1719,7 @@ -ButtonState +ButtonState @@ -4643,924 +1774,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - - - - - -
-
-

color

- - -
-
- - -
-

Emits when a color sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

detach

- - -
-
- - -
-

Emits when an attached motor or sensor is detached from the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

disconnect

- - -
-
- - -
-

Emits when the hub is disconnected.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

distance

- - -
-
- - -
-

Emits when a distance sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

rotate

- - -
-
- - -
-

Emits when a rotation sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
rotation - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

tilt

- - -
-
- - -
-

Emits when a tilt sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
x - - -number - - - - -
y - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -5639,7 +1854,7 @@ Documentation generated by JSDoc 3.6.3 - on Tue Dec 3rd 2019 + on Fri Feb 7th 2020 using the DocStrap template. diff --git a/docs/classes.list.html b/docs/classes.list.html index 6d0338f..5d56af0 100644 --- a/docs/classes.list.html +++ b/docs/classes.list.html @@ -33,21 +33,14 @@ - - @@ -149,10 +142,7 @@

Classes

-
BoostMoveHub
-
- -
ControlPlusHub
+
BaseHub
DuploTrainBase
@@ -164,13 +154,13 @@
LPF2Hub
-
PoweredUP
+
MoveHub
-
PUPHub
+
RemoteControl
-
PUPRemote
+
TechnicMediumHub
WeDo2SmartHub
@@ -195,7 +185,7 @@
-

accel

+

absolute

@@ -203,7 +193,7 @@
-

Emits when accelerometer detects movement. Measured in mG.

+

Emits when a the motors absolute position is changed.

@@ -238,79 +228,7 @@ - port - - - - - -string - - - - - - - - - - - - - - - - - - x - - - - - -number - - - - - - - - - - - - - - - - - - y - - - - - -number - - - - - - - - - - - - - - - - - - z + absolute @@ -345,15 +263,6 @@ -
Inherited From:
-
- -
- @@ -380,355 +289,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

attach

- - -
-
- - -
-

Emits when a motor or sensor is attached to the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
type - - -DeviceType - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

button

- - -
-
- - -
-

Emits when a button is pressed.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
button - - -string - - - - -
state - - -ButtonState - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -802,30 +364,6 @@ - - - port - - - - - -string - - - - - - - - - - - - - - - color @@ -834,7 +372,7 @@ -Color +Color @@ -863,15 +401,6 @@ -
Inherited From:
-
- -
- @@ -898,8 +427,8 @@
@@ -973,30 +502,6 @@ - - - port - - - - - -string - - - - - - - - - - - - - - - color @@ -1005,7 +510,7 @@ -Color +Color @@ -1058,15 +563,6 @@ -
Inherited From:
-
- -
- @@ -1093,262 +589,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

detach

- - -
-
- - -
-

Emits when an attached motor or sensor is detached from the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

disconnect

- - -
-
- - -
-

Emits when the hub is disconnected.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -1422,30 +664,6 @@ - - - port - - - - - -string - - - - - - - - - - - - - - - distance @@ -1483,15 +701,6 @@ -
Inherited From:
-
- -
- @@ -1518,8 +727,8 @@
@@ -1552,7 +761,7 @@
-

gyro

+

current

@@ -1560,7 +769,7 @@
-

Emits when gyroscope detects movement. Measured in DPS - degrees per second.

+

Emits when a current change is detected.

@@ -1595,79 +804,7 @@ - port - - - - - -string - - - - - - - - - - - - - - - - - - x - - - - - -number - - - - - - - - - - - - - - - - - - y - - - - - -number - - - - - - - - - - - - - - - - - - z + current @@ -1702,15 +839,6 @@ -
Inherited From:
-
- -
- @@ -1737,740 +865,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

rotate

- - -
-
- - -
-

Emits when a rotation sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
rotation - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

speed

- - -
-
- - -
-

Emits on a speed change.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
speed - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

temp

- - -
-
- - -
-

Emits when a change is detected on a temperature sensor. Measured in degrees centigrade.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -

For Control+ Hubs, port will be "CPU" as the sensor reports CPU temperature.

temp - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

tilt

- - -
-
- - -
-

Emits when a tilt sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -

If the event is fired from the Move Hub or Control+ Hub's in-built tilt sensor, the special port "TILT" is used.

x - - -number - - - - -
y - - -number - - - - -
z - - -number - - - - -

(Only available when using a Control+ Hub)

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -2688,184 +1084,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

attach

- - -
-
- - -
-

Emits when a motor or sensor is attached to the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
type - - -DeviceType - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -2971,7 +1191,7 @@ -ButtonState +ButtonState @@ -3035,1531 +1255,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

color

- - -
-
- - -
-

Emits when a color sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

colorAndDistance

- - -
-
- - -
-

A combined color and distance event, emits when the sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

detach

- - -
-
- - -
-

Emits when an attached motor or sensor is detached from the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

disconnect

- - -
-
- - -
-

Emits when the hub is disconnected.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

distance

- - -
-
- - -
-

Emits when a distance sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

gyro

- - -
-
- - -
-

Emits when gyroscope detects movement. Measured in DPS - degrees per second.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
x - - -number - - - - -
y - - -number - - - - -
z - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

rotate

- - -
-
- - -
-

Emits when a rotation sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
rotation - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

speed

- - -
-
- - -
-

Emits on a speed change.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
speed - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

temp

- - -
-
- - -
-

Emits when a change is detected on a temperature sensor. Measured in degrees centigrade.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -

For Control+ Hubs, port will be "CPU" as the sensor reports CPU temperature.

temp - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -4633,30 +1330,6 @@ - - - port - - - - - -string - - - - - - - - - - -

If the event is fired from the Move Hub or Control+ Hub's in-built tilt sensor, the special port "TILT" is used.

- - - - x @@ -4704,30 +1377,6 @@ - - - - z - - - - - -number - - - - - - - - - - -

(Only available when using a Control+ Hub)

- - - @@ -4777,8 +1426,284 @@
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

color

+ + +
+
+ + +
+

Emits when a color sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
color + + +Color + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

speed

+ + +
+
+ + +
+

Emits on a speed change.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
speed + + +number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -4996,8 +1921,8 @@
@@ -5038,7 +1963,7 @@
-

Emits when a motor or sensor is attached to the Hub.

+

Emits when a device is attached to the Hub.

@@ -5073,37 +1998,13 @@ - port + device -string - - - - - - - - - - - - - - - - - - type - - - - - -DeviceType +Device @@ -5132,21 +2033,7 @@ -
Inherited From:
-
- -
- - -
Overrides:
-
@@ -5172,8 +2059,146 @@
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

attach

+ + +
+
+ + +
+

Emits when a device is detached from the Hub.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
device + + +Device + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -5279,7 +2304,7 @@ -ButtonState +ButtonState @@ -5343,526 +2368,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

color

- - -
-
- - -
-

Emits when a color sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

colorAndDistance

- - -
-
- - -
-

A combined color and distance event, emits when the sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

detach

- - -
-
- - -
-

Emits when an attached motor or sensor is detached from the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -5923,191 +2430,6 @@ -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

distance

- - -
-
- - -
-

Emits when a distance sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- @@ -6134,740 +2456,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

gyro

- - -
-
- - -
-

Emits when gyroscope detects movement. Measured in DPS - degrees per second.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
x - - -number - - - - -
y - - -number - - - - -
z - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

rotate

- - -
-
- - -
-

Emits when a rotation sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
rotation - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

speed

- - -
-
- - -
-

Emits on a speed change.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
speed - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

temp

- - -
-
- - -
-

Emits when a change is detected on a temperature sensor. Measured in degrees centigrade.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -

For Control+ Hubs, port will be "CPU" as the sensor reports CPU temperature.

temp - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -6941,30 +2531,6 @@ - - - port - - - - - -string - - - - - - - - - - -

If the event is fired from the Move Hub or Control+ Hub's in-built tilt sensor, the special port "TILT" is used.

- - - - x @@ -7012,30 +2578,6 @@ - - - - z - - - - - -number - - - - - - - - - - -

(Only available when using a Control+ Hub)

- - - @@ -7085,396 +2627,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

attach

- - -
-
- - -
-

Emits when a motor or sensor is attached to the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
type - - -DeviceType - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

detach

- - -
-
- - -
-

Emits when an attached motor or sensor is detached from the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

disconnect

- - -
-
- - -
-

Emits when the hub is disconnected.

-
- - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -7683,179 +2837,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

attach

- - -
-
- - -
-

Emits when a motor or sensor is attached to the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
type - - -DeviceType - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -7961,7 +2944,7 @@ -ButtonState +ButtonState @@ -8016,1458 +2999,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

color

- - -
-
- - -
-

Emits when a color sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

colorAndDistance

- - -
-
- - -
-

A combined color and distance event, emits when the sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

detach

- - -
-
- - -
-

Emits when an attached motor or sensor is detached from the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

disconnect

- - -
-
- - -
-

Emits when the hub is disconnected.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

distance

- - -
-
- - -
-

Emits when a distance sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

gyro

- - -
-
- - -
-

Emits when gyroscope detects movement. Measured in DPS - degrees per second.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
x - - -number - - - - -
y - - -number - - - - -
z - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

rotate

- - -
-
- - -
-

Emits when a rotation sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
rotation - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

speed

- - -
-
- - -
-

Emits on a speed change.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
speed - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

temp

- - -
-
- - -
-

Emits when a change is detected on a temperature sensor. Measured in degrees centigrade.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -

For Control+ Hubs, port will be "CPU" as the sensor reports CPU temperature.

temp - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -9541,30 +3074,6 @@ - - - port - - - - - -string - - - - - - - - - - -

If the event is fired from the Move Hub or Control+ Hub's in-built tilt sensor, the special port "TILT" is used.

- - - - x @@ -9612,30 +3121,6 @@ - - - - z - - - - - -number - - - - - - - - - - -

(Only available when using a Control+ Hub)

- - - @@ -9676,8 +3161,8 @@
@@ -9710,7 +3195,7 @@
-

discover

+

distance

@@ -9718,7 +3203,7 @@
-

Emits when a Powered UP Hub device is found.

+

Emits when a distance sensor is activated.

@@ -9753,28 +3238,13 @@ - hub + distance -WeDo2SmartHub -| - -BoostMoveHub -| - -ControlPlusHub -| - -PUPHub -| - -PUPRemote -| - -DuploTrainBase +number @@ -9785,7 +3255,7 @@ - +

Distance, in millimeters.

@@ -9829,8 +3299,8 @@
@@ -10048,184 +3518,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

attach

- - -
-
- - -
-

Emits when a motor or sensor is attached to the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
type - - -DeviceType - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -10331,7 +3625,7 @@ -ButtonState +ButtonState @@ -10395,1531 +3689,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

color

- - -
-
- - -
-

Emits when a color sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

colorAndDistance

- - -
-
- - -
-

A combined color and distance event, emits when the sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

detach

- - -
-
- - -
-

Emits when an attached motor or sensor is detached from the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

disconnect

- - -
-
- - -
-

Emits when the hub is disconnected.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

distance

- - -
-
- - -
-

Emits when a distance sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

gyro

- - -
-
- - -
-

Emits when gyroscope detects movement. Measured in DPS - degrees per second.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
x - - -number - - - - -
y - - -number - - - - -
z - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

rotate

- - -
-
- - -
-

Emits when a rotation sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
rotation - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

speed

- - -
-
- - -
-

Emits on a speed change.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
speed - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

temp

- - -
-
- - -
-

Emits when a change is detected on a temperature sensor. Measured in degrees centigrade.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -

For Control+ Hubs, port will be "CPU" as the sensor reports CPU temperature.

temp - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -11993,30 +3764,6 @@ - - - port - - - - - -string - - - - - - - - - - -

If the event is fired from the Move Hub or Control+ Hub's in-built tilt sensor, the special port "TILT" is used.

- - - - x @@ -12064,30 +3811,6 @@ - - - - z - - - - - -number - - - - - - - - - - -

(Only available when using a Control+ Hub)

- - - @@ -12137,8 +3860,170 @@
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

tilt

+ + +
+
+ + +
+

Emits when a tilt sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +number + + + + +
y + + +number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -12356,184 +4241,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

attach

- - -
-
- - -
-

Emits when a motor or sensor is attached to the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
type - - -DeviceType - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -12639,7 +4348,7 @@ -ButtonState +ButtonState @@ -12703,8 +4412,593 @@
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

tilt

+ + +
+
+ + +
+

Emits when a tilt sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +number + + + + +
y + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

button

+ + +
+
+ + +
+

Emits when a button on the remote is pressed or released.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
event + + +number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

rotate

+ + +
+
+ + +
+

Emits when a rotation sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rotation + + +number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

from 0 to 100.

+ + +
+
+ + +
+

Emits when the ambient light changes.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ambient + + +number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -12778,30 +5072,6 @@ - - - port - - - - - -string - - - - - - - - - - - - - - - color @@ -12810,7 +5080,7 @@ -Color +Color @@ -12839,15 +5109,6 @@ -
Inherited From:
-
- -
- @@ -12874,8 +5135,8 @@
@@ -12908,7 +5169,7 @@
-

colorAndDistance

+

from 0 to 100.

@@ -12916,7 +5177,7 @@
-

A combined color and distance event, emits when the sensor is activated.

+

Emits when the light reflectivity changes.

@@ -12951,13 +5212,13 @@ - port + reflect -string +number @@ -12972,29 +5233,119 @@ + + - - - color + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + +
+
+

from 40 to 2500mm

+ + +
+
- - - -Color + +
+

Emits when the detected distance changes (Slow sampling covers 40mm to 2500mm).

+
+ + + - - + + +
Parameters:
+ - + + + + + + - + - - + + + + + + + + @@ -13016,7 +5367,7 @@ - + @@ -13034,15 +5385,6 @@ -
Inherited From:
-
- -
- @@ -13069,8 +5411,8 @@
@@ -13103,7 +5445,7 @@
-

detach

+

from 50 to 320mm

@@ -13111,7 +5453,7 @@
-

Emits when an attached motor or sensor is detached from the Hub.

+

Emits when the detected distance changes (Fast sampling covers 50mm to 320mm).

@@ -13146,285 +5488,7 @@ - - - - - - - - - - - - - - -
NameType
Description

Distance, in millimeters.

port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

disconnect

- - -
-
- - -
-

Emits when the hub is disconnected.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - -
Overrides:
-
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

distance

- - -
-
- - -
-

Emits when a distance sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + +
NameTypeDescription
port - - -string - - - - -
distancefastDistance @@ -13441,7 +5505,631 @@ -

Distance, in millimeters.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

touch Touched on/off (boolean).

+ + +
+
+ + +
+

Emits when the sensor is touched.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
touch + + +boolean + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

in newtons (0-10).

+ + +
+
+ + +
+

Emits when force is applied.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
force + + +number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

from 0-3.

+ + +
+
+ + +
+

Emits when the sensor is tapped.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tapped + + +number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

accel

+ + +
+
+ + +
+

Emits when accelerometer detects movement. Measured in mG.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -13463,7 +6151,7 @@
@@ -13494,8 +6182,350 @@
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

button

+ + +
+
+ + +
+

Emits when a button is pressed.

+
+ + + + + + + + +
Parameters:
+ + +
NameTypeDescription
port + + +string + + + + +
x + + +number + + + + +
y + + +number + + + + +
z + + +number + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
button + + +string + + + + +
state + + +ButtonState + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

tilt

+ + +
+
+ + +
+

Emits when a tilt sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
x + + +number + + + + +
y + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -13569,30 +6599,6 @@ - - - port - - - - - -string - - - - - - - - - - - - - - - x @@ -13678,15 +6684,6 @@ -
Inherited From:
-
- -
- @@ -13713,521 +6710,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

rotate

- - -
-
- - -
-

Emits when a rotation sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
rotation - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

speed

- - -
-
- - -
-

Emits on a speed change.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
speed - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

temp

- - -
-
- - -
-

Emits when a change is detected on a temperature sensor. Measured in degrees centigrade.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -

For Control+ Hubs, port will be "CPU" as the sensor reports CPU temperature.

temp - - -number - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -14301,30 +6785,6 @@ - - - port - - - - - -string - - - - - - - - - - -

If the event is fired from the Move Hub or Control+ Hub's in-built tilt sensor, the special port "TILT" is used.

- - - - x @@ -14392,7 +6852,7 @@ -

(Only available when using a Control+ Hub)

+ @@ -14410,15 +6870,6 @@ -
Inherited From:
-
- -
- @@ -14445,8 +6896,8 @@
@@ -14479,7 +6930,7 @@
-

attach

+

voltage

@@ -14487,7 +6938,7 @@
-

Emits when a motor or sensor is attached to the Hub.

+

Emits when a voltage change is detected.

@@ -14522,37 +6973,13 @@ - port + voltage -string - - - - - - - - - - - - - - - - - - type - - - - - -DeviceType +number @@ -14581,15 +7008,6 @@ -
Inherited From:
-
- -
- @@ -14616,8 +7034,8 @@
@@ -14723,7 +7141,7 @@ -ButtonState +ButtonState @@ -14778,924 +7196,8 @@
-
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

color

- - -
-
- - -
-

Emits when a color sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
color - - -Color - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

detach

- - -
-
- - -
-

Emits when an attached motor or sensor is detached from the Hub.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
- - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

disconnect

- - -
-
- - -
-

Emits when the hub is disconnected.

-
- - - - - - - - - - -
- - - - - - - -
Inherited From:
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

distance

- - -
-
- - -
-

Emits when a distance sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
distance - - -number - - - - -

Distance, in millimeters.

- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

rotate

- - -
-
- - -
-

Emits when a rotation sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
rotation - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

tilt

- - -
-
- - -
-

Emits when a tilt sensor is activated.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
port - - -string - - - - -
x - - -number - - - - -
y - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -15774,7 +7276,7 @@ Documentation generated by JSDoc 3.6.3 - on Tue Dec 3rd 2019 + on Fri Feb 7th 2020 using the DocStrap template. diff --git a/docs/consts.js.html b/docs/consts.js.html index 15c52b7..05bd8d0 100644 --- a/docs/consts.js.html +++ b/docs/consts.js.html @@ -33,14 +33,14 @@ @@ -90,7 +90,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); * @typedef HubType * @property {number} UNKNOWN 0 * @property {number} WEDO2_SMART_HUB 1 - * @property {number} BOOST_MOVE_HUB 2 + * @property {number} MOVE_HUB 2 * @property {number} POWERED_UP_HUB 3 * @property {number} POWERED_UP_REMOTE 4 * @property {number} DUPLO_TRAIN_HUB 5 @@ -100,18 +100,18 @@ var HubType; (function (HubType) { HubType[HubType["UNKNOWN"] = 0] = "UNKNOWN"; HubType[HubType["WEDO2_SMART_HUB"] = 1] = "WEDO2_SMART_HUB"; - HubType[HubType["BOOST_MOVE_HUB"] = 2] = "BOOST_MOVE_HUB"; - HubType[HubType["POWERED_UP_HUB"] = 3] = "POWERED_UP_HUB"; - HubType[HubType["POWERED_UP_REMOTE"] = 4] = "POWERED_UP_REMOTE"; - HubType[HubType["DUPLO_TRAIN_HUB"] = 5] = "DUPLO_TRAIN_HUB"; - HubType[HubType["CONTROL_PLUS_HUB"] = 6] = "CONTROL_PLUS_HUB"; + HubType[HubType["MOVE_HUB"] = 2] = "MOVE_HUB"; + HubType[HubType["HUB"] = 3] = "HUB"; + HubType[HubType["REMOTE_CONTROL"] = 4] = "REMOTE_CONTROL"; + HubType[HubType["DUPLO_TRAIN_BASE"] = 5] = "DUPLO_TRAIN_BASE"; + HubType[HubType["TECHNIC_MEDIUM_HUB"] = 6] = "TECHNIC_MEDIUM_HUB"; })(HubType = exports.HubType || (exports.HubType = {})); // tslint:disable-next-line exports.HubTypeNames = HubType; /** * @typedef DeviceType * @property {number} UNKNOWN 0 - * @property {number} BASIC_MOTOR 1 + * @property {number} SIMPLE_MEDIUM_LINEAR_MOTOR 1 * @property {number} TRAIN_MOTOR 2 * @property {number} LED_LIGHTS 8 * @property {number} VOLTAGE 20 @@ -120,9 +120,9 @@ exports.HubTypeNames = HubType; * @property {number} RGB_LIGHT 23 * @property {number} WEDO2_TILT 34 * @property {number} WEDO2_DISTANCE 35 - * @property {number} BOOST_DISTANCE 37 - * @property {number} BOOST_TACHO_MOTOR 38 - * @property {number} BOOST_MOVE_HUB_MOTOR 39 + * @property {number} COLOR_DISTANCE_SENSOR 37 + * @property {number} MEDIUM_LINEAR_MOTOR 38 + * @property {number} MOVE_HUB_MEDIUM_LINEAR_MOTOR 39 * @property {number} BOOST_TILT 40 * @property {number} DUPLO_TRAIN_BASE_MOTOR 41 * @property {number} DUPLO_TRAIN_BASE_SPEAKER 42 @@ -138,32 +138,37 @@ exports.HubTypeNames = HubType; var DeviceType; (function (DeviceType) { DeviceType[DeviceType["UNKNOWN"] = 0] = "UNKNOWN"; - DeviceType[DeviceType["BASIC_MOTOR"] = 1] = "BASIC_MOTOR"; + DeviceType[DeviceType["SIMPLE_MEDIUM_LINEAR_MOTOR"] = 1] = "SIMPLE_MEDIUM_LINEAR_MOTOR"; DeviceType[DeviceType["TRAIN_MOTOR"] = 2] = "TRAIN_MOTOR"; - DeviceType[DeviceType["LED_LIGHTS"] = 8] = "LED_LIGHTS"; - DeviceType[DeviceType["VOLTAGE"] = 20] = "VOLTAGE"; - DeviceType[DeviceType["CURRENT"] = 21] = "CURRENT"; - DeviceType[DeviceType["PIEZO_TONE"] = 22] = "PIEZO_TONE"; - DeviceType[DeviceType["RGB_LIGHT"] = 23] = "RGB_LIGHT"; - DeviceType[DeviceType["WEDO2_TILT"] = 34] = "WEDO2_TILT"; - DeviceType[DeviceType["WEDO2_DISTANCE"] = 35] = "WEDO2_DISTANCE"; - DeviceType[DeviceType["BOOST_DISTANCE"] = 37] = "BOOST_DISTANCE"; - DeviceType[DeviceType["BOOST_TACHO_MOTOR"] = 38] = "BOOST_TACHO_MOTOR"; - DeviceType[DeviceType["BOOST_MOVE_HUB_MOTOR"] = 39] = "BOOST_MOVE_HUB_MOTOR"; - DeviceType[DeviceType["BOOST_TILT"] = 40] = "BOOST_TILT"; + DeviceType[DeviceType["LIGHT"] = 8] = "LIGHT"; + DeviceType[DeviceType["VOLTAGE_SENSOR"] = 20] = "VOLTAGE_SENSOR"; + DeviceType[DeviceType["CURRENT_SENSOR"] = 21] = "CURRENT_SENSOR"; + DeviceType[DeviceType["PIEZO_BUZZER"] = 22] = "PIEZO_BUZZER"; + DeviceType[DeviceType["HUB_LED"] = 23] = "HUB_LED"; + DeviceType[DeviceType["TILT_SENSOR"] = 34] = "TILT_SENSOR"; + DeviceType[DeviceType["MOTION_SENSOR"] = 35] = "MOTION_SENSOR"; + DeviceType[DeviceType["COLOR_DISTANCE_SENSOR"] = 37] = "COLOR_DISTANCE_SENSOR"; + DeviceType[DeviceType["MEDIUM_LINEAR_MOTOR"] = 38] = "MEDIUM_LINEAR_MOTOR"; + DeviceType[DeviceType["MOVE_HUB_MEDIUM_LINEAR_MOTOR"] = 39] = "MOVE_HUB_MEDIUM_LINEAR_MOTOR"; + DeviceType[DeviceType["MOVE_HUB_TILT_SENSOR"] = 40] = "MOVE_HUB_TILT_SENSOR"; DeviceType[DeviceType["DUPLO_TRAIN_BASE_MOTOR"] = 41] = "DUPLO_TRAIN_BASE_MOTOR"; DeviceType[DeviceType["DUPLO_TRAIN_BASE_SPEAKER"] = 42] = "DUPLO_TRAIN_BASE_SPEAKER"; - DeviceType[DeviceType["DUPLO_TRAIN_BASE_COLOR"] = 43] = "DUPLO_TRAIN_BASE_COLOR"; + DeviceType[DeviceType["DUPLO_TRAIN_BASE_COLOR_SENSOR"] = 43] = "DUPLO_TRAIN_BASE_COLOR_SENSOR"; DeviceType[DeviceType["DUPLO_TRAIN_BASE_SPEEDOMETER"] = 44] = "DUPLO_TRAIN_BASE_SPEEDOMETER"; - DeviceType[DeviceType["CONTROL_PLUS_LARGE_MOTOR"] = 46] = "CONTROL_PLUS_LARGE_MOTOR"; - DeviceType[DeviceType["CONTROL_PLUS_XLARGE_MOTOR"] = 47] = "CONTROL_PLUS_XLARGE_MOTOR"; - DeviceType[DeviceType["CONTROL_PLUS_GEST"] = 54] = "CONTROL_PLUS_GEST"; - DeviceType[DeviceType["POWERED_UP_REMOTE_BUTTON"] = 55] = "POWERED_UP_REMOTE_BUTTON"; - DeviceType[DeviceType["RSSI"] = 56] = "RSSI"; - DeviceType[DeviceType["CONTROL_PLUS_ACCELEROMETER"] = 57] = "CONTROL_PLUS_ACCELEROMETER"; - DeviceType[DeviceType["CONTROL_PLUS_GYRO"] = 58] = "CONTROL_PLUS_GYRO"; - DeviceType[DeviceType["CONTROL_PLUS_TILT"] = 59] = "CONTROL_PLUS_TILT"; - DeviceType[DeviceType["TEMPERATURE"] = 60] = "TEMPERATURE"; + DeviceType[DeviceType["TECHNIC_LARGE_LINEAR_MOTOR"] = 46] = "TECHNIC_LARGE_LINEAR_MOTOR"; + DeviceType[DeviceType["TECHNIC_XLARGE_LINEAR_MOTOR"] = 47] = "TECHNIC_XLARGE_LINEAR_MOTOR"; + DeviceType[DeviceType["TECHNIC_MEDIUM_ANGULAR_MOTOR"] = 48] = "TECHNIC_MEDIUM_ANGULAR_MOTOR"; + DeviceType[DeviceType["TECHNIC_LARGE_ANGULAR_MOTOR"] = 49] = "TECHNIC_LARGE_ANGULAR_MOTOR"; + DeviceType[DeviceType["TECHNIC_MEDIUM_HUB_GEST_SENSOR"] = 54] = "TECHNIC_MEDIUM_HUB_GEST_SENSOR"; + DeviceType[DeviceType["REMOTE_CONTROL_BUTTON"] = 55] = "REMOTE_CONTROL_BUTTON"; + DeviceType[DeviceType["REMOTE_CONTROL_RSSI"] = 56] = "REMOTE_CONTROL_RSSI"; + DeviceType[DeviceType["TECHNIC_MEDIUM_HUB_ACCELEROMETER"] = 57] = "TECHNIC_MEDIUM_HUB_ACCELEROMETER"; + DeviceType[DeviceType["TECHNIC_MEDIUM_HUB_GYRO_SENSOR"] = 58] = "TECHNIC_MEDIUM_HUB_GYRO_SENSOR"; + DeviceType[DeviceType["TECHNIC_MEDIUM_HUB_TILT_SENSOR"] = 59] = "TECHNIC_MEDIUM_HUB_TILT_SENSOR"; + DeviceType[DeviceType["TECHNIC_MEDIUM_HUB_TEMPERATURE_SENSOR"] = 60] = "TECHNIC_MEDIUM_HUB_TEMPERATURE_SENSOR"; + DeviceType[DeviceType["TECHNIC_COLOR_SENSOR"] = 61] = "TECHNIC_COLOR_SENSOR"; + DeviceType[DeviceType["TECHNIC_DISTANCE_SENSOR"] = 62] = "TECHNIC_DISTANCE_SENSOR"; + DeviceType[DeviceType["TECHNIC_FORCE_SENSOR"] = 63] = "TECHNIC_FORCE_SENSOR"; // Spike Prime })(DeviceType = exports.DeviceType || (exports.DeviceType = {})); // tslint:disable-next-line exports.DeviceTypeNames = DeviceType; @@ -209,12 +214,22 @@ exports.ColorNames = Color; */ var ButtonState; (function (ButtonState) { - ButtonState[ButtonState["PRESSED"] = 0] = "PRESSED"; - ButtonState[ButtonState["RELEASED"] = 1] = "RELEASED"; - ButtonState[ButtonState["UP"] = 2] = "UP"; - ButtonState[ButtonState["DOWN"] = 3] = "DOWN"; - ButtonState[ButtonState["STOP"] = 4] = "STOP"; + ButtonState[ButtonState["PRESSED"] = 2] = "PRESSED"; + ButtonState[ButtonState["RELEASED"] = 0] = "RELEASED"; + ButtonState[ButtonState["UP"] = 1] = "UP"; + ButtonState[ButtonState["DOWN"] = 255] = "DOWN"; + ButtonState[ButtonState["STOP"] = 127] = "STOP"; })(ButtonState = exports.ButtonState || (exports.ButtonState = {})); +/** + * @typedef BrakingStyle + * @property {number} HOLD 127 + * @property {number} BRAKE 128 + */ +var BrakingStyle; +(function (BrakingStyle) { + BrakingStyle[BrakingStyle["HOLD"] = 127] = "HOLD"; + BrakingStyle[BrakingStyle["BRAKE"] = 128] = "BRAKE"; +})(BrakingStyle = exports.BrakingStyle || (exports.BrakingStyle = {})); /** * @typedef DuploTrainBaseSound * @property {number} BRAKE 3 @@ -233,11 +248,11 @@ var DuploTrainBaseSound; })(DuploTrainBaseSound = exports.DuploTrainBaseSound || (exports.DuploTrainBaseSound = {})); var BLEManufacturerData; (function (BLEManufacturerData) { - BLEManufacturerData[BLEManufacturerData["DUPLO_TRAIN_HUB_ID"] = 32] = "DUPLO_TRAIN_HUB_ID"; - BLEManufacturerData[BLEManufacturerData["BOOST_MOVE_HUB_ID"] = 64] = "BOOST_MOVE_HUB_ID"; - BLEManufacturerData[BLEManufacturerData["POWERED_UP_HUB_ID"] = 65] = "POWERED_UP_HUB_ID"; - BLEManufacturerData[BLEManufacturerData["POWERED_UP_REMOTE_ID"] = 66] = "POWERED_UP_REMOTE_ID"; - BLEManufacturerData[BLEManufacturerData["CONTROL_PLUS_LARGE_HUB"] = 128] = "CONTROL_PLUS_LARGE_HUB"; + BLEManufacturerData[BLEManufacturerData["DUPLO_TRAIN_BASE_ID"] = 32] = "DUPLO_TRAIN_BASE_ID"; + BLEManufacturerData[BLEManufacturerData["MOVE_HUB_ID"] = 64] = "MOVE_HUB_ID"; + BLEManufacturerData[BLEManufacturerData["HUB_ID"] = 65] = "HUB_ID"; + BLEManufacturerData[BLEManufacturerData["REMOTE_CONTROL_ID"] = 66] = "REMOTE_CONTROL_ID"; + BLEManufacturerData[BLEManufacturerData["TECHNIC_MEDIUM_HUB"] = 128] = "TECHNIC_MEDIUM_HUB"; })(BLEManufacturerData = exports.BLEManufacturerData || (exports.BLEManufacturerData = {})); var BLEService; (function (BLEService) { @@ -310,7 +325,7 @@ var BLECharacteristic; Documentation generated by JSDoc 3.6.3 - on Tue Dec 3rd 2019 + on Fri Feb 7th 2020 using the DocStrap template. diff --git a/docs/devices_absolutemotor.js.html b/docs/devices_absolutemotor.js.html new file mode 100644 index 0000000..b326086 --- /dev/null +++ b/docs/devices_absolutemotor.js.html @@ -0,0 +1,296 @@ + + + + + + + node-poweredup Source: devices/absolutemotor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/absolutemotor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const tachomotor_1 = require("./tachomotor");
+const Consts = __importStar(require("../consts"));
+const utils_1 = require("../utils");
+class AbsoluteMotor extends tachomotor_1.TachoMotor {
+    constructor(hub, portId, modeMap = {}, type = Consts.DeviceType.UNKNOWN) {
+        super(hub, portId, Object.assign({}, modeMap, exports.ModeMap), type);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.ABSOLUTE:
+                const angle = utils_1.normalizeAngle(message.readInt16LE(this.isWeDo2SmartHub ? 2 : 4));
+                /**
+                 * Emits when a the motors absolute position is changed.
+                 * @event AbsoluteMotor#absolute
+                 * @param {number} absolute
+                 */
+                this.notify("absolute", { angle });
+                break;
+            default:
+                super.receive(message);
+                break;
+        }
+    }
+    /**
+     * Rotate a motor by a given angle.
+     * @method AbsoluteMotor#gotoAngle
+     * @param {number} angle Absolute position the motor should go to (degrees from 0).
+     * @param {number} [speed=100] For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100.
+     * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
+     */
+    gotoAngle(angle, speed = 100) {
+        if (!this.isVirtualPort && angle instanceof Array) {
+            throw new Error("Only virtual ports can accept multiple positions");
+        }
+        if (this.isWeDo2SmartHub) {
+            throw new Error("Absolute positioning is not available on the WeDo 2.0 Smart Hub");
+        }
+        this.cancelEventTimer();
+        return new Promise((resolve) => {
+            this._busy = true;
+            if (speed === undefined || speed === null) {
+                speed = 100;
+            }
+            let message;
+            if (angle instanceof Array) {
+                message = Buffer.from([0x81, this.portId, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, utils_1.mapSpeed(speed), 0x64, this._brakeStyle, 0x00]);
+                message.writeInt32LE(utils_1.normalizeAngle(angle[0]), 4);
+                message.writeInt32LE(utils_1.normalizeAngle(angle[1]), 8);
+            }
+            else {
+                message = Buffer.from([0x81, this.portId, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, utils_1.mapSpeed(speed), 0x64, this._brakeStyle, 0x00]);
+                message.writeInt32LE(utils_1.normalizeAngle(angle), 4);
+            }
+            this.send(message);
+            this._finished = () => {
+                return resolve();
+            };
+        });
+    }
+}
+exports.AbsoluteMotor = AbsoluteMotor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["ROTATION"] = 2] = "ROTATION";
+    Mode[Mode["ABSOLUTE"] = 3] = "ABSOLUTE";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "rotate": Mode.ROTATION,
+    "absolute": Mode.ABSOLUTE
+};
+//# sourceMappingURL=absolutemotor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_basicmotor.js.html b/docs/devices_basicmotor.js.html new file mode 100644 index 0000000..5a8203b --- /dev/null +++ b/docs/devices_basicmotor.js.html @@ -0,0 +1,285 @@ + + + + + + + node-poweredup Source: devices/basicmotor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/basicmotor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+const utils_1 = require("../utils");
+class BasicMotor extends device_1.Device {
+    constructor(hub, portId, modeMap, type = Consts.DeviceType.UNKNOWN) {
+        super(hub, portId, modeMap, type);
+    }
+    /**
+     * 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.
+     */
+    setPower(power, interrupt = true) {
+        if (interrupt) {
+            this.cancelEventTimer();
+        }
+        return new Promise((resolve) => {
+            this.writeDirect(0x00, Buffer.from([utils_1.mapSpeed(power)]));
+            return resolve();
+        });
+    }
+    /**
+     * Ramp the motor power.
+     * @method BasicMotor#rampPower
+     * @param {number} fromPower For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
+     * @param {number} toPower For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
+     * @param {number} time How long the ramp should last (in milliseconds).
+     * @returns {Promise} Resolved upon successful completion of command.
+     */
+    rampPower(fromPower, toPower, time) {
+        this.cancelEventTimer();
+        return new Promise((resolve) => {
+            utils_1.calculateRamp(this, fromPower, toPower, time)
+                .on("changePower", (power) => {
+                this.setPower(power, false);
+            })
+                .on("finished", resolve);
+        });
+    }
+    /**
+     * Stop the motor.
+     * @method BasicMotor#stop
+     * @returns {Promise} Resolved upon successful completion of command.
+     */
+    stop() {
+        this.cancelEventTimer();
+        return this.setPower(0);
+    }
+    /**
+     * Brake the motor.
+     * @method BasicMotor#brake
+     * @returns {Promise} Resolved upon successful completion of command.
+     */
+    brake() {
+        this.cancelEventTimer();
+        return this.setPower(Consts.BrakingStyle.BRAKE);
+    }
+}
+exports.BasicMotor = BasicMotor;
+//# sourceMappingURL=basicmotor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_colordistancesensor.js.html b/docs/devices_colordistancesensor.js.html new file mode 100644 index 0000000..ecbb848 --- /dev/null +++ b/docs/devices_colordistancesensor.js.html @@ -0,0 +1,295 @@ + + + + + + + node-poweredup Source: devices/colordistancesensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/colordistancesensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class ColorDistanceSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.COLOR_DISTANCE_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.COLOR:
+                if (message[this.isWeDo2SmartHub ? 2 : 4] <= 10) {
+                    const color = message[this.isWeDo2SmartHub ? 2 : 4];
+                    /**
+                     * Emits when a color sensor is activated.
+                     * @event ColorDistanceSensor#color
+                     * @param {Color} color
+                     */
+                    this.notify("color", { color });
+                }
+                break;
+            case Mode.DISTANCE:
+                if (this.isWeDo2SmartHub) {
+                    break;
+                }
+                if (message[4] <= 10) {
+                    const distance = Math.floor(message[4] * 25.4) - 20;
+                    /**
+                     * Emits when a distance sensor is activated.
+                     * @event ColorDistanceSensor#distance
+                     * @param {number} distance Distance, in millimeters.
+                     */
+                    this.notify("distance", { distance });
+                }
+                break;
+            case Mode.COLOR_AND_DISTANCE:
+                if (this.isWeDo2SmartHub) {
+                    break;
+                }
+                let distance = message[5];
+                const partial = message[7];
+                if (partial > 0) {
+                    distance += 1.0 / partial;
+                }
+                distance = Math.floor(distance * 25.4) - 20;
+                /**
+                 * A combined color and distance event, emits when the sensor is activated.
+                 * @event ColorDistanceSensor#colorAndDistance
+                 * @param {Color} color
+                 * @param {number} distance Distance, in millimeters.
+                 */
+                if (message[4] <= 10) {
+                    const color = message[4];
+                    this.notify("colorAndDistance", { color, distance });
+                }
+                break;
+        }
+    }
+}
+exports.ColorDistanceSensor = ColorDistanceSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["COLOR"] = 0] = "COLOR";
+    Mode[Mode["DISTANCE"] = 1] = "DISTANCE";
+    Mode[Mode["COLOR_AND_DISTANCE"] = 8] = "COLOR_AND_DISTANCE";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "color": Mode.COLOR,
+    "distance": Mode.DISTANCE,
+    "colorAndDistance": Mode.COLOR_AND_DISTANCE
+};
+//# sourceMappingURL=colordistancesensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_currentsensor.js.html b/docs/devices_currentsensor.js.html new file mode 100644 index 0000000..1505e38 --- /dev/null +++ b/docs/devices_currentsensor.js.html @@ -0,0 +1,275 @@ + + + + + + + node-poweredup Source: devices/currentsensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/currentsensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class CurrentSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.CURRENT_SENSOR);
+    }
+    receive(message) {
+        const mode = this.mode;
+        switch (mode) {
+            case Mode.CURRENT:
+                if (this.isWeDo2SmartHub) {
+                    const current = message.readInt16LE(2) / 1000;
+                    this.notify("current", { current });
+                }
+                else {
+                    let maxCurrentValue = MaxCurrentValue[this.hub.type];
+                    if (maxCurrentValue === undefined) {
+                        maxCurrentValue = MaxCurrentValue[Consts.HubType.UNKNOWN];
+                    }
+                    let maxCurrentRaw = MaxCurrentRaw[this.hub.type];
+                    if (maxCurrentRaw === undefined) {
+                        maxCurrentRaw = MaxCurrentRaw[Consts.HubType.UNKNOWN];
+                    }
+                    const current = message.readUInt16LE(4) * maxCurrentValue / maxCurrentRaw;
+                    /**
+                     * Emits when a current change is detected.
+                     * @event CurrentSensor#current
+                     * @param {number} current
+                     */
+                    this.notify("current", { current });
+                }
+                break;
+        }
+    }
+}
+exports.CurrentSensor = CurrentSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["CURRENT"] = 0] = "CURRENT";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "current": Mode.CURRENT
+};
+const MaxCurrentValue = {
+    [Consts.HubType.UNKNOWN]: 2444,
+    [Consts.HubType.TECHNIC_MEDIUM_HUB]: 4175,
+};
+const MaxCurrentRaw = {
+    [Consts.HubType.UNKNOWN]: 4095,
+};
+//# sourceMappingURL=currentsensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_duplotrainbasecolorsensor.js.html b/docs/devices_duplotrainbasecolorsensor.js.html new file mode 100644 index 0000000..8a4df3a --- /dev/null +++ b/docs/devices_duplotrainbasecolorsensor.js.html @@ -0,0 +1,256 @@ + + + + + + + node-poweredup Source: devices/duplotrainbasecolorsensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/duplotrainbasecolorsensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class DuploTrainBaseColorSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.DUPLO_TRAIN_BASE_COLOR_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.COLOR:
+                if (message[4] <= 10) {
+                    const color = message[4];
+                    /**
+                     * Emits when a color sensor is activated.
+                     * @event DuploTrainBaseColorSensor#color
+                     * @param {Color} color
+                     */
+                    this.notify("color", { color });
+                }
+                break;
+        }
+    }
+}
+exports.DuploTrainBaseColorSensor = DuploTrainBaseColorSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["COLOR"] = 0] = "COLOR";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "color": Mode.COLOR
+};
+//# sourceMappingURL=duplotrainbasecolorsensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_duplotrainbasespeaker.js.html b/docs/devices_duplotrainbasespeaker.js.html new file mode 100644 index 0000000..f7985b8 --- /dev/null +++ b/docs/devices_duplotrainbasespeaker.js.html @@ -0,0 +1,250 @@ + + + + + + + node-poweredup Source: devices/duplotrainbasespeaker.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/duplotrainbasespeaker.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class DuploTrainBaseSpeaker extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, {}, Consts.DeviceType.DUPLO_TRAIN_BASE_SPEAKER);
+    }
+    /**
+     * Play a built-in train sound.
+     * @method DuploTrainBaseSpeaker#playSound
+     * @param {DuploTrainBaseSound} sound
+     * @returns {Promise} Resolved upon successful issuance of command.
+     */
+    playSound(sound) {
+        return new Promise((resolve, reject) => {
+            this.subscribe(Mode.SOUND);
+            this.writeDirect(0x01, Buffer.from([sound]));
+            return resolve();
+        });
+    }
+}
+exports.DuploTrainBaseSpeaker = DuploTrainBaseSpeaker;
+var Mode;
+(function (Mode) {
+    Mode[Mode["SOUND"] = 1] = "SOUND";
+})(Mode = exports.Mode || (exports.Mode = {}));
+//# sourceMappingURL=duplotrainbasespeaker.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_duplotrainbasespeedometer.js.html b/docs/devices_duplotrainbasespeedometer.js.html new file mode 100644 index 0000000..6be089b --- /dev/null +++ b/docs/devices_duplotrainbasespeedometer.js.html @@ -0,0 +1,254 @@ + + + + + + + node-poweredup Source: devices/duplotrainbasespeedometer.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/duplotrainbasespeedometer.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class DuploTrainBaseSpeedometer extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.DUPLO_TRAIN_BASE_SPEEDOMETER);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.SPEED:
+                const speed = message.readInt16LE(4);
+                /**
+                 * Emits on a speed change.
+                 * @event DuploTrainBaseSpeedometer#speed
+                 * @param {number} speed
+                 */
+                this.notify("speed", { speed });
+                break;
+        }
+    }
+}
+exports.DuploTrainBaseSpeedometer = DuploTrainBaseSpeedometer;
+var Mode;
+(function (Mode) {
+    Mode[Mode["SPEED"] = 0] = "SPEED";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "speed": Mode.SPEED
+};
+//# sourceMappingURL=duplotrainbasespeedometer.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_hubled.js.html b/docs/devices_hubled.js.html new file mode 100644 index 0000000..3340263 --- /dev/null +++ b/docs/devices_hubled.js.html @@ -0,0 +1,281 @@ + + + + + + + node-poweredup Source: devices/hubled.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/hubled.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class HubLED extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, {}, Consts.DeviceType.HUB_LED);
+    }
+    /**
+     * Set the color of the LED on the Hub via a color value.
+     * @method HubLED#setColor
+     * @param {Color} color
+     * @returns {Promise} Resolved upon successful issuance of command.
+     */
+    setColor(color) {
+        return new Promise((resolve, reject) => {
+            if (typeof color === "boolean") {
+                color = 0;
+            }
+            if (this.isWeDo2SmartHub) {
+                this.send(Buffer.from([0x06, 0x17, 0x01, 0x01]), Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE);
+                this.send(Buffer.from([0x06, 0x04, 0x01, color]), Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
+            }
+            else {
+                this.subscribe(Mode.COLOR);
+                this.writeDirect(0x00, Buffer.from([color]));
+            }
+            return resolve();
+        });
+    }
+    /**
+     * Set the color of the LED on the Hub via RGB values.
+     * @method HubLED#setRGB
+     * @param {number} red
+     * @param {number} green
+     * @param {number} blue
+     * @returns {Promise} Resolved upon successful issuance of command.
+     */
+    setRGB(red, green, blue) {
+        return new Promise((resolve, reject) => {
+            if (this.isWeDo2SmartHub) {
+                this.send(Buffer.from([0x06, 0x17, 0x01, 0x02]), Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE);
+                this.send(Buffer.from([0x06, 0x04, 0x03, red, green, blue]), Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
+            }
+            else {
+                this.subscribe(Mode.RGB);
+                this.writeDirect(0x01, Buffer.from([red, green, blue]));
+            }
+            return resolve();
+        });
+    }
+}
+exports.HubLED = HubLED;
+var Mode;
+(function (Mode) {
+    Mode[Mode["COLOR"] = 0] = "COLOR";
+    Mode[Mode["RGB"] = 1] = "RGB";
+})(Mode = exports.Mode || (exports.Mode = {}));
+//# sourceMappingURL=hubled.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_light.js.html b/docs/devices_light.js.html new file mode 100644 index 0000000..87521bc --- /dev/null +++ b/docs/devices_light.js.html @@ -0,0 +1,267 @@ + + + + + + + node-poweredup Source: devices/light.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/light.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+const utils_1 = require("../utils");
+class Light extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, {}, Consts.DeviceType.LIGHT);
+    }
+    /**
+     * Set the light brightness.
+     * @method Light#setBrightness
+     * @param {number} brightness Brightness value between 0-100 (0 is off)
+     * @returns {Promise} Resolved upon successful completion of command.
+     */
+    setBrightness(brightness, interrupt = true) {
+        if (interrupt) {
+            this.cancelEventTimer();
+        }
+        return new Promise((resolve) => {
+            this.writeDirect(0x00, Buffer.from([brightness]));
+            return resolve();
+        });
+    }
+    /**
+     * Ramp the light brightness.
+     * @method Light#rampBrightness
+     * @param {number} fromBrightness Brightness value between 0-100 (0 is off)
+     * @param {number} toBrightness Brightness value between 0-100 (0 is off)
+     * @param {number} time How long the ramp should last (in milliseconds).
+     * @returns {Promise} Resolved upon successful completion of command.
+     */
+    rampBrightness(fromBrightness, toBrightness, time) {
+        this.cancelEventTimer();
+        return new Promise((resolve) => {
+            utils_1.calculateRamp(this, fromBrightness, toBrightness, time)
+                .on("changePower", (power) => {
+                this.setBrightness(power, false);
+            })
+                .on("finished", resolve);
+        });
+    }
+}
+exports.Light = Light;
+//# sourceMappingURL=light.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_motionsensor.js.html b/docs/devices_motionsensor.js.html new file mode 100644 index 0000000..c4f16b1 --- /dev/null +++ b/docs/devices_motionsensor.js.html @@ -0,0 +1,258 @@ + + + + + + + node-poweredup Source: devices/motionsensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/motionsensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class MotionSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.MOTION_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.DISTANCE:
+                let distance = message[this.isWeDo2SmartHub ? 2 : 4];
+                if (message[this.isWeDo2SmartHub ? 3 : 5] === 1) {
+                    distance = distance + 255;
+                }
+                distance *= 10;
+                /**
+                 * Emits when a distance sensor is activated.
+                 * @event MotionSensor#distance
+                 * @param {number} distance Distance, in millimeters.
+                 */
+                this.notify("distance", { distance });
+                break;
+        }
+    }
+}
+exports.MotionSensor = MotionSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["DISTANCE"] = 0] = "DISTANCE";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "distance": Mode.DISTANCE
+};
+//# sourceMappingURL=motionsensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_movehubtiltsensor.js.html b/docs/devices_movehubtiltsensor.js.html new file mode 100644 index 0000000..c3bdc7c --- /dev/null +++ b/docs/devices_movehubtiltsensor.js.html @@ -0,0 +1,256 @@ + + + + + + + node-poweredup Source: devices/movehubtiltsensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/movehubtiltsensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class MoveHubTiltSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.MOVE_HUB_TILT_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.TILT:
+                /**
+                 * Emits when a tilt sensor is activated.
+                 * @event MoveHubTiltSensor#tilt
+                 * @param {number} x
+                 * @param {number} y
+                 */
+                const x = -message.readInt8(4);
+                const y = message.readInt8(5);
+                this.notify("tilt", { x, y });
+                break;
+        }
+    }
+}
+exports.MoveHubTiltSensor = MoveHubTiltSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["TILT"] = 0] = "TILT";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "tilt": Mode.TILT
+};
+//# sourceMappingURL=movehubtiltsensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_piezobuzzer.js.html b/docs/devices_piezobuzzer.js.html new file mode 100644 index 0000000..9edb6bd --- /dev/null +++ b/docs/devices_piezobuzzer.js.html @@ -0,0 +1,249 @@ + + + + + + + node-poweredup Source: devices/piezobuzzer.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/piezobuzzer.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class PiezoBuzzer extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, {}, Consts.DeviceType.PIEZO_BUZZER);
+    }
+    /**
+     * Play a tone on the Hub's in-built buzzer
+     * @method PiezoBuzzer#playTone
+     * @param {number} frequency
+     * @param {number} time How long the tone should play for (in milliseconds).
+     * @returns {Promise} Resolved upon successful completion of command (ie. once the tone has finished playing).
+     */
+    playTone(frequency, time) {
+        return new Promise((resolve) => {
+            const data = Buffer.from([0x05, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00]);
+            data.writeUInt16LE(frequency, 3);
+            data.writeUInt16LE(time, 5);
+            this.send(data, Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
+            global.setTimeout(resolve, time);
+        });
+    }
+}
+exports.PiezoBuzzer = PiezoBuzzer;
+//# sourceMappingURL=piezobuzzer.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_remotecontrolbutton.js.html b/docs/devices_remotecontrolbutton.js.html new file mode 100644 index 0000000..db27234 --- /dev/null +++ b/docs/devices_remotecontrolbutton.js.html @@ -0,0 +1,260 @@ + + + + + + + node-poweredup Source: devices/remotecontrolbutton.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/remotecontrolbutton.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class RemoteControlButton extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.REMOTE_CONTROL_BUTTON);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.BUTTON_EVENTS:
+                /**
+                 * Emits when a button on the remote is pressed or released.
+                 * @event RemoteControlButton#button
+                 * @param {number} event
+                 */
+                const event = message[4];
+                this.notify("remoteButton", { event });
+                break;
+        }
+    }
+}
+exports.RemoteControlButton = RemoteControlButton;
+var Mode;
+(function (Mode) {
+    Mode[Mode["BUTTON_EVENTS"] = 0] = "BUTTON_EVENTS";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "remoteButton": Mode.BUTTON_EVENTS
+};
+exports.ButtonState = {
+    "UP": 0x01,
+    "DOWN": 0xff,
+    "STOP": 0x7f,
+    "RELEASED": 0x00,
+};
+//# sourceMappingURL=remotecontrolbutton.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_tachomotor.js.html b/docs/devices_tachomotor.js.html new file mode 100644 index 0000000..1e2ce11 --- /dev/null +++ b/docs/devices_tachomotor.js.html @@ -0,0 +1,336 @@ + + + + + + + node-poweredup Source: devices/tachomotor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/tachomotor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const basicmotor_1 = require("./basicmotor");
+const Consts = __importStar(require("../consts"));
+const utils_1 = require("../utils");
+class TachoMotor extends basicmotor_1.BasicMotor {
+    constructor(hub, portId, modeMap = {}, type = Consts.DeviceType.UNKNOWN) {
+        super(hub, portId, Object.assign({}, modeMap, exports.ModeMap), type);
+        this._brakeStyle = Consts.BrakingStyle.BRAKE;
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.ROTATION:
+                const degrees = message.readInt32LE(this.isWeDo2SmartHub ? 2 : 4);
+                /**
+                 * Emits when a rotation sensor is activated.
+                 * @event TachoMotor#rotate
+                 * @param {number} rotation
+                 */
+                this.notify("rotate", { degrees });
+                break;
+        }
+    }
+    setBrakingStyle(style) {
+        this._brakeStyle = style;
+    }
+    /**
+     * Set the motor speed.
+     * @method TachoMotor#setSpeed
+     * @param {number} speed 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.
+     */
+    setSpeed(speed, time) {
+        if (!this.isVirtualPort && speed instanceof Array) {
+            throw new Error("Only virtual ports can accept multiple speeds");
+        }
+        if (this.isWeDo2SmartHub) {
+            throw new Error("Motor speed is not available on the WeDo 2.0 Smart Hub");
+        }
+        this.cancelEventTimer();
+        return new Promise((resolve) => {
+            this._busy = true;
+            if (speed === undefined || speed === null) {
+                speed = 100;
+            }
+            let message;
+            if (time !== undefined) {
+                if (speed instanceof Array) {
+                    message = Buffer.from([0x81, this.portId, 0x11, 0x0a, 0x00, 0x00, utils_1.mapSpeed(speed[0]), utils_1.mapSpeed(speed[1]), 0x64, this._brakeStyle, 0x00]);
+                }
+                else {
+                    message = Buffer.from([0x81, this.portId, 0x11, 0x09, 0x00, 0x00, utils_1.mapSpeed(speed), 0x64, this._brakeStyle, 0x00]);
+                }
+                message.writeUInt16LE(time, 4);
+            }
+            else {
+                if (speed instanceof Array) {
+                    message = Buffer.from([0x81, this.portId, 0x11, 0x08, utils_1.mapSpeed(speed[0]), utils_1.mapSpeed(speed[1]), 0x64, this._brakeStyle, 0x00]);
+                }
+                else {
+                    message = Buffer.from([0x81, this.portId, 0x11, 0x07, utils_1.mapSpeed(speed), 0x64, 0x03, 0x64, this._brakeStyle, 0x00]);
+                }
+            }
+            this.send(message);
+            this._finished = () => {
+                return resolve();
+            };
+        });
+    }
+    /**
+     * Rotate a motor by a given amount of degrees.
+     * @method TachoMotor#rotateByDegrees
+     * @param {number} degrees How much the motor should be rotated (in degrees).
+     * @param {number} [speed=100] For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100.
+     * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
+     */
+    rotateByDegrees(degrees, speed) {
+        if (!this.isVirtualPort && speed instanceof Array) {
+            throw new Error("Only virtual ports can accept multiple speeds");
+        }
+        if (this.isWeDo2SmartHub) {
+            throw new Error("Rotation is not available on the WeDo 2.0 Smart Hub");
+        }
+        this.cancelEventTimer();
+        return new Promise((resolve) => {
+            this._busy = true;
+            if (speed === undefined || speed === null) {
+                speed = 100;
+            }
+            let message;
+            if (speed instanceof Array) {
+                message = Buffer.from([0x81, this.portId, 0x11, 0x0c, 0x00, 0x00, 0x00, 0x00, utils_1.mapSpeed(speed[0]), utils_1.mapSpeed(speed[1]), 0x64, this._brakeStyle, 0x03]);
+            }
+            else {
+                message = Buffer.from([0x81, this.portId, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, utils_1.mapSpeed(speed), 0x64, this._brakeStyle, 0x03]);
+            }
+            message.writeUInt32LE(degrees, 4);
+            this.send(message);
+            this._finished = () => {
+                return resolve();
+            };
+        });
+    }
+}
+exports.TachoMotor = TachoMotor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["ROTATION"] = 2] = "ROTATION";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "rotate": Mode.ROTATION
+};
+//# sourceMappingURL=tachomotor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_techniccolorsensor.js.html b/docs/devices_techniccolorsensor.js.html new file mode 100644 index 0000000..104ed63 --- /dev/null +++ b/docs/devices_techniccolorsensor.js.html @@ -0,0 +1,278 @@ + + + + + + + node-poweredup Source: devices/techniccolorsensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/techniccolorsensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class TechnicColorSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.TECHNIC_COLOR_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.COLOR:
+                if (message[4] <= 10) {
+                    const color = message[4];
+                    /**
+                     * Emits when a color sensor is activated.
+                     * @event TechnicColorSensor#color
+                     * @param {Color} color
+                     */
+                    this.notify("color", { color });
+                }
+                break;
+            case Mode.REFLECTIVITY:
+                const reflect = message[4];
+                /**
+                 * Emits when the light reflectivity changes.
+                 * @event TechnicColorSensor#reflect Percentage, from 0 to 100.
+                 * @param {number} reflect
+                 */
+                this.notify("reflect", { reflect });
+                break;
+            case Mode.AMBIENT_LIGHT:
+                const ambient = message[4];
+                /**
+                 * Emits when the ambient light changes.
+                 * @event TechnicColorSensor#ambient Percentage, from 0 to 100.
+                 * @param {number} ambient
+                 */
+                this.notify("ambient", { ambient });
+                break;
+        }
+    }
+}
+exports.TechnicColorSensor = TechnicColorSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["COLOR"] = 0] = "COLOR";
+    Mode[Mode["REFLECTIVITY"] = 1] = "REFLECTIVITY";
+    Mode[Mode["AMBIENT_LIGHT"] = 2] = "AMBIENT_LIGHT";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "color": Mode.COLOR,
+    "reflect": Mode.REFLECTIVITY,
+    "ambient": Mode.AMBIENT_LIGHT
+};
+//# sourceMappingURL=techniccolorsensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_technicdistancesensor.js.html b/docs/devices_technicdistancesensor.js.html new file mode 100644 index 0000000..ede059c --- /dev/null +++ b/docs/devices_technicdistancesensor.js.html @@ -0,0 +1,277 @@ + + + + + + + node-poweredup Source: devices/technicdistancesensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/technicdistancesensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class TechnicDistanceSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.TECHNIC_DISTANCE_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.DISTANCE:
+                const distance = message.readUInt16LE(4);
+                /**
+                 * Emits when the detected distance changes (Slow sampling covers 40mm to 2500mm).
+                 * @event TechnicDistanceSensor#distance Distance, from 40 to 2500mm
+                 * @param {number} distance
+                 */
+                this.notify("distance", { distance });
+                break;
+            case Mode.FAST_DISTANCE:
+                const fastDistance = message.readUInt16LE(4);
+                /**
+                 * Emits when the detected distance changes (Fast sampling covers 50mm to 320mm).
+                 * @event TechnicDistanceSensor#fastDistance Distance, from 50 to 320mm
+                 * @param {number} fastDistance
+                 */
+                this.notify("fastDistance", { fastDistance });
+                break;
+        }
+    }
+    /**
+     * Set the brightness (or turn on/off) the lights around the eyes.
+     * @method TechnicDistanceSensor#setBrightness
+     * @param {number} topLeft Top left quadrant (above left eye). 0-100 brightness.
+     * @param {number} bottomLeft Bottom left quadrant (below left eye). 0-100 brightness.
+     * @param {number} topRight Top right quadrant (above right eye). 0-100 brightness.
+     * @param {number} bottomRight Bottom right quadrant (below right eye). 0-100 brightness.
+     * @returns {Promise} Resolved upon successful completion of command.
+     */
+    setBrightness(topLeft, bottomLeft, topRight, bottomRight) {
+        this.writeDirect(0x05, Buffer.from([topLeft, topRight, bottomLeft, bottomRight]));
+    }
+}
+exports.TechnicDistanceSensor = TechnicDistanceSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["DISTANCE"] = 0] = "DISTANCE";
+    Mode[Mode["FAST_DISTANCE"] = 1] = "FAST_DISTANCE";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "distance": Mode.DISTANCE,
+    "fastDistance": Mode.FAST_DISTANCE
+};
+//# sourceMappingURL=technicdistancesensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_technicforcesensor.js.html b/docs/devices_technicforcesensor.js.html new file mode 100644 index 0000000..3d2c10e --- /dev/null +++ b/docs/devices_technicforcesensor.js.html @@ -0,0 +1,276 @@ + + + + + + + node-poweredup Source: devices/technicforcesensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/technicforcesensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class TechnicForceSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.TECHNIC_FORCE_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.FORCE:
+                const force = message[4] / 10;
+                /**
+                 * Emits when force is applied.
+                 * @event TechnicForceSensor#force Force, in newtons (0-10).
+                 * @param {number} force
+                 */
+                this.notify("force", { force });
+                break;
+            case Mode.TOUCHED:
+                const touched = message[4] ? true : false;
+                /**
+                 * Emits when the sensor is touched.
+                 * @event TechnicForceSensor#touch Touched on/off (boolean).
+                 * @param {boolean} touch
+                 */
+                this.notify("touched", { touched });
+                break;
+            case Mode.TAPPED:
+                const tapped = message[4];
+                /**
+                 * Emits when the sensor is tapped.
+                 * @event TechnicForceSensor#tapped How hard the sensor was tapped, from 0-3.
+                 * @param {number} tapped
+                 */
+                this.notify("tapped", { tapped });
+                break;
+        }
+    }
+}
+exports.TechnicForceSensor = TechnicForceSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["FORCE"] = 0] = "FORCE";
+    Mode[Mode["TOUCHED"] = 1] = "TOUCHED";
+    Mode[Mode["TAPPED"] = 2] = "TAPPED";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "force": Mode.FORCE,
+    "touched": Mode.TOUCHED,
+    "tapped": Mode.TAPPED
+};
+//# sourceMappingURL=technicforcesensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_technicmediumhubaccelerometersensor.js.html b/docs/devices_technicmediumhubaccelerometersensor.js.html new file mode 100644 index 0000000..a5b737f --- /dev/null +++ b/docs/devices_technicmediumhubaccelerometersensor.js.html @@ -0,0 +1,259 @@ + + + + + + + node-poweredup Source: devices/technicmediumhubaccelerometersensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/technicmediumhubaccelerometersensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class TechnicMediumHubAccelerometerSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.TECHNIC_MEDIUM_HUB_ACCELEROMETER);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.ACCEL:
+                /**
+                 * Emits when accelerometer detects movement. Measured in mG.
+                 * @event LPF2Hub#accel
+                 * @param {string} port
+                 * @param {number} x
+                 * @param {number} y
+                 * @param {number} z
+                 */
+                const x = Math.round(message.readInt16LE(4) / 4.096);
+                const y = Math.round(message.readInt16LE(6) / 4.096);
+                const z = Math.round(message.readInt16LE(8) / 4.096);
+                this.notify("accel", { x, y, z });
+                break;
+        }
+    }
+}
+exports.TechnicMediumHubAccelerometerSensor = TechnicMediumHubAccelerometerSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["ACCEL"] = 0] = "ACCEL";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "accel": Mode.ACCEL
+};
+//# sourceMappingURL=technicmediumhubaccelerometersensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_technicmediumhubgyrosensor.js.html b/docs/devices_technicmediumhubgyrosensor.js.html new file mode 100644 index 0000000..b267432 --- /dev/null +++ b/docs/devices_technicmediumhubgyrosensor.js.html @@ -0,0 +1,258 @@ + + + + + + + node-poweredup Source: devices/technicmediumhubgyrosensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/technicmediumhubgyrosensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class TechnicMediumHubGyroSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.TECHNIC_MEDIUM_HUB_GYRO_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.GYRO:
+                /**
+                 * Emits when gyroscope detects movement. Measured in DPS - degrees per second.
+                 * @event TechnicMediumHubGyroSensor#gyro
+                 * @param {number} x
+                 * @param {number} y
+                 * @param {number} z
+                 */
+                const x = Math.round(message.readInt16LE(4) * 7 / 400);
+                const y = Math.round(message.readInt16LE(6) * 7 / 400);
+                const z = Math.round(message.readInt16LE(8) * 7 / 400);
+                this.notify("gyro", { x, y, z });
+                break;
+        }
+    }
+}
+exports.TechnicMediumHubGyroSensor = TechnicMediumHubGyroSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["GYRO"] = 0] = "GYRO";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "gyro": Mode.GYRO
+};
+//# sourceMappingURL=technicmediumhubgyrosensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_technicmediumhubtiltsensor.js.html b/docs/devices_technicmediumhubtiltsensor.js.html new file mode 100644 index 0000000..0453b84 --- /dev/null +++ b/docs/devices_technicmediumhubtiltsensor.js.html @@ -0,0 +1,258 @@ + + + + + + + node-poweredup Source: devices/technicmediumhubtiltsensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/technicmediumhubtiltsensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class TechnicMediumHubTiltSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.TECHNIC_MEDIUM_HUB_TILT_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.TILT:
+                /**
+                 * Emits when a tilt sensor is activated.
+                 * @event TechnicMediumHubTiltSensor#tilt
+                 * @param {number} x
+                 * @param {number} y
+                 * @param {number} z
+                 */
+                const z = -message.readInt16LE(4);
+                const y = message.readInt16LE(6);
+                const x = message.readInt16LE(8);
+                this.notify("tilt", { x, y, z });
+                break;
+        }
+    }
+}
+exports.TechnicMediumHubTiltSensor = TechnicMediumHubTiltSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["TILT"] = 0] = "TILT";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "tilt": Mode.TILT
+};
+//# sourceMappingURL=technicmediumhubtiltsensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_tiltsensor.js.html b/docs/devices_tiltsensor.js.html new file mode 100644 index 0000000..4c09882 --- /dev/null +++ b/docs/devices_tiltsensor.js.html @@ -0,0 +1,256 @@ + + + + + + + node-poweredup Source: devices/tiltsensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/tiltsensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class TiltSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.TILT_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.TILT:
+                const x = message.readInt8(this.isWeDo2SmartHub ? 2 : 4);
+                const y = message.readInt8(this.isWeDo2SmartHub ? 3 : 5);
+                /**
+                 * Emits when a tilt sensor is activated.
+                 * @event LPF2Hub#tilt
+                 * @param {number} x
+                 * @param {number} y
+                 */
+                this.notify("tilt", { x, y });
+                break;
+        }
+    }
+}
+exports.TiltSensor = TiltSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["TILT"] = 0] = "TILT";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "tilt": Mode.TILT
+};
+//# sourceMappingURL=tiltsensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/devices_voltagesensor.js.html b/docs/devices_voltagesensor.js.html new file mode 100644 index 0000000..a341a20 --- /dev/null +++ b/docs/devices_voltagesensor.js.html @@ -0,0 +1,279 @@ + + + + + + + node-poweredup Source: devices/voltagesensor.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: devices/voltagesensor.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const device_1 = require("./device");
+const Consts = __importStar(require("../consts"));
+class VoltageSensor extends device_1.Device {
+    constructor(hub, portId) {
+        super(hub, portId, exports.ModeMap, Consts.DeviceType.VOLTAGE_SENSOR);
+    }
+    receive(message) {
+        const mode = this._mode;
+        switch (mode) {
+            case Mode.VOLTAGE:
+                if (this.isWeDo2SmartHub) {
+                    const voltage = message.readInt16LE(2) / 40;
+                    this.notify("voltage", { voltage });
+                }
+                else {
+                    let maxVoltageValue = MaxVoltageValue[this.hub.type];
+                    if (maxVoltageValue === undefined) {
+                        maxVoltageValue = MaxVoltageValue[Consts.HubType.UNKNOWN];
+                    }
+                    let maxVoltageRaw = MaxVoltageRaw[this.hub.type];
+                    if (maxVoltageRaw === undefined) {
+                        maxVoltageRaw = MaxVoltageRaw[Consts.HubType.UNKNOWN];
+                    }
+                    const voltage = message.readUInt16LE(4) * maxVoltageValue / maxVoltageRaw;
+                    /**
+                     * Emits when a voltage change is detected.
+                     * @event VoltageSensor#voltage
+                     * @param {number} voltage
+                     */
+                    this.notify("voltage", { voltage });
+                }
+                break;
+        }
+    }
+}
+exports.VoltageSensor = VoltageSensor;
+var Mode;
+(function (Mode) {
+    Mode[Mode["VOLTAGE"] = 0] = "VOLTAGE";
+})(Mode = exports.Mode || (exports.Mode = {}));
+exports.ModeMap = {
+    "voltage": Mode.VOLTAGE
+};
+const MaxVoltageValue = {
+    [Consts.HubType.UNKNOWN]: 9.615,
+    [Consts.HubType.DUPLO_TRAIN_BASE]: 6.4,
+    [Consts.HubType.REMOTE_CONTROL]: 6.4,
+};
+const MaxVoltageRaw = {
+    [Consts.HubType.UNKNOWN]: 3893,
+    [Consts.HubType.DUPLO_TRAIN_BASE]: 3047,
+    [Consts.HubType.REMOTE_CONTROL]: 3200,
+    [Consts.HubType.TECHNIC_MEDIUM_HUB]: 4095,
+};
+//# sourceMappingURL=voltagesensor.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Fri Feb 7th 2020 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/global.html b/docs/global.html index be0995b..2d215b1 100644 --- a/docs/global.html +++ b/docs/global.html @@ -33,14 +33,14 @@ @@ -161,8 +161,8 @@

-
-

ButtonState

+
+

BrakingStyle

@@ -201,7 +201,7 @@ - PRESSED + HOLD @@ -218,14 +218,14 @@ -

0

+

127

- RELEASED + BRAKE @@ -242,79 +242,7 @@ -

1

- - - - - - - UP - - - - - -number - - - - - - - - - - -

2

- - - - - - - DOWN - - - - - -number - - - - - - - - - - -

3

- - - - - - - STOP - - - - - -number - - - - - - - - - - -

4

+

128

@@ -356,7 +284,150 @@ +
+ + + + + + + + + + + + + + + +
+
+

BrakingStyle

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
HOLD + + +number + + + + +

127

BRAKE + + +number + + + + +

128

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -571,7 +642,222 @@ +
+ + + + + + + + + + + + + + + +
+
+

ButtonState

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
PRESSED + + +number + + + + +

0

RELEASED + + +number + + + + +

1

UP + + +number + + + + +

2

DOWN + + +number + + + + +

3

STOP + + +number + + + + +

4

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -954,7 +1240,7 @@
@@ -1337,7 +1623,7 @@ @@ -1421,7 +1707,7 @@ - BASIC_MOTOR + SIMPLE_MEDIUM_LINEAR_MOTOR @@ -1637,7 +1923,7 @@ - BOOST_DISTANCE + COLOR_DISTANCE_SENSOR @@ -1661,7 +1947,7 @@ - BOOST_TACHO_MOTOR + MEDIUM_LINEAR_MOTOR @@ -1685,7 +1971,7 @@ - BOOST_MOVE_HUB_MOTOR + MOVE_HUB_MEDIUM_LINEAR_MOTOR @@ -2092,7 +2378,7 @@ - BASIC_MOTOR + SIMPLE_MEDIUM_LINEAR_MOTOR @@ -2308,7 +2594,7 @@ - BOOST_DISTANCE + COLOR_DISTANCE_SENSOR @@ -2332,7 +2618,7 @@ - BOOST_TACHO_MOTOR + MEDIUM_LINEAR_MOTOR @@ -2356,7 +2642,7 @@ - BOOST_MOVE_HUB_MOTOR + MOVE_HUB_MEDIUM_LINEAR_MOTOR @@ -2894,7 +3180,7 @@ @@ -3109,7 +3395,7 @@ @@ -3217,7 +3503,7 @@ - BOOST_MOVE_HUB + MOVE_HUB @@ -3480,7 +3766,7 @@ - BOOST_MOVE_HUB + MOVE_HUB @@ -3704,7 +3990,7 @@ Documentation generated by JSDoc 3.6.3 - on Tue Dec 3rd 2019 + on Fri Feb 7th 2020 using the DocStrap template. diff --git a/docs/hubs_basehub.js.html b/docs/hubs_basehub.js.html new file mode 100644 index 0000000..af7ab7a --- /dev/null +++ b/docs/hubs_basehub.js.html @@ -0,0 +1,543 @@ + + + + + + + node-poweredup Source: hubs/basehub.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: hubs/basehub.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const events_1 = require("events");
+const colordistancesensor_1 = require("../devices/colordistancesensor");
+const currentsensor_1 = require("../devices/currentsensor");
+const device_1 = require("../devices/device");
+const duplotrainbasecolorsensor_1 = require("../devices/duplotrainbasecolorsensor");
+const duplotrainbasemotor_1 = require("../devices/duplotrainbasemotor");
+const duplotrainbasespeaker_1 = require("../devices/duplotrainbasespeaker");
+const duplotrainbasespeedometer_1 = require("../devices/duplotrainbasespeedometer");
+const hubled_1 = require("../devices/hubled");
+const light_1 = require("../devices/light");
+const mediumlinearmotor_1 = require("../devices/mediumlinearmotor");
+const motionsensor_1 = require("../devices/motionsensor");
+const movehubmediumlinearmotor_1 = require("../devices/movehubmediumlinearmotor");
+const movehubtiltsensor_1 = require("../devices/movehubtiltsensor");
+const piezobuzzer_1 = require("../devices/piezobuzzer");
+const remotecontrolbutton_1 = require("../devices/remotecontrolbutton");
+const simplemediumlinearmotor_1 = require("../devices/simplemediumlinearmotor");
+const techniccolorsensor_1 = require("../devices/techniccolorsensor");
+const technicdistancesensor_1 = require("../devices/technicdistancesensor");
+const technicforcesensor_1 = require("../devices/technicforcesensor");
+const techniclargeangularmotor_1 = require("../devices/techniclargeangularmotor");
+const techniclargelinearmotor_1 = require("../devices/techniclargelinearmotor");
+const technicmediumangularmotor_1 = require("../devices/technicmediumangularmotor");
+const technicmediumhubaccelerometersensor_1 = require("../devices/technicmediumhubaccelerometersensor");
+const technicmediumhubgyrosensor_1 = require("../devices/technicmediumhubgyrosensor");
+const technicmediumhubtiltsensor_1 = require("../devices/technicmediumhubtiltsensor");
+const technicxlargelinearmotor_1 = require("../devices/technicxlargelinearmotor");
+const tiltsensor_1 = require("../devices/tiltsensor");
+const trainmotor_1 = require("../devices/trainmotor");
+const voltagesensor_1 = require("../devices/voltagesensor");
+const Consts = __importStar(require("../consts"));
+const Debug = require("debug");
+const debug = Debug("basehub");
+/**
+ * @class BaseHub
+ * @extends EventEmitter
+ */
+class BaseHub extends events_1.EventEmitter {
+    constructor(bleDevice, portMap = {}, type = Consts.HubType.UNKNOWN) {
+        super();
+        this._attachedDevices = {};
+        this._name = "";
+        this._firmwareVersion = "0.0.00.0000";
+        this._hardwareVersion = "0.0.00.0000";
+        this._primaryMACAddress = "00:00:00:00:00:00";
+        this._batteryLevel = 100;
+        this._rssi = -60;
+        this._portMap = {};
+        this._virtualPorts = [];
+        this._attachCallbacks = [];
+        this.setMaxListeners(23); // Technic Medium Hub has 9 built in devices + 4 external ports. Node.js throws a warning after 10 attached event listeners.
+        this._type = type;
+        this._bleDevice = bleDevice;
+        this._portMap = Object.assign({}, portMap);
+        bleDevice.on("disconnect", () => {
+            /**
+             * Emits when the hub is disconnected.
+             * @event Hub#disconnect
+             */
+            this.emit("disconnect");
+        });
+    }
+    /**
+     * @readonly
+     * @property {string} name Name of the hub
+     */
+    get name() {
+        return this._bleDevice.name;
+    }
+    /**
+     * @readonly
+     * @property {string} type Hub type
+     */
+    get type() {
+        return this._type;
+    }
+    /**
+     * @readonly
+     * @property {string[]} ports Array of port names
+     */
+    get ports() {
+        return Object.keys(this._portMap);
+    }
+    /**
+     * @readonly
+     * @property {string} firmwareVersion Firmware version of the hub
+     */
+    get firmwareVersion() {
+        return this._firmwareVersion;
+    }
+    /**
+     * @readonly
+     * @property {string} firmwareVersion Hardware version of the hub
+     */
+    get hardwareVersion() {
+        return this._hardwareVersion;
+    }
+    /**
+     * @readonly
+     * @property {string} primaryMACAddress Primary MAC address of the hub
+     */
+    get primaryMACAddress() {
+        return this._primaryMACAddress;
+    }
+    /**
+     * @readonly
+     * @property {string} uuid UUID of the hub
+     */
+    get uuid() {
+        return this._bleDevice.uuid;
+    }
+    /**
+     * @readonly
+     * @property {number} batteryLevel Battery level of the hub (Percentage between 0-100)
+     */
+    get batteryLevel() {
+        return this._batteryLevel;
+    }
+    /**
+     * @readonly
+     * @property {number} rssi Signal strength of the hub
+     */
+    get rssi() {
+        return this._rssi;
+    }
+    /**
+     * Connect to the Hub.
+     * @method Hub#connect
+     * @returns {Promise} Resolved upon successful connect.
+     */
+    connect() {
+        return new Promise(async (connectResolve, connectReject) => {
+            if (this._bleDevice.connecting) {
+                return connectReject("Already connecting");
+            }
+            else if (this._bleDevice.connected) {
+                return connectReject("Already connected");
+            }
+            await this._bleDevice.connect();
+            return connectResolve();
+        });
+    }
+    /**
+     * Disconnect the Hub.
+     * @method Hub#disconnect
+     * @returns {Promise} Resolved upon successful disconnect.
+     */
+    disconnect() {
+        return this._bleDevice.disconnect();
+    }
+    getDeviceAtPort(portName) {
+        const portId = this._portMap[portName];
+        if (portId !== undefined) {
+            return this._attachedDevices[portId];
+        }
+        else {
+            return undefined;
+        }
+    }
+    waitForDeviceAtPort(portName) {
+        return new Promise((resolve) => {
+            const existingDevice = this.getDeviceAtPort(portName);
+            if (existingDevice) {
+                return resolve(existingDevice);
+            }
+            this._attachCallbacks.push((device) => {
+                if (device.portName === portName) {
+                    resolve(device);
+                    return true;
+                }
+                else {
+                    return false;
+                }
+            });
+        });
+    }
+    getDevices() {
+        return Object.values(this._attachedDevices);
+    }
+    getDevicesByType(deviceType) {
+        return this.getDevices().filter((device) => device.type === deviceType);
+    }
+    waitForDeviceByType(deviceType) {
+        return new Promise((resolve) => {
+            const existingDevices = this.getDevicesByType(deviceType);
+            if (existingDevices.length >= 1) {
+                return resolve(existingDevices[0]);
+            }
+            this._attachCallbacks.push((device) => {
+                if (device.type === deviceType) {
+                    resolve(device);
+                    return true;
+                }
+                else {
+                    return false;
+                }
+            });
+        });
+    }
+    getPortNameForPortId(portId) {
+        for (const port of Object.keys(this._portMap)) {
+            if (this._portMap[port] === portId) {
+                return port;
+            }
+        }
+        return;
+    }
+    isPortVirtual(portId) {
+        return (this._virtualPorts.indexOf(portId) > -1);
+    }
+    /**
+     * Sleep a given amount of time.
+     *
+     * This is a helper method to make it easier to add delays into a chain of commands.
+     * @method Hub#sleep
+     * @param {number} delay How long to sleep (in milliseconds).
+     * @returns {Promise} Resolved after the delay is finished.
+     */
+    sleep(delay) {
+        return new Promise((resolve) => {
+            global.setTimeout(resolve, delay);
+        });
+    }
+    /**
+     * Wait until a given list of concurrently running commands are complete.
+     *
+     * This is a helper method to make it easier to wait for concurrent commands to complete.
+     * @method Hub#wait
+     * @param {Array<Promise<any>>} commands Array of executing commands.
+     * @returns {Promise} Resolved after the commands are finished.
+     */
+    wait(commands) {
+        return Promise.all(commands);
+    }
+    send(message, uuid, callback) {
+        if (callback) {
+            callback();
+        }
+    }
+    subscribe(portId, deviceType, mode) {
+        // NK Do nothing here
+    }
+    unsubscribe(portId, deviceType, mode) {
+        // NK Do nothing here
+    }
+    _attachDevice(device) {
+        this._attachedDevices[device.portId] = device;
+        /**
+         * Emits when a device is attached to the Hub.
+         * @event Hub#attach
+         * @param {Device} device
+         */
+        this.emit("attach", device);
+        debug(`Attached device type ${device.type} (${Consts.DeviceTypeNames[device.type]}) on port ${device.portName} (${device.portId})`);
+        let i = this._attachCallbacks.length;
+        while (i--) {
+            const callback = this._attachCallbacks[i];
+            if (callback(device)) {
+                this._attachCallbacks.splice(i, 1);
+            }
+        }
+    }
+    _detachDevice(device) {
+        delete this._attachedDevices[device.portId];
+        /**
+         * Emits when a device is detached from the Hub.
+         * @event Hub#attach
+         * @param {Device} device
+         */
+        this.emit("detach", device);
+        debug(`Detached device type ${device.type} (${Consts.DeviceTypeNames[device.type]}) on port ${device.portName} (${device.portId})`);
+    }
+    _createDevice(deviceType, portId) {
+        let constructor;
+        // NK TODO: This needs to go in a better place
+        const deviceConstructors = {
+            [Consts.DeviceType.LIGHT]: light_1.Light,
+            [Consts.DeviceType.TRAIN_MOTOR]: trainmotor_1.TrainMotor,
+            [Consts.DeviceType.SIMPLE_MEDIUM_LINEAR_MOTOR]: simplemediumlinearmotor_1.SimpleMediumLinearMotor,
+            [Consts.DeviceType.MOVE_HUB_MEDIUM_LINEAR_MOTOR]: movehubmediumlinearmotor_1.MoveHubMediumLinearMotor,
+            [Consts.DeviceType.MOTION_SENSOR]: motionsensor_1.MotionSensor,
+            [Consts.DeviceType.TILT_SENSOR]: tiltsensor_1.TiltSensor,
+            [Consts.DeviceType.MOVE_HUB_TILT_SENSOR]: movehubtiltsensor_1.MoveHubTiltSensor,
+            [Consts.DeviceType.PIEZO_BUZZER]: piezobuzzer_1.PiezoBuzzer,
+            [Consts.DeviceType.TECHNIC_COLOR_SENSOR]: techniccolorsensor_1.TechnicColorSensor,
+            [Consts.DeviceType.TECHNIC_DISTANCE_SENSOR]: technicdistancesensor_1.TechnicDistanceSensor,
+            [Consts.DeviceType.TECHNIC_FORCE_SENSOR]: technicforcesensor_1.TechnicForceSensor,
+            [Consts.DeviceType.TECHNIC_MEDIUM_HUB_TILT_SENSOR]: technicmediumhubtiltsensor_1.TechnicMediumHubTiltSensor,
+            [Consts.DeviceType.TECHNIC_MEDIUM_HUB_GYRO_SENSOR]: technicmediumhubgyrosensor_1.TechnicMediumHubGyroSensor,
+            [Consts.DeviceType.TECHNIC_MEDIUM_HUB_ACCELEROMETER]: technicmediumhubaccelerometersensor_1.TechnicMediumHubAccelerometerSensor,
+            [Consts.DeviceType.MEDIUM_LINEAR_MOTOR]: mediumlinearmotor_1.MediumLinearMotor,
+            [Consts.DeviceType.TECHNIC_MEDIUM_ANGULAR_MOTOR]: technicmediumangularmotor_1.TechnicMediumAngularMotor,
+            [Consts.DeviceType.TECHNIC_LARGE_ANGULAR_MOTOR]: techniclargeangularmotor_1.TechnicLargeAngularMotor,
+            [Consts.DeviceType.TECHNIC_LARGE_LINEAR_MOTOR]: techniclargelinearmotor_1.TechnicLargeLinearMotor,
+            [Consts.DeviceType.TECHNIC_XLARGE_LINEAR_MOTOR]: technicxlargelinearmotor_1.TechnicXLargeLinearMotor,
+            [Consts.DeviceType.COLOR_DISTANCE_SENSOR]: colordistancesensor_1.ColorDistanceSensor,
+            [Consts.DeviceType.VOLTAGE_SENSOR]: voltagesensor_1.VoltageSensor,
+            [Consts.DeviceType.CURRENT_SENSOR]: currentsensor_1.CurrentSensor,
+            [Consts.DeviceType.REMOTE_CONTROL_BUTTON]: remotecontrolbutton_1.RemoteControlButton,
+            [Consts.DeviceType.HUB_LED]: hubled_1.HubLED,
+            [Consts.DeviceType.DUPLO_TRAIN_BASE_COLOR_SENSOR]: duplotrainbasecolorsensor_1.DuploTrainBaseColorSensor,
+            [Consts.DeviceType.DUPLO_TRAIN_BASE_MOTOR]: duplotrainbasemotor_1.DuploTrainBaseMotor,
+            [Consts.DeviceType.DUPLO_TRAIN_BASE_SPEAKER]: duplotrainbasespeaker_1.DuploTrainBaseSpeaker,
+            [Consts.DeviceType.DUPLO_TRAIN_BASE_SPEEDOMETER]: duplotrainbasespeedometer_1.DuploTrainBaseSpeedometer
+        };
+        constructor = deviceConstructors[deviceType];
+        if (constructor) {
+            return new constructor(this, portId);
+        }
+        else {
+            return new device_1.Device(this, portId, undefined, deviceType);
+        }
+    }
+    _getDeviceByPortId(portId) {
+        return this._attachedDevices[portId];
+    }
+}
+exports.BaseHub = BaseHub;
+//# sourceMappingURL=basehub.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/hubs_duplotrainbase.js.html b/docs/hubs_duplotrainbase.js.html new file mode 100644 index 0000000..7d4c71b --- /dev/null +++ b/docs/hubs_duplotrainbase.js.html @@ -0,0 +1,263 @@ + + + + + + + node-poweredup Source: hubs/duplotrainbase.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: hubs/duplotrainbase.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const lpf2hub_1 = require("./lpf2hub");
+const Consts = __importStar(require("../consts"));
+const Debug = require("debug");
+const debug = Debug("duplotrainbase");
+/**
+ * The DuploTrainBase is emitted if the discovered device is a Duplo Train Base.
+ * @class DuploTrainBase
+ * @extends LPF2Hub
+ * @extends BaseHub
+ */
+class DuploTrainBase extends lpf2hub_1.LPF2Hub {
+    static IsDuploTrainBase(peripheral) {
+        return (peripheral.advertisement &&
+            peripheral.advertisement.serviceUuids &&
+            peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
+            peripheral.advertisement.manufacturerData &&
+            peripheral.advertisement.manufacturerData.length > 3 &&
+            peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.DUPLO_TRAIN_BASE_ID);
+    }
+    constructor(device) {
+        super(device, exports.PortMap, Consts.HubType.DUPLO_TRAIN_BASE);
+        debug("Discovered Duplo Train Base");
+    }
+    connect() {
+        return new Promise(async (resolve, reject) => {
+            debug("Connecting to Duplo Train Base");
+            await super.connect();
+            debug("Connect completed");
+            return resolve();
+        });
+    }
+}
+exports.DuploTrainBase = DuploTrainBase;
+exports.PortMap = {
+    "MOTOR": 0,
+    "COLOR": 18,
+    "SPEEDOMETER": 19
+};
+//# sourceMappingURL=duplotrainbase.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/hubs_hub.js.html b/docs/hubs_hub.js.html new file mode 100644 index 0000000..bf00f19 --- /dev/null +++ b/docs/hubs_hub.js.html @@ -0,0 +1,275 @@ + + + + + + + node-poweredup Source: hubs/hub.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: hubs/hub.js

+ +
+
+
"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const compare_versions_1 = __importDefault(require("compare-versions"));
+const lpf2hub_1 = require("./lpf2hub");
+const Consts = __importStar(require("../consts"));
+const Debug = require("debug");
+const debug = Debug("hub");
+/**
+ * The Hub is emitted if the discovered device is a Hub.
+ * @class Hub
+ * @extends LPF2Hub
+ * @extends BaseHub
+ */
+class Hub extends lpf2hub_1.LPF2Hub {
+    constructor(device) {
+        super(device, exports.PortMap, Consts.HubType.HUB);
+        this._currentPort = 0x3b;
+        debug("Discovered Powered UP Hub");
+    }
+    static IsHub(peripheral) {
+        return (peripheral.advertisement &&
+            peripheral.advertisement.serviceUuids &&
+            peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
+            peripheral.advertisement.manufacturerData &&
+            peripheral.advertisement.manufacturerData.length > 3 &&
+            peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.HUB_ID);
+    }
+    connect() {
+        return new Promise(async (resolve, reject) => {
+            debug("Connecting to Powered UP Hub");
+            await super.connect();
+            debug("Connect completed");
+            return resolve();
+        });
+    }
+    _checkFirmware(version) {
+        if (compare_versions_1.default("1.1.00.0004", version) === 1) {
+            throw new Error(`Your Powered Up Hub's (${this.name}) firmware is out of date and unsupported by this library. Please update it via the official Powered Up app.`);
+        }
+    }
+}
+exports.Hub = Hub;
+exports.PortMap = {
+    "A": 0,
+    "B": 1,
+    "HUB_LED": 50,
+    "CURRENT_SENSOR": 59,
+    "VOLTAGE_SENSOR": 60
+};
+//# sourceMappingURL=hub.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/hubs_lpf2hub.js.html b/docs/hubs_lpf2hub.js.html new file mode 100644 index 0000000..13d46e8 --- /dev/null +++ b/docs/hubs_lpf2hub.js.html @@ -0,0 +1,552 @@ + + + + + + + node-poweredup Source: hubs/lpf2hub.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: hubs/lpf2hub.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const basehub_1 = require("./basehub");
+const Consts = __importStar(require("../consts"));
+const utils_1 = require("../utils");
+const Debug = require("debug");
+const debug = Debug("lpf2hub");
+const modeInfoDebug = Debug("lpf2hubmodeinfo");
+/**
+ * @class LPF2Hub
+ * @extends BaseHub
+ */
+class LPF2Hub extends basehub_1.BaseHub {
+    constructor() {
+        super(...arguments);
+        this._messageBuffer = Buffer.alloc(0);
+        this._propertyRequestCallbacks = {};
+    }
+    connect() {
+        return new Promise(async (resolve, reject) => {
+            debug("LPF2Hub connecting");
+            await super.connect();
+            await this._bleDevice.discoverCharacteristicsForService(Consts.BLEService.LPF2_HUB);
+            this._bleDevice.subscribeToCharacteristic(Consts.BLECharacteristic.LPF2_ALL, this._parseMessage.bind(this));
+            await this.sleep(500);
+            this._requestHubPropertyReports(0x02); // Activate button reports
+            await this._requestHubPropertyValue(0x03); // Request firmware version
+            await this._requestHubPropertyValue(0x04); // Request hardware version
+            this._requestHubPropertyReports(0x05); // Activate RSSI updates
+            this._requestHubPropertyReports(0x06); // Activate battery level reports
+            await this._requestHubPropertyValue(0x0d); // Request primary MAC address
+            this.emit("connect");
+            debug("LPF2Hub connected");
+            resolve();
+        });
+    }
+    /**
+     * Shutdown the Hub.
+     * @method LPF2Hub#shutdown
+     * @returns {Promise} Resolved upon successful disconnect.
+     */
+    shutdown() {
+        return new Promise((resolve, reject) => {
+            this.send(Buffer.from([0x02, 0x01]), Consts.BLECharacteristic.LPF2_ALL, () => {
+                return resolve();
+            });
+        });
+    }
+    /**
+     * Set the name of the Hub.
+     * @method LPF2Hub#setName
+     * @param {string} name New name of the hub (14 characters or less, ASCII only).
+     * @returns {Promise} Resolved upon successful issuance of command.
+     */
+    setName(name) {
+        if (name.length > 14) {
+            throw new Error("Name must be 14 characters or less");
+        }
+        return new Promise((resolve, reject) => {
+            let data = Buffer.from([0x01, 0x01, 0x01]);
+            data = Buffer.concat([data, Buffer.from(name, "ascii")]);
+            // Send this twice, as sometimes the first time doesn't take
+            this.send(data, Consts.BLECharacteristic.LPF2_ALL);
+            this.send(data, Consts.BLECharacteristic.LPF2_ALL);
+            this._name = name;
+            return resolve();
+        });
+    }
+    send(message, uuid, callback) {
+        message = Buffer.concat([Buffer.alloc(2), message]);
+        message[0] = message.length;
+        debug("Sent Message (LPF2_ALL)", message);
+        this._bleDevice.writeToCharacteristic(uuid, message, callback);
+    }
+    subscribe(portId, deviceType, mode) {
+        this.send(Buffer.from([0x41, portId, mode, 0x01, 0x00, 0x00, 0x00, 0x01]), Consts.BLECharacteristic.LPF2_ALL);
+    }
+    unsubscribe(portId, mode) {
+        this.send(Buffer.from([0x41, portId, mode, 0x01, 0x00, 0x00, 0x00, 0x00]), Consts.BLECharacteristic.LPF2_ALL);
+    }
+    createVirtualPort(firstPortName, secondPortName) {
+        const firstDevice = this.getDeviceAtPort(firstPortName);
+        if (!firstDevice) {
+            throw new Error(`Port ${firstPortName} does not have an attached device`);
+        }
+        const secondDevice = this.getDeviceAtPort(secondPortName);
+        if (!secondDevice) {
+            throw new Error(`Port ${secondPortName} does not have an attached device`);
+        }
+        if (firstDevice.type !== secondDevice.type) {
+            throw new Error(`Both devices must be of the same type to create a virtual port`);
+        }
+        this.send(Buffer.from([0x61, 0x01, firstDevice.portId, secondDevice.portId]), Consts.BLECharacteristic.LPF2_ALL);
+    }
+    _checkFirmware(version) {
+        return;
+    }
+    _parseMessage(data) {
+        if (data) {
+            this._messageBuffer = Buffer.concat([this._messageBuffer, data]);
+        }
+        if (this._messageBuffer.length <= 0) {
+            return;
+        }
+        const len = this._messageBuffer[0];
+        if (len >= this._messageBuffer.length) {
+            const message = this._messageBuffer.slice(0, len);
+            this._messageBuffer = this._messageBuffer.slice(len);
+            debug("Received Message (LPF2_ALL)", message);
+            switch (message[2]) {
+                case 0x01: {
+                    const property = message[3];
+                    const callback = this._propertyRequestCallbacks[property];
+                    if (callback) {
+                        callback(message);
+                    }
+                    else {
+                        this._parseHubPropertyResponse(message);
+                    }
+                    delete this._propertyRequestCallbacks[property];
+                    break;
+                }
+                case 0x04: {
+                    this._parsePortMessage(message);
+                    break;
+                }
+                case 0x43: {
+                    this._parsePortInformationResponse(message);
+                    break;
+                }
+                case 0x44: {
+                    this._parseModeInformationResponse(message);
+                    break;
+                }
+                case 0x45: {
+                    this._parseSensorMessage(message);
+                    break;
+                }
+                case 0x82: {
+                    this._parsePortAction(message);
+                    break;
+                }
+            }
+            if (this._messageBuffer.length > 0) {
+                this._parseMessage();
+            }
+        }
+    }
+    _requestHubPropertyValue(property) {
+        return new Promise((resolve) => {
+            this._propertyRequestCallbacks[property] = (message) => {
+                this._parseHubPropertyResponse(message);
+                return resolve();
+            };
+            this.send(Buffer.from([0x01, property, 0x05]), Consts.BLECharacteristic.LPF2_ALL);
+        });
+    }
+    _requestHubPropertyReports(property) {
+        this.send(Buffer.from([0x01, property, 0x02]), Consts.BLECharacteristic.LPF2_ALL);
+    }
+    _parseHubPropertyResponse(message) {
+        // Button press reports
+        if (message[3] === 0x02) {
+            if (message[5] === 1) {
+                /**
+                 * Emits when a button is pressed.
+                 * @event LPF2Hub#button
+                 * @param {string} button
+                 * @param {ButtonState} state
+                 */
+                this.emit("button", { event: Consts.ButtonState.PRESSED });
+                return;
+            }
+            else if (message[5] === 0) {
+                this.emit("button", { event: Consts.ButtonState.RELEASED });
+                return;
+            }
+            // Firmware version
+        }
+        else if (message[3] === 0x03) {
+            this._firmwareVersion = utils_1.decodeVersion(message.readInt32LE(5));
+            this._checkFirmware(this._firmwareVersion);
+            // Hardware version
+        }
+        else if (message[3] === 0x04) {
+            this._hardwareVersion = utils_1.decodeVersion(message.readInt32LE(5));
+            // RSSI update
+        }
+        else if (message[3] === 0x05) {
+            const rssi = message.readInt8(5);
+            if (rssi !== 0) {
+                this._rssi = rssi;
+                this.emit("rssi", { rssi: this._rssi });
+            }
+            // primary MAC Address
+        }
+        else if (message[3] === 0x0d) {
+            this._primaryMACAddress = utils_1.decodeMACAddress(message.slice(5));
+            // Battery level reports
+        }
+        else if (message[3] === 0x06) {
+            const batteryLevel = message[5];
+            if (batteryLevel !== this._batteryLevel) {
+                this._batteryLevel = batteryLevel;
+                this.emit("batteryLevel", { batteryLevel });
+            }
+        }
+    }
+    _parsePortMessage(message) {
+        const portId = message[3];
+        const event = message[4];
+        const deviceType = event ? message.readUInt16LE(5) : 0;
+        // Handle device attachments
+        if (event === 0x01) {
+            if (modeInfoDebug.enabled) {
+                const deviceTypeName = Consts.DeviceTypeNames[message[5]] || "Unknown";
+                modeInfoDebug(`Port ${utils_1.toHex(portId)}, type ${utils_1.toHex(deviceType, 4)} (${deviceTypeName})`);
+                const hwVersion = utils_1.decodeVersion(message.readInt32LE(7));
+                const swVersion = utils_1.decodeVersion(message.readInt32LE(11));
+                modeInfoDebug(`Port ${utils_1.toHex(portId)}, hardware version ${hwVersion}, software version ${swVersion}`);
+                this._sendPortInformationRequest(portId);
+            }
+            const device = this._createDevice(deviceType, portId);
+            this._attachDevice(device);
+            // Handle device detachments
+        }
+        else if (event === 0x00) {
+            const device = this._getDeviceByPortId(portId);
+            if (device) {
+                this._detachDevice(device);
+                if (this.isPortVirtual(portId)) {
+                    const portName = this.getPortNameForPortId(portId);
+                    if (portName) {
+                        delete this._portMap[portName];
+                    }
+                    this._virtualPorts = this._virtualPorts.filter((virtualPortId) => virtualPortId !== portId);
+                }
+            }
+            // Handle virtual port creation
+        }
+        else if (event === 0x02) {
+            const firstPortName = this.getPortNameForPortId(message[7]);
+            const secondPortName = this.getPortNameForPortId(message[8]);
+            // @ts-ignore NK These should never be undefined
+            const virtualPortName = firstPortName + secondPortName;
+            const virtualPortId = message[3];
+            this._portMap[virtualPortName] = virtualPortId;
+            this._virtualPorts.push(virtualPortId);
+            const device = this._createDevice(deviceType, virtualPortId);
+            this._attachDevice(device);
+        }
+    }
+    _sendPortInformationRequest(port) {
+        this.send(Buffer.from([0x21, port, 0x01]), Consts.BLECharacteristic.LPF2_ALL);
+        this.send(Buffer.from([0x21, port, 0x02]), Consts.BLECharacteristic.LPF2_ALL); // Mode combinations
+    }
+    _parsePortInformationResponse(message) {
+        const port = message[3];
+        if (message[4] === 2) {
+            const modeCombinationMasks = [];
+            for (let i = 5; i < message.length; i += 2) {
+                modeCombinationMasks.push(message.readUInt16LE(i));
+            }
+            modeInfoDebug(`Port ${utils_1.toHex(port)}, mode combinations [${modeCombinationMasks.map((c) => utils_1.toBin(c, 0)).join(", ")}]`);
+            return;
+        }
+        const count = message[6];
+        const input = utils_1.toBin(message.readUInt16LE(7), count);
+        const output = utils_1.toBin(message.readUInt16LE(9), count);
+        modeInfoDebug(`Port ${utils_1.toHex(port)}, total modes ${count}, input modes ${input}, output modes ${output}`);
+        for (let i = 0; i < count; i++) {
+            this._sendModeInformationRequest(port, i, 0x00); // Mode Name
+            this._sendModeInformationRequest(port, i, 0x01); // RAW Range
+            this._sendModeInformationRequest(port, i, 0x02); // PCT Range
+            this._sendModeInformationRequest(port, i, 0x03); // SI Range
+            this._sendModeInformationRequest(port, i, 0x04); // SI Symbol
+            this._sendModeInformationRequest(port, i, 0x80); // Value Format
+        }
+    }
+    _sendModeInformationRequest(port, mode, type) {
+        this.send(Buffer.from([0x22, port, mode, type]), Consts.BLECharacteristic.LPF2_ALL);
+    }
+    _parseModeInformationResponse(message) {
+        const port = utils_1.toHex(message[3]);
+        const mode = message[4];
+        const type = message[5];
+        switch (type) {
+            case 0x00: // Mode Name
+                modeInfoDebug(`Port ${port}, mode ${mode}, name ${message.slice(6, message.length).toString()}`);
+                break;
+            case 0x01: // RAW Range
+                modeInfoDebug(`Port ${port}, mode ${mode}, RAW min ${message.readFloatLE(6)}, max ${message.readFloatLE(10)}`);
+                break;
+            case 0x02: // PCT Range
+                modeInfoDebug(`Port ${port}, mode ${mode}, PCT min ${message.readFloatLE(6)}, max ${message.readFloatLE(10)}`);
+                break;
+            case 0x03: // SI Range
+                modeInfoDebug(`Port ${port}, mode ${mode}, SI min ${message.readFloatLE(6)}, max ${message.readFloatLE(10)}`);
+                break;
+            case 0x04: // SI Symbol
+                modeInfoDebug(`Port ${port}, mode ${mode}, SI symbol ${message.slice(6, message.length).toString()}`);
+                break;
+            case 0x80: // Value Format
+                const numValues = message[6];
+                const dataType = ["8bit", "16bit", "32bit", "float"][message[7]];
+                const totalFigures = message[8];
+                const decimals = message[9];
+                modeInfoDebug(`Port ${port}, mode ${mode}, Value ${numValues} x ${dataType}, Decimal format ${totalFigures}.${decimals}`);
+        }
+    }
+    _parsePortAction(message) {
+        const portId = message[3];
+        const device = this._getDeviceByPortId(portId);
+        if (device) {
+            const finished = (message[4] === 0x0a);
+            if (finished) {
+                device.finish();
+            }
+        }
+    }
+    _parseSensorMessage(message) {
+        const portId = message[3];
+        const device = this._getDeviceByPortId(portId);
+        if (device) {
+            device.receive(message);
+        }
+    }
+}
+exports.LPF2Hub = LPF2Hub;
+//# sourceMappingURL=lpf2hub.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/hubs_movehub.js.html b/docs/hubs_movehub.js.html new file mode 100644 index 0000000..8e2433e --- /dev/null +++ b/docs/hubs_movehub.js.html @@ -0,0 +1,277 @@ + + + + + + + node-poweredup Source: hubs/movehub.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: hubs/movehub.js

+ +
+
+
"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const compare_versions_1 = __importDefault(require("compare-versions"));
+const lpf2hub_1 = require("./lpf2hub");
+const Consts = __importStar(require("../consts"));
+const Debug = require("debug");
+const debug = Debug("movehub");
+/**
+ * The MoveHub is emitted if the discovered device is a Move Hub.
+ * @class MoveHub
+ * @extends LPF2Hub
+ * @extends BaseHub
+ */
+class MoveHub extends lpf2hub_1.LPF2Hub {
+    static IsMoveHub(peripheral) {
+        return (peripheral.advertisement &&
+            peripheral.advertisement.serviceUuids &&
+            peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
+            peripheral.advertisement.manufacturerData &&
+            peripheral.advertisement.manufacturerData.length > 3 &&
+            peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.MOVE_HUB_ID);
+    }
+    constructor(device) {
+        super(device, exports.PortMap, Consts.HubType.MOVE_HUB);
+        debug("Discovered Move Hub");
+    }
+    connect() {
+        return new Promise(async (resolve, reject) => {
+            debug("Connecting to Move Hub");
+            await super.connect();
+            debug("Connect completed");
+            return resolve();
+        });
+    }
+    _checkFirmware(version) {
+        if (compare_versions_1.default("2.0.00.0017", version) === 1) {
+            throw new Error(`Your Move Hub's (${this.name}) firmware is out of date and unsupported by this library. Please update it via the official Powered Up app.`);
+        }
+    }
+}
+exports.MoveHub = MoveHub;
+exports.PortMap = {
+    "A": 0,
+    "B": 1,
+    "C": 2,
+    "D": 3,
+    "HUB_LED": 50,
+    "TILT_SENSOR": 58,
+    "CURRENT_SENSOR": 59,
+    "VOLTAGE_SENSOR": 60
+};
+//# sourceMappingURL=movehub.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/hubs_remotecontrol.js.html b/docs/hubs_remotecontrol.js.html new file mode 100644 index 0000000..e46113a --- /dev/null +++ b/docs/hubs_remotecontrol.js.html @@ -0,0 +1,265 @@ + + + + + + + node-poweredup Source: hubs/remotecontrol.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: hubs/remotecontrol.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const lpf2hub_1 = require("./lpf2hub");
+const Consts = __importStar(require("../consts"));
+const Debug = require("debug");
+const debug = Debug("remotecontrol");
+/**
+ * The RemoteControl is emitted if the discovered device is a Remote Control.
+ * @class RemoteControl
+ * @extends LPF2Hub
+ * @extends BaseHub
+ */
+class RemoteControl extends lpf2hub_1.LPF2Hub {
+    static IsRemoteControl(peripheral) {
+        return (peripheral.advertisement &&
+            peripheral.advertisement.serviceUuids &&
+            peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
+            peripheral.advertisement.manufacturerData &&
+            peripheral.advertisement.manufacturerData.length > 3 &&
+            peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.REMOTE_CONTROL_ID);
+    }
+    constructor(device) {
+        super(device, exports.PortMap, Consts.HubType.REMOTE_CONTROL);
+        debug("Discovered Powered UP Remote");
+    }
+    connect() {
+        return new Promise(async (resolve, reject) => {
+            debug("Connecting to Powered UP Remote");
+            await super.connect();
+            debug("Connect completed");
+            return resolve();
+        });
+    }
+}
+exports.RemoteControl = RemoteControl;
+exports.PortMap = {
+    "LEFT": 0,
+    "RIGHT": 1,
+    "HUB_LED": 52,
+    "VOLTAGE_SENSOR": 59,
+    "REMOTE_CONTROL_RSSI": 60
+};
+//# sourceMappingURL=remotecontrol.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/hubs_technicmediumhub.js.html b/docs/hubs_technicmediumhub.js.html new file mode 100644 index 0000000..b5791f7 --- /dev/null +++ b/docs/hubs_technicmediumhub.js.html @@ -0,0 +1,271 @@ + + + + + + + node-poweredup Source: hubs/technicmediumhub.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: hubs/technicmediumhub.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const lpf2hub_1 = require("./lpf2hub");
+const Consts = __importStar(require("../consts"));
+const Debug = require("debug");
+const debug = Debug("technicmediumhub");
+/**
+ * The TechnicMediumHub is emitted if the discovered device is a Technic Medium Hub.
+ * @class TechnicMediumHub
+ * @extends LPF2Hub
+ * @extends BaseHub
+ */
+class TechnicMediumHub extends lpf2hub_1.LPF2Hub {
+    static IsTechnicMediumHub(peripheral) {
+        return (peripheral.advertisement &&
+            peripheral.advertisement.serviceUuids &&
+            peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
+            peripheral.advertisement.manufacturerData &&
+            peripheral.advertisement.manufacturerData.length > 3 &&
+            peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.TECHNIC_MEDIUM_HUB);
+    }
+    constructor(device) {
+        super(device, exports.PortMap, Consts.HubType.TECHNIC_MEDIUM_HUB);
+        debug("Discovered Control+ Hub");
+    }
+    connect() {
+        return new Promise(async (resolve, reject) => {
+            debug("Connecting to Control+ Hub");
+            await super.connect();
+            this.send(Buffer.from([0x41, 0x3d, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x01]), Consts.BLECharacteristic.LPF2_ALL); // Temperature
+            debug("Connect completed");
+            return resolve();
+        });
+    }
+}
+exports.TechnicMediumHub = TechnicMediumHub;
+exports.PortMap = {
+    "A": 0,
+    "B": 1,
+    "C": 2,
+    "D": 3,
+    "HUB_LED": 50,
+    "CURRENT_SENSOR": 59,
+    "VOLTAGE_SENSOR": 60,
+    "ACCELEROMETER": 97,
+    "GYRO_SENSOR": 98,
+    "TILT_SENSOR": 99
+};
+//# sourceMappingURL=technicmediumhub.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/hubs_wedo2smarthub.js.html b/docs/hubs_wedo2smarthub.js.html new file mode 100644 index 0000000..724ce5e --- /dev/null +++ b/docs/hubs_wedo2smarthub.js.html @@ -0,0 +1,417 @@ + + + + + + + node-poweredup Source: hubs/wedo2smarthub.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: hubs/wedo2smarthub.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const basehub_1 = require("./basehub");
+const Consts = __importStar(require("../consts"));
+const utils_1 = require("../utils");
+const Debug = require("debug");
+const debug = Debug("wedo2smarthub");
+/**
+ * The WeDo2SmartHub is emitted if the discovered device is a WeDo 2.0 Smart Hub.
+ * @class WeDo2SmartHub
+ * @extends BaseHub
+ */
+class WeDo2SmartHub extends basehub_1.BaseHub {
+    constructor(device) {
+        super(device, exports.PortMap, Consts.HubType.WEDO2_SMART_HUB);
+        this._lastTiltX = 0;
+        this._lastTiltY = 0;
+        debug("Discovered WeDo 2.0 Smart Hub");
+    }
+    static IsWeDo2SmartHub(peripheral) {
+        return (peripheral.advertisement &&
+            peripheral.advertisement.serviceUuids &&
+            peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.WEDO2_SMART_HUB.replace(/-/g, "")) >= 0);
+    }
+    connect() {
+        return new Promise(async (resolve, reject) => {
+            debug("Connecting to WeDo 2.0 Smart Hub");
+            await super.connect();
+            await this._bleDevice.discoverCharacteristicsForService(Consts.BLEService.WEDO2_SMART_HUB);
+            await this._bleDevice.discoverCharacteristicsForService(Consts.BLEService.WEDO2_SMART_HUB_2);
+            if (!utils_1.isWebBluetooth) {
+                await this._bleDevice.discoverCharacteristicsForService(Consts.BLEService.WEDO2_SMART_HUB_3);
+                await this._bleDevice.discoverCharacteristicsForService(Consts.BLEService.WEDO2_SMART_HUB_4);
+                await this._bleDevice.discoverCharacteristicsForService(Consts.BLEService.WEDO2_SMART_HUB_5);
+            }
+            else {
+                await this._bleDevice.discoverCharacteristicsForService("battery_service");
+                await this._bleDevice.discoverCharacteristicsForService("device_information");
+            }
+            debug("Connect completed");
+            this.emit("connect");
+            resolve();
+            this._bleDevice.subscribeToCharacteristic(Consts.BLECharacteristic.WEDO2_PORT_TYPE, this._parsePortMessage.bind(this));
+            this._bleDevice.subscribeToCharacteristic(Consts.BLECharacteristic.WEDO2_SENSOR_VALUE, this._parseSensorMessage.bind(this));
+            this._bleDevice.subscribeToCharacteristic(Consts.BLECharacteristic.WEDO2_BUTTON, this._parseSensorMessage.bind(this));
+            if (!utils_1.isWebBluetooth) {
+                this._bleDevice.subscribeToCharacteristic(Consts.BLECharacteristic.WEDO2_BATTERY, this._parseBatteryMessage.bind(this));
+                this._bleDevice.readFromCharacteristic(Consts.BLECharacteristic.WEDO2_BATTERY, (err, data) => {
+                    if (data) {
+                        this._parseBatteryMessage(data);
+                    }
+                });
+            }
+            else {
+                this._bleDevice.readFromCharacteristic("00002a19-0000-1000-8000-00805f9b34fb", (err, data) => {
+                    if (data) {
+                        this._parseBatteryMessage(data);
+                    }
+                });
+                this._bleDevice.subscribeToCharacteristic("00002a19-0000-1000-8000-00805f9b34fb", this._parseHighCurrentAlert.bind(this));
+            }
+            this._bleDevice.subscribeToCharacteristic(Consts.BLECharacteristic.WEDO2_HIGH_CURRENT_ALERT, this._parseHighCurrentAlert.bind(this));
+            if (!utils_1.isWebBluetooth) {
+                this._bleDevice.readFromCharacteristic(Consts.BLECharacteristic.WEDO2_FIRMWARE_REVISION, (err, data) => {
+                    if (data) {
+                        this._parseFirmwareRevisionString(data);
+                    }
+                });
+            }
+            else {
+                this._bleDevice.readFromCharacteristic("00002a26-0000-1000-8000-00805f9b34fb", (err, data) => {
+                    if (data) {
+                        this._parseFirmwareRevisionString(data);
+                    }
+                });
+            }
+        });
+    }
+    /**
+     * Shutdown the Hub.
+     * @method WeDo2SmartHub#shutdown
+     * @returns {Promise} Resolved upon successful disconnect.
+     */
+    shutdown() {
+        return new Promise((resolve, reject) => {
+            this.send(Buffer.from([0x00]), Consts.BLECharacteristic.WEDO2_DISCONNECT, () => {
+                return resolve();
+            });
+        });
+    }
+    /**
+     * Set the name of the Hub.
+     * @method WeDo2SmartHub#setName
+     * @param {string} name New name of the hub (14 characters or less, ASCII only).
+     * @returns {Promise} Resolved upon successful issuance of command.
+     */
+    setName(name) {
+        if (name.length > 14) {
+            throw new Error("Name must be 14 characters or less");
+        }
+        return new Promise((resolve, reject) => {
+            const data = Buffer.from(name, "ascii");
+            // Send this twice, as sometimes the first time doesn't take
+            this.send(data, Consts.BLECharacteristic.WEDO2_NAME_ID);
+            this.send(data, Consts.BLECharacteristic.WEDO2_NAME_ID);
+            this._name = name;
+            return resolve();
+        });
+    }
+    send(message, uuid, callback) {
+        if (debug.enabled) {
+            debug(`Sent Message (${this._getCharacteristicNameFromUUID(uuid)})`, message);
+        }
+        this._bleDevice.writeToCharacteristic(uuid, message, callback);
+    }
+    subscribe(portId, deviceType, mode) {
+        this.send(Buffer.from([0x01, 0x02, portId, deviceType, mode, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01]), Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE);
+    }
+    unsubscribe(portId, deviceType, mode) {
+        this.send(Buffer.from([0x01, 0x02, portId, deviceType, mode, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]), Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE);
+    }
+    _getCharacteristicNameFromUUID(uuid) {
+        const keys = Object.keys(Consts.BLECharacteristic);
+        for (let i = 0; i < keys.length; i++) {
+            const key = keys[i];
+            if (Consts.BLECharacteristic[key] === uuid) {
+                return key;
+            }
+        }
+        return "UNKNOWN";
+    }
+    _parseHighCurrentAlert(data) {
+        debug("Received Message (WEDO2_HIGH_CURRENT_ALERT)", data);
+    }
+    _parseBatteryMessage(data) {
+        debug("Received Message (WEDO2_BATTERY)", data);
+        const batteryLevel = data[0];
+        if (batteryLevel !== this._batteryLevel) {
+            this._batteryLevel = batteryLevel;
+            this.emit("batteryLevel", { batteryLevel });
+        }
+    }
+    _parseFirmwareRevisionString(data) {
+        debug("Received Message (WEDO2_FIRMWARE_REVISION)", data);
+        this._firmwareVersion = data.toString();
+    }
+    _parsePortMessage(data) {
+        debug("Received Message (WEDO2_PORT_TYPE)", data);
+        const portId = data[0];
+        const event = data[1];
+        const deviceType = event ? data[3] : 0;
+        if (event === 0x01) {
+            const device = this._createDevice(deviceType, portId);
+            this._attachDevice(device);
+        }
+        else if (event === 0x00) {
+            const device = this._getDeviceByPortId(portId);
+            if (device) {
+                this._detachDevice(device);
+            }
+        }
+    }
+    _parseSensorMessage(message) {
+        debug("Received Message (WEDO2_SENSOR_VALUE)", message);
+        if (message[0] === 0x01) {
+            /**
+             * Emits when a button is pressed.
+             * @event WeDo2SmartHub#button
+             * @param {string} button
+             * @param {ButtonState} state
+             */
+            this.emit("button", { event: Consts.ButtonState.PRESSED });
+            return;
+        }
+        else if (message[0] === 0x00) {
+            this.emit("button", { event: Consts.ButtonState.RELEASED });
+            return;
+        }
+        const portId = message[1];
+        const device = this._getDeviceByPortId(portId);
+        if (device) {
+            device.receive(message);
+        }
+    }
+}
+exports.WeDo2SmartHub = WeDo2SmartHub;
+exports.PortMap = {
+    "A": 1,
+    "B": 2,
+    "CURRENT_SENSOR": 3,
+    "VOLTAGE_SENSOR": 4,
+    "PIEZO_BUZZER": 5,
+    "HUB_LED": 6
+};
+//# sourceMappingURL=wedo2smarthub.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/index.html b/docs/index.html index 8df7b00..e99f5cd 100644 --- a/docs/index.html +++ b/docs/index.html @@ -33,21 +33,14 @@ - - @@ -290,17 +283,22 @@ const poweredUP = new PoweredUP.PoweredUP(); poweredUP.on("discover", async (hub) => { // Wait to discover a Hub console.log(`Discovered ${hub.name}!`); 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"); - await hub.sleep(3000); // Sleep for 3 seconds before starting while (true) { // Repeat indefinitely 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"); - 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 - console.log("Running motor A at speed -50 for 1 seconds"); - 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 + console.log("Running motor A at speed -50 for 1 second"); + 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 } }); @@ -360,7 +358,7 @@ console.log("Scanning for Hubs..."); Documentation generated by JSDoc 3.6.3 - on Tue Dec 3rd 2019 + on Fri Feb 7th 2020 using the DocStrap template. diff --git a/docs/poweredup-node.js.html b/docs/poweredup-node.js.html index 0bfb7ae..46a1b7d 100644 --- a/docs/poweredup-node.js.html +++ b/docs/poweredup-node.js.html @@ -33,14 +33,14 @@ @@ -86,13 +86,13 @@
"use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
-const boostmovehub_1 = require("./boostmovehub");
-const controlplushub_1 = require("./controlplushub");
-const duplotrainbase_1 = require("./duplotrainbase");
-const nobledevice_1 = require("./nobledevice");
-const puphub_1 = require("./puphub");
-const pupremote_1 = require("./pupremote");
-const wedo2smarthub_1 = require("./wedo2smarthub");
+const nobleabstraction_1 = require("./nobleabstraction");
+const duplotrainbase_1 = require("./hubs/duplotrainbase");
+const hub_1 = require("./hubs/hub");
+const movehub_1 = require("./hubs/movehub");
+const remotecontrol_1 = require("./hubs/remotecontrol");
+const technicmediumhub_1 = require("./hubs/technicmediumhub");
+const wedo2smarthub_1 = require("./hubs/wedo2smarthub");
 const events_1 = require("events");
 const Debug = require("debug");
 const debug = Debug("poweredup");
@@ -122,7 +122,6 @@ noble.on("stateChange", (state) => {
 class PoweredUP extends events_1.EventEmitter {
     constructor() {
         super();
-        this.autoSubscribe = true;
         this._connectedHubs = {};
         this._discoveryEventHandler = this._discoveryEventHandler.bind(this);
     }
@@ -156,60 +155,69 @@ class PoweredUP extends events_1.EventEmitter {
     }
     /**
      * Retrieve a list of Powered UP Hubs.
-     * @method PoweredUP#getConnectedHubs
-     * @returns {Hub[]}
+     * @method PoweredUP#getHubs
+     * @returns {BaseHub[]}
      */
-    getConnectedHubs() {
-        return Object.keys(this._connectedHubs).map((uuid) => this._connectedHubs[uuid]);
+    getHubs() {
+        return Object.values(this._connectedHubs);
     }
     /**
      * Retrieve a Powered UP Hub by UUID.
-     * @method PoweredUP#getConnectedHubByUUID
+     * @method PoweredUP#getHubByUUID
      * @param {string} uuid
-     * @returns {Hub | null}
+     * @returns {BaseHub | null}
      */
-    getConnectedHubByUUID(uuid) {
+    getHubByUUID(uuid) {
         return this._connectedHubs[uuid];
     }
     /**
      * Retrieve a Powered UP Hub by primary MAC address.
-     * @method PoweredUP#getConnectedHubByPrimaryMACAddress
+     * @method PoweredUP#getHubByPrimaryMACAddress
      * @param {string} address
-     * @returns {Hub}
+     * @returns {BaseHub}
      */
-    getConnectedHubByPrimaryMACAddress(address) {
-        return Object.keys(this._connectedHubs).map((uuid) => this._connectedHubs[uuid]).filter((hub) => hub.primaryMACAddress === address)[0];
+    getHubByPrimaryMACAddress(address) {
+        return Object.values(this._connectedHubs).filter((hub) => hub.primaryMACAddress === address)[0];
     }
     /**
      * Retrieve a list of Powered UP Hub by name.
-     * @method PoweredUP#getConnectedHubsByName
+     * @method PoweredUP#getHubsByName
      * @param {string} name
-     * @returns {Hub[]}
+     * @returns {BaseHub[]}
      */
-    getConnectedHubsByName(name) {
-        return Object.keys(this._connectedHubs).map((uuid) => this._connectedHubs[uuid]).filter((hub) => hub.name === name);
+    getHubsByName(name) {
+        return Object.values(this._connectedHubs).filter((hub) => hub.name === name);
+    }
+    /**
+     * Retrieve a list of Powered UP Hub by type.
+     * @method PoweredUP#getHubsByType
+     * @param {string} name
+     * @returns {BaseHub[]}
+     */
+    getHubsByType(hubType) {
+        return Object.values(this._connectedHubs).filter((hub) => hub.type === hubType);
     }
     async _discoveryEventHandler(peripheral) {
         peripheral.removeAllListeners();
-        const device = new nobledevice_1.NobleDevice(peripheral);
+        const device = new nobleabstraction_1.NobleDevice(peripheral);
         let hub;
         if (await wedo2smarthub_1.WeDo2SmartHub.IsWeDo2SmartHub(peripheral)) {
-            hub = new wedo2smarthub_1.WeDo2SmartHub(device, this.autoSubscribe);
+            hub = new wedo2smarthub_1.WeDo2SmartHub(device);
         }
-        else if (await boostmovehub_1.BoostMoveHub.IsBoostMoveHub(peripheral)) {
-            hub = new boostmovehub_1.BoostMoveHub(device, this.autoSubscribe);
+        else if (await movehub_1.MoveHub.IsMoveHub(peripheral)) {
+            hub = new movehub_1.MoveHub(device);
         }
-        else if (await puphub_1.PUPHub.IsPUPHub(peripheral)) {
-            hub = new puphub_1.PUPHub(device, this.autoSubscribe);
+        else if (await hub_1.Hub.IsHub(peripheral)) {
+            hub = new hub_1.Hub(device);
         }
-        else if (await pupremote_1.PUPRemote.IsPUPRemote(peripheral)) {
-            hub = new pupremote_1.PUPRemote(device, this.autoSubscribe);
+        else if (await remotecontrol_1.RemoteControl.IsRemoteControl(peripheral)) {
+            hub = new remotecontrol_1.RemoteControl(device);
         }
         else if (await duplotrainbase_1.DuploTrainBase.IsDuploTrainBase(peripheral)) {
-            hub = new duplotrainbase_1.DuploTrainBase(device, this.autoSubscribe);
+            hub = new duplotrainbase_1.DuploTrainBase(device);
         }
-        else if (await controlplushub_1.ControlPlusHub.IsControlPlusHub(peripheral)) {
-            hub = new controlplushub_1.ControlPlusHub(device, this.autoSubscribe);
+        else if (await technicmediumhub_1.TechnicMediumHub.IsTechnicMediumHub(peripheral)) {
+            hub = new technicmediumhub_1.TechnicMediumHub(device);
         }
         else {
             return;
@@ -230,7 +238,7 @@ class PoweredUP extends events_1.EventEmitter {
             /**
              * Emits when a Powered UP Hub device is found.
              * @event PoweredUP#discover
-             * @param {WeDo2SmartHub | BoostMoveHub | ControlPlusHub | PUPHub | PUPRemote | DuploTrainBase} hub
+             * @param {WeDo2SmartHub | MoveHub | TechnicMediumHub | Hub | RemoteControl | DuploTrainBase} hub
              */
             this.emit("discover", hub);
         });
@@ -282,7 +290,7 @@ exports.PoweredUP = PoweredUP;
 
 	Documentation generated by JSDoc 3.6.3
 	
-		on Tue Dec 3rd 2019
+		on Fri Feb 7th 2020
 	
 	using the DocStrap template.
 
diff --git a/docs/quicksearch.html b/docs/quicksearch.html
index 1d14541..942391b 100644
--- a/docs/quicksearch.html
+++ b/docs/quicksearch.html
@@ -7,7 +7,7 @@