diff --git a/README.md b/README.md index 984e2d2..b50f208 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ### Introduction -LEGO Powered Up is the successor to Power Functions, the system for adding electronics to LEGO models. Powered Up is a collection of ranges - starting with LEGO WeDo 2.0 released in 2016, LEGO Boost released in 2017, and LEGO Powered Up released in 2018. It also includes the 2018 Duplo App-Controlled Train sets. +LEGO Powered Up is the successor to Power Functions, the system for adding electronics to LEGO models. Powered Up is a collection of ranges - starting with LEGO WeDo 2.0 released in 2016, LEGO Boost released in 2017, LEGO Powered Up released in 2018, and LEGO Technic CONTROL+ released in 2019. It also includes the 2018 Duplo App-Controlled Train sets. This library allows communication and control of Powered Up devices and peripherals via Javascript, both from Node.js and from the browser using Web Bluetooth. @@ -25,15 +25,17 @@ Note: node-poweredup has been tested on macOS 10.13 and Debian/Raspbian on the R While most Powered Up components and Hubs are compatible with each other, there are exceptions. For example, there is limited backwards compatibility between newer components and the WeDo 2.0 Smart Hub. However WeDo 2.0 components are fully forwards compatible with newer Hubs. -| Device Name | Product Code | Type | WeDo 2.0 Smart Hub | Boost Move Hub | Powered Up Hub | Availability | -| ------------------------------- | ------------ | ------------- | ------------------ | -------------- | -------------- | ------------ | -| WeDo 2.0 Tilt Sensor | 45305 | Sensor | Yes | Yes | Yes | 45300 | -| WeDo 2.0 Motion Sensor | 45304 | Sensor | Yes | Yes | Yes | 45300 | -| WeDo 2.0 Medium Motor | 45303 | Motor | Yes | Yes | Yes | 45300
76112 | -| Boost Color and Distance Sensor | 88007 | Sensor | *Partial* | Yes | Yes | 17101 | -| Boost Tacho Motor | 88008 | Motor/Sensor | *Partial* | Yes | Yes | 17101 | -| Powered Up Train Motor | 88011 | Motor | Yes | Yes | Yes | 60197
60198 | -| Powered Up LED Lights | 88005 | Light | Yes | Yes | Yes | 88005 | +| Device Name | Product Code | Type | WeDo 2.0 Smart Hub | Boost Move Hub | Powered Up Hub | Control+ Hub | Availability | +| ------------------------------- | ------------ | ------------- | ------------------ | -------------- | -------------- | ------------ | ----- | +| WeDo 2.0 Tilt Sensor | 45305 | Sensor | Yes | Yes | Yes | Yes | 45300 | +| WeDo 2.0 Motion Sensor | 45304 | Sensor | Yes | Yes | Yes | Yes | 45300 | +| WeDo 2.0 Medium Motor | 45303 | Motor | Yes | Yes | Yes | Yes | 45300
76112 | +| Boost Color and Distance Sensor | 88007 | Sensor | *Partial* | Yes | Yes | Yes | 17101 | +| Boost Tacho Motor | 88008 | Motor/Sensor | *Partial* | Yes | Yes | Yes | 17101 | +| Powered Up Train Motor | 88011 | Motor | Yes | Yes | Yes | Yes | 60197
60198 | +| Powered Up LED Lights | 88005 | Light | Yes | Yes | Yes | Yes | 88005 | +| Control+ Large Motor | 22169 | Motor/Sensor | *Partial* | No | Yes | Yes | 42099 | +| Control+ XLarge Motor | 22172 | Motor/Sensor | *Partial* | No | Yes | Yes | 42099
42100 | In addition, the Hubs themselves have certain built-in features which this library exposes. @@ -44,13 +46,15 @@ In addition, the Hubs themselves have certain built-in features which this libra | Powered Up Hub | 88009 | RGB LED
Button | 60197
60198
76112 | | Powered Up Remote | 88010 | RGB LED
Left and Right Control Buttons
Button | 60197
60198 | | Duplo Train Base | 28743 | RGB LED/Headlights
Speaker
Speedometer
Motor
Color and Distance Sensor
Button | 10874
10875 | - +| Control+ Hub | 22127 | RGB LED
Button | 42099
42100 | ### Known Issues and Limitations * The Boost Color and Distance sensor only works in color mode with the WeDo 2.0 Smart Hub. -* When used with the WeDo 2.0 Smart Hub, the Boost Tacho Motor does not support rotating the motor by angle. +* When used with the WeDo 2.0 Smart Hub, the Boost Tacho Motor and Control+ Motors do not support rotating the motor by angle. + +* When used with the Boost Move Hub, the Control+ Motors do not currently accept commands. ### Documentation diff --git a/docs/BoostMoveHub.html b/docs/BoostMoveHub.html index 527fa51..e65398b 100644 --- a/docs/BoostMoveHub.html +++ b/docs/BoostMoveHub.html @@ -33,14 +33,14 @@ @@ -153,7 +153,7 @@ @@ -1257,7 +1257,7 @@ @@ -2037,7 +2037,7 @@ @@ -2665,7 +2665,7 @@ @@ -2922,7 +2922,7 @@ @@ -3163,7 +3163,7 @@ @@ -4584,7 +4584,7 @@ @@ -4755,7 +4755,7 @@ @@ -4950,7 +4950,7 @@ @@ -5273,7 +5273,7 @@ @@ -5444,7 +5444,7 @@ @@ -5639,7 +5639,7 @@ @@ -5716,9 +5716,9 @@ - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/ControlPlusHub.html b/docs/ControlPlusHub.html new file mode 100644 index 0000000..654e40c --- /dev/null +++ b/docs/ControlPlusHub.html @@ -0,0 +1,5812 @@ + + + + + + + node-poweredup Class: ControlPlusHub + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Class: ControlPlusHub

