Laying the groundwork for PUP light support
This commit is contained in:
parent
09c638a8d4
commit
e72dbd33a9
98
DOCS.md
98
DOCS.md
@ -84,6 +84,7 @@ Emits when a Powered UP Hub device is found.
|
||||
* [.setMotorSpeed(port, speed, [time])](#WeDo2SmartHub+setMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#WeDo2SmartHub+rampMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.playSound(frequency, time)](#WeDo2SmartHub+playSound) ⇒ <code>Promise</code>
|
||||
* [.setLightBrightness(port, brightness, [time])](#WeDo2SmartHub+setLightBrightness) ⇒ <code>Promise</code>
|
||||
* [.connect()](#Hub+connect) ⇒ <code>Promise</code>
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
@ -227,6 +228,20 @@ Play a sound on the Hub's in-built buzzer
|
||||
| frequency | <code>number</code> | |
|
||||
| time | <code>number</code> | How long the sound should play for (in milliseconds). |
|
||||
|
||||
<a name="WeDo2SmartHub+setLightBrightness"></a>
|
||||
|
||||
### weDo2SmartHub.setLightBrightness(port, brightness, [time]) ⇒ <code>Promise</code>
|
||||
Set the light brightness on a given port.
|
||||
|
||||
**Kind**: instance method of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| port | <code>string</code> | |
|
||||
| brightness | <code>number</code> | Brightness value between 0-100 (0 is off) |
|
||||
| [time] | <code>number</code> | How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
### weDo2SmartHub.connect() ⇒ <code>Promise</code>
|
||||
@ -392,11 +407,12 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
* [.uuid](#Hub+uuid)
|
||||
* [.rssi](#Hub+rssi)
|
||||
* [.batteryLevel](#Hub+batteryLevel)
|
||||
* [.setLEDColor(color)](#BoostMoveHub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.setMotorSpeed(port, speed, [time])](#BoostMoveHub+setMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#BoostMoveHub+rampMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.setMotorAngle(port, angle, [speed])](#BoostMoveHub+setMotorAngle) ⇒ <code>Promise</code>
|
||||
* [.setLightBrightness(port, brightness, [time])](#BoostMoveHub+setLightBrightness) ⇒ <code>Promise</code>
|
||||
* [.setName(name)](#LPF2Hub+setName) ⇒ <code>Promise</code>
|
||||
* [.setLEDColor(color)](#LPF2Hub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.connect()](#Hub+connect) ⇒ <code>Promise</code>
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
@ -471,18 +487,6 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
|
||||
| --- | --- | --- |
|
||||
| batteryLevel | <code>number</code> | Battery level of the hub (Percentage between 0-100) |
|
||||
|
||||
<a name="BoostMoveHub+setLEDColor"></a>
|
||||
|
||||
### boostMoveHub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
Set the color of the LED on the Hub via a color value.
|
||||
|
||||
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| color | <code>number</code> | A number representing one of the LED color consts. |
|
||||
|
||||
<a name="BoostMoveHub+setMotorSpeed"></a>
|
||||
|
||||
### boostMoveHub.setMotorSpeed(port, speed, [time]) ⇒ <code>Promise</code>
|
||||
@ -526,6 +530,20 @@ Rotate a motor by a given angle.
|
||||
| angle | <code>number</code> | | How much the motor should be rotated (in degrees). |
|
||||
| [speed] | <code>number</code> \| <code>Array.<number></code> | <code>100</code> | 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. |
|
||||
|
||||
<a name="BoostMoveHub+setLightBrightness"></a>
|
||||
|
||||
### boostMoveHub.setLightBrightness(port, brightness, [time]) ⇒ <code>Promise</code>
|
||||
Set the light brightness on a given port.
|
||||
|
||||
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| port | <code>string</code> | |
|
||||
| brightness | <code>number</code> | Brightness value between 0-100 (0 is off) |
|
||||
| [time] | <code>number</code> | How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
|
||||
|
||||
<a name="LPF2Hub+setName"></a>
|
||||
|
||||
### boostMoveHub.setName(name) ⇒ <code>Promise</code>
|
||||
@ -538,6 +556,18 @@ Set the name of the Hub.
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="LPF2Hub+setLEDColor"></a>
|
||||
|
||||
### boostMoveHub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
Set the color of the LED on the Hub via a color value.
|
||||
|
||||
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| color | <code>number</code> | A number representing one of the LED color consts. |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
### boostMoveHub.connect() ⇒ <code>Promise</code>
|
||||
@ -703,10 +733,11 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
* [.uuid](#Hub+uuid)
|
||||
* [.rssi](#Hub+rssi)
|
||||
* [.batteryLevel](#Hub+batteryLevel)
|
||||
* [.setLEDColor(color)](#PUPHub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.setMotorSpeed(port, speed, [time])](#PUPHub+setMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#PUPHub+rampMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.setLightBrightness(port, brightness, [time])](#PUPHub+setLightBrightness) ⇒ <code>Promise</code>
|
||||
* [.setName(name)](#LPF2Hub+setName) ⇒ <code>Promise</code>
|
||||
* [.setLEDColor(color)](#LPF2Hub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.connect()](#Hub+connect) ⇒ <code>Promise</code>
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
@ -780,18 +811,6 @@ The PUPHub is emitted if the discovered device is a Powered Up Hub.
|
||||
| --- | --- | --- |
|
||||
| batteryLevel | <code>number</code> | Battery level of the hub (Percentage between 0-100) |
|
||||
|
||||
<a name="PUPHub+setLEDColor"></a>
|
||||
|
||||
### pupHub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
Set the color of the LED on the Hub via a color value.
|
||||
|
||||
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| color | <code>number</code> | A number representing one of the LED color consts. |
|
||||
|
||||
<a name="PUPHub+setMotorSpeed"></a>
|
||||
|
||||
### pupHub.setMotorSpeed(port, speed, [time]) ⇒ <code>Promise</code>
|
||||
@ -821,6 +840,20 @@ Ramp the motor speed on a given port.
|
||||
| toSpeed | <code>number</code> | For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. |
|
||||
| time | <code>number</code> | How long the ramp should last (in milliseconds). |
|
||||
|
||||
<a name="PUPHub+setLightBrightness"></a>
|
||||
|
||||
### pupHub.setLightBrightness(port, brightness, [time]) ⇒ <code>Promise</code>
|
||||
Set the light brightness on a given port.
|
||||
|
||||
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| port | <code>string</code> | |
|
||||
| brightness | <code>number</code> | Brightness value between 0-100 (0 is off) |
|
||||
| [time] | <code>number</code> | How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
|
||||
|
||||
<a name="LPF2Hub+setName"></a>
|
||||
|
||||
### pupHub.setName(name) ⇒ <code>Promise</code>
|
||||
@ -833,6 +866,18 @@ Set the name of the Hub.
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="LPF2Hub+setLEDColor"></a>
|
||||
|
||||
### pupHub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
Set the color of the LED on the Hub via a color value.
|
||||
|
||||
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| color | <code>number</code> | A number representing one of the LED color consts. |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
### pupHub.connect() ⇒ <code>Promise</code>
|
||||
@ -1062,6 +1107,7 @@ The PUPRemote is emitted if the discovered device is a Powered Up Remote.
|
||||
Set the color of the LED on the Remote via a color value.
|
||||
|
||||
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
|
||||
**Overrides**: [<code>setLEDColor</code>](#LPF2Hub+setLEDColor)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
|
||||
|
||||
| Param | Type | Description |
|
||||
|
98
README.md
98
README.md
@ -163,6 +163,7 @@ Emits when a Powered UP Hub device is found.
|
||||
* [.setMotorSpeed(port, speed, [time])](#WeDo2SmartHub+setMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#WeDo2SmartHub+rampMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.playSound(frequency, time)](#WeDo2SmartHub+playSound) ⇒ <code>Promise</code>
|
||||
* [.setLightBrightness(port, brightness, [time])](#WeDo2SmartHub+setLightBrightness) ⇒ <code>Promise</code>
|
||||
* [.connect()](#Hub+connect) ⇒ <code>Promise</code>
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
@ -306,6 +307,20 @@ Play a sound on the Hub's in-built buzzer
|
||||
| frequency | <code>number</code> | |
|
||||
| time | <code>number</code> | How long the sound should play for (in milliseconds). |
|
||||
|
||||
<a name="WeDo2SmartHub+setLightBrightness"></a>
|
||||
|
||||
### weDo2SmartHub.setLightBrightness(port, brightness, [time]) ⇒ <code>Promise</code>
|
||||
Set the light brightness on a given port.
|
||||
|
||||
**Kind**: instance method of [<code>WeDo2SmartHub</code>](#WeDo2SmartHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| port | <code>string</code> | |
|
||||
| brightness | <code>number</code> | Brightness value between 0-100 (0 is off) |
|
||||
| [time] | <code>number</code> | How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
### weDo2SmartHub.connect() ⇒ <code>Promise</code>
|
||||
@ -471,11 +486,12 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
* [.uuid](#Hub+uuid)
|
||||
* [.rssi](#Hub+rssi)
|
||||
* [.batteryLevel](#Hub+batteryLevel)
|
||||
* [.setLEDColor(color)](#BoostMoveHub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.setMotorSpeed(port, speed, [time])](#BoostMoveHub+setMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#BoostMoveHub+rampMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.setMotorAngle(port, angle, [speed])](#BoostMoveHub+setMotorAngle) ⇒ <code>Promise</code>
|
||||
* [.setLightBrightness(port, brightness, [time])](#BoostMoveHub+setLightBrightness) ⇒ <code>Promise</code>
|
||||
* [.setName(name)](#LPF2Hub+setName) ⇒ <code>Promise</code>
|
||||
* [.setLEDColor(color)](#LPF2Hub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.connect()](#Hub+connect) ⇒ <code>Promise</code>
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
@ -550,18 +566,6 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
|
||||
| --- | --- | --- |
|
||||
| batteryLevel | <code>number</code> | Battery level of the hub (Percentage between 0-100) |
|
||||
|
||||
<a name="BoostMoveHub+setLEDColor"></a>
|
||||
|
||||
### boostMoveHub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
Set the color of the LED on the Hub via a color value.
|
||||
|
||||
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| color | <code>number</code> | A number representing one of the LED color consts. |
|
||||
|
||||
<a name="BoostMoveHub+setMotorSpeed"></a>
|
||||
|
||||
### boostMoveHub.setMotorSpeed(port, speed, [time]) ⇒ <code>Promise</code>
|
||||
@ -605,6 +609,20 @@ Rotate a motor by a given angle.
|
||||
| angle | <code>number</code> | | How much the motor should be rotated (in degrees). |
|
||||
| [speed] | <code>number</code> \| <code>Array.<number></code> | <code>100</code> | 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. |
|
||||
|
||||
<a name="BoostMoveHub+setLightBrightness"></a>
|
||||
|
||||
### boostMoveHub.setLightBrightness(port, brightness, [time]) ⇒ <code>Promise</code>
|
||||
Set the light brightness on a given port.
|
||||
|
||||
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| port | <code>string</code> | |
|
||||
| brightness | <code>number</code> | Brightness value between 0-100 (0 is off) |
|
||||
| [time] | <code>number</code> | How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
|
||||
|
||||
<a name="LPF2Hub+setName"></a>
|
||||
|
||||
### boostMoveHub.setName(name) ⇒ <code>Promise</code>
|
||||
@ -617,6 +635,18 @@ Set the name of the Hub.
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="LPF2Hub+setLEDColor"></a>
|
||||
|
||||
### boostMoveHub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
Set the color of the LED on the Hub via a color value.
|
||||
|
||||
**Kind**: instance method of [<code>BoostMoveHub</code>](#BoostMoveHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| color | <code>number</code> | A number representing one of the LED color consts. |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
### boostMoveHub.connect() ⇒ <code>Promise</code>
|
||||
@ -782,10 +812,11 @@ Emits when an attached motor or sensor is detached from the Hub.
|
||||
* [.uuid](#Hub+uuid)
|
||||
* [.rssi](#Hub+rssi)
|
||||
* [.batteryLevel](#Hub+batteryLevel)
|
||||
* [.setLEDColor(color)](#PUPHub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.setMotorSpeed(port, speed, [time])](#PUPHub+setMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#PUPHub+rampMotorSpeed) ⇒ <code>Promise</code>
|
||||
* [.setLightBrightness(port, brightness, [time])](#PUPHub+setLightBrightness) ⇒ <code>Promise</code>
|
||||
* [.setName(name)](#LPF2Hub+setName) ⇒ <code>Promise</code>
|
||||
* [.setLEDColor(color)](#LPF2Hub+setLEDColor) ⇒ <code>Promise</code>
|
||||
* [.connect()](#Hub+connect) ⇒ <code>Promise</code>
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
@ -859,18 +890,6 @@ The PUPHub is emitted if the discovered device is a Powered Up Hub.
|
||||
| --- | --- | --- |
|
||||
| batteryLevel | <code>number</code> | Battery level of the hub (Percentage between 0-100) |
|
||||
|
||||
<a name="PUPHub+setLEDColor"></a>
|
||||
|
||||
### pupHub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
Set the color of the LED on the Hub via a color value.
|
||||
|
||||
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| color | <code>number</code> | A number representing one of the LED color consts. |
|
||||
|
||||
<a name="PUPHub+setMotorSpeed"></a>
|
||||
|
||||
### pupHub.setMotorSpeed(port, speed, [time]) ⇒ <code>Promise</code>
|
||||
@ -900,6 +919,20 @@ Ramp the motor speed on a given port.
|
||||
| toSpeed | <code>number</code> | For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. |
|
||||
| time | <code>number</code> | How long the ramp should last (in milliseconds). |
|
||||
|
||||
<a name="PUPHub+setLightBrightness"></a>
|
||||
|
||||
### pupHub.setLightBrightness(port, brightness, [time]) ⇒ <code>Promise</code>
|
||||
Set the light brightness on a given port.
|
||||
|
||||
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| port | <code>string</code> | |
|
||||
| brightness | <code>number</code> | Brightness value between 0-100 (0 is off) |
|
||||
| [time] | <code>number</code> | How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
|
||||
|
||||
<a name="LPF2Hub+setName"></a>
|
||||
|
||||
### pupHub.setName(name) ⇒ <code>Promise</code>
|
||||
@ -912,6 +945,18 @@ Set the name of the Hub.
|
||||
| --- | --- | --- |
|
||||
| name | <code>string</code> | New name of the hub (14 characters or less, ASCII only). |
|
||||
|
||||
<a name="LPF2Hub+setLEDColor"></a>
|
||||
|
||||
### pupHub.setLEDColor(color) ⇒ <code>Promise</code>
|
||||
Set the color of the LED on the Hub via a color value.
|
||||
|
||||
**Kind**: instance method of [<code>PUPHub</code>](#PUPHub)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| color | <code>number</code> | A number representing one of the LED color consts. |
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
### pupHub.connect() ⇒ <code>Promise</code>
|
||||
@ -1141,6 +1186,7 @@ The PUPRemote is emitted if the discovered device is a Powered Up Remote.
|
||||
Set the color of the LED on the Remote via a color value.
|
||||
|
||||
**Kind**: instance method of [<code>PUPRemote</code>](#PUPRemote)
|
||||
**Overrides**: [<code>setLEDColor</code>](#LPF2Hub+setLEDColor)
|
||||
**Returns**: <code>Promise</code> - Resolved upon successful issuance of command.
|
||||
|
||||
| Param | Type | Description |
|
||||
|
@ -48,24 +48,6 @@ export class BoostMoveHub extends LPF2Hub {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the color of the LED on the Hub via a color value.
|
||||
* @method BoostMoveHub#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, 0x32, 0x11, 0x51, 0x00, color]);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the motor speed on a given port.
|
||||
* @method BoostMoveHub#setMotorSpeed
|
||||
@ -187,4 +169,27 @@ export class BoostMoveHub extends LPF2Hub {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the light brightness on a given port.
|
||||
* @method BoostMoveHub#setLightBrightness
|
||||
* @param {string} port
|
||||
* @param {number} brightness Brightness value between 0-100 (0 is off)
|
||||
* @param {number} [time] How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely.
|
||||
* @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
|
||||
*/
|
||||
public setLightBrightness (port: string, brightness: number, time?: number) {
|
||||
const portObj = this._portLookup(port);
|
||||
return new Promise((resolve, reject) => {
|
||||
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
setTimeout(() => {
|
||||
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
}, time);
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
18
lpf2hub.ts
18
lpf2hub.ts
@ -69,6 +69,24 @@ export class LPF2Hub extends Hub {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the color of the LED on the Hub via a color value.
|
||||
* @method LPF2Hub#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, 0x32, 0x11, 0x51, 0x00, color]);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
41
puphub.ts
41
puphub.ts
@ -54,24 +54,6 @@ export class PUPHub extends LPF2Hub {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the color of the LED on the Hub via a color value.
|
||||
* @method PUPHub#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, 0x32, 0x11, 0x51, 0x00, color]);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the motor speed on a given port.
|
||||
* @method PUPHub#setMotorSpeed
|
||||
@ -147,4 +129,27 @@ export class PUPHub extends LPF2Hub {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the light brightness on a given port.
|
||||
* @method PUPHub#setLightBrightness
|
||||
* @param {string} port
|
||||
* @param {number} brightness Brightness value between 0-100 (0 is off)
|
||||
* @param {number} [time] How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely.
|
||||
* @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
|
||||
*/
|
||||
public setLightBrightness (port: string, brightness: number, time?: number) {
|
||||
const portObj = this._portLookup(port);
|
||||
return new Promise((resolve, reject) => {
|
||||
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
setTimeout(() => {
|
||||
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
}, time);
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -174,6 +174,29 @@ export class WeDo2SmartHub extends Hub {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the light brightness on a given port.
|
||||
* @method WeDo2SmartHub#setLightBrightness
|
||||
* @param {string} port
|
||||
* @param {number} brightness Brightness value between 0-100 (0 is off)
|
||||
* @param {number} [time] How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely.
|
||||
* @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
|
||||
*/
|
||||
public setLightBrightness (port: string, brightness: number, time?: number) {
|
||||
const portObj = this._portLookup(port);
|
||||
return new Promise((resolve, reject) => {
|
||||
const data = Buffer.from([this._portLookup(port).value, 0x01, 0x02, this._mapSpeed(brightness)]);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
setTimeout(() => {
|
||||
const data = Buffer.from([this._portLookup(port).value, 0x01, 0x02, 0x00]);
|
||||
this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data);
|
||||
return resolve();
|
||||
}, time);
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user