diff --git a/DOCS.md b/DOCS.md index 9ff14b0..f60fa32 100644 --- a/DOCS.md +++ b/DOCS.md @@ -11,7 +11,7 @@
LPF2Hub
LPF2Hub
LPF2Hub
WeDo2SmartHub
](#WeDo2SmartHub) \| [BoostMoveHub
](#BoostMoveHub) \| [PUPHub
](#PUPHub) \| [PUPRemote
](#PUPRemote) \| [DuploTrainHub
](#DuploTrainHub) |
+| hub | [WeDo2SmartHub
](#WeDo2SmartHub) \| [BoostMoveHub
](#BoostMoveHub) \| [PUPHub
](#PUPHub) \| [PUPRemote
](#PUPRemote) \| [DuploTrainBase
](#DuploTrainBase) |
@@ -85,7 +85,7 @@ Emits when a Powered UP Hub device is found.
* [.setLEDRGB(red, green, blue)](#WeDo2SmartHub+setLEDRGB) ⇒ Promise
* [.setMotorSpeed(port, speed, [time])](#WeDo2SmartHub+setMotorSpeed) ⇒ Promise
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#WeDo2SmartHub+rampMotorSpeed) ⇒ Promise
- * [.playSound(frequency, time)](#WeDo2SmartHub+playSound) ⇒ Promise
+ * [.playTone(frequency, time)](#WeDo2SmartHub+playTone) ⇒ Promise
* [.setLightBrightness(port, brightness, [time])](#WeDo2SmartHub+setLightBrightness) ⇒ Promise
* [.connect()](#Hub+connect) ⇒ Promise
* [.disconnect()](#Hub+disconnect) ⇒ Promise
@@ -217,18 +217,18 @@ Ramp the motor speed on a given port.
| toSpeed | number
| For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. |
| time | number
| How long the ramp should last (in milliseconds). |
-
+
-### weDo2SmartHub.playSound(frequency, time) ⇒ Promise
-Play a sound on the Hub's in-built buzzer
+### weDo2SmartHub.playTone(frequency, time) ⇒ Promise
+Play a tone on the Hub's in-built buzzer
**Kind**: instance method of [WeDo2SmartHub
](#WeDo2SmartHub)
-**Returns**: Promise
- Resolved upon successful completion of command (ie. once the sound has finished playing).
+**Returns**: Promise
- Resolved upon successful completion of command (ie. once the tone has finished playing).
| Param | Type | Description |
| --- | --- | --- |
| frequency | number
| |
-| time | number
| How long the sound should play for (in milliseconds). |
+| time | number
| How long the tone should play for (in milliseconds). |
@@ -1208,41 +1208,42 @@ Emits when a button is pressed.
| button | string
| |
| state | number
| A number representing one of the button state consts. |
-
+
-## DuploTrainHub ⇐ LPF2Hub
+## DuploTrainBase ⇐ LPF2Hub
**Kind**: global class
**Extends**: LPF2Hub
, Hub
-* [DuploTrainHub](#DuploTrainHub) ⇐ LPF2Hub
- * [new DuploTrainHub()](#new_DuploTrainHub_new)
+* [DuploTrainBase](#DuploTrainBase) ⇐ LPF2Hub
+ * [new DuploTrainBase()](#new_DuploTrainBase_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
- * [.setMotorSpeed(port, speed, [time])](#DuploTrainHub+setMotorSpeed) ⇒ Promise
- * [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#DuploTrainHub+rampMotorSpeed) ⇒ Promise
+ * [.setLEDColor(color)](#DuploTrainBase+setLEDColor) ⇒ Promise
+ * [.setMotorSpeed(port, speed, [time])](#DuploTrainBase+setMotorSpeed) ⇒ Promise
+ * [.playSound(sound)](#DuploTrainBase+playSound) ⇒ Promise
+ * [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#DuploTrainBase+rampMotorSpeed) ⇒ Promise
* [.setName(name)](#LPF2Hub+setName) ⇒ Promise
- * [.setLEDColor(color)](#LPF2Hub+setLEDColor) ⇒ Promise
* [.connect()](#Hub+connect) ⇒ Promise
* [.disconnect()](#Hub+disconnect) ⇒ Promise
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ Promise
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ Promise
* [.sleep(delay)](#Hub+sleep) ⇒ Promise
* [.wait(commands)](#Hub+wait) ⇒ Promise
- * ["button" (button, state)](#LPF2Hub+event_button)
* ["color" (port, color)](#LPF2Hub+event_color)
+ * ["speed" (port, speed)](#LPF2Hub+event_speed)
-
+
-### new DuploTrainHub()
-The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
+### new DuploTrainBase()
+The DuploTrainBase is emitted if the discovered device is a Duplo Train Base.
-### duploTrainHub.current
-**Kind**: instance property of [DuploTrainHub
](#DuploTrainHub)
+### duploTrainBase.current
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
**Read only**: true
**Properties**
@@ -1252,8 +1253,8 @@ The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
-### duploTrainHub.name
-**Kind**: instance property of [DuploTrainHub
](#DuploTrainHub)
+### duploTrainBase.name
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [name
](#Hub+name)
**Read only**: true
**Properties**
@@ -1264,8 +1265,8 @@ The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
-### duploTrainHub.uuid
-**Kind**: instance property of [DuploTrainHub
](#DuploTrainHub)
+### duploTrainBase.uuid
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [uuid
](#Hub+uuid)
**Read only**: true
**Properties**
@@ -1276,8 +1277,8 @@ The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
-### duploTrainHub.rssi
-**Kind**: instance property of [DuploTrainHub
](#DuploTrainHub)
+### duploTrainBase.rssi
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [rssi
](#Hub+rssi)
**Read only**: true
**Properties**
@@ -1288,8 +1289,8 @@ The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
-### duploTrainHub.batteryLevel
-**Kind**: instance property of [DuploTrainHub
](#DuploTrainHub)
+### duploTrainBase.batteryLevel
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [batteryLevel
](#Hub+batteryLevel)
**Read only**: true
**Properties**
@@ -1298,12 +1299,25 @@ The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
| --- | --- | --- |
| batteryLevel | number
| Battery level of the hub (Percentage between 0-100) |
-
+
-### duploTrainHub.setMotorSpeed(port, speed, [time]) ⇒ Promise
+### duploTrainBase.setLEDColor(color) ⇒ Promise
+Set the color of the LED on the train via a color value.
+
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
+**Overrides**: [setLEDColor
](#LPF2Hub+setLEDColor)
+**Returns**: Promise
- Resolved upon successful issuance of command.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| color | number
| A number representing one of the LED color consts. |
+
+
+
+### duploTrainBase.setMotorSpeed(port, speed, [time]) ⇒ Promise
Set the motor speed on a given port.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Returns**: Promise
- Resolved upon successful completion of command. If time is specified, this is once the motor is finished.
| Param | Type | Description |
@@ -1312,12 +1326,24 @@ Set the motor speed on a given port.
| speed | number
\| Array.<number>
| For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds. |
| [time] | number
| How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely. |
-
+
-### duploTrainHub.rampMotorSpeed(port, fromSpeed, toSpeed, time) ⇒ Promise
+### duploTrainBase.playSound(sound) ⇒ Promise
+Play a built-in train sound.
+
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
+**Returns**: Promise
- Resolved upon successful issuance of command.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| sound | number
| A number representing one of the Train Base sound consts. |
+
+
+
+### duploTrainBase.rampMotorSpeed(port, fromSpeed, toSpeed, time) ⇒ Promise
Ramp the motor speed on a given port.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Returns**: Promise
- Resolved upon successful completion of command.
| Param | Type | Description |
@@ -1329,50 +1355,38 @@ Ramp the motor speed on a given port.
-### duploTrainHub.setName(name) ⇒ Promise
+### duploTrainBase.setName(name) ⇒ Promise
Set the name of the Hub.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Returns**: Promise
- Resolved upon successful issuance of command.
| Param | Type | Description |
| --- | --- | --- |
| name | string
| New name of the hub (14 characters or less, ASCII only). |
-
-
-### duploTrainHub.setLEDColor(color) ⇒ Promise
-Set the color of the LED on the Hub via a color value.
-
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
-**Returns**: Promise
- Resolved upon successful issuance of command.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| color | number
| A number representing one of the LED color consts. |
-
-### duploTrainHub.connect() ⇒ Promise
+### duploTrainBase.connect() ⇒ Promise
Connect to the Hub.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [connect
](#Hub+connect)
**Returns**: Promise
- Resolved upon successful connect.
-### duploTrainHub.disconnect() ⇒ Promise
+### duploTrainBase.disconnect() ⇒ Promise
Disconnect the Hub.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [disconnect
](#Hub+disconnect)
**Returns**: Promise
- Resolved upon successful disconnect.
-### duploTrainHub.subscribe(port, [mode]) ⇒ Promise
+### duploTrainBase.subscribe(port, [mode]) ⇒ Promise
Subscribe to sensor notifications on a given port.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [subscribe
](#Hub+subscribe)
**Returns**: Promise
- Resolved upon successful issuance of command.
@@ -1383,10 +1397,10 @@ Subscribe to sensor notifications on a given port.
-### duploTrainHub.unsubscribe(port) ⇒ Promise
+### duploTrainBase.unsubscribe(port) ⇒ Promise
Unsubscribe to sensor notifications on a given port.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [unsubscribe
](#Hub+unsubscribe)
**Returns**: Promise
- Resolved upon successful issuance of command.
@@ -1396,12 +1410,12 @@ Unsubscribe to sensor notifications on a given port.
-### duploTrainHub.sleep(delay) ⇒ Promise
+### duploTrainBase.sleep(delay) ⇒ Promise
Sleep a given amount of time.
This is a helper method to make it easier to add delays into a chain of commands.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [sleep
](#Hub+sleep)
**Returns**: Promise
- Resolved after the delay is finished.
@@ -1411,12 +1425,12 @@ This is a helper method to make it easier to add delays into a chain of commands
-### duploTrainHub.wait(commands) ⇒ Promise
+### duploTrainBase.wait(commands) ⇒ Promise
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.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [wait
](#Hub+wait)
**Returns**: Promise
- Resolved after the commands are finished.
@@ -1424,27 +1438,27 @@ This is a helper method to make it easier to wait for concurrent commands to com
| --- | --- | --- |
| commands | Array.<Promise.<any>>
| Array of executing commands. |
-
-
-### "button" (button, state)
-Emits when a button is pressed.
-
-**Kind**: event emitted by [DuploTrainHub
](#DuploTrainHub)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| button | string
| |
-| state | number
| A number representing one of the button state consts. |
-
### "color" (port, color)
Emits when a color sensor is activated.
-**Kind**: event emitted by [DuploTrainHub
](#DuploTrainHub)
+**Kind**: event emitted by [DuploTrainBase
](#DuploTrainBase)
| Param | Type | Description |
| --- | --- | --- |
| port | string
| |
| color | number
| A number representing one of the LED color consts. |
+
+
+### "speed" (port, speed)
+Emits on a speed change.
+
+**Kind**: event emitted by [DuploTrainBase
](#DuploTrainBase)
+
+| Param | Type |
+| --- | --- |
+| port | string
|
+| speed | number
|
+
diff --git a/README.md b/README.md
index 1d5f9c1..f13baec 100644
--- a/README.md
+++ b/README.md
@@ -90,7 +90,7 @@ Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian R
LPF2Hub
LPF2Hub
LPF2Hub
WeDo2SmartHub
](#WeDo2SmartHub) \| [BoostMoveHub
](#BoostMoveHub) \| [PUPHub
](#PUPHub) \| [PUPRemote
](#PUPRemote) \| [DuploTrainHub
](#DuploTrainHub) |
+| hub | [WeDo2SmartHub
](#WeDo2SmartHub) \| [BoostMoveHub
](#BoostMoveHub) \| [PUPHub
](#PUPHub) \| [PUPRemote
](#PUPRemote) \| [DuploTrainBase
](#DuploTrainBase) |
@@ -164,7 +164,7 @@ Emits when a Powered UP Hub device is found.
* [.setLEDRGB(red, green, blue)](#WeDo2SmartHub+setLEDRGB) ⇒ Promise
* [.setMotorSpeed(port, speed, [time])](#WeDo2SmartHub+setMotorSpeed) ⇒ Promise
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#WeDo2SmartHub+rampMotorSpeed) ⇒ Promise
- * [.playSound(frequency, time)](#WeDo2SmartHub+playSound) ⇒ Promise
+ * [.playTone(frequency, time)](#WeDo2SmartHub+playTone) ⇒ Promise
* [.setLightBrightness(port, brightness, [time])](#WeDo2SmartHub+setLightBrightness) ⇒ Promise
* [.connect()](#Hub+connect) ⇒ Promise
* [.disconnect()](#Hub+disconnect) ⇒ Promise
@@ -296,18 +296,18 @@ Ramp the motor speed on a given port.
| toSpeed | number
| For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. |
| time | number
| How long the ramp should last (in milliseconds). |
-
+
-### weDo2SmartHub.playSound(frequency, time) ⇒ Promise
-Play a sound on the Hub's in-built buzzer
+### weDo2SmartHub.playTone(frequency, time) ⇒ Promise
+Play a tone on the Hub's in-built buzzer
**Kind**: instance method of [WeDo2SmartHub
](#WeDo2SmartHub)
-**Returns**: Promise
- Resolved upon successful completion of command (ie. once the sound has finished playing).
+**Returns**: Promise
- Resolved upon successful completion of command (ie. once the tone has finished playing).
| Param | Type | Description |
| --- | --- | --- |
| frequency | number
| |
-| time | number
| How long the sound should play for (in milliseconds). |
+| time | number
| How long the tone should play for (in milliseconds). |
@@ -1287,41 +1287,42 @@ Emits when a button is pressed.
| button | string
| |
| state | number
| A number representing one of the button state consts. |
-
+
-## DuploTrainHub ⇐ LPF2Hub
+## DuploTrainBase ⇐ LPF2Hub
**Kind**: global class
**Extends**: LPF2Hub
, Hub
-* [DuploTrainHub](#DuploTrainHub) ⇐ LPF2Hub
- * [new DuploTrainHub()](#new_DuploTrainHub_new)
+* [DuploTrainBase](#DuploTrainBase) ⇐ LPF2Hub
+ * [new DuploTrainBase()](#new_DuploTrainBase_new)
* [.current](#LPF2Hub+current)
* [.name](#Hub+name)
* [.uuid](#Hub+uuid)
* [.rssi](#Hub+rssi)
* [.batteryLevel](#Hub+batteryLevel)
- * [.setMotorSpeed(port, speed, [time])](#DuploTrainHub+setMotorSpeed) ⇒ Promise
- * [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#DuploTrainHub+rampMotorSpeed) ⇒ Promise
+ * [.setLEDColor(color)](#DuploTrainBase+setLEDColor) ⇒ Promise
+ * [.setMotorSpeed(port, speed, [time])](#DuploTrainBase+setMotorSpeed) ⇒ Promise
+ * [.playSound(sound)](#DuploTrainBase+playSound) ⇒ Promise
+ * [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#DuploTrainBase+rampMotorSpeed) ⇒ Promise
* [.setName(name)](#LPF2Hub+setName) ⇒ Promise
- * [.setLEDColor(color)](#LPF2Hub+setLEDColor) ⇒ Promise
* [.connect()](#Hub+connect) ⇒ Promise
* [.disconnect()](#Hub+disconnect) ⇒ Promise
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ Promise
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ Promise
* [.sleep(delay)](#Hub+sleep) ⇒ Promise
* [.wait(commands)](#Hub+wait) ⇒ Promise
- * ["button" (button, state)](#LPF2Hub+event_button)
* ["color" (port, color)](#LPF2Hub+event_color)
+ * ["speed" (port, speed)](#LPF2Hub+event_speed)
-
+
-### new DuploTrainHub()
-The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
+### new DuploTrainBase()
+The DuploTrainBase is emitted if the discovered device is a Duplo Train Base.
-### duploTrainHub.current
-**Kind**: instance property of [DuploTrainHub
](#DuploTrainHub)
+### duploTrainBase.current
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
**Read only**: true
**Properties**
@@ -1331,8 +1332,8 @@ The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
-### duploTrainHub.name
-**Kind**: instance property of [DuploTrainHub
](#DuploTrainHub)
+### duploTrainBase.name
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [name
](#Hub+name)
**Read only**: true
**Properties**
@@ -1343,8 +1344,8 @@ The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
-### duploTrainHub.uuid
-**Kind**: instance property of [DuploTrainHub
](#DuploTrainHub)
+### duploTrainBase.uuid
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [uuid
](#Hub+uuid)
**Read only**: true
**Properties**
@@ -1355,8 +1356,8 @@ The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
-### duploTrainHub.rssi
-**Kind**: instance property of [DuploTrainHub
](#DuploTrainHub)
+### duploTrainBase.rssi
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [rssi
](#Hub+rssi)
**Read only**: true
**Properties**
@@ -1367,8 +1368,8 @@ The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
-### duploTrainHub.batteryLevel
-**Kind**: instance property of [DuploTrainHub
](#DuploTrainHub)
+### duploTrainBase.batteryLevel
+**Kind**: instance property of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [batteryLevel
](#Hub+batteryLevel)
**Read only**: true
**Properties**
@@ -1377,12 +1378,25 @@ The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
| --- | --- | --- |
| batteryLevel | number
| Battery level of the hub (Percentage between 0-100) |
-
+
-### duploTrainHub.setMotorSpeed(port, speed, [time]) ⇒ Promise
+### duploTrainBase.setLEDColor(color) ⇒ Promise
+Set the color of the LED on the train via a color value.
+
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
+**Overrides**: [setLEDColor
](#LPF2Hub+setLEDColor)
+**Returns**: Promise
- Resolved upon successful issuance of command.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| color | number
| A number representing one of the LED color consts. |
+
+
+
+### duploTrainBase.setMotorSpeed(port, speed, [time]) ⇒ Promise
Set the motor speed on a given port.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Returns**: Promise
- Resolved upon successful completion of command. If time is specified, this is once the motor is finished.
| Param | Type | Description |
@@ -1391,12 +1405,24 @@ Set the motor speed on a given port.
| speed | number
\| Array.<number>
| For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds. |
| [time] | number
| How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely. |
-
+
-### duploTrainHub.rampMotorSpeed(port, fromSpeed, toSpeed, time) ⇒ Promise
+### duploTrainBase.playSound(sound) ⇒ Promise
+Play a built-in train sound.
+
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
+**Returns**: Promise
- Resolved upon successful issuance of command.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| sound | number
| A number representing one of the Train Base sound consts. |
+
+
+
+### duploTrainBase.rampMotorSpeed(port, fromSpeed, toSpeed, time) ⇒ Promise
Ramp the motor speed on a given port.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Returns**: Promise
- Resolved upon successful completion of command.
| Param | Type | Description |
@@ -1408,50 +1434,38 @@ Ramp the motor speed on a given port.
-### duploTrainHub.setName(name) ⇒ Promise
+### duploTrainBase.setName(name) ⇒ Promise
Set the name of the Hub.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Returns**: Promise
- Resolved upon successful issuance of command.
| Param | Type | Description |
| --- | --- | --- |
| name | string
| New name of the hub (14 characters or less, ASCII only). |
-
-
-### duploTrainHub.setLEDColor(color) ⇒ Promise
-Set the color of the LED on the Hub via a color value.
-
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
-**Returns**: Promise
- Resolved upon successful issuance of command.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| color | number
| A number representing one of the LED color consts. |
-
-### duploTrainHub.connect() ⇒ Promise
+### duploTrainBase.connect() ⇒ Promise
Connect to the Hub.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [connect
](#Hub+connect)
**Returns**: Promise
- Resolved upon successful connect.
-### duploTrainHub.disconnect() ⇒ Promise
+### duploTrainBase.disconnect() ⇒ Promise
Disconnect the Hub.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [disconnect
](#Hub+disconnect)
**Returns**: Promise
- Resolved upon successful disconnect.
-### duploTrainHub.subscribe(port, [mode]) ⇒ Promise
+### duploTrainBase.subscribe(port, [mode]) ⇒ Promise
Subscribe to sensor notifications on a given port.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [subscribe
](#Hub+subscribe)
**Returns**: Promise
- Resolved upon successful issuance of command.
@@ -1462,10 +1476,10 @@ Subscribe to sensor notifications on a given port.
-### duploTrainHub.unsubscribe(port) ⇒ Promise
+### duploTrainBase.unsubscribe(port) ⇒ Promise
Unsubscribe to sensor notifications on a given port.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [unsubscribe
](#Hub+unsubscribe)
**Returns**: Promise
- Resolved upon successful issuance of command.
@@ -1475,12 +1489,12 @@ Unsubscribe to sensor notifications on a given port.
-### duploTrainHub.sleep(delay) ⇒ Promise
+### duploTrainBase.sleep(delay) ⇒ Promise
Sleep a given amount of time.
This is a helper method to make it easier to add delays into a chain of commands.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [sleep
](#Hub+sleep)
**Returns**: Promise
- Resolved after the delay is finished.
@@ -1490,12 +1504,12 @@ This is a helper method to make it easier to add delays into a chain of commands
-### duploTrainHub.wait(commands) ⇒ Promise
+### duploTrainBase.wait(commands) ⇒ Promise
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.
-**Kind**: instance method of [DuploTrainHub
](#DuploTrainHub)
+**Kind**: instance method of [DuploTrainBase
](#DuploTrainBase)
**Overrides**: [wait
](#Hub+wait)
**Returns**: Promise
- Resolved after the commands are finished.
@@ -1503,27 +1517,27 @@ This is a helper method to make it easier to wait for concurrent commands to com
| --- | --- | --- |
| commands | Array.<Promise.<any>>
| Array of executing commands. |
-
-
-### "button" (button, state)
-Emits when a button is pressed.
-
-**Kind**: event emitted by [DuploTrainHub
](#DuploTrainHub)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| button | string
| |
-| state | number
| A number representing one of the button state consts. |
-
### "color" (port, color)
Emits when a color sensor is activated.
-**Kind**: event emitted by [DuploTrainHub
](#DuploTrainHub)
+**Kind**: event emitted by [DuploTrainBase
](#DuploTrainBase)
| Param | Type | Description |
| --- | --- | --- |
| port | string
| |
| color | number
| A number representing one of the LED color consts. |
+
+
+### "speed" (port, speed)
+Emits on a speed change.
+
+**Kind**: event emitted by [DuploTrainBase
](#DuploTrainBase)
+
+| Param | Type |
+| --- | --- |
+| port | string
|
+| speed | number
|
+
diff --git a/boostmovehub.ts b/boostmovehub.ts
index 49012ad..27df0e8 100644
--- a/boostmovehub.ts
+++ b/boostmovehub.ts
@@ -18,6 +18,14 @@ const debug = Debug("boostmovehub");
export class BoostMoveHub extends LPF2Hub {
+ // We set JSDoc to ignore these events as a Boost Move Hub will never emit them.
+
+ /**
+ * @event BoostMoveHub#speed
+ * @ignore
+ */
+
+
public static IsBoostMoveHub (peripheral: Peripheral) {
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.LPF2_HUB) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.BOOST_MOVE_HUB_ID);
}
diff --git a/consts.ts b/consts.ts
index de220c3..8972fe9 100644
--- a/consts.ts
+++ b/consts.ts
@@ -7,6 +7,7 @@ export enum Hubs {
DUPLO_TRAIN_HUB = 5
}
+
export enum Devices {
UNKNOWN = 0,
BASIC_MOTOR = 1,
@@ -19,6 +20,10 @@ export enum Devices {
BOOST_TACHO_MOTOR = 38,
BOOST_MOVE_HUB_MOTOR = 39,
BOOST_TILT = 40,
+ DUPLO_TRAIN_BASE_MOTOR = 41,
+ DUPLO_TRAIN_BASE_SPEAKER = 42,
+ DUPLO_TRAIN_BASE_COLOR = 43,
+ DUPLO_TRAIN_BASE_SPEEDOMETER = 44,
POWERED_UP_REMOTE_BUTTON = 55
}
@@ -38,6 +43,7 @@ export enum Colors {
NONE = 255
}
+
export enum ButtonStates {
PRESSED = 0,
RELEASED = 1,
@@ -46,13 +52,22 @@ export enum ButtonStates {
STOP = 4
}
+
+export enum DuploTrainBaseSounds {
+ STATION_DEPARTURE = 5,
+ WATER_REFILL = 7,
+ HORN = 9
+}
+
+
export enum BLEManufacturerData {
BOOST_MOVE_HUB_ID = 64,
POWERED_UP_HUB_ID = 65,
POWERED_UP_REMOTE_ID = 66,
- DUPLO_TRAIN_HUB_ID = 66
+ DUPLO_TRAIN_HUB_ID = 32
}
+
export enum BLEServices {
WEDO2_SMART_HUB = "000015231212efde1523785feabcd123",
LPF2_HUB = "000016231212efde1623785feabcd123"
diff --git a/duplotrainhub.ts b/duplotrainbase.ts
similarity index 55%
rename from duplotrainhub.ts
rename to duplotrainbase.ts
index 2072451..7a4a117 100644
--- a/duplotrainhub.ts
+++ b/duplotrainbase.ts
@@ -6,47 +6,52 @@ import { Port } from "./port";
import * as Consts from "./consts";
import Debug = require("debug");
-const debug = Debug("duplotrainhub");
+const debug = Debug("duploTrainBase");
/**
- * The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub.
- * @class DuploTrainHub
+ * The DuploTrainBase is emitted if the discovered device is a Duplo Train Base.
+ * @class DuploTrainBase
* @extends LPF2Hub
* @extends Hub
*/
-export class DuploTrainHub extends LPF2Hub {
+export class DuploTrainBase extends LPF2Hub {
- // We set JSDoc to ignore these events as a Duplo Train Hub will never emit them.
+ // We set JSDoc to ignore these events as a Duplo Train Base will never emit them.
/**
- * @event DuploTrainHub#distance
+ * @event DuploTrainBase#distance
* @ignore
*/
/**
- * @event DuploTrainHub#tilt
+ * @event DuploTrainBase#tilt
* @ignore
*/
/**
- * @event DuploTrainHub#rotate
+ * @event DuploTrainBase#rotate
* @ignore
*/
/**
- * @event DuploTrainHub#attach
+ * @event DuploTrainBase#button
* @ignore
*/
/**
- * @event DuploTrainHub#detach
+ * @event DuploTrainBase#attach
+ * @ignore
+ */
+
+ /**
+ * @event DuploTrainBase#detach
* @ignore
*/
- public static IsDuploTrainHub (peripheral: Peripheral) {
+ public static IsDuploTrainBase (peripheral: Peripheral) {
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.LPF2_HUB) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.DUPLO_TRAIN_HUB_ID);
}
@@ -55,15 +60,17 @@ export class DuploTrainHub extends LPF2Hub {
super(peripheral, autoSubscribe);
this.type = Consts.Hubs.DUPLO_TRAIN_HUB;
this._ports = {
- "MOTOR": new Port("MOTOR", 0)
+ "MOTOR": new Port("MOTOR", 0),
+ "COLOR": new Port("COLOR", 18),
+ "SPEEDOMETER": new Port("SPEEDOMETER", 19)
};
- debug("Discovered Duplo Train Hub");
+ debug("Discovered Duplo Train Base");
}
public connect () {
return new Promise(async (resolve, reject) => {
- debug("Connecting to Duplo Train Hub");
+ debug("Connecting to Duplo Train Base");
await super.connect();
debug("Connect completed");
return resolve();
@@ -71,26 +78,34 @@ export class DuploTrainHub extends LPF2Hub {
}
+ /**
+ * Set the color of the LED on the train via a color value.
+ * @method DuploTrainBase#setLEDColor
+ * @param {number} color A number representing one of the LED color consts.
+ * @returns {Promise} Resolved upon successful issuance of command.
+ */
+ public setLEDColor (color: number | boolean) {
+ return new Promise((resolve, reject) => {
+ if (color === false) {
+ color = 0;
+ }
+ const data = Buffer.from([0x81, 0x11, 0x11, 0x51, 0x00, color]);
+ this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
+ return resolve();
+ });
+ }
+
+
/**
* Set the motor speed on a given port.
- * @method DuploTrainHub#setMotorSpeed
+ * @method DuploTrainBase#setMotorSpeed
* @param {string} port
* @param {number | Array.