+
+ +
+ +

+ ControlPlusHub +

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

new ControlPlusHub()

+ + +
+
+ + +
+

The ControlPlusHub is emitted if the discovered device is a Control+ Hub.

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

Extends

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

Members

+ +
+ +
+
+

<readonly> batteryLevel

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

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

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

<readonly> current

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
current + + +number + + + + +

Current usage of the hub (Milliamps)

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

<readonly> firmwareVersion

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

Firmware version of the hub

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

<readonly> name

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

Name of the hub

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

<readonly> rssi

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

Signal strength of the hub

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

<readonly> uuid

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

UUID of the hub

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

<readonly> voltage

+ + +
+
+ + + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
voltage + + +number + + + + +

Voltage of the hub (Volts)

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

Methods

+ +
+ +
+
+

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 + + + +
+
+ + + + + +
+ + + +
+
+

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 + + + +
+
+ + + + + +
+ + + +
+
+

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 + + + +
+
+ + + + + +
+ + + +
+
+

setMotorAngle(port, angle [, speed])

+ + +
+
+ + +
+

Rotate a motor by a given angle.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeArgumentDefaultDescription
port + + +string + + + + + + + + + + + + +
angle + + +number + + + + + + + + + + + + +

How much the motor should be rotated (in degrees).

speed + + +number +| + +Array.<number> + + + + + + + <optional>
+ + + + + +
+ + 100 + +

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.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

Resolved upon successful completion of command (ie. once the motor is finished).

+
+ + + +
+
+ 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)

+ + +
+
+ + +
+

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 + + + +
+
+ + + + + +
+ + + +
+
+

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 + + + +
+
+ + + + + +
+ +
+ + + + + +

Events

+ +
+ +
+
+

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:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

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:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

distance

+ + +
+
+ + +
+

Emits when a distance sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
distance + + +number + + + + +

Distance, in millimeters.

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

rotate

+ + +
+
+ + +
+

Emits when a rotation sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
rotation + + +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's in-built tilt sensor, the special port "TILT" is used.

x + + +number + + + + +
y + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ + + + +
+
+ +
+ + +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/DuploTrainBase.html b/docs/DuploTrainBase.html index 6560333..31c83ed 100644 --- a/docs/DuploTrainBase.html +++ b/docs/DuploTrainBase.html @@ -33,14 +33,14 @@ @@ -4071,7 +4071,7 @@ @@ -4242,7 +4242,7 @@ @@ -4319,9 +4319,9 @@ - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/Hub.html b/docs/Hub.html index 71039b1..ea03a4c 100644 --- a/docs/Hub.html +++ b/docs/Hub.html @@ -33,14 +33,14 @@ @@ -2584,9 +2584,9 @@ - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/LPF2Hub.html b/docs/LPF2Hub.html index 3ec2d34..abf5777 100644 --- a/docs/LPF2Hub.html +++ b/docs/LPF2Hub.html @@ -33,14 +33,14 @@ @@ -3326,7 +3326,7 @@ @@ -3488,7 +3488,7 @@ @@ -3674,7 +3674,7 @@ @@ -3983,7 +3983,7 @@ @@ -4145,7 +4145,7 @@ @@ -4307,7 +4307,7 @@ @@ -4493,7 +4493,7 @@ @@ -4570,9 +4570,9 @@ - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/PUPHub.html b/docs/PUPHub.html index b188603..4274b98 100644 --- a/docs/PUPHub.html +++ b/docs/PUPHub.html @@ -33,14 +33,14 @@ @@ -1257,7 +1257,7 @@ @@ -2037,7 +2037,7 @@ @@ -2665,7 +2665,7 @@ @@ -2922,7 +2922,7 @@ @@ -3163,7 +3163,7 @@ @@ -4584,7 +4584,7 @@ @@ -4755,7 +4755,7 @@ @@ -4950,7 +4950,7 @@ @@ -5273,7 +5273,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

rotate

+ + +
+
+ + +
+

