Merge remote-tracking branch 'nathankellenicki/master'

This commit is contained in:
Shane Church 2018-12-31 21:44:26 -06:00
commit 0cc7c00352
16 changed files with 1045 additions and 280 deletions

54
.circleci/config.yml Normal file
View File

@ -0,0 +1,54 @@
version: 2
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/node:8.11.4
jobs:
build:
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-
- run: sudo apt-get install -y bluetooth bluez libbluetooth-dev libudev-dev
- run: npm install
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: npm run all
- persist_to_workspace:
root: ~/repo
paths: .
deploy:
<<: *defaults
steps:
- attach_workspace:
at: ~/repo
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$npm_TOKEN" > ~/repo/.npmrc
- run:
name: Publish package
command: npm publish
workflows:
version: 2
build-deploy:
jobs:
- build:
filters:
tags:
only: /^v.*/
- deploy:
requires:
- build
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/

View File

@ -1,3 +1,7 @@
[![CircleCI](https://circleci.com/gh/nathankellenicki/node-poweredup.svg?style=shield)](https://circleci.com/gh/nathankellenicki/node-poweredup)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/node-poweredup?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
![NPM Version](https://img.shields.io/npm/v/node-poweredup.svg?style=flat)
# **node-poweredup** - A Node.js module to interface with LEGO Powered UP components. # **node-poweredup** - A Node.js module to interface with LEGO Powered UP components.
### Introduction ### Introduction
@ -28,15 +32,25 @@ 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. 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.
| Name | Type | WeDo 2.0 Smart Hub | Boost Move Hub | Powered UP Hub | Availability | | Device Name | Product Code | Type | WeDo 2.0 Smart Hub | Boost Move Hub | Powered UP Hub | Availability |
| ------------------------------- | ------------- | ------------------ | -------------- | -------------- | ------------ | | ------------------------------- | ------------ | ------------- | ------------------ | -------------- | -------------- | ------------ |
| WeDo 2.0 Tilt Sensor | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> | | WeDo 2.0 Tilt Sensor | <a href="https://brickset.com/sets/45305-1/">45305</a> | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| WeDo 2.0 Motion Sensor | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> | | WeDo 2.0 Motion Sensor | <a href="https://brickset.com/sets/45304-1/">45304</a> | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| WeDo 2.0 Medium Motor | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a> | | WeDo 2.0 Medium Motor | <a href="https://brickset.com/sets/45303-1/">45303</a> | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a> |
| Boost Color and Distance Sensor | Sensor | *Partial* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> | | Boost Color and Distance Sensor | <a href="https://brickset.com/sets/88007-1/">88007</a> | Sensor | *Partial* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Boost Tacho Motor | Motor/Sensor | *Partial* | Yes | *Partial* | <a href="https://brickset.com/sets/17101-1/">17101</a> | | Boost Tacho Motor | <a href="https://brickset.com/sets/88008-1/">88008</a> | Motor/Sensor | *Partial* | Yes | *Partial* | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Powered UP Train Motor | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> | | Powered UP Train Motor | <a href="https://brickset.com/sets/88011-1/">88011</a> | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
| Powered UP LED Lights | Light | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> | | Powered UP LED Lights | <a href="https://brickset.com/sets/88005-1/">88005</a> | Light | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> |
In addition, the Hubs themselves have certain built-in features which this library exposes.
| Hub Name | Product Code | Built-In Features | Availability |
| ------------------ | ------------ | ---------------------- | ------------ |
| WeDo 2.0 Smart hub | <a href="https://brickset.com/sets/45301-1/">45301</a> | RGB LED<br />Piezo Buzzer<br />Button | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| Boost Move Hub | <a href="https://brickset.com/sets/88006-1/">88006</a> | RGB LED<br />Tilt Sensor<br />2x Tacho Motors<br />Button | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Powered UP Hub | <a href="https://brickset.com/sets/88009-1/">88009</a> | RGB LED<br />Button | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a><br /><a href="https://brickset.com/sets/76112-1/">76112</a> |
| Powered UP Remote | <a href="https://brickset.com/sets/88010-1/">88010</a> | RGB LED<br />Left and Right Control Buttons<br />Button | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
| Duplo Train Base | 28743 | RGB LED/Headlights<br />Speaker<br />Speedometer<br />Motor<br />Color and Distance Sensor<br />Button | <a href="https://brickset.com/sets/10874-1/">10874</a><br /><a href="https://brickset.com/sets/10875-1/">10875</a> |
### Known Issues and Limitations ### Known Issues and Limitations

396
DOCS.md
View File

@ -15,6 +15,21 @@
<dd></dd> <dd></dd>
</dl> </dl>
## Typedefs
<dl>
<dt><a href="#HubType">HubType</a></dt>
<dd></dd>
<dt><a href="#DeviceType">DeviceType</a></dt>
<dd></dd>
<dt><a href="#Color">Color</a></dt>
<dd></dd>
<dt><a href="#ButtonState">ButtonState</a></dt>
<dd></dd>
<dt><a href="#DuploTrainBaseSound">DuploTrainBaseSound</a></dt>
<dd></dd>
</dl>
<a name="PoweredUP"></a> <a name="PoweredUP"></a>
## PoweredUP ⇐ <code>EventEmitter</code> ## PoweredUP ⇐ <code>EventEmitter</code>
@ -93,6 +108,8 @@ Emits when a Powered UP Hub device is found.
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code> * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code> * [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code> * [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
* [.getHubType()](#Hub+getHubType) ⇒ [<code>HubType</code>](#HubType)
* [.getPortDeviceType(port)](#Hub+getPortDeviceType) ⇒ [<code>DeviceType</code>](#DeviceType)
* ["button" (button, state)](#WeDo2SmartHub+event_button) * ["button" (button, state)](#WeDo2SmartHub+event_button)
* ["distance" (port, distance)](#WeDo2SmartHub+event_distance) * ["distance" (port, distance)](#WeDo2SmartHub+event_distance)
* ["color" (port, color)](#WeDo2SmartHub+event_color) * ["color" (port, color)](#WeDo2SmartHub+event_color)
@ -170,9 +187,9 @@ Set the color of the LED on the Hub via a color value.
**Kind**: instance method of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub) **Kind**: instance method of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="WeDo2SmartHub+setLEDRGB"></a> <a name="WeDo2SmartHub+setLEDRGB"></a>
@ -312,6 +329,23 @@ This is a helper method to make it easier to wait for concurrent commands to com
| --- | --- | --- | | --- | --- | --- |
| commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. | | commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. |
<a name="Hub+getHubType"></a>
### weDo2SmartHub.getHubType() ⇒ [<code>HubType</code>](#HubType)
Get the hub type.
**Kind**: instance method of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
<a name="Hub+getPortDeviceType"></a>
### weDo2SmartHub.getPortDeviceType(port) ⇒ [<code>DeviceType</code>](#DeviceType)
Get the device type for a given port.
**Kind**: instance method of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
<a name="WeDo2SmartHub+event_button"></a> <a name="WeDo2SmartHub+event_button"></a>
### "button" (button, state) ### "button" (button, state)
@ -319,10 +353,10 @@ Emits when a button is pressed.
**Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub) **Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| button | <code>string</code> | | | button | <code>string</code> |
| state | <code>number</code> | A number representing one of the button state consts. | | state | [<code>ButtonState</code>](#ButtonState) |
<a name="WeDo2SmartHub+event_distance"></a> <a name="WeDo2SmartHub+event_distance"></a>
@ -343,10 +377,10 @@ Emits when a color sensor is activated.
**Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub) **Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="WeDo2SmartHub+event_tilt"></a> <a name="WeDo2SmartHub+event_tilt"></a>
@ -380,10 +414,10 @@ Emits when a motor or sensor is attached to the Hub.
**Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub) **Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> |
| type | <code>number</code> | A number representing one of the peripheral consts. | | type | [<code>DeviceType</code>](#DeviceType) |
<a name="Hub+event_detach"></a> <a name="Hub+event_detach"></a>
@ -422,9 +456,12 @@ Emits when an attached motor or sensor is detached from the Hub.
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code> * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code> * [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code> * [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
* [.getHubType()](#Hub+getHubType) ⇒ [<code>HubType</code>](#HubType)
* [.getPortDeviceType(port)](#Hub+getPortDeviceType) ⇒ [<code>DeviceType</code>](#DeviceType)
* ["button" (button, state)](#LPF2Hub+event_button) * ["button" (button, state)](#LPF2Hub+event_button)
* ["distance" (port, distance)](#LPF2Hub+event_distance) * ["distance" (port, distance)](#LPF2Hub+event_distance)
* ["color" (port, color)](#LPF2Hub+event_color) * ["color" (port, color)](#LPF2Hub+event_color)
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt) * ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
* ["rotate" (port, rotation)](#LPF2Hub+event_rotate) * ["rotate" (port, rotation)](#LPF2Hub+event_rotate)
* ["attach" (port, type)](#Hub+event_attach) * ["attach" (port, type)](#Hub+event_attach)
@ -450,6 +487,7 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
### boostMoveHub.name ### boostMoveHub.name
**Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>name</code>](#Hub+name)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -461,6 +499,7 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
### boostMoveHub.uuid ### boostMoveHub.uuid
**Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>uuid</code>](#Hub+uuid)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -472,6 +511,7 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
### boostMoveHub.rssi ### boostMoveHub.rssi
**Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>rssi</code>](#Hub+rssi)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -483,6 +523,7 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
### boostMoveHub.batteryLevel ### boostMoveHub.batteryLevel
**Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>batteryLevel</code>](#Hub+batteryLevel)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -567,9 +608,9 @@ Set the color of the LED on the Hub via a color value.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="LPF2Hub+setLEDRGB"></a> <a name="LPF2Hub+setLEDRGB"></a>
@ -599,6 +640,7 @@ Connect to the Hub.
Disconnect the Hub. Disconnect the Hub.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>disconnect</code>](#Hub+disconnect)
**Returns**: <code>Promise</code> - Resolved upon successful disconnect. **Returns**: <code>Promise</code> - Resolved upon successful disconnect.
<a name="Hub+subscribe"></a> <a name="Hub+subscribe"></a>
@ -606,6 +648,7 @@ Disconnect the Hub.
Subscribe to sensor notifications on a given port. Subscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>subscribe</code>](#Hub+subscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type | Description |
@ -619,6 +662,7 @@ Subscribe to sensor notifications on a given port.
Unsubscribe to sensor notifications on a given port. Unsubscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>unsubscribe</code>](#Hub+unsubscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | | Param | Type |
@ -633,6 +677,7 @@ Sleep a given amount of time.
This is a helper method to make it easier to add delays into a chain of commands. This is a helper method to make it easier to add delays into a chain of commands.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>sleep</code>](#Hub+sleep)
**Returns**: <code>Promise</code> - Resolved after the delay is finished. **Returns**: <code>Promise</code> - Resolved after the delay is finished.
| Param | Type | Description | | Param | Type | Description |
@ -647,12 +692,32 @@ 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. This is a helper method to make it easier to wait for concurrent commands to complete.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>wait</code>](#Hub+wait)
**Returns**: <code>Promise</code> - Resolved after the commands are finished. **Returns**: <code>Promise</code> - Resolved after the commands are finished.
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. | | commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. |
<a name="Hub+getHubType"></a>
### boostMoveHub.getHubType() ⇒ [<code>HubType</code>](#HubType)
Get the hub type.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>getHubType</code>](#Hub+getHubType)
<a name="Hub+getPortDeviceType"></a>
### boostMoveHub.getPortDeviceType(port) ⇒ [<code>DeviceType</code>](#DeviceType)
Get the device type for a given port.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>getPortDeviceType</code>](#Hub+getPortDeviceType)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
<a name="LPF2Hub+event_button"></a> <a name="LPF2Hub+event_button"></a>
### "button" (button, state) ### "button" (button, state)
@ -660,10 +725,10 @@ Emits when a button is pressed.
**Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| button | <code>string</code> | | | button | <code>string</code> |
| state | <code>number</code> | A number representing one of the button state consts. | | state | [<code>ButtonState</code>](#ButtonState) |
<a name="LPF2Hub+event_distance"></a> <a name="LPF2Hub+event_distance"></a>
@ -684,10 +749,23 @@ Emits when a color sensor is activated.
**Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
| color | [<code>Color</code>](#Color) |
<a name="LPF2Hub+event_colorAndDistance"></a>
### "colorAndDistance" (port, color, distance)
A combined color and distance event, emits when the sensor is activated.
**Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub)
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> | |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) | |
| distance | <code>number</code> | Distance, in millimeters. |
<a name="LPF2Hub+event_tilt"></a> <a name="LPF2Hub+event_tilt"></a>
@ -720,11 +798,12 @@ Emits when a rotation sensor is activated.
Emits when a motor or sensor is attached to the Hub. Emits when a motor or sensor is attached to the Hub.
**Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>attach</code>](#Hub+event_attach)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> |
| type | <code>number</code> | A number representing one of the peripheral consts. | | type | [<code>DeviceType</code>](#DeviceType) |
<a name="Hub+event_detach"></a> <a name="Hub+event_detach"></a>
@ -732,6 +811,7 @@ Emits when a motor or sensor is attached to the Hub.
Emits when an attached motor or sensor is detached from the Hub. Emits when an attached motor or sensor is detached from the Hub.
**Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>detach</code>](#Hub+event_detach)
| Param | Type | | Param | Type |
| --- | --- | | --- | --- |
@ -762,9 +842,12 @@ Emits when an attached motor or sensor is detached from the Hub.
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code> * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code> * [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code> * [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
* [.getHubType()](#Hub+getHubType) ⇒ [<code>HubType</code>](#HubType)
* [.getPortDeviceType(port)](#Hub+getPortDeviceType) ⇒ [<code>DeviceType</code>](#DeviceType)
* ["button" (button, state)](#LPF2Hub+event_button) * ["button" (button, state)](#LPF2Hub+event_button)
* ["distance" (port, distance)](#LPF2Hub+event_distance) * ["distance" (port, distance)](#LPF2Hub+event_distance)
* ["color" (port, color)](#LPF2Hub+event_color) * ["color" (port, color)](#LPF2Hub+event_color)
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt) * ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
* ["attach" (port, type)](#Hub+event_attach) * ["attach" (port, type)](#Hub+event_attach)
* ["detach" (port)](#Hub+event_detach) * ["detach" (port)](#Hub+event_detach)
@ -789,6 +872,7 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
### pupHub.name ### pupHub.name
**Kind**: instance property of [<code>PUPHub</code>](#PUPHub) **Kind**: instance property of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>name</code>](#Hub+name)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -800,6 +884,7 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
### pupHub.uuid ### pupHub.uuid
**Kind**: instance property of [<code>PUPHub</code>](#PUPHub) **Kind**: instance property of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>uuid</code>](#Hub+uuid)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -811,6 +896,7 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
### pupHub.rssi ### pupHub.rssi
**Kind**: instance property of [<code>PUPHub</code>](#PUPHub) **Kind**: instance property of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>rssi</code>](#Hub+rssi)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -822,6 +908,7 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
### pupHub.batteryLevel ### pupHub.batteryLevel
**Kind**: instance property of [<code>PUPHub</code>](#PUPHub) **Kind**: instance property of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>batteryLevel</code>](#Hub+batteryLevel)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -892,9 +979,9 @@ Set the color of the LED on the Hub via a color value.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="LPF2Hub+setLEDRGB"></a> <a name="LPF2Hub+setLEDRGB"></a>
@ -924,6 +1011,7 @@ Connect to the Hub.
Disconnect the Hub. Disconnect the Hub.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>disconnect</code>](#Hub+disconnect)
**Returns**: <code>Promise</code> - Resolved upon successful disconnect. **Returns**: <code>Promise</code> - Resolved upon successful disconnect.
<a name="Hub+subscribe"></a> <a name="Hub+subscribe"></a>
@ -931,6 +1019,7 @@ Disconnect the Hub.
Subscribe to sensor notifications on a given port. Subscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>subscribe</code>](#Hub+subscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type | Description |
@ -944,6 +1033,7 @@ Subscribe to sensor notifications on a given port.
Unsubscribe to sensor notifications on a given port. Unsubscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>unsubscribe</code>](#Hub+unsubscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | | Param | Type |
@ -958,6 +1048,7 @@ Sleep a given amount of time.
This is a helper method to make it easier to add delays into a chain of commands. This is a helper method to make it easier to add delays into a chain of commands.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>sleep</code>](#Hub+sleep)
**Returns**: <code>Promise</code> - Resolved after the delay is finished. **Returns**: <code>Promise</code> - Resolved after the delay is finished.
| Param | Type | Description | | Param | Type | Description |
@ -972,12 +1063,32 @@ 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. This is a helper method to make it easier to wait for concurrent commands to complete.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>wait</code>](#Hub+wait)
**Returns**: <code>Promise</code> - Resolved after the commands are finished. **Returns**: <code>Promise</code> - Resolved after the commands are finished.
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. | | commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. |
<a name="Hub+getHubType"></a>
### pupHub.getHubType() ⇒ [<code>HubType</code>](#HubType)
Get the hub type.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>getHubType</code>](#Hub+getHubType)
<a name="Hub+getPortDeviceType"></a>
### pupHub.getPortDeviceType(port) ⇒ [<code>DeviceType</code>](#DeviceType)
Get the device type for a given port.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>getPortDeviceType</code>](#Hub+getPortDeviceType)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
<a name="LPF2Hub+event_button"></a> <a name="LPF2Hub+event_button"></a>
### "button" (button, state) ### "button" (button, state)
@ -985,10 +1096,10 @@ Emits when a button is pressed.
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub) **Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| button | <code>string</code> | | | button | <code>string</code> |
| state | <code>number</code> | A number representing one of the button state consts. | | state | [<code>ButtonState</code>](#ButtonState) |
<a name="LPF2Hub+event_distance"></a> <a name="LPF2Hub+event_distance"></a>
@ -1009,10 +1120,23 @@ Emits when a color sensor is activated.
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub) **Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
| color | [<code>Color</code>](#Color) |
<a name="LPF2Hub+event_colorAndDistance"></a>
### "colorAndDistance" (port, color, distance)
A combined color and distance event, emits when the sensor is activated.
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> | |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) | |
| distance | <code>number</code> | Distance, in millimeters. |
<a name="LPF2Hub+event_tilt"></a> <a name="LPF2Hub+event_tilt"></a>
@ -1033,11 +1157,12 @@ Emits when a tilt sensor is activated.
Emits when a motor or sensor is attached to the Hub. Emits when a motor or sensor is attached to the Hub.
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub) **Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>attach</code>](#Hub+event_attach)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> |
| type | <code>number</code> | A number representing one of the peripheral consts. | | type | [<code>DeviceType</code>](#DeviceType) |
<a name="Hub+event_detach"></a> <a name="Hub+event_detach"></a>
@ -1045,6 +1170,7 @@ Emits when a motor or sensor is attached to the Hub.
Emits when an attached motor or sensor is detached from the Hub. Emits when an attached motor or sensor is detached from the Hub.
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub) **Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>detach</code>](#Hub+event_detach)
| Param | Type | | Param | Type |
| --- | --- | | --- | --- |
@ -1072,7 +1198,10 @@ Emits when an attached motor or sensor is detached from the Hub.
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code> * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code> * [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code> * [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
* [.getHubType()](#Hub+getHubType) ⇒ [<code>HubType</code>](#HubType)
* [.getPortDeviceType(port)](#Hub+getPortDeviceType) ⇒ [<code>DeviceType</code>](#DeviceType)
* ["button" (button, state)](#LPF2Hub+event_button) * ["button" (button, state)](#LPF2Hub+event_button)
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
<a name="new_PUPRemote_new"></a> <a name="new_PUPRemote_new"></a>
@ -1094,6 +1223,7 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
### pupRemote.name ### pupRemote.name
**Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>name</code>](#Hub+name)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -1105,6 +1235,7 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
### pupRemote.uuid ### pupRemote.uuid
**Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>uuid</code>](#Hub+uuid)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -1116,6 +1247,7 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
### pupRemote.rssi ### pupRemote.rssi
**Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>rssi</code>](#Hub+rssi)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -1127,6 +1259,7 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
### pupRemote.batteryLevel ### pupRemote.batteryLevel
**Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>batteryLevel</code>](#Hub+batteryLevel)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -1143,9 +1276,9 @@ Set the color of the LED on the Remote via a color value.
**Overrides**: [<code>setLEDColor</code>](#LPF2Hub+setLEDColor) **Overrides**: [<code>setLEDColor</code>](#LPF2Hub+setLEDColor)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="PUPRemote+setLEDRGB"></a> <a name="PUPRemote+setLEDRGB"></a>
@ -1188,6 +1321,7 @@ Connect to the Hub.
Disconnect the Hub. Disconnect the Hub.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>disconnect</code>](#Hub+disconnect)
**Returns**: <code>Promise</code> - Resolved upon successful disconnect. **Returns**: <code>Promise</code> - Resolved upon successful disconnect.
<a name="Hub+subscribe"></a> <a name="Hub+subscribe"></a>
@ -1195,6 +1329,7 @@ Disconnect the Hub.
Subscribe to sensor notifications on a given port. Subscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>subscribe</code>](#Hub+subscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type | Description |
@ -1208,6 +1343,7 @@ Subscribe to sensor notifications on a given port.
Unsubscribe to sensor notifications on a given port. Unsubscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>unsubscribe</code>](#Hub+unsubscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | | Param | Type |
@ -1222,6 +1358,7 @@ Sleep a given amount of time.
This is a helper method to make it easier to add delays into a chain of commands. This is a helper method to make it easier to add delays into a chain of commands.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>sleep</code>](#Hub+sleep)
**Returns**: <code>Promise</code> - Resolved after the delay is finished. **Returns**: <code>Promise</code> - Resolved after the delay is finished.
| Param | Type | Description | | Param | Type | Description |
@ -1236,12 +1373,32 @@ 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. This is a helper method to make it easier to wait for concurrent commands to complete.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>wait</code>](#Hub+wait)
**Returns**: <code>Promise</code> - Resolved after the commands are finished. **Returns**: <code>Promise</code> - Resolved after the commands are finished.
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. | | commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. |
<a name="Hub+getHubType"></a>
### pupRemote.getHubType() ⇒ [<code>HubType</code>](#HubType)
Get the hub type.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>getHubType</code>](#Hub+getHubType)
<a name="Hub+getPortDeviceType"></a>
### pupRemote.getPortDeviceType(port) ⇒ [<code>DeviceType</code>](#DeviceType)
Get the device type for a given port.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>getPortDeviceType</code>](#Hub+getPortDeviceType)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
<a name="LPF2Hub+event_button"></a> <a name="LPF2Hub+event_button"></a>
### "button" (button, state) ### "button" (button, state)
@ -1249,10 +1406,23 @@ Emits when a button is pressed.
**Kind**: event emitted by [<code>PUPRemote</code>](#PUPRemote) **Kind**: event emitted by [<code>PUPRemote</code>](#PUPRemote)
| Param | Type |
| --- | --- |
| button | <code>string</code> |
| state | [<code>ButtonState</code>](#ButtonState) |
<a name="LPF2Hub+event_colorAndDistance"></a>
### "colorAndDistance" (port, color, distance)
A combined color and distance event, emits when the sensor is activated.
**Kind**: event emitted by [<code>PUPRemote</code>](#PUPRemote)
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| button | <code>string</code> | | | port | <code>string</code> | |
| state | <code>number</code> | A number representing one of the button state consts. | | color | [<code>Color</code>](#Color) | |
| distance | <code>number</code> | Distance, in millimeters. |
<a name="DuploTrainBase"></a> <a name="DuploTrainBase"></a>
@ -1279,7 +1449,10 @@ Emits when a button is pressed.
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code> * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code> * [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code> * [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
* [.getHubType()](#Hub+getHubType) ⇒ [<code>HubType</code>](#HubType)
* [.getPortDeviceType(port)](#Hub+getPortDeviceType) ⇒ [<code>DeviceType</code>](#DeviceType)
* ["color" (port, color)](#LPF2Hub+event_color) * ["color" (port, color)](#LPF2Hub+event_color)
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
* ["speed" (port, speed)](#LPF2Hub+event_speed) * ["speed" (port, speed)](#LPF2Hub+event_speed)
<a name="new_DuploTrainBase_new"></a> <a name="new_DuploTrainBase_new"></a>
@ -1355,9 +1528,9 @@ Set the color of the LED on the train via a color value.
**Overrides**: [<code>setLEDColor</code>](#LPF2Hub+setLEDColor) **Overrides**: [<code>setLEDColor</code>](#LPF2Hub+setLEDColor)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="DuploTrainBase+setMotorSpeed"></a> <a name="DuploTrainBase+setMotorSpeed"></a>
@ -1381,9 +1554,9 @@ Play a built-in train sound.
**Kind**: instance method of [<code>DuploTrainBase</code>](#DuploTrainBase) **Kind**: instance method of [<code>DuploTrainBase</code>](#DuploTrainBase)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| sound | <code>number</code> | A number representing one of the Train Base sound consts. | | sound | [<code>DuploTrainBaseSound</code>](#DuploTrainBaseSound) |
<a name="DuploTrainBase+rampMotorSpeed"></a> <a name="DuploTrainBase+rampMotorSpeed"></a>
@ -1499,6 +1672,25 @@ This is a helper method to make it easier to wait for concurrent commands to com
| --- | --- | --- | | --- | --- | --- |
| commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. | | commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. |
<a name="Hub+getHubType"></a>
### duploTrainBase.getHubType() ⇒ [<code>HubType</code>](#HubType)
Get the hub type.
**Kind**: instance method of [<code>DuploTrainBase</code>](#DuploTrainBase)
**Overrides**: [<code>getHubType</code>](#Hub+getHubType)
<a name="Hub+getPortDeviceType"></a>
### duploTrainBase.getPortDeviceType(port) ⇒ [<code>DeviceType</code>](#DeviceType)
Get the device type for a given port.
**Kind**: instance method of [<code>DuploTrainBase</code>](#DuploTrainBase)
**Overrides**: [<code>getPortDeviceType</code>](#Hub+getPortDeviceType)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
<a name="LPF2Hub+event_color"></a> <a name="LPF2Hub+event_color"></a>
### "color" (port, color) ### "color" (port, color)
@ -1506,10 +1698,23 @@ Emits when a color sensor is activated.
**Kind**: event emitted by [<code>DuploTrainBase</code>](#DuploTrainBase) **Kind**: event emitted by [<code>DuploTrainBase</code>](#DuploTrainBase)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
| color | [<code>Color</code>](#Color) |
<a name="LPF2Hub+event_colorAndDistance"></a>
### "colorAndDistance" (port, color, distance)
A combined color and distance event, emits when the sensor is activated.
**Kind**: event emitted by [<code>DuploTrainBase</code>](#DuploTrainBase)
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> | |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) | |
| distance | <code>number</code> | Distance, in millimeters. |
<a name="LPF2Hub+event_speed"></a> <a name="LPF2Hub+event_speed"></a>
@ -1523,3 +1728,92 @@ Emits on a speed change.
| port | <code>string</code> | | port | <code>string</code> |
| speed | <code>number</code> | | speed | <code>number</code> |
<a name="HubType"></a>
## HubType
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| UNKNOWN | <code>number</code> | 0 |
| WEDO2_SMART_HUB | <code>number</code> | 1 |
| BOOST_MOVE_HUB | <code>number</code> | 2 |
| POWERED_UP_HUB | <code>number</code> | 3 |
| POWERED_UP_REMOTE | <code>number</code> | 4 |
| DUPLO_TRAIN_HUB | <code>number</code> | 5 |
<a name="DeviceType"></a>
## DeviceType
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| UNKNOWN | <code>number</code> | 0 |
| BASIC_MOTOR | <code>number</code> | 1 |
| TRAIN_MOTOR | <code>number</code> | 2 |
| LED_LIGHTS | <code>number</code> | 8 |
| BOOST_LED | <code>number</code> | 22 |
| WEDO2_TILT | <code>number</code> | 34 |
| WEDO2_DISTANCE | <code>number</code> | 35 |
| BOOST_DISTANCE | <code>number</code> | 37 |
| BOOST_TACHO_MOTOR | <code>number</code> | 38 |
| BOOST_MOVE_HUB_MOTOR | <code>number</code> | 39 |
| BOOST_TILT | <code>number</code> | 40 |
| DUPLO_TRAIN_BASE_MOTOR | <code>number</code> | 41 |
| DUPLO_TRAIN_BASE_SPEAKER | <code>number</code> | 42 |
| DUPLO_TRAIN_BASE_COLOR | <code>number</code> | 43 |
| DUPLO_TRAIN_BASE_SPEEDOMETER | <code>number</code> | 44 |
| POWERED_UP_REMOTE_BUTTON | <code>number</code> | 55 |
<a name="Color"></a>
## Color
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| BLACK | <code>number</code> | 0 |
| PINK | <code>number</code> | 1 |
| PURPLE | <code>number</code> | 2 |
| BLUE | <code>number</code> | 3 |
| LIGHT_BLUE | <code>number</code> | 4 |
| CYAN | <code>number</code> | 5 |
| GREEN | <code>number</code> | 6 |
| YELLOW | <code>number</code> | 7 |
| ORANGE | <code>number</code> | 8 |
| RED | <code>number</code> | 9 |
| WHITE | <code>number</code> | 10 |
| NONE | <code>number</code> | 255 |
<a name="ButtonState"></a>
## ButtonState
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| PRESSED | <code>number</code> | 0 |
| RELEASED | <code>number</code> | 1 |
| UP | <code>number</code> | 2 |
| DOWN | <code>number</code> | 3 |
| STOP | <code>number</code> | 4 |
<a name="DuploTrainBaseSound"></a>
## DuploTrainBaseSound
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| BRAKE | <code>number</code> | 3 |
| STATION_DEPARTURE | <code>number</code> | 5 |
| WATER_REFILL | <code>number</code> | 7 |
| HORN | <code>number</code> | 9 |
| STEAM | <code>number</code> | 10 |

428
README.md
View File

@ -1,3 +1,7 @@
[![CircleCI](https://circleci.com/gh/nathankellenicki/node-poweredup.svg?style=shield)](https://circleci.com/gh/nathankellenicki/node-poweredup)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/node-poweredup?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
![NPM Version](https://img.shields.io/npm/v/node-poweredup.svg?style=flat)
# **node-poweredup** - A Node.js module to interface with LEGO Powered UP components. # **node-poweredup** - A Node.js module to interface with LEGO Powered UP components.
### Introduction ### Introduction
@ -28,15 +32,25 @@ 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. 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.
| Name | Type | WeDo 2.0 Smart Hub | Boost Move Hub | Powered UP Hub | Availability | | Device Name | Product Code | Type | WeDo 2.0 Smart Hub | Boost Move Hub | Powered UP Hub | Availability |
| ------------------------------- | ------------- | ------------------ | -------------- | -------------- | ------------ | | ------------------------------- | ------------ | ------------- | ------------------ | -------------- | -------------- | ------------ |
| WeDo 2.0 Tilt Sensor | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> | | WeDo 2.0 Tilt Sensor | <a href="https://brickset.com/sets/45305-1/">45305</a> | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| WeDo 2.0 Motion Sensor | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> | | WeDo 2.0 Motion Sensor | <a href="https://brickset.com/sets/45304-1/">45304</a> | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| WeDo 2.0 Medium Motor | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a> | | WeDo 2.0 Medium Motor | <a href="https://brickset.com/sets/45303-1/">45303</a> | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a> |
| Boost Color and Distance Sensor | Sensor | *Partial* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> | | Boost Color and Distance Sensor | <a href="https://brickset.com/sets/88007-1/">88007</a> | Sensor | *Partial* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Boost Tacho Motor | Motor/Sensor | *Partial* | Yes | *Partial* | <a href="https://brickset.com/sets/17101-1/">17101</a> | | Boost Tacho Motor | <a href="https://brickset.com/sets/88008-1/">88008</a> | Motor/Sensor | *Partial* | Yes | *Partial* | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Powered UP Train Motor | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> | | Powered UP Train Motor | <a href="https://brickset.com/sets/88011-1/">88011</a> | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
| Powered UP LED Lights | Light | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> | | Powered UP LED Lights | <a href="https://brickset.com/sets/88005-1/">88005</a> | Light | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> |
In addition, the Hubs themselves have certain built-in features which this library exposes.
| Hub Name | Product Code | Built-In Features | Availability |
| ------------------ | ------------ | ---------------------- | ------------ |
| WeDo 2.0 Smart hub | <a href="https://brickset.com/sets/45301-1/">45301</a> | RGB LED<br />Piezo Buzzer<br />Button | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| Boost Move Hub | <a href="https://brickset.com/sets/88006-1/">88006</a> | RGB LED<br />Tilt Sensor<br />2x Tacho Motors<br />Button | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Powered UP Hub | <a href="https://brickset.com/sets/88009-1/">88009</a> | RGB LED<br />Button | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a><br /><a href="https://brickset.com/sets/76112-1/">76112</a> |
| Powered UP Remote | <a href="https://brickset.com/sets/88010-1/">88010</a> | RGB LED<br />Left and Right Control Buttons<br />Button | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
| Duplo Train Base | 28743 | RGB LED/Headlights<br />Speaker<br />Speedometer<br />Motor<br />Color and Distance Sensor<br />Button | <a href="https://brickset.com/sets/10874-1/">10874</a><br /><a href="https://brickset.com/sets/10875-1/">10875</a> |
### Known Issues and Limitations ### Known Issues and Limitations
@ -94,6 +108,21 @@ Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian R
<dd></dd> <dd></dd>
</dl> </dl>
## Typedefs
<dl>
<dt><a href="#HubType">HubType</a></dt>
<dd></dd>
<dt><a href="#DeviceType">DeviceType</a></dt>
<dd></dd>
<dt><a href="#Color">Color</a></dt>
<dd></dd>
<dt><a href="#ButtonState">ButtonState</a></dt>
<dd></dd>
<dt><a href="#DuploTrainBaseSound">DuploTrainBaseSound</a></dt>
<dd></dd>
</dl>
<a name="PoweredUP"></a> <a name="PoweredUP"></a>
## PoweredUP ⇐ <code>EventEmitter</code> ## PoweredUP ⇐ <code>EventEmitter</code>
@ -172,6 +201,8 @@ Emits when a Powered UP Hub device is found.
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code> * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code> * [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code> * [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
* [.getHubType()](#Hub+getHubType) ⇒ [<code>HubType</code>](#HubType)
* [.getPortDeviceType(port)](#Hub+getPortDeviceType) ⇒ [<code>DeviceType</code>](#DeviceType)
* ["button" (button, state)](#WeDo2SmartHub+event_button) * ["button" (button, state)](#WeDo2SmartHub+event_button)
* ["distance" (port, distance)](#WeDo2SmartHub+event_distance) * ["distance" (port, distance)](#WeDo2SmartHub+event_distance)
* ["color" (port, color)](#WeDo2SmartHub+event_color) * ["color" (port, color)](#WeDo2SmartHub+event_color)
@ -249,9 +280,9 @@ Set the color of the LED on the Hub via a color value.
**Kind**: instance method of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub) **Kind**: instance method of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="WeDo2SmartHub+setLEDRGB"></a> <a name="WeDo2SmartHub+setLEDRGB"></a>
@ -391,6 +422,23 @@ This is a helper method to make it easier to wait for concurrent commands to com
| --- | --- | --- | | --- | --- | --- |
| commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. | | commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. |
<a name="Hub+getHubType"></a>
### weDo2SmartHub.getHubType() ⇒ [<code>HubType</code>](#HubType)
Get the hub type.
**Kind**: instance method of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
<a name="Hub+getPortDeviceType"></a>
### weDo2SmartHub.getPortDeviceType(port) ⇒ [<code>DeviceType</code>](#DeviceType)
Get the device type for a given port.
**Kind**: instance method of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
<a name="WeDo2SmartHub+event_button"></a> <a name="WeDo2SmartHub+event_button"></a>
### "button" (button, state) ### "button" (button, state)
@ -398,10 +446,10 @@ Emits when a button is pressed.
**Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub) **Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| button | <code>string</code> | | | button | <code>string</code> |
| state | <code>number</code> | A number representing one of the button state consts. | | state | [<code>ButtonState</code>](#ButtonState) |
<a name="WeDo2SmartHub+event_distance"></a> <a name="WeDo2SmartHub+event_distance"></a>
@ -422,10 +470,10 @@ Emits when a color sensor is activated.
**Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub) **Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="WeDo2SmartHub+event_tilt"></a> <a name="WeDo2SmartHub+event_tilt"></a>
@ -459,10 +507,10 @@ Emits when a motor or sensor is attached to the Hub.
**Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub) **Kind**: event emitted by [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> |
| type | <code>number</code> | A number representing one of the peripheral consts. | | type | [<code>DeviceType</code>](#DeviceType) |
<a name="Hub+event_detach"></a> <a name="Hub+event_detach"></a>
@ -501,9 +549,12 @@ Emits when an attached motor or sensor is detached from the Hub.
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code> * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code> * [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code> * [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
* [.getHubType()](#Hub+getHubType) ⇒ [<code>HubType</code>](#HubType)
* [.getPortDeviceType(port)](#Hub+getPortDeviceType) ⇒ [<code>DeviceType</code>](#DeviceType)
* ["button" (button, state)](#LPF2Hub+event_button) * ["button" (button, state)](#LPF2Hub+event_button)
* ["distance" (port, distance)](#LPF2Hub+event_distance) * ["distance" (port, distance)](#LPF2Hub+event_distance)
* ["color" (port, color)](#LPF2Hub+event_color) * ["color" (port, color)](#LPF2Hub+event_color)
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt) * ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
* ["rotate" (port, rotation)](#LPF2Hub+event_rotate) * ["rotate" (port, rotation)](#LPF2Hub+event_rotate)
* ["attach" (port, type)](#Hub+event_attach) * ["attach" (port, type)](#Hub+event_attach)
@ -529,6 +580,7 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
### boostMoveHub.name ### boostMoveHub.name
**Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>name</code>](#Hub+name)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -540,6 +592,7 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
### boostMoveHub.uuid ### boostMoveHub.uuid
**Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>uuid</code>](#Hub+uuid)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -551,6 +604,7 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
### boostMoveHub.rssi ### boostMoveHub.rssi
**Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>rssi</code>](#Hub+rssi)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -562,6 +616,7 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
### boostMoveHub.batteryLevel ### boostMoveHub.batteryLevel
**Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance property of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>batteryLevel</code>](#Hub+batteryLevel)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -646,9 +701,9 @@ Set the color of the LED on the Hub via a color value.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="LPF2Hub+setLEDRGB"></a> <a name="LPF2Hub+setLEDRGB"></a>
@ -678,6 +733,7 @@ Connect to the Hub.
Disconnect the Hub. Disconnect the Hub.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>disconnect</code>](#Hub+disconnect)
**Returns**: <code>Promise</code> - Resolved upon successful disconnect. **Returns**: <code>Promise</code> - Resolved upon successful disconnect.
<a name="Hub+subscribe"></a> <a name="Hub+subscribe"></a>
@ -685,6 +741,7 @@ Disconnect the Hub.
Subscribe to sensor notifications on a given port. Subscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>subscribe</code>](#Hub+subscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type | Description |
@ -698,6 +755,7 @@ Subscribe to sensor notifications on a given port.
Unsubscribe to sensor notifications on a given port. Unsubscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>unsubscribe</code>](#Hub+unsubscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | | Param | Type |
@ -712,6 +770,7 @@ Sleep a given amount of time.
This is a helper method to make it easier to add delays into a chain of commands. This is a helper method to make it easier to add delays into a chain of commands.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>sleep</code>](#Hub+sleep)
**Returns**: <code>Promise</code> - Resolved after the delay is finished. **Returns**: <code>Promise</code> - Resolved after the delay is finished.
| Param | Type | Description | | Param | Type | Description |
@ -726,12 +785,32 @@ 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. This is a helper method to make it easier to wait for concurrent commands to complete.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>wait</code>](#Hub+wait)
**Returns**: <code>Promise</code> - Resolved after the commands are finished. **Returns**: <code>Promise</code> - Resolved after the commands are finished.
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. | | commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. |
<a name="Hub+getHubType"></a>
### boostMoveHub.getHubType() ⇒ [<code>HubType</code>](#HubType)
Get the hub type.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>getHubType</code>](#Hub+getHubType)
<a name="Hub+getPortDeviceType"></a>
### boostMoveHub.getPortDeviceType(port) ⇒ [<code>DeviceType</code>](#DeviceType)
Get the device type for a given port.
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>getPortDeviceType</code>](#Hub+getPortDeviceType)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
<a name="LPF2Hub+event_button"></a> <a name="LPF2Hub+event_button"></a>
### "button" (button, state) ### "button" (button, state)
@ -739,10 +818,10 @@ Emits when a button is pressed.
**Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| button | <code>string</code> | | | button | <code>string</code> |
| state | <code>number</code> | A number representing one of the button state consts. | | state | [<code>ButtonState</code>](#ButtonState) |
<a name="LPF2Hub+event_distance"></a> <a name="LPF2Hub+event_distance"></a>
@ -763,10 +842,23 @@ Emits when a color sensor is activated.
**Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
| color | [<code>Color</code>](#Color) |
<a name="LPF2Hub+event_colorAndDistance"></a>
### "colorAndDistance" (port, color, distance)
A combined color and distance event, emits when the sensor is activated.
**Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub)
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> | |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) | |
| distance | <code>number</code> | Distance, in millimeters. |
<a name="LPF2Hub+event_tilt"></a> <a name="LPF2Hub+event_tilt"></a>
@ -799,11 +891,12 @@ Emits when a rotation sensor is activated.
Emits when a motor or sensor is attached to the Hub. Emits when a motor or sensor is attached to the Hub.
**Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>attach</code>](#Hub+event_attach)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> |
| type | <code>number</code> | A number representing one of the peripheral consts. | | type | [<code>DeviceType</code>](#DeviceType) |
<a name="Hub+event_detach"></a> <a name="Hub+event_detach"></a>
@ -811,6 +904,7 @@ Emits when a motor or sensor is attached to the Hub.
Emits when an attached motor or sensor is detached from the Hub. Emits when an attached motor or sensor is detached from the Hub.
**Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub) **Kind**: event emitted by [<code>BoostMoveHub</code>](#BoostMoveHub)
**Overrides**: [<code>detach</code>](#Hub+event_detach)
| Param | Type | | Param | Type |
| --- | --- | | --- | --- |
@ -841,9 +935,12 @@ Emits when an attached motor or sensor is detached from the Hub.
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code> * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code> * [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code> * [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
* [.getHubType()](#Hub+getHubType) ⇒ [<code>HubType</code>](#HubType)
* [.getPortDeviceType(port)](#Hub+getPortDeviceType) ⇒ [<code>DeviceType</code>](#DeviceType)
* ["button" (button, state)](#LPF2Hub+event_button) * ["button" (button, state)](#LPF2Hub+event_button)
* ["distance" (port, distance)](#LPF2Hub+event_distance) * ["distance" (port, distance)](#LPF2Hub+event_distance)
* ["color" (port, color)](#LPF2Hub+event_color) * ["color" (port, color)](#LPF2Hub+event_color)
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
* ["tilt" (port, x, y)](#LPF2Hub+event_tilt) * ["tilt" (port, x, y)](#LPF2Hub+event_tilt)
* ["attach" (port, type)](#Hub+event_attach) * ["attach" (port, type)](#Hub+event_attach)
* ["detach" (port)](#Hub+event_detach) * ["detach" (port)](#Hub+event_detach)
@ -868,6 +965,7 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
### pupHub.name ### pupHub.name
**Kind**: instance property of [<code>PUPHub</code>](#PUPHub) **Kind**: instance property of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>name</code>](#Hub+name)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -879,6 +977,7 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
### pupHub.uuid ### pupHub.uuid
**Kind**: instance property of [<code>PUPHub</code>](#PUPHub) **Kind**: instance property of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>uuid</code>](#Hub+uuid)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -890,6 +989,7 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
### pupHub.rssi ### pupHub.rssi
**Kind**: instance property of [<code>PUPHub</code>](#PUPHub) **Kind**: instance property of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>rssi</code>](#Hub+rssi)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -901,6 +1001,7 @@ The PUPHub is emitted if the discovered device is a Powered UP Hub.
### pupHub.batteryLevel ### pupHub.batteryLevel
**Kind**: instance property of [<code>PUPHub</code>](#PUPHub) **Kind**: instance property of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>batteryLevel</code>](#Hub+batteryLevel)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -971,9 +1072,9 @@ Set the color of the LED on the Hub via a color value.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="LPF2Hub+setLEDRGB"></a> <a name="LPF2Hub+setLEDRGB"></a>
@ -1003,6 +1104,7 @@ Connect to the Hub.
Disconnect the Hub. Disconnect the Hub.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>disconnect</code>](#Hub+disconnect)
**Returns**: <code>Promise</code> - Resolved upon successful disconnect. **Returns**: <code>Promise</code> - Resolved upon successful disconnect.
<a name="Hub+subscribe"></a> <a name="Hub+subscribe"></a>
@ -1010,6 +1112,7 @@ Disconnect the Hub.
Subscribe to sensor notifications on a given port. Subscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>subscribe</code>](#Hub+subscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type | Description |
@ -1023,6 +1126,7 @@ Subscribe to sensor notifications on a given port.
Unsubscribe to sensor notifications on a given port. Unsubscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>unsubscribe</code>](#Hub+unsubscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | | Param | Type |
@ -1037,6 +1141,7 @@ Sleep a given amount of time.
This is a helper method to make it easier to add delays into a chain of commands. This is a helper method to make it easier to add delays into a chain of commands.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>sleep</code>](#Hub+sleep)
**Returns**: <code>Promise</code> - Resolved after the delay is finished. **Returns**: <code>Promise</code> - Resolved after the delay is finished.
| Param | Type | Description | | Param | Type | Description |
@ -1051,12 +1156,32 @@ 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. This is a helper method to make it easier to wait for concurrent commands to complete.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub) **Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>wait</code>](#Hub+wait)
**Returns**: <code>Promise</code> - Resolved after the commands are finished. **Returns**: <code>Promise</code> - Resolved after the commands are finished.
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. | | commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. |
<a name="Hub+getHubType"></a>
### pupHub.getHubType() ⇒ [<code>HubType</code>](#HubType)
Get the hub type.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>getHubType</code>](#Hub+getHubType)
<a name="Hub+getPortDeviceType"></a>
### pupHub.getPortDeviceType(port) ⇒ [<code>DeviceType</code>](#DeviceType)
Get the device type for a given port.
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>getPortDeviceType</code>](#Hub+getPortDeviceType)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
<a name="LPF2Hub+event_button"></a> <a name="LPF2Hub+event_button"></a>
### "button" (button, state) ### "button" (button, state)
@ -1064,10 +1189,10 @@ Emits when a button is pressed.
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub) **Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| button | <code>string</code> | | | button | <code>string</code> |
| state | <code>number</code> | A number representing one of the button state consts. | | state | [<code>ButtonState</code>](#ButtonState) |
<a name="LPF2Hub+event_distance"></a> <a name="LPF2Hub+event_distance"></a>
@ -1088,10 +1213,23 @@ Emits when a color sensor is activated.
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub) **Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
| color | [<code>Color</code>](#Color) |
<a name="LPF2Hub+event_colorAndDistance"></a>
### "colorAndDistance" (port, color, distance)
A combined color and distance event, emits when the sensor is activated.
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> | |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) | |
| distance | <code>number</code> | Distance, in millimeters. |
<a name="LPF2Hub+event_tilt"></a> <a name="LPF2Hub+event_tilt"></a>
@ -1112,11 +1250,12 @@ Emits when a tilt sensor is activated.
Emits when a motor or sensor is attached to the Hub. Emits when a motor or sensor is attached to the Hub.
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub) **Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>attach</code>](#Hub+event_attach)
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> |
| type | <code>number</code> | A number representing one of the peripheral consts. | | type | [<code>DeviceType</code>](#DeviceType) |
<a name="Hub+event_detach"></a> <a name="Hub+event_detach"></a>
@ -1124,6 +1263,7 @@ Emits when a motor or sensor is attached to the Hub.
Emits when an attached motor or sensor is detached from the Hub. Emits when an attached motor or sensor is detached from the Hub.
**Kind**: event emitted by [<code>PUPHub</code>](#PUPHub) **Kind**: event emitted by [<code>PUPHub</code>](#PUPHub)
**Overrides**: [<code>detach</code>](#Hub+event_detach)
| Param | Type | | Param | Type |
| --- | --- | | --- | --- |
@ -1151,7 +1291,10 @@ Emits when an attached motor or sensor is detached from the Hub.
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code> * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code> * [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code> * [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
* [.getHubType()](#Hub+getHubType) ⇒ [<code>HubType</code>](#HubType)
* [.getPortDeviceType(port)](#Hub+getPortDeviceType) ⇒ [<code>DeviceType</code>](#DeviceType)
* ["button" (button, state)](#LPF2Hub+event_button) * ["button" (button, state)](#LPF2Hub+event_button)
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
<a name="new_PUPRemote_new"></a> <a name="new_PUPRemote_new"></a>
@ -1173,6 +1316,7 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
### pupRemote.name ### pupRemote.name
**Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>name</code>](#Hub+name)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -1184,6 +1328,7 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
### pupRemote.uuid ### pupRemote.uuid
**Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>uuid</code>](#Hub+uuid)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -1195,6 +1340,7 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
### pupRemote.rssi ### pupRemote.rssi
**Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>rssi</code>](#Hub+rssi)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -1206,6 +1352,7 @@ The PUPRemote is emitted if the discovered device is a Powered UP Remote.
### pupRemote.batteryLevel ### pupRemote.batteryLevel
**Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance property of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>batteryLevel</code>](#Hub+batteryLevel)
**Read only**: true **Read only**: true
**Properties** **Properties**
@ -1222,9 +1369,9 @@ Set the color of the LED on the Remote via a color value.
**Overrides**: [<code>setLEDColor</code>](#LPF2Hub+setLEDColor) **Overrides**: [<code>setLEDColor</code>](#LPF2Hub+setLEDColor)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="PUPRemote+setLEDRGB"></a> <a name="PUPRemote+setLEDRGB"></a>
@ -1267,6 +1414,7 @@ Connect to the Hub.
Disconnect the Hub. Disconnect the Hub.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>disconnect</code>](#Hub+disconnect)
**Returns**: <code>Promise</code> - Resolved upon successful disconnect. **Returns**: <code>Promise</code> - Resolved upon successful disconnect.
<a name="Hub+subscribe"></a> <a name="Hub+subscribe"></a>
@ -1274,6 +1422,7 @@ Disconnect the Hub.
Subscribe to sensor notifications on a given port. Subscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>subscribe</code>](#Hub+subscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type | Description |
@ -1287,6 +1436,7 @@ Subscribe to sensor notifications on a given port.
Unsubscribe to sensor notifications on a given port. Unsubscribe to sensor notifications on a given port.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>unsubscribe</code>](#Hub+unsubscribe)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | | Param | Type |
@ -1301,6 +1451,7 @@ Sleep a given amount of time.
This is a helper method to make it easier to add delays into a chain of commands. This is a helper method to make it easier to add delays into a chain of commands.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>sleep</code>](#Hub+sleep)
**Returns**: <code>Promise</code> - Resolved after the delay is finished. **Returns**: <code>Promise</code> - Resolved after the delay is finished.
| Param | Type | Description | | Param | Type | Description |
@ -1315,12 +1466,32 @@ 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. This is a helper method to make it easier to wait for concurrent commands to complete.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote) **Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>wait</code>](#Hub+wait)
**Returns**: <code>Promise</code> - Resolved after the commands are finished. **Returns**: <code>Promise</code> - Resolved after the commands are finished.
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. | | commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. |
<a name="Hub+getHubType"></a>
### pupRemote.getHubType() ⇒ [<code>HubType</code>](#HubType)
Get the hub type.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>getHubType</code>](#Hub+getHubType)
<a name="Hub+getPortDeviceType"></a>
### pupRemote.getPortDeviceType(port) ⇒ [<code>DeviceType</code>](#DeviceType)
Get the device type for a given port.
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
**Overrides**: [<code>getPortDeviceType</code>](#Hub+getPortDeviceType)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
<a name="LPF2Hub+event_button"></a> <a name="LPF2Hub+event_button"></a>
### "button" (button, state) ### "button" (button, state)
@ -1328,10 +1499,23 @@ Emits when a button is pressed.
**Kind**: event emitted by [<code>PUPRemote</code>](#PUPRemote) **Kind**: event emitted by [<code>PUPRemote</code>](#PUPRemote)
| Param | Type |
| --- | --- |
| button | <code>string</code> |
| state | [<code>ButtonState</code>](#ButtonState) |
<a name="LPF2Hub+event_colorAndDistance"></a>
### "colorAndDistance" (port, color, distance)
A combined color and distance event, emits when the sensor is activated.
**Kind**: event emitted by [<code>PUPRemote</code>](#PUPRemote)
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| button | <code>string</code> | | | port | <code>string</code> | |
| state | <code>number</code> | A number representing one of the button state consts. | | color | [<code>Color</code>](#Color) | |
| distance | <code>number</code> | Distance, in millimeters. |
<a name="DuploTrainBase"></a> <a name="DuploTrainBase"></a>
@ -1358,7 +1542,10 @@ Emits when a button is pressed.
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code> * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
* [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code> * [.sleep(delay)](#Hub+sleep) ⇒ <code>Promise</code>
* [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code> * [.wait(commands)](#Hub+wait) ⇒ <code>Promise</code>
* [.getHubType()](#Hub+getHubType) ⇒ [<code>HubType</code>](#HubType)
* [.getPortDeviceType(port)](#Hub+getPortDeviceType) ⇒ [<code>DeviceType</code>](#DeviceType)
* ["color" (port, color)](#LPF2Hub+event_color) * ["color" (port, color)](#LPF2Hub+event_color)
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
* ["speed" (port, speed)](#LPF2Hub+event_speed) * ["speed" (port, speed)](#LPF2Hub+event_speed)
<a name="new_DuploTrainBase_new"></a> <a name="new_DuploTrainBase_new"></a>
@ -1434,9 +1621,9 @@ Set the color of the LED on the train via a color value.
**Overrides**: [<code>setLEDColor</code>](#LPF2Hub+setLEDColor) **Overrides**: [<code>setLEDColor</code>](#LPF2Hub+setLEDColor)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) |
<a name="DuploTrainBase+setMotorSpeed"></a> <a name="DuploTrainBase+setMotorSpeed"></a>
@ -1460,9 +1647,9 @@ Play a built-in train sound.
**Kind**: instance method of [<code>DuploTrainBase</code>](#DuploTrainBase) **Kind**: instance method of [<code>DuploTrainBase</code>](#DuploTrainBase)
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command. **Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
| Param | Type | Description | | Param | Type |
| --- | --- | --- | | --- | --- |
| sound | <code>number</code> | A number representing one of the Train Base sound consts. | | sound | [<code>DuploTrainBaseSound</code>](#DuploTrainBaseSound) |
<a name="DuploTrainBase+rampMotorSpeed"></a> <a name="DuploTrainBase+rampMotorSpeed"></a>
@ -1578,6 +1765,25 @@ This is a helper method to make it easier to wait for concurrent commands to com
| --- | --- | --- | | --- | --- | --- |
| commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. | | commands | <code>Array.&lt;Promise.&lt;any&gt;&gt;</code> | Array of executing commands. |
<a name="Hub+getHubType"></a>
### duploTrainBase.getHubType() ⇒ [<code>HubType</code>](#HubType)
Get the hub type.
**Kind**: instance method of [<code>DuploTrainBase</code>](#DuploTrainBase)
**Overrides**: [<code>getHubType</code>](#Hub+getHubType)
<a name="Hub+getPortDeviceType"></a>
### duploTrainBase.getPortDeviceType(port) ⇒ [<code>DeviceType</code>](#DeviceType)
Get the device type for a given port.
**Kind**: instance method of [<code>DuploTrainBase</code>](#DuploTrainBase)
**Overrides**: [<code>getPortDeviceType</code>](#Hub+getPortDeviceType)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
<a name="LPF2Hub+event_color"></a> <a name="LPF2Hub+event_color"></a>
### "color" (port, color) ### "color" (port, color)
@ -1585,10 +1791,23 @@ Emits when a color sensor is activated.
**Kind**: event emitted by [<code>DuploTrainBase</code>](#DuploTrainBase) **Kind**: event emitted by [<code>DuploTrainBase</code>](#DuploTrainBase)
| Param | Type |
| --- | --- |
| port | <code>string</code> |
| color | [<code>Color</code>](#Color) |
<a name="LPF2Hub+event_colorAndDistance"></a>
### "colorAndDistance" (port, color, distance)
A combined color and distance event, emits when the sensor is activated.
**Kind**: event emitted by [<code>DuploTrainBase</code>](#DuploTrainBase)
| Param | Type | Description | | Param | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| port | <code>string</code> | | | port | <code>string</code> | |
| color | <code>number</code> | A number representing one of the LED color consts. | | color | [<code>Color</code>](#Color) | |
| distance | <code>number</code> | Distance, in millimeters. |
<a name="LPF2Hub+event_speed"></a> <a name="LPF2Hub+event_speed"></a>
@ -1602,3 +1821,92 @@ Emits on a speed change.
| port | <code>string</code> | | port | <code>string</code> |
| speed | <code>number</code> | | speed | <code>number</code> |
<a name="HubType"></a>
## HubType
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| UNKNOWN | <code>number</code> | 0 |
| WEDO2_SMART_HUB | <code>number</code> | 1 |
| BOOST_MOVE_HUB | <code>number</code> | 2 |
| POWERED_UP_HUB | <code>number</code> | 3 |
| POWERED_UP_REMOTE | <code>number</code> | 4 |
| DUPLO_TRAIN_HUB | <code>number</code> | 5 |
<a name="DeviceType"></a>
## DeviceType
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| UNKNOWN | <code>number</code> | 0 |
| BASIC_MOTOR | <code>number</code> | 1 |
| TRAIN_MOTOR | <code>number</code> | 2 |
| LED_LIGHTS | <code>number</code> | 8 |
| BOOST_LED | <code>number</code> | 22 |
| WEDO2_TILT | <code>number</code> | 34 |
| WEDO2_DISTANCE | <code>number</code> | 35 |
| BOOST_DISTANCE | <code>number</code> | 37 |
| BOOST_TACHO_MOTOR | <code>number</code> | 38 |
| BOOST_MOVE_HUB_MOTOR | <code>number</code> | 39 |
| BOOST_TILT | <code>number</code> | 40 |
| DUPLO_TRAIN_BASE_MOTOR | <code>number</code> | 41 |
| DUPLO_TRAIN_BASE_SPEAKER | <code>number</code> | 42 |
| DUPLO_TRAIN_BASE_COLOR | <code>number</code> | 43 |
| DUPLO_TRAIN_BASE_SPEEDOMETER | <code>number</code> | 44 |
| POWERED_UP_REMOTE_BUTTON | <code>number</code> | 55 |
<a name="Color"></a>
## Color
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| BLACK | <code>number</code> | 0 |
| PINK | <code>number</code> | 1 |
| PURPLE | <code>number</code> | 2 |
| BLUE | <code>number</code> | 3 |
| LIGHT_BLUE | <code>number</code> | 4 |
| CYAN | <code>number</code> | 5 |
| GREEN | <code>number</code> | 6 |
| YELLOW | <code>number</code> | 7 |
| ORANGE | <code>number</code> | 8 |
| RED | <code>number</code> | 9 |
| WHITE | <code>number</code> | 10 |
| NONE | <code>number</code> | 255 |
<a name="ButtonState"></a>
## ButtonState
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| PRESSED | <code>number</code> | 0 |
| RELEASED | <code>number</code> | 1 |
| UP | <code>number</code> | 2 |
| DOWN | <code>number</code> | 3 |
| STOP | <code>number</code> | 4 |
<a name="DuploTrainBaseSound"></a>
## DuploTrainBaseSound
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| BRAKE | <code>number</code> | 3 |
| STATION_DEPARTURE | <code>number</code> | 5 |
| WATER_REFILL | <code>number</code> | 7 |
| HORN | <code>number</code> | 9 |
| STEAM | <code>number</code> | 10 |

View File

@ -27,13 +27,13 @@ export class BoostMoveHub extends LPF2Hub {
public static IsBoostMoveHub (peripheral: Peripheral) { public static IsBoostMoveHub (peripheral: Peripheral) {
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.BOOST_MOVE_HUB_ID); return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.BOOST_MOVE_HUB_ID);
} }
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) { constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
super(peripheral, autoSubscribe); super(peripheral, autoSubscribe);
this.type = Consts.Hubs.BOOST_MOVE_HUB; this.type = Consts.HubType.BOOST_MOVE_HUB;
this._ports = { this._ports = {
"A": new Port("A", 55), "A": new Port("A", 55),
"B": new Port("B", 56), "B": new Port("B", 56),
@ -82,7 +82,7 @@ export class BoostMoveHub extends LPF2Hub {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (time && typeof time === "number") { if (time && typeof time === "number") {
if (portObj.type === Consts.Devices.BOOST_TACHO_MOTOR || portObj.type === Consts.Devices.BOOST_MOVE_HUB_MOTOR) { if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR) {
portObj.busy = true; portObj.busy = true;
let data = null; let data = null;
if (portObj.id === "AB") { if (portObj.id === "AB") {
@ -92,17 +92,17 @@ export class BoostMoveHub extends LPF2Hub {
data = Buffer.from([0x81, portObj.value, 0x11, 0x09, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x09, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
} }
data.writeUInt16LE(time > 65535 ? 65535 : time, 4); data.writeUInt16LE(time > 65535 ? 65535 : time, 4);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
return resolve(); return resolve();
}; };
} else { } else {
// @ts-ignore: The type of speed is properly checked at the start // @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)]); const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
const timeout = global.setTimeout(() => { const timeout = global.setTimeout(() => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]); const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
// @ts-ignore: The type of time is properly checked at the start // @ts-ignore: The type of time is properly checked at the start
}, time); }, time);
@ -111,7 +111,7 @@ export class BoostMoveHub extends LPF2Hub {
} else { } else {
if (portObj.type === Consts.Devices.BOOST_TACHO_MOTOR || portObj.type === Consts.Devices.BOOST_MOVE_HUB_MOTOR) { if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR) {
portObj.busy = true; portObj.busy = true;
let data = null; let data = null;
if (portObj.id === "AB") { if (portObj.id === "AB") {
@ -120,14 +120,14 @@ export class BoostMoveHub extends LPF2Hub {
// @ts-ignore: The type of speed is properly checked at the start // @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]); data = Buffer.from([0x81, portObj.value, 0x11, 0x01, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
} }
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
return resolve(); return resolve();
}; };
} else { } else {
// @ts-ignore: The type of speed is properly checked at the start // @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)]); const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
} }
} }
@ -167,7 +167,7 @@ export class BoostMoveHub extends LPF2Hub {
*/ */
public setMotorAngle (port: string, angle: number, speed: number | [number, number] = 100) { public setMotorAngle (port: string, angle: number, speed: number | [number, number] = 100) {
const portObj = this._portLookup(port); const portObj = this._portLookup(port);
if (!(portObj.type === Consts.Devices.BOOST_TACHO_MOTOR || portObj.type === Consts.Devices.BOOST_MOVE_HUB_MOTOR)) { 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"); throw new Error("Angle rotation is only available when using a Boost Tacho Motor or Boost Move Hub Motor");
} }
if (portObj.id !== "AB" && speed instanceof Array) { if (portObj.id !== "AB" && speed instanceof Array) {
@ -184,7 +184,7 @@ export class BoostMoveHub extends LPF2Hub {
data = Buffer.from([0x81, portObj.value, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]); data = Buffer.from([0x81, portObj.value, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
} }
data.writeUInt32LE(angle, 4); data.writeUInt32LE(angle, 4);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => { portObj.finished = () => {
return resolve(); return resolve();
}; };
@ -205,11 +205,11 @@ export class BoostMoveHub extends LPF2Hub {
portObj.cancelEventTimer(); portObj.cancelEventTimer();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]); const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
if (time) { if (time) {
const timeout = global.setTimeout(() => { const timeout = global.setTimeout(() => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]); const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
}, time); }, time);
portObj.setEventTimer(timeout); portObj.setEventTimer(timeout);

View File

@ -1,4 +1,13 @@
export enum Hubs { /**
* @typedef HubType
* @property {number} UNKNOWN 0
* @property {number} WEDO2_SMART_HUB 1
* @property {number} BOOST_MOVE_HUB 2
* @property {number} POWERED_UP_HUB 3
* @property {number} POWERED_UP_REMOTE 4
* @property {number} DUPLO_TRAIN_HUB 5
*/
export enum HubType {
UNKNOWN = 0, UNKNOWN = 0,
WEDO2_SMART_HUB = 1, WEDO2_SMART_HUB = 1,
BOOST_MOVE_HUB = 2, BOOST_MOVE_HUB = 2,
@ -8,7 +17,26 @@ export enum Hubs {
} }
export enum Devices { /**
* @typedef DeviceType
* @property {number} UNKNOWN 0
* @property {number} BASIC_MOTOR 1
* @property {number} TRAIN_MOTOR 2
* @property {number} LED_LIGHTS 8
* @property {number} BOOST_LED 22
* @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} BOOST_TILT 40
* @property {number} DUPLO_TRAIN_BASE_MOTOR 41
* @property {number} DUPLO_TRAIN_BASE_SPEAKER 42
* @property {number} DUPLO_TRAIN_BASE_COLOR 43
* @property {number} DUPLO_TRAIN_BASE_SPEEDOMETER 44
* @property {number} POWERED_UP_REMOTE_BUTTON 55
*/
export enum DeviceType {
UNKNOWN = 0, UNKNOWN = 0,
BASIC_MOTOR = 1, BASIC_MOTOR = 1,
TRAIN_MOTOR = 2, TRAIN_MOTOR = 2,
@ -28,7 +56,22 @@ export enum Devices {
} }
export enum Colors { /**
* @typedef Color
* @property {number} BLACK 0
* @property {number} PINK 1
* @property {number} PURPLE 2
* @property {number} BLUE 3
* @property {number} LIGHT_BLUE 4
* @property {number} CYAN 5
* @property {number} GREEN 6
* @property {number} YELLOW 7
* @property {number} ORANGE 8
* @property {number} RED 9
* @property {number} WHITE 10
* @property {number} NONE 255
*/
export enum Color {
BLACK = 0, BLACK = 0,
PINK = 1, PINK = 1,
PURPLE = 2, PURPLE = 2,
@ -44,7 +87,15 @@ export enum Colors {
} }
export enum ButtonStates { /**
* @typedef ButtonState
* @property {number} PRESSED 0
* @property {number} RELEASED 1
* @property {number} UP 2
* @property {number} DOWN 3
* @property {number} STOP 4
*/
export enum ButtonState {
PRESSED = 0, PRESSED = 0,
RELEASED = 1, RELEASED = 1,
UP = 2, UP = 2,
@ -53,10 +104,20 @@ export enum ButtonStates {
} }
export enum DuploTrainBaseSounds { /**
* @typedef DuploTrainBaseSound
* @property {number} BRAKE 3
* @property {number} STATION_DEPARTURE 5
* @property {number} WATER_REFILL 7
* @property {number} HORN 9
* @property {number} STEAM 10
*/
export enum DuploTrainBaseSound {
BREAK = 3,
STATION_DEPARTURE = 5, STATION_DEPARTURE = 5,
WATER_REFILL = 7, WATER_REFILL = 7,
HORN = 9 HORN = 9,
STEAM = 10
} }
@ -68,13 +129,13 @@ export enum BLEManufacturerData {
} }
export enum BLEServices { export enum BLEService {
WEDO2_SMART_HUB = "00001523-1212-efde-1523-785feabcd123", WEDO2_SMART_HUB = "00001523-1212-efde-1523-785feabcd123",
LPF2_HUB = "00001623-1212-efde-1623-785feabcd123" LPF2_HUB = "00001623-1212-efde-1623-785feabcd123"
} }
export enum BLECharacteristics { export enum BLECharacteristic {
WEDO2_BATTERY = "2a19", WEDO2_BATTERY = "2a19",
WEDO2_BUTTON = "00001526-1212-efde-1523-785feabcd123", // "1526" WEDO2_BUTTON = "00001526-1212-efde-1523-785feabcd123", // "1526"
WEDO2_PORT_TYPE = "00001527-1212-efde-1523-785feabcd123", // "1527" // Handles plugging and unplugging of devices on WeDo 2.0 Smart Hub WEDO2_PORT_TYPE = "00001527-1212-efde-1523-785feabcd123", // "1527" // Handles plugging and unplugging of devices on WeDo 2.0 Smart Hub

View File

@ -52,13 +52,13 @@ export class DuploTrainBase extends LPF2Hub {
public static IsDuploTrainBase (peripheral: Peripheral) { public static IsDuploTrainBase (peripheral: Peripheral) {
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.DUPLO_TRAIN_HUB_ID); return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.DUPLO_TRAIN_HUB_ID);
} }
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) { constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
super(peripheral, autoSubscribe); super(peripheral, autoSubscribe);
this.type = Consts.Hubs.DUPLO_TRAIN_HUB; this.type = Consts.HubType.DUPLO_TRAIN_HUB;
this._ports = { this._ports = {
"MOTOR": new Port("MOTOR", 0), "MOTOR": new Port("MOTOR", 0),
"COLOR": new Port("COLOR", 18), "COLOR": new Port("COLOR", 18),
@ -81,7 +81,7 @@ export class DuploTrainBase extends LPF2Hub {
/** /**
* Set the color of the LED on the train via a color value. * Set the color of the LED on the train via a color value.
* @method DuploTrainBase#setLEDColor * @method DuploTrainBase#setLEDColor
* @param {number} color A number representing one of the LED color consts. * @param {Color} color
* @returns {Promise} Resolved upon successful issuance of command. * @returns {Promise} Resolved upon successful issuance of command.
*/ */
public setLEDColor (color: number | boolean) { public setLEDColor (color: number | boolean) {
@ -90,7 +90,7 @@ export class DuploTrainBase extends LPF2Hub {
color = 0; color = 0;
} }
const data = Buffer.from([0x81, 0x11, 0x11, 0x51, 0x00, color]); const data = Buffer.from([0x81, 0x11, 0x11, 0x51, 0x00, color]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
}); });
} }
@ -119,16 +119,16 @@ export class DuploTrainBase extends LPF2Hub {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (time && typeof time === "number") { if (time && typeof time === "number") {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]); const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
const timeout = global.setTimeout(() => { const timeout = global.setTimeout(() => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]); const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
}, time); }, time);
portObj.setEventTimer(timeout); portObj.setEventTimer(timeout);
} else { } else {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]); const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
} }
}); });
@ -138,13 +138,13 @@ export class DuploTrainBase extends LPF2Hub {
/** /**
* Play a built-in train sound. * Play a built-in train sound.
* @method DuploTrainBase#playSound * @method DuploTrainBase#playSound
* @param {number} sound A number representing one of the Train Base sound consts. * @param {DuploTrainBaseSound} sound
* @returns {Promise} Resolved upon successful issuance of command. * @returns {Promise} Resolved upon successful issuance of command.
*/ */
public playSound (sound: number) { public playSound (sound: number) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const data = Buffer.from([0x81, 0x01, 0x11, 0x51, 0x01, sound]); const data = Buffer.from([0x81, 0x01, 0x11, 0x51, 0x01, sound]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
}); });
} }

43
hub.ts
View File

@ -19,7 +19,7 @@ export class Hub extends EventEmitter {
public autoSubscribe: boolean = true; public autoSubscribe: boolean = true;
public useSpeedMap: boolean = true; public useSpeedMap: boolean = true;
public type: Consts.Hubs = Consts.Hubs.UNKNOWN; public type: Consts.HubType = Consts.HubType.UNKNOWN;
protected _ports: {[port: string]: Port} = {}; protected _ports: {[port: string]: Port} = {};
protected _characteristics: {[uuid: string]: Characteristic} = {}; protected _characteristics: {[uuid: string]: Characteristic} = {};
@ -216,6 +216,27 @@ export class Hub extends EventEmitter {
} }
/**
* Get the hub type.
* @method Hub#getHubType
* @returns {HubType}
*/
public getHubType () {
return this.type;
}
/**
* Get the device type for a given port.
* @method Hub#getPortDeviceType
* @param {string} port
* @returns {DeviceType}
*/
public getPortDeviceType (port: string) {
return this._portLookup(port).type;
}
protected _getCharacteristic (uuid: string) { protected _getCharacteristic (uuid: string) {
return this._characteristics[uuid.replace(/-/g, "")]; return this._characteristics[uuid.replace(/-/g, "")];
} }
@ -257,12 +278,12 @@ export class Hub extends EventEmitter {
* Emits when a motor or sensor is attached to the Hub. * Emits when a motor or sensor is attached to the Hub.
* @event Hub#attach * @event Hub#attach
* @param {string} port * @param {string} port
* @param {number} type A number representing one of the peripheral consts. * @param {DeviceType} type
*/ */
this.emit("attach", port.id, type); this.emit("attach", port.id, type);
} }
} else { } else {
port.type = Consts.Devices.UNKNOWN; port.type = Consts.DeviceType.UNKNOWN;
debug(`Port ${port.id} disconnected`); debug(`Port ${port.id} disconnected`);
/** /**
* Emits when an attached motor or sensor is detached from the Hub. * Emits when an attached motor or sensor is detached from the Hub.
@ -349,19 +370,19 @@ export class Hub extends EventEmitter {
} }
private _getModeForDeviceType (type: Consts.Devices) { private _getModeForDeviceType (type: Consts.DeviceType) {
switch (type) { switch (type) {
case Consts.Devices.BASIC_MOTOR: case Consts.DeviceType.BASIC_MOTOR:
return 0x02; return 0x02;
case Consts.Devices.TRAIN_MOTOR: case Consts.DeviceType.TRAIN_MOTOR:
return 0x02; return 0x02;
case Consts.Devices.BOOST_TACHO_MOTOR: case Consts.DeviceType.BOOST_TACHO_MOTOR:
return 0x02; return 0x02;
case Consts.Devices.BOOST_MOVE_HUB_MOTOR: case Consts.DeviceType.BOOST_MOVE_HUB_MOTOR:
return 0x02; return 0x02;
case Consts.Devices.BOOST_DISTANCE: case Consts.DeviceType.BOOST_DISTANCE:
return (this.type === Consts.Hubs.WEDO2_SMART_HUB ? 0x00 : 0x08); return (this.type === Consts.HubType.WEDO2_SMART_HUB ? 0x00 : 0x08);
case Consts.Devices.BOOST_TILT: case Consts.DeviceType.BOOST_TILT:
return 0x04; return 0x04;
default: default:
return 0x00; return 0x00;

View File

@ -37,13 +37,13 @@ export class LPF2Hub extends Hub {
public connect () { public connect () {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
await super.connect(); await super.connect();
const characteristic = this._getCharacteristic(Consts.BLECharacteristics.LPF2_ALL); const characteristic = this._getCharacteristic(Consts.BLECharacteristic.LPF2_ALL);
this._subscribeToCharacteristic(characteristic, this._parseMessage.bind(this)); this._subscribeToCharacteristic(characteristic, this._parseMessage.bind(this));
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x01, 0x02, 0x02])); // Activate button reports this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x02, 0x02])); // Activate button reports
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x41, 0x3b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate current reports this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x3b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate current reports
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x41, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports
if (this.type === Consts.Hubs.DUPLO_TRAIN_HUB) { if (this.type === Consts.HubType.DUPLO_TRAIN_HUB) {
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x41, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01])); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01]));
} }
return resolve(); return resolve();
}); });
@ -64,8 +64,8 @@ export class LPF2Hub extends Hub {
let data = Buffer.from([0x01, 0x01, 0x01]); let data = Buffer.from([0x01, 0x01, 0x01]);
data = Buffer.concat([data, Buffer.from(name, "ascii")]); data = Buffer.concat([data, Buffer.from(name, "ascii")]);
// Send this twice, as sometimes the first time doesn't take // Send this twice, as sometimes the first time doesn't take
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
this._name = name; this._name = name;
return resolve(); return resolve();
}); });
@ -75,18 +75,18 @@ export class LPF2Hub extends Hub {
/** /**
* Set the color of the LED on the Hub via a color value. * Set the color of the LED on the Hub via a color value.
* @method LPF2Hub#setLEDColor * @method LPF2Hub#setLEDColor
* @param {number} color A number representing one of the LED color consts. * @param {Color} color
* @returns {Promise} Resolved upon successful issuance of command. * @returns {Promise} Resolved upon successful issuance of command.
*/ */
public setLEDColor (color: number | boolean) { public setLEDColor (color: number | boolean) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let data = Buffer.from([0x41, 0x32, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]); let data = Buffer.from([0x41, 0x32, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
if (color === false) { if (color === false) {
color = 0; color = 0;
} }
data = Buffer.from([0x81, 0x32, 0x11, 0x51, 0x00, color]); data = Buffer.from([0x81, 0x32, 0x11, 0x51, 0x00, color]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
}); });
} }
@ -103,21 +103,21 @@ export class LPF2Hub extends Hub {
public setLEDRGB (red: number, green: number, blue: number) { public setLEDRGB (red: number, green: number, blue: number) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let data = Buffer.from([0x41, 0x32, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]); let data = Buffer.from([0x41, 0x32, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
data = Buffer.from([0x81, 0x32, 0x11, 0x51, 0x01, red, green, blue]); data = Buffer.from([0x81, 0x32, 0x11, 0x51, 0x01, red, green, blue]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
}); });
} }
protected _activatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) { protected _activatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) {
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x01]), callback); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x01]), callback);
} }
protected _deactivatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) { protected _deactivatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) {
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, Buffer.from([0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x00]), callback); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x00]), callback);
} }
@ -186,12 +186,12 @@ export class LPF2Hub extends Hub {
* Emits when a button is pressed. * Emits when a button is pressed.
* @event LPF2Hub#button * @event LPF2Hub#button
* @param {string} button * @param {string} button
* @param {number} state A number representing one of the button state consts. * @param {ButtonState} state
*/ */
this.emit("button", "GREEN", Consts.ButtonStates.PRESSED); this.emit("button", "GREEN", Consts.ButtonState.PRESSED);
return; return;
} else if (data[5] === 0) { } else if (data[5] === 0) {
this.emit("button", "GREEN", Consts.ButtonStates.RELEASED); this.emit("button", "GREEN", Consts.ButtonState.RELEASED);
return; return;
} }
} }
@ -242,12 +242,12 @@ export class LPF2Hub extends Hub {
private _parseSensorMessage (data: Buffer) { private _parseSensorMessage (data: Buffer) {
if ((data[3] === 0x3b && this.type === Consts.Hubs.POWERED_UP_REMOTE) || (data[3] === 0x3c && this.type !== Consts.Hubs.POWERED_UP_REMOTE)) { // Voltage if ((data[3] === 0x3b && this.type === Consts.HubType.POWERED_UP_REMOTE) || (data[3] === 0x3c && this.type !== Consts.HubType.POWERED_UP_REMOTE)) { // Voltage
data = this._padMessage(data, 6); data = this._padMessage(data, 6);
const batteryLevel = (data.readUInt16LE(4) / 4096) * 100; const batteryLevel = (data.readUInt16LE(4) / 4096) * 100;
this._batteryLevel = Math.floor(batteryLevel); this._batteryLevel = Math.floor(batteryLevel);
return; return;
} else if (data[3] === 0x3b && this.type !== Consts.Hubs.POWERED_UP_REMOTE) { // Current (Non-PUP Remote) } else if (data[3] === 0x3b && this.type !== Consts.HubType.POWERED_UP_REMOTE) { // Current (Non-PUP Remote)
data = this._padMessage(data, 6); data = this._padMessage(data, 6);
const current = data.readUInt16LE(4) / 4096; const current = data.readUInt16LE(4) / 4096;
this._current = current * 100; this._current = current * 100;
@ -267,7 +267,7 @@ export class LPF2Hub extends Hub {
if (port && port.connected) { if (port && port.connected) {
switch (port.type) { switch (port.type) {
case Consts.Devices.WEDO2_DISTANCE: case Consts.DeviceType.WEDO2_DISTANCE:
{ {
let distance = data[4]; let distance = data[4];
if (data[5] === 1) { if (data[5] === 1) {
@ -282,14 +282,14 @@ export class LPF2Hub extends Hub {
this.emit("distance", port.id, distance * 10); this.emit("distance", port.id, distance * 10);
break; break;
} }
case Consts.Devices.BOOST_DISTANCE: case Consts.DeviceType.BOOST_DISTANCE:
{ {
/** /**
* Emits when a color sensor is activated. * Emits when a color sensor is activated.
* @event LPF2Hub#color * @event LPF2Hub#color
* @param {string} port * @param {string} port
* @param {number} color A number representing one of the LED color consts. * @param {Color} color
*/ */
if (data[4] <= 10) { if (data[4] <= 10) {
this.emit("color", port.id, data[4]); this.emit("color", port.id, data[4]);
@ -299,13 +299,26 @@ export class LPF2Hub extends Hub {
const partial = data[7]; const partial = data[7];
if (partial > 0) { if (partial > 0) {
distance += 1 / partial; distance += 1.0 / partial;
} }
this.emit("distance", port.id, Math.floor(distance * 25.4) - 20); distance = Math.floor(distance * 25.4) - 20;
this.emit("distance", port.id, distance);
/**
* A combined color and distance event, emits when the sensor is activated.
* @event LPF2Hub#colorAndDistance
* @param {string} port
* @param {Color} color
* @param {number} distance Distance, in millimeters.
*/
if (data[4] <= 10) {
this.emit("colorAndDistance", port.id, data[4], distance);
}
break; break;
} }
case Consts.Devices.WEDO2_TILT: case Consts.DeviceType.WEDO2_TILT:
{ {
const tiltX = data[4] > 160 ? data[4] - 255 : data[4] - (data[4] * 2); const tiltX = data[4] > 160 ? data[4] - 255 : data[4] - (data[4] * 2);
const tiltY = data[5] > 160 ? 255 - data[5] : data[5] - (data[5] * 2); const tiltY = data[5] > 160 ? 255 - data[5] : data[5] - (data[5] * 2);
@ -321,9 +334,9 @@ export class LPF2Hub extends Hub {
this.emit("tilt", port.id, this._lastTiltX, this._lastTiltY); this.emit("tilt", port.id, this._lastTiltX, this._lastTiltY);
break; break;
} }
case Consts.Devices.BOOST_TACHO_MOTOR: case Consts.DeviceType.BOOST_TACHO_MOTOR:
{ {
const rotation = data.readInt32LE(2); const rotation = data.readInt32LE(4);
/** /**
* Emits when a rotation sensor is activated. * Emits when a rotation sensor is activated.
* @event LPF2Hub#rotate * @event LPF2Hub#rotate
@ -333,53 +346,53 @@ export class LPF2Hub extends Hub {
this.emit("rotate", port.id, rotation); this.emit("rotate", port.id, rotation);
break; break;
} }
case Consts.Devices.BOOST_MOVE_HUB_MOTOR: case Consts.DeviceType.BOOST_MOVE_HUB_MOTOR:
{ {
const rotation = data.readInt32LE(2); const rotation = data.readInt32LE(4);
this.emit("rotate", port.id, rotation); this.emit("rotate", port.id, rotation);
break; break;
} }
case Consts.Devices.BOOST_TILT: case Consts.DeviceType.BOOST_TILT:
{ {
const tiltX = data[4] > 160 ? data[4] - 255 : data[4]; const tiltX = data[4] > 160 ? data[4] - 255 : data[4];
const tiltY = data[5] > 160 ? 255 - data[5] : data[5] - (data[5] * 2); const tiltY = data[5] > 160 ? 255 - data[5] : data[5] - (data[5] * 2);
this.emit("tilt", port.id, tiltX, tiltY); this.emit("tilt", port.id, tiltX, tiltY);
break; break;
} }
case Consts.Devices.POWERED_UP_REMOTE_BUTTON: case Consts.DeviceType.POWERED_UP_REMOTE_BUTTON:
{ {
switch (data[4]) { switch (data[4]) {
case 0x01: case 0x01:
{ {
this.emit("button", port.id, Consts.ButtonStates.UP); this.emit("button", port.id, Consts.ButtonState.UP);
break; break;
} }
case 0xff: case 0xff:
{ {
this.emit("button", port.id, Consts.ButtonStates.DOWN); this.emit("button", port.id, Consts.ButtonState.DOWN);
break; break;
} }
case 0x7f: case 0x7f:
{ {
this.emit("button", port.id, Consts.ButtonStates.STOP); this.emit("button", port.id, Consts.ButtonState.STOP);
break; break;
} }
case 0x00: case 0x00:
{ {
this.emit("button", port.id, Consts.ButtonStates.RELEASED); this.emit("button", port.id, Consts.ButtonState.RELEASED);
break; break;
} }
} }
break; break;
} }
case Consts.Devices.DUPLO_TRAIN_BASE_COLOR: case Consts.DeviceType.DUPLO_TRAIN_BASE_COLOR:
{ {
if (data[4] <= 10) { if (data[4] <= 10) {
this.emit("color", port.id, data[4]); this.emit("color", port.id, data[4]);
} }
break; break;
} }
case Consts.Devices.DUPLO_TRAIN_BASE_SPEEDOMETER: case Consts.DeviceType.DUPLO_TRAIN_BASE_SPEEDOMETER:
{ {
/** /**
* Emits on a speed change. * Emits on a speed change.

52
package-lock.json generated
View File

@ -5,9 +5,9 @@
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@types/debug": { "@types/debug": {
"version": "0.0.30", "version": "0.0.31",
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-0.0.30.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/@/@types/debug/_attachments/debug-0.0.31.tgz",
"integrity": "sha512-orGL5LXERPYsLov6CWs3Fh6203+dXzJkR7OnddIr2514Hsecwc8xRpzCapshBbKFImCsvS/mk6+FWiN5LyZJAQ==", "integrity": "sha512-LS1MCPaQKqspg7FvexuhmDbWUhE2yIJ+4AgVIyObfc06/UKZ8REgxGNjZc82wPLWmbeOm7S+gSsLgo75TanG4A==",
"dev": true "dev": true
}, },
"@types/events": { "@types/events": {
@ -27,9 +27,9 @@
} }
}, },
"@types/node": { "@types/node": {
"version": "10.12.3", "version": "10.12.9",
"resolved": "https://npm-registry.rancher.sie.sony.com/@/@types/node/_attachments/node-10.12.3.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.9.tgz",
"integrity": "sha512-sfGmOtSMSbQ/AKG8V9xD1gmjquC9awIIZ/Kj309pHb2n3bcRAcGMQv5nJ6gCXZVsneGE4+ve8DXKRCsrg3TFzg==", "integrity": "sha512-eajkMXG812/w3w4a1OcBlaTwsFPO5F7fJ/amy+tieQxEMWBlbV1JGSjkFM+zkHNf81Cad+dfIRA+IBkvmvdAeA==",
"dev": true "dev": true
}, },
"abbrev": { "abbrev": {
@ -370,7 +370,7 @@
}, },
"cross-spawn": { "cross-spawn": {
"version": "6.0.5", "version": "6.0.5",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/c/cross-spawn/_attachments/cross-spawn-6.0.5.tgz",
"integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==",
"requires": { "requires": {
"nice-try": "^1.0.4", "nice-try": "^1.0.4",
@ -381,9 +381,9 @@
} }
}, },
"debug": { "debug": {
"version": "3.2.6", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/d/debug/_attachments/debug-4.1.0.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==",
"requires": { "requires": {
"ms": "^2.1.1" "ms": "^2.1.1"
} }
@ -602,7 +602,7 @@
}, },
"isexe": { "isexe": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/i/isexe/_attachments/isexe-2.0.0.tgz",
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA="
}, },
"js-tokens": { "js-tokens": {
@ -787,7 +787,7 @@
}, },
"ms": { "ms": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/m/ms/_attachments/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
}, },
"nan": { "nan": {
@ -798,7 +798,7 @@
}, },
"napi-thread-safe-callback": { "napi-thread-safe-callback": {
"version": "0.0.6", "version": "0.0.6",
"resolved": "https://registry.npmjs.org/napi-thread-safe-callback/-/napi-thread-safe-callback-0.0.6.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/n/napi-thread-safe-callback/_attachments/napi-thread-safe-callback-0.0.6.tgz",
"integrity": "sha512-X7uHCOCdY4u0yamDxDrv3jF2NtYc8A1nvPzBQgvpoSX+WB3jAe2cVNsY448V1ucq7Whf9Wdy02HEUoLW5rJKWg==" "integrity": "sha512-X7uHCOCdY4u0yamDxDrv3jF2NtYc8A1nvPzBQgvpoSX+WB3jAe2cVNsY448V1ucq7Whf9Wdy02HEUoLW5rJKWg=="
}, },
"needle": { "needle": {
@ -828,7 +828,7 @@
}, },
"nice-try": { "nice-try": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/n/nice-try/_attachments/nice-try-1.0.5.tgz",
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
}, },
"noble": { "noble": {
@ -858,8 +858,8 @@
} }
}, },
"noble-mac": { "noble-mac": {
"version": "git+https://github.com/Timeular/noble-mac.git#a776e9a5b66abeb45707559321e3007a0b397b48", "version": "git+https://github.com/Timeular/noble-mac.git#af4418ef5fb1ec97a662687f6a11b7f7cc59b2b4",
"from": "git+https://github.com/Timeular/noble-mac.git#a776e9a", "from": "git+https://github.com/Timeular/noble-mac.git#af4418e",
"requires": { "requires": {
"cross-spawn": "^6.0.5", "cross-spawn": "^6.0.5",
"napi-thread-safe-callback": "0.0.6", "napi-thread-safe-callback": "0.0.6",
@ -869,9 +869,9 @@
} }
}, },
"node-addon-api": { "node-addon-api": {
"version": "1.4.0", "version": "1.6.1",
"resolved": "https://npm-registry.rancher.sie.sony.com/n/node-addon-api/_attachments/node-addon-api-1.4.0.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/n/node-addon-api/_attachments/node-addon-api-1.6.1.tgz",
"integrity": "sha512-agquHPHnxYGox7Rjz2+TZQeOiH8IVbNFSTyTPA+peMUAP6klgrBH5dcwHsNNChQh7l/dtF0JNmZPbCqd5OXOIQ==" "integrity": "sha512-GcLOYrG5/enbqH4SMsqXt6GQUQGGnDnE3FLDZzXYkCgQHuZV5UDFR+EboeY8kpG0avroyOjpFQ2qLEBosFcRIA=="
}, },
"node-pre-gyp": { "node-pre-gyp": {
"version": "0.10.3", "version": "0.10.3",
@ -990,7 +990,7 @@
}, },
"path-key": { "path-key": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/p/path-key/_attachments/path-key-2.0.1.tgz",
"integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A="
}, },
"path-parse": { "path-parse": {
@ -1169,7 +1169,7 @@
}, },
"shebang-command": { "shebang-command": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/s/shebang-command/_attachments/shebang-command-1.2.0.tgz",
"integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=",
"requires": { "requires": {
"shebang-regex": "^1.0.0" "shebang-regex": "^1.0.0"
@ -1177,7 +1177,7 @@
}, },
"shebang-regex": { "shebang-regex": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/s/shebang-regex/_attachments/shebang-regex-1.0.0.tgz",
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM="
}, },
"signal-exit": { "signal-exit": {
@ -1367,9 +1367,9 @@
} }
}, },
"typescript": { "typescript": {
"version": "2.9.2", "version": "3.1.6",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/t/typescript/_attachments/typescript-3.1.6.tgz",
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==", "integrity": "sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA==",
"dev": true "dev": true
}, },
"typical": { "typical": {
@ -1435,7 +1435,7 @@
}, },
"which": { "which": {
"version": "1.3.1", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "resolved": "https://npm-registry.rancher.sie.sony.com/w/which/_attachments/which-1.3.1.tgz",
"integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
"requires": { "requires": {
"isexe": "^2.0.0" "isexe": "^2.0.0"

View File

@ -1,13 +1,13 @@
{ {
"name": "node-poweredup", "name": "node-poweredup",
"version": "1.1.7", "version": "1.4.5",
"description": "A Node.js module to interface with LEGO Powered UP components.", "description": "A Node.js module to interface with LEGO Powered UP components.",
"homepage": "https://github.com/nathankellenicki/node-poweredup/", "homepage": "https://github.com/nathankellenicki/node-poweredup/",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"scripts": { "scripts": {
"build": "tslint -c tslint.json \"*.ts\" && tsc", "build": "tslint -c tslint.json \"*.ts\" && tsc",
"docs": "jsdoc2md dist/poweredup.js dist/lpf2hub.js dist/wedo2smarthub.js dist/boostmovehub.js dist/puphub.js dist/pupremote.js dist/duplotrainbase.js dist/hub.js dist/consts.js > DOCS.md", "docs": "jsdoc2md dist/consts.js dist/poweredup.js dist/lpf2hub.js dist/wedo2smarthub.js dist/boostmovehub.js dist/puphub.js dist/pupremote.js dist/duplotrainbase.js dist/hub.js dist/consts.js > DOCS.md",
"readme": "cat ABOUT.md DOCS.md > README.md", "readme": "cat ABOUT.md DOCS.md > README.md",
"all": "npm run build && npm run docs && npm run readme", "all": "npm run build && npm run docs && npm run readme",
"prepublishOnly": "npm run build" "prepublishOnly": "npm run build"
@ -15,17 +15,17 @@
"author": "Nathan Kellenicki <nathan@kellenicki.com>", "author": "Nathan Kellenicki <nathan@kellenicki.com>",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"debug": "^3.1.0", "debug": "^4.1.0",
"noble": "1.9.1", "noble": "1.9.1",
"noble-mac": "https://github.com/Timeular/noble-mac.git#a776e9a" "noble-mac": "https://github.com/Timeular/noble-mac.git#af4418e"
}, },
"devDependencies": { "devDependencies": {
"jsdoc-to-markdown": "^4.0.1", "jsdoc-to-markdown": "^4.0.1",
"typescript": "^2.9.2", "typescript": "^3.1.6",
"tslint": "^5.10.0", "tslint": "^5.11.0",
"@types/debug": "0.0.30", "@types/debug": "0.0.31",
"@types/noble": "0.0.37", "@types/noble": "0.0.37",
"@types/node": "^10.3.4" "@types/node": "^10.12.9"
}, },
"resolutions": { "resolutions": {
"xpc-connection": "sandeepmistry/node-xpc-connection#pull/26/head" "xpc-connection": "sandeepmistry/node-xpc-connection#pull/26/head"

View File

@ -6,7 +6,7 @@ export class Port {
public id: string; public id: string;
public value: number; public value: number;
public type: Consts.Devices; public type: Consts.DeviceType;
public connected: boolean = false; public connected: boolean = false;
public busy: boolean = false; public busy: boolean = false;
public finished: (() => void) | null = null; public finished: (() => void) | null = null;
@ -16,7 +16,7 @@ export class Port {
constructor (id: string, value: number) { constructor (id: string, value: number) {
this.id = id; this.id = id;
this.value = value; this.value = value;
this.type = Consts.Devices.UNKNOWN; this.type = Consts.DeviceType.UNKNOWN;
} }
public cancelEventTimer () { public cancelEventTimer () {

View File

@ -22,7 +22,7 @@ let wantScan = false;
const startScanning = () => { const startScanning = () => {
if (isBrowserContext) { if (isBrowserContext) {
noble.startScanning([Consts.BLEServices.WEDO2_SMART_HUB, Consts.BLEServices.LPF2_HUB]); noble.startScanning([Consts.BLEService.WEDO2_SMART_HUB, Consts.BLEService.LPF2_HUB]);
} else { } else {
noble.startScanning(); noble.startScanning();
} }

View File

@ -32,13 +32,13 @@ export class PUPHub extends LPF2Hub {
public static IsPUPHub (peripheral: Peripheral) { public static IsPUPHub (peripheral: Peripheral) {
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_HUB_ID); return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_HUB_ID);
} }
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) { constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
super(peripheral, autoSubscribe); super(peripheral, autoSubscribe);
this.type = Consts.Hubs.POWERED_UP_HUB; this.type = Consts.HubType.POWERED_UP_HUB;
this._ports = { this._ports = {
"A": new Port("A", 0), "A": new Port("A", 0),
"B": new Port("B", 1), "B": new Port("B", 1),
@ -97,7 +97,7 @@ export class PUPHub extends LPF2Hub {
// @ts-ignore: The type of speed is properly checked at the start // @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x60, 0x00, this._mapSpeed(speed), 0x00, 0x00]); data = Buffer.from([0x81, portObj.value, 0x11, 0x60, 0x00, this._mapSpeed(speed), 0x00, 0x00]);
} }
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
const timeout = global.setTimeout(() => { const timeout = global.setTimeout(() => {
let data = null; let data = null;
if (portObj.id === "AB") { if (portObj.id === "AB") {
@ -105,7 +105,7 @@ export class PUPHub extends LPF2Hub {
} else { } else {
data = Buffer.from([0x81, portObj.value, 0x11, 0x60, 0x00, 0x00, 0x00, 0x00]); data = Buffer.from([0x81, portObj.value, 0x11, 0x60, 0x00, 0x00, 0x00, 0x00]);
} }
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
}, time); }, time);
portObj.setEventTimer(timeout); portObj.setEventTimer(timeout);
@ -117,7 +117,7 @@ export class PUPHub extends LPF2Hub {
// @ts-ignore: The type of speed is properly checked at the start // @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x60, 0x00, this._mapSpeed(speed), 0x00, 0x00]); data = Buffer.from([0x81, portObj.value, 0x11, 0x60, 0x00, this._mapSpeed(speed), 0x00, 0x00]);
} }
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
} }
}); });
@ -159,11 +159,11 @@ export class PUPHub extends LPF2Hub {
portObj.cancelEventTimer(); portObj.cancelEventTimer();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]); const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
if (time) { if (time) {
const timeout = global.setTimeout(() => { const timeout = global.setTimeout(() => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]); const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
}, time); }, time);
portObj.setEventTimer(timeout); portObj.setEventTimer(timeout);

View File

@ -57,13 +57,13 @@ export class PUPRemote extends LPF2Hub {
public static IsPUPRemote (peripheral: Peripheral) { public static IsPUPRemote (peripheral: Peripheral) {
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_REMOTE_ID); return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_REMOTE_ID);
} }
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) { constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
super(peripheral, autoSubscribe); super(peripheral, autoSubscribe);
this.type = Consts.Hubs.POWERED_UP_REMOTE; this.type = Consts.HubType.POWERED_UP_REMOTE;
this._ports = { this._ports = {
"LEFT": new Port("LEFT", 0), "LEFT": new Port("LEFT", 0),
"RIGHT": new Port("RIGHT", 1) "RIGHT": new Port("RIGHT", 1)
@ -85,18 +85,18 @@ export class PUPRemote extends LPF2Hub {
/** /**
* Set the color of the LED on the Remote via a color value. * Set the color of the LED on the Remote via a color value.
* @method PUPRemote#setLEDColor * @method PUPRemote#setLEDColor
* @param {number} color A number representing one of the LED color consts. * @param {Color} color
* @returns {Promise} Resolved upon successful issuance of command. * @returns {Promise} Resolved upon successful issuance of command.
*/ */
public setLEDColor (color: number | boolean) { public setLEDColor (color: number | boolean) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let data = Buffer.from([0x41, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]); let data = Buffer.from([0x41, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
if (color === false) { if (color === false) {
color = 0; color = 0;
} }
data = Buffer.from([0x81, 0x34, 0x11, 0x51, 0x00, color]); data = Buffer.from([0x81, 0x34, 0x11, 0x51, 0x00, color]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
}); });
} }
@ -113,9 +113,9 @@ export class PUPRemote extends LPF2Hub {
public setLEDRGB (red: number, green: number, blue: number) { public setLEDRGB (red: number, green: number, blue: number) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let data = Buffer.from([0x41, 0x34, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]); let data = Buffer.from([0x41, 0x34, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
data = Buffer.from([0x81, 0x34, 0x11, 0x51, 0x01, red, green, blue]); data = Buffer.from([0x81, 0x34, 0x11, 0x51, 0x01, red, green, blue]);
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve(); return resolve();
}); });
} }

View File

@ -26,7 +26,7 @@ export class WeDo2SmartHub extends Hub {
public static IsWeDo2SmartHub (peripheral: Peripheral) { public static IsWeDo2SmartHub (peripheral: Peripheral) {
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.WEDO2_SMART_HUB.replace(/-/g, "")) >= 0); return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.WEDO2_SMART_HUB.replace(/-/g, "")) >= 0);
} }
@ -36,7 +36,7 @@ export class WeDo2SmartHub extends Hub {
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) { constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
super(peripheral, autoSubscribe); super(peripheral, autoSubscribe);
this.type = Consts.Hubs.WEDO2_SMART_HUB; this.type = Consts.HubType.WEDO2_SMART_HUB;
this._ports = { this._ports = {
"A": new Port("A", 1), "A": new Port("A", 1),
"B": new Port("B", 2) "B": new Port("B", 2)
@ -49,12 +49,12 @@ export class WeDo2SmartHub extends Hub {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
debug("Connecting to WeDo 2.0 Smart Hub"); debug("Connecting to WeDo 2.0 Smart Hub");
await super.connect(); await super.connect();
this._subscribeToCharacteristic(this._getCharacteristic(Consts.BLECharacteristics.WEDO2_PORT_TYPE), this._parsePortMessage.bind(this)); this._subscribeToCharacteristic(this._getCharacteristic(Consts.BLECharacteristic.WEDO2_PORT_TYPE), this._parsePortMessage.bind(this));
this._subscribeToCharacteristic(this._getCharacteristic(Consts.BLECharacteristics.WEDO2_SENSOR_VALUE), this._parseSensorMessage.bind(this)); this._subscribeToCharacteristic(this._getCharacteristic(Consts.BLECharacteristic.WEDO2_SENSOR_VALUE), this._parseSensorMessage.bind(this));
this._subscribeToCharacteristic(this._getCharacteristic(Consts.BLECharacteristics.WEDO2_BUTTON), this._parseSensorMessage.bind(this)); this._subscribeToCharacteristic(this._getCharacteristic(Consts.BLECharacteristic.WEDO2_BUTTON), this._parseSensorMessage.bind(this));
this._subscribeToCharacteristic(this._getCharacteristic(Consts.BLECharacteristics.WEDO2_BATTERY), this._parseBatteryMessage.bind(this)); this._subscribeToCharacteristic(this._getCharacteristic(Consts.BLECharacteristic.WEDO2_BATTERY), this._parseBatteryMessage.bind(this));
this._subscribeToCharacteristic(this._getCharacteristic(Consts.BLECharacteristics.WEDO2_HIGH_CURRENT_ALERT), this._parseHighCurrentAlert.bind(this)); this._subscribeToCharacteristic(this._getCharacteristic(Consts.BLECharacteristic.WEDO2_HIGH_CURRENT_ALERT), this._parseHighCurrentAlert.bind(this));
this._getCharacteristic(Consts.BLECharacteristics.WEDO2_BATTERY).read((err, data) => { this._getCharacteristic(Consts.BLECharacteristic.WEDO2_BATTERY).read((err, data) => {
this._parseBatteryMessage(data); this._parseBatteryMessage(data);
}); });
debug("Connect completed"); debug("Connect completed");
@ -76,8 +76,8 @@ export class WeDo2SmartHub extends Hub {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const data = Buffer.from(name, "ascii"); const data = Buffer.from(name, "ascii");
// Send this twice, as sometimes the first time doesn't take // Send this twice, as sometimes the first time doesn't take
this._writeMessage(Consts.BLECharacteristics.WEDO2_NAME_ID, data); this._writeMessage(Consts.BLECharacteristic.WEDO2_NAME_ID, data);
this._writeMessage(Consts.BLECharacteristics.WEDO2_NAME_ID, data); this._writeMessage(Consts.BLECharacteristic.WEDO2_NAME_ID, data);
this._name = name; this._name = name;
return resolve(); return resolve();
}); });
@ -87,18 +87,18 @@ export class WeDo2SmartHub extends Hub {
/** /**
* Set the color of the LED on the Hub via a color value. * Set the color of the LED on the Hub via a color value.
* @method WeDo2SmartHub#setLEDColor * @method WeDo2SmartHub#setLEDColor
* @param {number} color A number representing one of the LED color consts. * @param {Color} color
* @returns {Promise} Resolved upon successful issuance of command. * @returns {Promise} Resolved upon successful issuance of command.
*/ */
public setLEDColor (color: number | boolean) { public setLEDColor (color: number | boolean) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let data = Buffer.from([0x06, 0x17, 0x01, 0x01]); let data = Buffer.from([0x06, 0x17, 0x01, 0x01]);
this._writeMessage(Consts.BLECharacteristics.WEDO2_PORT_TYPE_WRITE, data); this._writeMessage(Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE, data);
if (color === false) { if (color === false) {
color = 0; color = 0;
} }
data = Buffer.from([0x06, 0x04, 0x01, color]); data = Buffer.from([0x06, 0x04, 0x01, color]);
this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, data); this._writeMessage(Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE, data);
return resolve(); return resolve();
}); });
} }
@ -115,9 +115,9 @@ export class WeDo2SmartHub extends Hub {
public setLEDRGB (red: number, green: number, blue: number) { public setLEDRGB (red: number, green: number, blue: number) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let data = Buffer.from([0x06, 0x17, 0x01, 0x02]); let data = Buffer.from([0x06, 0x17, 0x01, 0x02]);
this._writeMessage(Consts.BLECharacteristics.WEDO2_PORT_TYPE_WRITE, data); this._writeMessage(Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE, data);
data = Buffer.from([0x06, 0x04, 0x03, red, green, blue]); data = Buffer.from([0x06, 0x04, 0x03, red, green, blue]);
this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, data); this._writeMessage(Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE, data);
return resolve(); return resolve();
}); });
} }
@ -144,10 +144,10 @@ export class WeDo2SmartHub extends Hub {
portObj.cancelEventTimer(); portObj.cancelEventTimer();
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, Buffer.from([portObj.value, 0x01, 0x02, this._mapSpeed(speed)])); this._writeMessage(Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE, Buffer.from([portObj.value, 0x01, 0x02, this._mapSpeed(speed)]));
if (time && typeof time === "number") { if (time && typeof time === "number") {
const timeout = global.setTimeout(() => { const timeout = global.setTimeout(() => {
this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, Buffer.from([portObj.value, 0x01, 0x02, 0x00])); this._writeMessage(Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE, Buffer.from([portObj.value, 0x01, 0x02, 0x00]));
return resolve(); return resolve();
}, time); }, time);
portObj.setEventTimer(timeout); portObj.setEventTimer(timeout);
@ -192,7 +192,7 @@ export class WeDo2SmartHub extends Hub {
const data = Buffer.from([0x05, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00]); const data = Buffer.from([0x05, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00]);
data.writeUInt16LE(frequency, 3); data.writeUInt16LE(frequency, 3);
data.writeUInt16LE(time, 5); data.writeUInt16LE(time, 5);
this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, data); this._writeMessage(Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE, data);
global.setTimeout(resolve, time); global.setTimeout(resolve, time);
}); });
} }
@ -211,11 +211,11 @@ export class WeDo2SmartHub extends Hub {
portObj.cancelEventTimer(); portObj.cancelEventTimer();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const data = Buffer.from([portObj.value, 0x01, 0x02, brightness]); const data = Buffer.from([portObj.value, 0x01, 0x02, brightness]);
this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, data); this._writeMessage(Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE, data);
if (time) { if (time) {
const timeout = global.setTimeout(() => { const timeout = global.setTimeout(() => {
const data = Buffer.from([portObj.value, 0x01, 0x02, 0x00]); const data = Buffer.from([portObj.value, 0x01, 0x02, 0x00]);
this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, data); this._writeMessage(Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE, data);
return resolve(); return resolve();
}, time); }, time);
portObj.setEventTimer(timeout); portObj.setEventTimer(timeout);
@ -227,12 +227,12 @@ export class WeDo2SmartHub extends Hub {
protected _activatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) { protected _activatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) {
this._writeMessage(Consts.BLECharacteristics.WEDO2_PORT_TYPE_WRITE, Buffer.from([0x01, 0x02, port, type, mode, 0x01, 0x00, 0x00, 0x00, format, 0x01]), callback); this._writeMessage(Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE, Buffer.from([0x01, 0x02, port, type, mode, 0x01, 0x00, 0x00, 0x00, format, 0x01]), callback);
} }
protected _deactivatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) { protected _deactivatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) {
this._writeMessage(Consts.BLECharacteristics.WEDO2_PORT_TYPE_WRITE, Buffer.from([0x01, 0x02, port, type, mode, 0x01, 0x00, 0x00, 0x00, format, 0x00]), callback); this._writeMessage(Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE, Buffer.from([0x01, 0x02, port, type, mode, 0x01, 0x00, 0x00, 0x00, format, 0x00]), callback);
} }
@ -276,12 +276,12 @@ export class WeDo2SmartHub extends Hub {
* Emits when a button is pressed. * Emits when a button is pressed.
* @event WeDo2SmartHub#button * @event WeDo2SmartHub#button
* @param {string} button * @param {string} button
* @param {number} state A number representing one of the button state consts. * @param {ButtonState} state
*/ */
this.emit("button", "GREEN", Consts.ButtonStates.PRESSED); this.emit("button", "GREEN", Consts.ButtonState.PRESSED);
return; return;
} else if (data[0] === 0x00) { } else if (data[0] === 0x00) {
this.emit("button", "GREEN", Consts.ButtonStates.RELEASED); this.emit("button", "GREEN", Consts.ButtonState.RELEASED);
return; return;
} }
@ -293,7 +293,7 @@ export class WeDo2SmartHub extends Hub {
if (port && port.connected) { if (port && port.connected) {
switch (port.type) { switch (port.type) {
case Consts.Devices.WEDO2_DISTANCE: case Consts.DeviceType.WEDO2_DISTANCE:
{ {
let distance = data[2]; let distance = data[2];
if (data[3] === 1) { if (data[3] === 1) {
@ -308,19 +308,19 @@ export class WeDo2SmartHub extends Hub {
this.emit("distance", port.id, distance * 10); this.emit("distance", port.id, distance * 10);
break; break;
} }
case Consts.Devices.BOOST_DISTANCE: case Consts.DeviceType.BOOST_DISTANCE:
{ {
const distance = data[2]; const distance = data[2];
/** /**
* Emits when a color sensor is activated. * Emits when a color sensor is activated.
* @event WeDo2SmartHub#color * @event WeDo2SmartHub#color
* @param {string} port * @param {string} port
* @param {number} color A number representing one of the LED color consts. * @param {Color} color
*/ */
this.emit("color", port.id, distance); this.emit("color", port.id, distance);
break; break;
} }
case Consts.Devices.WEDO2_TILT: case Consts.DeviceType.WEDO2_TILT:
{ {
this._lastTiltX = data[2]; this._lastTiltX = data[2];
if (this._lastTiltX > 100) { if (this._lastTiltX > 100) {
@ -340,7 +340,7 @@ export class WeDo2SmartHub extends Hub {
this.emit("tilt", port.id, this._lastTiltX, this._lastTiltY); this.emit("tilt", port.id, this._lastTiltX, this._lastTiltY);
break; break;
} }
case Consts.Devices.BOOST_TACHO_MOTOR: case Consts.DeviceType.BOOST_TACHO_MOTOR:
{ {
const rotation = data.readInt32LE(2); const rotation = data.readInt32LE(2);
/** /**