Added methods for fetching hub and device types
This commit is contained in:
parent
1e129ac77d
commit
7b192266ff
126
DOCS.md
126
DOCS.md
@ -18,6 +18,8 @@
|
|||||||
## Typedefs
|
## Typedefs
|
||||||
|
|
||||||
<dl>
|
<dl>
|
||||||
|
<dt><a href="#HubType">HubType</a></dt>
|
||||||
|
<dd></dd>
|
||||||
<dt><a href="#Device">Device</a></dt>
|
<dt><a href="#Device">Device</a></dt>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
<dt><a href="#Color">Color</a></dt>
|
<dt><a href="#Color">Color</a></dt>
|
||||||
@ -106,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>
|
||||||
* ["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)
|
||||||
@ -325,6 +329,23 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></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>
|
||||||
|
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)
|
||||||
@ -396,7 +417,7 @@ Emits when a motor or sensor is attached to the Hub.
|
|||||||
| Param | Type |
|
| Param | Type |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| port | <code>string</code> |
|
| port | <code>string</code> |
|
||||||
| type | [<code>Device</code>](#Device) |
|
| type | <code>DeviceType</code> |
|
||||||
|
|
||||||
<a name="Hub+event_detach"></a>
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
@ -435,6 +456,8 @@ 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>
|
||||||
* ["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)
|
||||||
@ -676,6 +699,25 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></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>
|
||||||
|
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)
|
||||||
@ -761,7 +803,7 @@ Emits when a motor or sensor is attached to the Hub.
|
|||||||
| Param | Type |
|
| Param | Type |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| port | <code>string</code> |
|
| port | <code>string</code> |
|
||||||
| type | [<code>Device</code>](#Device) |
|
| type | <code>DeviceType</code> |
|
||||||
|
|
||||||
<a name="Hub+event_detach"></a>
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
@ -800,6 +842,8 @@ 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>
|
||||||
* ["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)
|
||||||
@ -1026,6 +1070,25 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></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>
|
||||||
|
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)
|
||||||
@ -1099,7 +1162,7 @@ Emits when a motor or sensor is attached to the Hub.
|
|||||||
| Param | Type |
|
| Param | Type |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| port | <code>string</code> |
|
| port | <code>string</code> |
|
||||||
| type | [<code>Device</code>](#Device) |
|
| type | <code>DeviceType</code> |
|
||||||
|
|
||||||
<a name="Hub+event_detach"></a>
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
@ -1135,6 +1198,8 @@ 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>
|
||||||
* ["button" (button, state)](#LPF2Hub+event_button)
|
* ["button" (button, state)](#LPF2Hub+event_button)
|
||||||
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
|
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
|
||||||
|
|
||||||
@ -1315,6 +1380,25 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></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>
|
||||||
|
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)
|
||||||
@ -1365,6 +1449,8 @@ A combined color and distance event, emits when the sensor is activated.
|
|||||||
* [.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>
|
||||||
* ["color" (port, color)](#LPF2Hub+event_color)
|
* ["color" (port, color)](#LPF2Hub+event_color)
|
||||||
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
|
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
|
||||||
* ["speed" (port, speed)](#LPF2Hub+event_speed)
|
* ["speed" (port, speed)](#LPF2Hub+event_speed)
|
||||||
@ -1586,6 +1672,25 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></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>
|
||||||
|
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)
|
||||||
@ -1623,6 +1728,21 @@ 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="Device"></a>
|
<a name="Device"></a>
|
||||||
|
|
||||||
## Device
|
## Device
|
||||||
|
126
README.md
126
README.md
@ -101,6 +101,8 @@ Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian R
|
|||||||
## Typedefs
|
## Typedefs
|
||||||
|
|
||||||
<dl>
|
<dl>
|
||||||
|
<dt><a href="#HubType">HubType</a></dt>
|
||||||
|
<dd></dd>
|
||||||
<dt><a href="#Device">Device</a></dt>
|
<dt><a href="#Device">Device</a></dt>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
<dt><a href="#Color">Color</a></dt>
|
<dt><a href="#Color">Color</a></dt>
|
||||||
@ -189,6 +191,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>
|
||||||
* ["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)
|
||||||
@ -408,6 +412,23 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></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>
|
||||||
|
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)
|
||||||
@ -479,7 +500,7 @@ Emits when a motor or sensor is attached to the Hub.
|
|||||||
| Param | Type |
|
| Param | Type |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| port | <code>string</code> |
|
| port | <code>string</code> |
|
||||||
| type | [<code>Device</code>](#Device) |
|
| type | <code>DeviceType</code> |
|
||||||
|
|
||||||
<a name="Hub+event_detach"></a>
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
@ -518,6 +539,8 @@ 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>
|
||||||
* ["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)
|
||||||
@ -759,6 +782,25 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></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>
|
||||||
|
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)
|
||||||
@ -844,7 +886,7 @@ Emits when a motor or sensor is attached to the Hub.
|
|||||||
| Param | Type |
|
| Param | Type |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| port | <code>string</code> |
|
| port | <code>string</code> |
|
||||||
| type | [<code>Device</code>](#Device) |
|
| type | <code>DeviceType</code> |
|
||||||
|
|
||||||
<a name="Hub+event_detach"></a>
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
@ -883,6 +925,8 @@ 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>
|
||||||
* ["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)
|
||||||
@ -1109,6 +1153,25 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></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>
|
||||||
|
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)
|
||||||
@ -1182,7 +1245,7 @@ Emits when a motor or sensor is attached to the Hub.
|
|||||||
| Param | Type |
|
| Param | Type |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| port | <code>string</code> |
|
| port | <code>string</code> |
|
||||||
| type | [<code>Device</code>](#Device) |
|
| type | <code>DeviceType</code> |
|
||||||
|
|
||||||
<a name="Hub+event_detach"></a>
|
<a name="Hub+event_detach"></a>
|
||||||
|
|
||||||
@ -1218,6 +1281,8 @@ 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>
|
||||||
* ["button" (button, state)](#LPF2Hub+event_button)
|
* ["button" (button, state)](#LPF2Hub+event_button)
|
||||||
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
|
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
|
||||||
|
|
||||||
@ -1398,6 +1463,25 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></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>
|
||||||
|
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)
|
||||||
@ -1448,6 +1532,8 @@ A combined color and distance event, emits when the sensor is activated.
|
|||||||
* [.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>
|
||||||
* ["color" (port, color)](#LPF2Hub+event_color)
|
* ["color" (port, color)](#LPF2Hub+event_color)
|
||||||
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
|
* ["colorAndDistance" (port, color, distance)](#LPF2Hub+event_colorAndDistance)
|
||||||
* ["speed" (port, speed)](#LPF2Hub+event_speed)
|
* ["speed" (port, speed)](#LPF2Hub+event_speed)
|
||||||
@ -1669,6 +1755,25 @@ This is a helper method to make it easier to wait for concurrent commands to com
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| commands | <code>Array.<Promise.<any>></code> | Array of executing commands. |
|
| commands | <code>Array.<Promise.<any>></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>
|
||||||
|
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)
|
||||||
@ -1706,6 +1811,21 @@ 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="Device"></a>
|
<a name="Device"></a>
|
||||||
|
|
||||||
## Device
|
## Device
|
||||||
|
@ -33,7 +33,7 @@ export class BoostMoveHub extends LPF2Hub {
|
|||||||
|
|
||||||
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
||||||
super(peripheral, autoSubscribe);
|
super(peripheral, autoSubscribe);
|
||||||
this.type = Consts.Hub.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.Device.BOOST_TACHO_MOTOR || portObj.type === Consts.Device.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") {
|
||||||
@ -111,7 +111,7 @@ export class BoostMoveHub extends LPF2Hub {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (portObj.type === Consts.Device.BOOST_TACHO_MOTOR || portObj.type === Consts.Device.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") {
|
||||||
@ -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.Device.BOOST_TACHO_MOTOR || portObj.type === Consts.Device.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) {
|
||||||
|
13
consts.ts
13
consts.ts
@ -1,4 +1,13 @@
|
|||||||
export enum Hub {
|
/**
|
||||||
|
* @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,
|
||||||
@ -27,7 +36,7 @@ export enum Hub {
|
|||||||
* @property {number} DUPLO_TRAIN_BASE_SPEEDOMETER 44
|
* @property {number} DUPLO_TRAIN_BASE_SPEEDOMETER 44
|
||||||
* @property {number} POWERED_UP_REMOTE_BUTTON 55
|
* @property {number} POWERED_UP_REMOTE_BUTTON 55
|
||||||
*/
|
*/
|
||||||
export enum Device {
|
export enum DeviceType {
|
||||||
UNKNOWN = 0,
|
UNKNOWN = 0,
|
||||||
BASIC_MOTOR = 1,
|
BASIC_MOTOR = 1,
|
||||||
TRAIN_MOTOR = 2,
|
TRAIN_MOTOR = 2,
|
||||||
|
@ -58,7 +58,7 @@ export class DuploTrainBase extends LPF2Hub {
|
|||||||
|
|
||||||
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
||||||
super(peripheral, autoSubscribe);
|
super(peripheral, autoSubscribe);
|
||||||
this.type = Consts.Hub.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),
|
||||||
|
43
hub.ts
43
hub.ts
@ -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.Hub = Consts.Hub.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 {Device} type
|
* @param {DeviceType} type
|
||||||
*/
|
*/
|
||||||
this.emit("attach", port.id, type);
|
this.emit("attach", port.id, type);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
port.type = Consts.Device.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.Device) {
|
private _getModeForDeviceType (type: Consts.DeviceType) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Consts.Device.BASIC_MOTOR:
|
case Consts.DeviceType.BASIC_MOTOR:
|
||||||
return 0x02;
|
return 0x02;
|
||||||
case Consts.Device.TRAIN_MOTOR:
|
case Consts.DeviceType.TRAIN_MOTOR:
|
||||||
return 0x02;
|
return 0x02;
|
||||||
case Consts.Device.BOOST_TACHO_MOTOR:
|
case Consts.DeviceType.BOOST_TACHO_MOTOR:
|
||||||
return 0x02;
|
return 0x02;
|
||||||
case Consts.Device.BOOST_MOVE_HUB_MOTOR:
|
case Consts.DeviceType.BOOST_MOVE_HUB_MOTOR:
|
||||||
return 0x02;
|
return 0x02;
|
||||||
case Consts.Device.BOOST_DISTANCE:
|
case Consts.DeviceType.BOOST_DISTANCE:
|
||||||
return (this.type === Consts.Hub.WEDO2_SMART_HUB ? 0x00 : 0x08);
|
return (this.type === Consts.HubType.WEDO2_SMART_HUB ? 0x00 : 0x08);
|
||||||
case Consts.Device.BOOST_TILT:
|
case Consts.DeviceType.BOOST_TILT:
|
||||||
return 0x04;
|
return 0x04;
|
||||||
default:
|
default:
|
||||||
return 0x00;
|
return 0x00;
|
||||||
|
24
lpf2hub.ts
24
lpf2hub.ts
@ -42,7 +42,7 @@ export class LPF2Hub extends Hub {
|
|||||||
this._writeMessage(Consts.BLECharacteristic.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.BLECharacteristic.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.BLECharacteristic.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.Hub.DUPLO_TRAIN_HUB) {
|
if (this.type === Consts.HubType.DUPLO_TRAIN_HUB) {
|
||||||
this._writeMessage(Consts.BLECharacteristic.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();
|
||||||
@ -242,12 +242,12 @@ export class LPF2Hub extends Hub {
|
|||||||
|
|
||||||
private _parseSensorMessage (data: Buffer) {
|
private _parseSensorMessage (data: Buffer) {
|
||||||
|
|
||||||
if ((data[3] === 0x3b && this.type === Consts.Hub.POWERED_UP_REMOTE) || (data[3] === 0x3c && this.type !== Consts.Hub.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.Hub.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.Device.WEDO2_DISTANCE:
|
case Consts.DeviceType.WEDO2_DISTANCE:
|
||||||
{
|
{
|
||||||
let distance = data[4];
|
let distance = data[4];
|
||||||
if (data[5] === 1) {
|
if (data[5] === 1) {
|
||||||
@ -282,7 +282,7 @@ export class LPF2Hub extends Hub {
|
|||||||
this.emit("distance", port.id, distance * 10);
|
this.emit("distance", port.id, distance * 10);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Consts.Device.BOOST_DISTANCE:
|
case Consts.DeviceType.BOOST_DISTANCE:
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -318,7 +318,7 @@ export class LPF2Hub extends Hub {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Consts.Device.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);
|
||||||
@ -334,7 +334,7 @@ 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.Device.BOOST_TACHO_MOTOR:
|
case Consts.DeviceType.BOOST_TACHO_MOTOR:
|
||||||
{
|
{
|
||||||
const rotation = data.readInt32LE(4);
|
const rotation = data.readInt32LE(4);
|
||||||
/**
|
/**
|
||||||
@ -346,20 +346,20 @@ export class LPF2Hub extends Hub {
|
|||||||
this.emit("rotate", port.id, rotation);
|
this.emit("rotate", port.id, rotation);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Consts.Device.BOOST_MOVE_HUB_MOTOR:
|
case Consts.DeviceType.BOOST_MOVE_HUB_MOTOR:
|
||||||
{
|
{
|
||||||
const rotation = data.readInt32LE(4);
|
const rotation = data.readInt32LE(4);
|
||||||
this.emit("rotate", port.id, rotation);
|
this.emit("rotate", port.id, rotation);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Consts.Device.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.Device.POWERED_UP_REMOTE_BUTTON:
|
case Consts.DeviceType.POWERED_UP_REMOTE_BUTTON:
|
||||||
{
|
{
|
||||||
switch (data[4]) {
|
switch (data[4]) {
|
||||||
case 0x01:
|
case 0x01:
|
||||||
@ -385,14 +385,14 @@ export class LPF2Hub extends Hub {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Consts.Device.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.Device.DUPLO_TRAIN_BASE_SPEEDOMETER:
|
case Consts.DeviceType.DUPLO_TRAIN_BASE_SPEEDOMETER:
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Emits on a speed change.
|
* Emits on a speed change.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-poweredup",
|
"name": "node-poweredup",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"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",
|
||||||
|
4
port.ts
4
port.ts
@ -6,7 +6,7 @@ export class Port {
|
|||||||
|
|
||||||
public id: string;
|
public id: string;
|
||||||
public value: number;
|
public value: number;
|
||||||
public type: Consts.Device;
|
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.Device.UNKNOWN;
|
this.type = Consts.DeviceType.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public cancelEventTimer () {
|
public cancelEventTimer () {
|
||||||
|
@ -38,7 +38,7 @@ export class PUPHub extends LPF2Hub {
|
|||||||
|
|
||||||
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
||||||
super(peripheral, autoSubscribe);
|
super(peripheral, autoSubscribe);
|
||||||
this.type = Consts.Hub.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),
|
||||||
|
@ -63,7 +63,7 @@ export class PUPRemote extends LPF2Hub {
|
|||||||
|
|
||||||
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
constructor (peripheral: Peripheral, autoSubscribe: boolean = true) {
|
||||||
super(peripheral, autoSubscribe);
|
super(peripheral, autoSubscribe);
|
||||||
this.type = Consts.Hub.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)
|
||||||
|
@ -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.Hub.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)
|
||||||
@ -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.Device.WEDO2_DISTANCE:
|
case Consts.DeviceType.WEDO2_DISTANCE:
|
||||||
{
|
{
|
||||||
let distance = data[2];
|
let distance = data[2];
|
||||||
if (data[3] === 1) {
|
if (data[3] === 1) {
|
||||||
@ -308,7 +308,7 @@ export class WeDo2SmartHub extends Hub {
|
|||||||
this.emit("distance", port.id, distance * 10);
|
this.emit("distance", port.id, distance * 10);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Consts.Device.BOOST_DISTANCE:
|
case Consts.DeviceType.BOOST_DISTANCE:
|
||||||
{
|
{
|
||||||
const distance = data[2];
|
const distance = data[2];
|
||||||
/**
|
/**
|
||||||
@ -320,7 +320,7 @@ export class WeDo2SmartHub extends Hub {
|
|||||||
this.emit("color", port.id, distance);
|
this.emit("color", port.id, distance);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Consts.Device.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.Device.BOOST_TACHO_MOTOR:
|
case Consts.DeviceType.BOOST_TACHO_MOTOR:
|
||||||
{
|
{
|
||||||
const rotation = data.readInt32LE(2);
|
const rotation = data.readInt32LE(2);
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user