Emits when a rotation sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
rotation + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -5468,7 +5639,7 @@
@@ -5545,9 +5716,9 @@ - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/PUPRemote.html b/docs/PUPRemote.html index 892baa9..34c8c02 100644 --- a/docs/PUPRemote.html +++ b/docs/PUPRemote.html @@ -33,14 +33,14 @@ @@ -3268,7 +3268,7 @@ @@ -3463,7 +3463,7 @@ @@ -3540,9 +3540,9 @@ - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/PoweredUP.html b/docs/PoweredUP.html index d5a3e3f..558c77a 100644 --- a/docs/PoweredUP.html +++ b/docs/PoweredUP.html @@ -33,14 +33,14 @@ @@ -149,7 +149,7 @@ @@ -316,7 +316,7 @@ @@ -427,7 +427,7 @@ @@ -585,7 +585,7 @@ @@ -693,7 +693,7 @@ @@ -781,7 +781,7 @@ @@ -939,7 +939,7 @@ @@ -1016,9 +1016,9 @@ - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/WeDo2SmartHub.html b/docs/WeDo2SmartHub.html index 1379462..f2f4c88 100644 --- a/docs/WeDo2SmartHub.html +++ b/docs/WeDo2SmartHub.html @@ -33,14 +33,14 @@ @@ -5284,9 +5284,9 @@ - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/boostmovehub.js.html b/docs/boostmovehub.js.html index 297afc0..54cde12 100644 --- a/docs/boostmovehub.js.html +++ b/docs/boostmovehub.js.html @@ -33,14 +33,14 @@ @@ -85,6 +85,9 @@
"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 = {};
@@ -93,6 +96,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
     return result;
 };
 Object.defineProperty(exports, "__esModule", { value: true });
+const compare_versions_1 = __importDefault(require("compare-versions"));
 const lpf2hub_1 = require("./lpf2hub");
 const port_1 = require("./port");
 const Consts = __importStar(require("./consts"));
@@ -119,11 +123,11 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub {
         super(device, autoSubscribe);
         this.type = Consts.HubType.BOOST_MOVE_HUB;
         this._ports = {
-            "A": new port_1.Port("A", 55),
-            "B": new port_1.Port("B", 56),
-            "TILT": new port_1.Port("TILT", 58),
-            "C": new port_1.Port("C", 1),
-            "D": new port_1.Port("D", 2)
+            "A": new port_1.Port("A", 0),
+            "B": new port_1.Port("B", 1),
+            "C": new port_1.Port("C", 2),
+            "D": new port_1.Port("D", 3),
+            "TILT": new port_1.Port("TILT", 58)
         };
         this.on("attach", (port, type) => {
             this._combinePorts(port, type);
@@ -163,7 +167,10 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub {
         }
         return new Promise((resolve, reject) => {
             if (time && typeof time === "number") {
-                if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR) {
+                if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR ||
+                    portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR ||
+                    portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
+                    portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR) {
                     portObj.busy = true;
                     let data = null;
                     if (this._virtualPorts[portObj.id]) {
@@ -193,7 +200,10 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub {
                 }
             }
             else {
-                if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR) {
+                if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR ||
+                    portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR ||
+                    portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
+                    portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR) {
                     portObj.busy = true;
                     let data = null;
                     if (this._virtualPorts[portObj.id]) {
@@ -246,8 +256,11 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub {
      */
     setMotorAngle(port, angle, speed = 100) {
         const portObj = this._portLookup(port);
-        if (!(portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR)) {
-            throw new Error("Angle rotation is only available when using a Boost Tacho Motor or Boost Move Hub Motor");
+        if (!(portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR ||
+            portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR ||
+            portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
+            portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR)) {
+            throw new Error("Angle rotation is only available when using a Boost Tacho Motor, Boost Move Hub Motor, Control+ Medium Motor, or Control+ Large Motor");
         }
         if (!this._virtualPorts[portObj.id] && speed instanceof Array) {
             throw new Error(`Port ${portObj.id} can only accept a single speed`);
@@ -306,6 +319,11 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub {
             }
         });
     }
+    _checkFirmware(version) {
+        if (compare_versions_1.default("2.0.00.0023", version) === 1) {
+            throw new Error(`Your Boost 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.BoostMoveHub = BoostMoveHub;
 //# sourceMappingURL=boostmovehub.js.map
@@ -351,9 +369,9 @@ exports.BoostMoveHub = BoostMoveHub; - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/classes.list.html b/docs/classes.list.html index d6c2e6a..b6c7775 100644 --- a/docs/classes.list.html +++ b/docs/classes.list.html @@ -33,14 +33,14 @@ @@ -152,6 +152,9 @@
BoostMoveHub
+
ControlPlusHub
+
+
DuploTrainBase
@@ -506,7 +509,7 @@ @@ -677,7 +680,7 @@ @@ -872,7 +875,7 @@ @@ -1195,7 +1198,7 @@ @@ -1366,7 +1369,7 @@ @@ -1561,2299 +1564,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-

color

- - -
-
- - -
-

Emits when a color sensor is activated.

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

speed

- - -
-
- - -
-

Emits on a speed change.

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

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:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

attach

- - -
-
- - -
-

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

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

button

- - -
-
- - -
-

Emits when a button is pressed.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
button - - -string - - - - -
state - - -ButtonState - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

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:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

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:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

speed

- - -
-
- - -
-

Emits on a speed change.

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

tilt

- - -
-
- - -
-

Emits when a tilt sensor is activated.

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

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

x - - -number - - - - -
y - - -number - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - - - - - -
- - - -
-
-

discover

- - -
-
- - -
-

Emits when a Powered UP Hub device is found.

-
- - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
hub - - -WeDo2SmartHub -| - -BoostMoveHub -| - -PUPHub -| - -PUPRemote -| - -DuploTrainBase - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
-
@@ -4200,7 +1911,7 @@
@@ -4371,7 +2082,7 @@ @@ -4566,7 +2277,7 @@ @@ -4889,7 +2600,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

rotate

+ + +
+
+ + +
+

Emits when a rotation sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
rotation + + +number + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -5084,7 +2966,2475 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

color

+ + +
+
+ + +
+

Emits when a color sensor is activated.

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

speed

+ + +
+
+ + +
+

Emits on a speed change.

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

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:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

attach

+ + +
+
+ + +
+

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

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

button

+ + +
+
+ + +
+

Emits when a button is pressed.

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

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:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

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:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

speed

+ + +
+
+ + +
+

Emits on a speed change.

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

tilt

+ + +
+
+ + +
+

Emits when a tilt sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +

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

x + + +number + + + + +
y + + +number + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

discover

+ + +
+
+ + +
+

Emits when a Powered UP Hub device is found.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
hub + + +WeDo2SmartHub +| + +BoostMoveHub +| + +PUPHub +| + +PUPRemote +| + +DuploTrainBase + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+

attach

+ + +
+
+ + +
+

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

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
type + + +DeviceType + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + +
Overrides:
+
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -5255,7 +5605,178 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

color

+ + +
+
+ + +
+

Emits when a color sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
color + + +Color + + + + +
+ + + + +
+ + + + + + + +
Inherited From:
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+
@@ -5450,7 +5971,1062 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

detach

+ + +
+
+ + +
+

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

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

distance

+ + +
+
+ + +
+

Emits when a distance sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
distance + + +number + + + + +

Distance, in millimeters.

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

rotate

+ + +
+
+ + +
+

Emits when a rotation sensor is activated.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
port + + +string + + + + +
rotation + + +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's in-built tilt sensor, the special port "TILT" is used.

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

button

+ + +
+
+ + +
+

Emits when a button is pressed.

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
button + + +string + + + + +
state + + +ButtonState + + + + +
+ + + + +
+ + + + + + + +
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:
+
+
@@ -6679,9 +8255,9 @@ - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/consts.js.html b/docs/consts.js.html index 19f511c..3e56973 100644 --- a/docs/consts.js.html +++ b/docs/consts.js.html @@ -33,14 +33,14 @@ @@ -94,6 +94,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); * @property {number} POWERED_UP_HUB 3 * @property {number} POWERED_UP_REMOTE 4 * @property {number} DUPLO_TRAIN_HUB 5 + * @property {number} CONTROL_PLUS_HUB 6 */ var HubType; (function (HubType) { @@ -103,6 +104,7 @@ var HubType; 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 = exports.HubType || (exports.HubType = {})); // tslint:disable-next-line exports.HubTypeNames = Object.keys(HubType).reduce((result, item) => { @@ -127,6 +129,8 @@ exports.HubTypeNames = Object.keys(HubType).reduce((result, item) => { * @property {number} DUPLO_TRAIN_BASE_SPEAKER 42 * @property {number} DUPLO_TRAIN_BASE_COLOR 43 * @property {number} DUPLO_TRAIN_BASE_SPEEDOMETER 44 + * @property {number} CONTROL_PLUS_LARGE_MOTOR 46 + * @property {number} CONTROL_PLUS_XLARGE_MOTOR 47 * @property {number} POWERED_UP_REMOTE_BUTTON 55 */ var DeviceType; @@ -146,6 +150,8 @@ var DeviceType; 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_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["POWERED_UP_REMOTE_BUTTON"] = 55] = "POWERED_UP_REMOTE_BUTTON"; })(DeviceType = exports.DeviceType || (exports.DeviceType = {})); // tslint:disable-next-line @@ -224,10 +230,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["DUPLO_TRAIN_HUB_ID"] = 32] = "DUPLO_TRAIN_HUB_ID"; + BLEManufacturerData[BLEManufacturerData["CONTROL_PLUS_LARGE_HUB"] = 128] = "CONTROL_PLUS_LARGE_HUB"; })(BLEManufacturerData = exports.BLEManufacturerData || (exports.BLEManufacturerData = {})); var BLEService; (function (BLEService) { @@ -298,9 +305,9 @@ var BLECharacteristic; - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/controlplushub.js.html b/docs/controlplushub.js.html new file mode 100644 index 0000000..4996f0f --- /dev/null +++ b/docs/controlplushub.js.html @@ -0,0 +1,452 @@ + + + + + + + node-poweredup Source: controlplushub.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: controlplushub.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 port_1 = require("./port");
+const Consts = __importStar(require("./consts"));
+const Debug = require("debug");
+const debug = Debug("ControlPlusHub");
+/**
+ * The ControlPlusHub is emitted if the discovered device is a Control+ Hub.
+ * @class ControlPlusHub
+ * @extends LPF2Hub
+ * @extends Hub
+ */
+class ControlPlusHub extends lpf2hub_1.LPF2Hub {
+    // We set JSDoc to ignore these events as a Powered UP Remote will never emit them.
+    /**
+     * @event ControlPlusHub#speed
+     * @ignore
+     */
+    static IsControlPlusHub(peripheral) {
+        return (peripheral.advertisement &&
+            peripheral.advertisement.serviceUuids &&
+            peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.CONTROL_PLUS_LARGE_HUB);
+    }
+    constructor(device, autoSubscribe = true) {
+        super(device, autoSubscribe);
+        this.type = Consts.HubType.CONTROL_PLUS_HUB;
+        this._ports = {
+            "A": new port_1.Port("A", 0),
+            "B": new port_1.Port("B", 1),
+            "C": new port_1.Port("C", 2),
+            "D": new port_1.Port("D", 3),
+        };
+        this.on("attach", (port, type) => {
+            this._combinePorts(port, type);
+        });
+        debug("Discovered Control+ Hub");
+    }
+    connect() {
+        return new Promise(async (resolve, reject) => {
+            debug("Connecting to Control+ Hub");
+            await super.connect();
+            debug("Connect completed");
+            return resolve();
+        });
+    }
+    /**
+     * Set the motor speed on a given port.
+     * @method ControlPlusHub#setMotorSpeed
+     * @param {string} port
+     * @param {number | Array.<number>} speed 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.
+     * @param {number} [time] How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely.
+     * @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the motor is finished.
+     */
+    setMotorSpeed(port, speed, time) {
+        const portObj = this._portLookup(port);
+        if (!this._virtualPorts[portObj.id] && speed instanceof Array) {
+            throw new Error(`Port ${portObj.id} can only accept a single speed`);
+        }
+        let cancelEventTimer = true;
+        if (typeof time === "boolean") {
+            if (time === true) {
+                cancelEventTimer = false;
+            }
+            time = undefined;
+        }
+        if (cancelEventTimer) {
+            portObj.cancelEventTimer();
+        }
+        return new Promise((resolve, reject) => {
+            if (time && typeof time === "number") {
+                if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR ||
+                    portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR ||
+                    portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
+                    portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR) {
+                    portObj.busy = true;
+                    let data = null;
+                    if (this._virtualPorts[portObj.id]) {
+                        data = Buffer.from([0x81, portObj.value, 0x11, 0x0a, 0x00, 0x00, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
+                    }
+                    else {
+                        // @ts-ignore: The type of speed is properly checked at the start
+                        data = Buffer.from([0x81, portObj.value, 0x11, 0x09, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
+                    }
+                    data.writeUInt16LE(time > 65535 ? 65535 : time, 4);
+                    this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
+                    portObj.finished = () => {
+                        return resolve();
+                    };
+                }
+                else {
+                    // @ts-ignore: The type of speed is properly checked at the start
+                    const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
+                    this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
+                    const timeout = global.setTimeout(() => {
+                        const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
+                        this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
+                        return resolve();
+                        // @ts-ignore: The type of time is properly checked at the start
+                    }, time);
+                    portObj.setEventTimer(timeout);
+                }
+            }
+            else {
+                if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR) {
+                    portObj.busy = true;
+                    let data = null;
+                    if (this._virtualPorts[portObj.id]) {
+                        data = Buffer.from([0x81, portObj.value, 0x11, 0x02, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
+                    }
+                    else {
+                        // @ts-ignore: The type of speed is properly checked at the start
+                        data = Buffer.from([0x81, portObj.value, 0x11, 0x01, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
+                    }
+                    this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
+                    portObj.finished = () => {
+                        return resolve();
+                    };
+                }
+                else {
+                    // @ts-ignore: The type of speed is properly checked at the start
+                    const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
+                    this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
+                }
+            }
+        });
+    }
+    /**
+     * Ramp the motor speed on a given port.
+     * @method ControlPlusHub#rampMotorSpeed
+     * @param {string} port
+     * @param {number} fromSpeed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
+     * @param {number} toSpeed 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.
+     */
+    rampMotorSpeed(port, fromSpeed, toSpeed, time) {
+        const portObj = this._portLookup(port);
+        portObj.cancelEventTimer();
+        return new Promise((resolve, reject) => {
+            this._calculateRamp(fromSpeed, toSpeed, time, portObj)
+                .on("changeSpeed", (speed) => {
+                this.setMotorSpeed(port, speed, true);
+            })
+                .on("finished", resolve);
+        });
+    }
+    /**
+     * Rotate a motor by a given angle.
+     * @method ControlPlusHub#setMotorAngle
+     * @param {string} port
+     * @param {number} angle How much the motor should be rotated (in degrees).
+     * @param {number | Array.<number>} [speed=100] 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.
+     * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
+     */
+    setMotorAngle(port, angle, speed = 100) {
+        const portObj = this._portLookup(port);
+        if (!(portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR ||
+            portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR ||
+            portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
+            portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR)) {
+            throw new Error("Angle rotation is only available when using a Boost Tacho Motor, Boost Move Hub Motor, Control+ Medium Motor, or Control+ Large Motor");
+        }
+        if (!this._virtualPorts[portObj.id] && speed instanceof Array) {
+            throw new Error(`Port ${portObj.id} can only accept a single speed`);
+        }
+        portObj.cancelEventTimer();
+        return new Promise((resolve, reject) => {
+            portObj.busy = true;
+            let data = null;
+            if (this._virtualPorts[portObj.id]) {
+                data = Buffer.from([0x81, portObj.value, 0x11, 0x0c, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
+            }
+            else {
+                // @ts-ignore: The type of speed is properly checked at the start
+                data = Buffer.from([0x81, portObj.value, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
+            }
+            data.writeUInt32LE(angle, 4);
+            this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
+            portObj.finished = () => {
+                return resolve();
+            };
+        });
+    }
+    /**
+     * Fully (hard) stop the motor on a given port.
+     * @method ControlPlusHub#brakeMotor
+     * @param {string} port
+     * @returns {Promise} Resolved upon successful completion of command.
+     */
+    brakeMotor(port) {
+        return this.setMotorSpeed(port, 127);
+    }
+    /**
+     * Set the light brightness on a given port.
+     * @method ControlPlusHub#setLightBrightness
+     * @param {string} port
+     * @param {number} brightness Brightness value between 0-100 (0 is off)
+     * @param {number} [time] How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely.
+     * @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
+     */
+    setLightBrightness(port, brightness, time) {
+        const portObj = this._portLookup(port);
+        portObj.cancelEventTimer();
+        return new Promise((resolve, reject) => {
+            const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]);
+            this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
+            if (time) {
+                const timeout = global.setTimeout(() => {
+                    const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
+                    this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
+                    return resolve();
+                }, time);
+                portObj.setEventTimer(timeout);
+            }
+            else {
+                return resolve();
+            }
+        });
+    }
+}
+exports.ControlPlusHub = ControlPlusHub;
+//# sourceMappingURL=controlplushub.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + +
+ + + + node-poweredup by Nathan Kellenicki licensed under the MIT license. + + + + Documentation generated by JSDoc 3.6.3 + + on Tue Aug 6th 2019 + + using the DocStrap template. + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/duplotrainbase.js.html b/docs/duplotrainbase.js.html index 9c983f2..4b70e8b 100644 --- a/docs/duplotrainbase.js.html +++ b/docs/duplotrainbase.js.html @@ -33,14 +33,14 @@ @@ -298,9 +298,9 @@ exports.DuploTrainBase = DuploTrainBase; - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/global.html b/docs/global.html index 850a56b..d440477 100644 --- a/docs/global.html +++ b/docs/global.html @@ -33,14 +33,14 @@ @@ -356,7 +356,7 @@
@@ -571,7 +571,7 @@ @@ -954,7 +954,7 @@ @@ -1337,7 +1337,7 @@ @@ -1755,6 +1755,54 @@ + + + CONTROL_PLUS_LARGE_MOTOR + + + + + +number + + + + + + + + + + +

46

+ + + + + + + CONTROL_PLUS_XLARGE_MOTOR + + + + + +number + + + + + + + + + + +

47

+ + + + POWERED_UP_REMOTE_BUTTON @@ -1816,7 +1864,7 @@ @@ -2234,6 +2282,54 @@ + + + CONTROL_PLUS_LARGE_MOTOR + + + + + +number + + + + + + + + + + +

46

+ + + + + + + CONTROL_PLUS_XLARGE_MOTOR + + + + + +number + + + + + + + + + + +

47

+ + + + POWERED_UP_REMOTE_BUTTON @@ -2295,7 +2391,7 @@ @@ -2510,7 +2606,7 @@ @@ -2725,7 +2821,7 @@ @@ -2926,6 +3022,30 @@ + + + + CONTROL_PLUS_HUB + + + + + +number + + + + + + + + + + +

6

+ + + @@ -3165,6 +3285,30 @@ + + + + CONTROL_PLUS_HUB + + + + + +number + + + + + + + + + + +

6

+ + + @@ -3270,9 +3414,9 @@ - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/hub.js.html b/docs/hub.js.html index ae9ec0e..8765fdd 100644 --- a/docs/hub.js.html +++ b/docs/hub.js.html @@ -33,14 +33,14 @@ @@ -403,6 +403,10 @@ class Hub extends events_1.EventEmitter { return 0x02; case Consts.DeviceType.BOOST_MOVE_HUB_MOTOR: return 0x02; + case Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR: + return 0x02; + case Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR: + return 0x02; case Consts.DeviceType.BOOST_DISTANCE: return (this.type === Consts.HubType.WEDO2_SMART_HUB ? 0x00 : 0x08); case Consts.DeviceType.BOOST_TILT: @@ -456,9 +460,9 @@ exports.Hub = Hub; - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/index.html b/docs/index.html index a5b0f93..a435d03 100644 --- a/docs/index.html +++ b/docs/index.html @@ -33,14 +33,14 @@ @@ -100,13 +100,20 @@
-

Drone
NPM Version

-

node-poweredup - A Javascript module to interface with LEGO Powered Up components.

Introduction

LEGO Powered Up is the successor to Power Functions, the system for adding electronics to LEGO models. Powered Up is a collection of ranges - starting with LEGO WeDo 2.0 released in 2016, LEGO Boost released in 2017, and LEGO Powered Up released in 2018. It also includes the 2018 Duplo App-Controlled Train sets.

+

Drone
+NPM Version

+

node-poweredup - A Javascript module to interface with LEGO Powered Up components.

+

Introduction

+

LEGO Powered Up is the successor to Power Functions, the system for adding electronics to LEGO models. Powered Up is a collection of ranges - starting with LEGO WeDo 2.0 released in 2016, LEGO Boost released in 2017, LEGO Powered Up released in 2018, and LEGO Technic CONTROL+ released in 2019. It also includes the 2018 Duplo App-Controlled Train sets.

This library allows communication and control of Powered Up devices and peripherals via Javascript, both from Node.js and from the browser using Web Bluetooth.

-

Node.js Installation

Node.js v8.0 required.

-
npm install node-poweredup --save

node-poweredup uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are certain dependencies which may need installed first.

+

Node.js Installation

+

Node.js v8.0 required.

+
npm install node-poweredup --save
+
+

node-poweredup uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are certain dependencies which may need installed first.

Note: node-poweredup has been tested on macOS 10.13 and Debian/Raspbian on the Raspberry Pi 3 Model B.

-

Compatibility

While most Powered Up components and Hubs are compatible with each other, there are exceptions. For example, there is limited backwards compatibility between newer components and the WeDo 2.0 Smart Hub. However WeDo 2.0 components are fully forwards compatible with newer Hubs.

+

Compatibility

+

While most Powered Up components and Hubs are compatible with each other, there are exceptions. For example, there is limited backwards compatibility between newer components and the WeDo 2.0 Smart Hub. However WeDo 2.0 components are fully forwards compatible with newer Hubs.

@@ -116,6 +123,7 @@ + @@ -127,6 +135,7 @@ + @@ -136,6 +145,7 @@ + @@ -145,6 +155,7 @@ + @@ -154,6 +165,7 @@ + @@ -163,6 +175,7 @@ + @@ -172,6 +185,7 @@ + @@ -181,8 +195,29 @@ + + + + + + + + + + + + + + + + + + + + +
WeDo 2.0 Smart Hub Boost Move Hub Powered Up HubControl+ Hub Availability
Yes Yes YesYes 45300
Yes Yes YesYes 45300
Yes Yes YesYes 45300
76112
Partial Yes YesYes 17101
Partial Yes YesYes 17101
Yes Yes YesYes 60197
60198
Yes Yes YesYes 88005
Control+ Large Motor22169Motor/SensorPartialNoYesYes42099
Control+ XLarge Motor22172Motor/SensorPartialNoYesYes42099
42100

In addition, the Hubs themselves have certain built-in features which this library exposes.

@@ -226,16 +261,30 @@ RGB LED/Headlights
Speaker
Speedometer
Motor
Color and Distance Sensor
Button 10874
10875 + +Control+ Hub +22127 +RGB LED
Button +42099
42100 + -

Known Issues and Limitations

    -
  • The Boost Color and Distance sensor only works in color mode with the WeDo 2.0 Smart Hub.

    +

    Known Issues and Limitations

    +
      +
    • +

      The Boost Color and Distance sensor only works in color mode with the WeDo 2.0 Smart Hub.

    • -
    • When used with the WeDo 2.0 Smart Hub, the Boost Tacho Motor does not support rotating the motor by angle.

      +
    • +

      When used with the WeDo 2.0 Smart Hub, the Boost Tacho Motor and Control+ Motors do not support rotating the motor by angle.

      +
    • +
    • +

      When used with the Boost Move Hub, the Control+ Motors do not currently accept commands.

    -

    Documentation

    Full documentation is available here.

    -

    Node.js Sample Usage

    const PoweredUP = require("node-poweredup");
    +

    Documentation

    +

    Full documentation is available here.

    +

    Node.js Sample Usage

    +
    const PoweredUP = require("node-poweredup");
     const poweredUP = new PoweredUP.PoweredUP();
     
     poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
    @@ -257,8 +306,11 @@ poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
     });
     
     poweredUP.scan(); // Start scanning for Hubs
    -console.log("Scanning for Hubs...");

    More examples are available in the "examples" directory.

    -

    Credits

    Thanks go to Jorge Pereira (@JorgePe), Sebastian Raff (@hobbyquaker), Valentin Heun (@vheun), Johan Korten (@jakorten), and Andrey Pokhilko (@undera) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered Up protocols.

+console.log("Scanning for Hubs..."); + +

More examples are available in the "examples" directory.

+

Credits

+

Thanks go to Jorge Pereira (@JorgePe), Sebastian Raff (@hobbyquaker), Valentin Heun (@vheun), Johan Korten (@jakorten), and Andrey Pokhilko (@undera) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered Up protocols.

@@ -306,9 +358,9 @@ console.log("Scanning for Hubs...");

More examples are - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/lpf2hub.js.html b/docs/lpf2hub.js.html index 3b2a589..ece49b4 100644 --- a/docs/lpf2hub.js.html +++ b/docs/lpf2hub.js.html @@ -33,14 +33,14 @@

@@ -223,6 +223,7 @@ class LPF2Hub extends hub_1.Hub { if (portObj) { Object.keys(this._ports).forEach((id) => { if (this._ports[id].type === type && this._ports[id].value !== portObj.value && !this._virtualPorts[`${portObj.value < this._ports[id].value ? portObj.id : this._ports[id].id}${portObj.value > this._ports[id].value ? portObj.id : this._ports[id].id}`]) { + debug("Combining ports", portObj.value < this._ports[id].value ? portObj.id : id, portObj.value > this._ports[id].value ? portObj.id : id); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x61, 0x01, portObj.value < this._ports[id].value ? portObj.value : this._ports[id].value, portObj.value > this._ports[id].value ? portObj.value : this._ports[id].value])); } }); @@ -455,6 +456,16 @@ class LPF2Hub extends hub_1.Hub { this.emit("rotate", port.id, rotation); break; } + case Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR: { + const rotation = data.readInt32LE(4); + this.emit("rotate", port.id, rotation); + break; + } + case Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR: { + const rotation = data.readInt32LE(4); + this.emit("rotate", port.id, rotation); + break; + } case Consts.DeviceType.BOOST_TILT: { const tiltX = data[4] > 160 ? data[4] - 255 : data[4]; const tiltY = data[5] > 160 ? 255 - data[5] : data[5] - (data[5] * 2); @@ -547,9 +558,9 @@ exports.LPF2Hub = LPF2Hub; - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/poweredup-node.js.html b/docs/poweredup-node.js.html index 5e3a10f..4721a60 100644 --- a/docs/poweredup-node.js.html +++ b/docs/poweredup-node.js.html @@ -33,14 +33,14 @@ @@ -87,6 +87,7 @@ class="sunlight-highlight-javascript linenums">"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"); @@ -198,6 +199,9 @@ class PoweredUP extends events_1.EventEmitter { else if (await duplotrainbase_1.DuploTrainBase.IsDuploTrainBase(peripheral)) { hub = new duplotrainbase_1.DuploTrainBase(device, this.autoSubscribe); } + else if (await controlplushub_1.ControlPlusHub.IsControlPlusHub(peripheral)) { + hub = new controlplushub_1.ControlPlusHub(device, this.autoSubscribe); + } else { return; } @@ -267,9 +271,9 @@ exports.PoweredUP = PoweredUP; - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/puphub.js.html b/docs/puphub.js.html index 171e4aa..b790eb0 100644 --- a/docs/puphub.js.html +++ b/docs/puphub.js.html @@ -33,14 +33,14 @@ @@ -110,10 +110,6 @@ const debug = Debug("puphub"); */ class PUPHub extends lpf2hub_1.LPF2Hub { // We set JSDoc to ignore these events as a Powered UP Remote will never emit them. - /** - * @event PUPHub#rotate - * @ignore - */ /** * @event PUPHub#speed * @ignore @@ -168,7 +164,10 @@ class PUPHub extends lpf2hub_1.LPF2Hub { } return new Promise((resolve, reject) => { if (time && typeof time === "number") { - if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR) { + if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || + portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR || + portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR || + portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR) { portObj.busy = true; let data = null; if (this._virtualPorts[portObj.id]) { @@ -251,8 +250,11 @@ class PUPHub extends lpf2hub_1.LPF2Hub { */ setMotorAngle(port, angle, speed = 100) { const portObj = this._portLookup(port); - if (!(portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR)) { - throw new Error("Angle rotation is only available when using a Boost Tacho Motor or Boost Move Hub Motor"); + if (!(portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || + portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR || + portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR || + portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR)) { + throw new Error("Angle rotation is only available when using a Boost Tacho Motor, Boost Move Hub Motor, Control+ Medium Motor, or Control+ Large Motor"); } if (!this._virtualPorts[portObj.id] && speed instanceof Array) { throw new Error(`Port ${portObj.id} can only accept a single speed`); @@ -361,9 +363,9 @@ exports.PUPHub = PUPHub; - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/pupremote.js.html b/docs/pupremote.js.html index 7a7f19b..471029c 100644 --- a/docs/pupremote.js.html +++ b/docs/pupremote.js.html @@ -33,14 +33,14 @@ @@ -236,9 +236,9 @@ exports.PUPRemote = PUPRemote; - Documentation generated by JSDoc 3.5.5 + Documentation generated by JSDoc 3.6.3 - on Fri Jul 19th 2019 + on Tue Aug 6th 2019 using the DocStrap template. diff --git a/docs/quicksearch.html b/docs/quicksearch.html index ec1d517..3fdc451 100644 --- a/docs/quicksearch.html +++ b/docs/quicksearch.html @@ -7,7 +7,7 @@