diff --git a/DOCS.md b/DOCS.md
index 91520ad..49828b5 100644
--- a/DOCS.md
+++ b/DOCS.md
@@ -84,6 +84,7 @@ Emits when a Powered UP Hub device is found.
* [.setMotorSpeed(port, speed, [time])](#WeDo2SmartHub+setMotorSpeed) ⇒ Promise
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#WeDo2SmartHub+rampMotorSpeed) ⇒ Promise
* [.playSound(frequency, time)](#WeDo2SmartHub+playSound) ⇒ Promise
+ * [.setLightBrightness(port, brightness, [time])](#WeDo2SmartHub+setLightBrightness) ⇒ Promise
* [.connect()](#Hub+connect) ⇒ Promise
* [.disconnect()](#Hub+disconnect) ⇒ Promise
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ Promise
@@ -227,6 +228,20 @@ Play a sound on the Hub's in-built buzzer
| frequency | number
| |
| time | number
| How long the sound should play for (in milliseconds). |
+
+
+### weDo2SmartHub.setLightBrightness(port, brightness, [time]) ⇒ Promise
+Set the light brightness on a given port.
+
+**Kind**: instance method of [WeDo2SmartHub
](#WeDo2SmartHub)
+**Returns**: Promise
- Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| port | string
| |
+| brightness | number
| Brightness value between 0-100 (0 is off) |
+| [time] | number
| How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
+
### weDo2SmartHub.connect() ⇒ Promise
@@ -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) ⇒ Promise
* [.setMotorSpeed(port, speed, [time])](#BoostMoveHub+setMotorSpeed) ⇒ Promise
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#BoostMoveHub+rampMotorSpeed) ⇒ Promise
* [.setMotorAngle(port, angle, [speed])](#BoostMoveHub+setMotorAngle) ⇒ Promise
+ * [.setLightBrightness(port, brightness, [time])](#BoostMoveHub+setLightBrightness) ⇒ 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
@@ -471,18 +487,6 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
| --- | --- | --- |
| batteryLevel | number
| Battery level of the hub (Percentage between 0-100) |
-
-
-### boostMoveHub.setLEDColor(color) ⇒ Promise
-Set the color of the LED on the Hub via a color value.
-
-**Kind**: instance method of [BoostMoveHub
](#BoostMoveHub)
-**Returns**: Promise
- Resolved upon successful issuance of command.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| color | number
| A number representing one of the LED color consts. |
-
### boostMoveHub.setMotorSpeed(port, speed, [time]) ⇒ Promise
@@ -526,6 +530,20 @@ Rotate a motor by a given angle.
| angle | number
| | How much the motor should be rotated (in degrees). |
| [speed] | number
\| Array.<number>
| 100
| For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds. |
+
+
+### boostMoveHub.setLightBrightness(port, brightness, [time]) ⇒ Promise
+Set the light brightness on a given port.
+
+**Kind**: instance method of [BoostMoveHub
](#BoostMoveHub)
+**Returns**: Promise
- Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| port | string
| |
+| brightness | number
| Brightness value between 0-100 (0 is off) |
+| [time] | number
| How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
+
### boostMoveHub.setName(name) ⇒ Promise
@@ -538,6 +556,18 @@ Set the name of the Hub.
| --- | --- | --- |
| name | string
| New name of the hub (14 characters or less, ASCII only). |
+
+
+### boostMoveHub.setLEDColor(color) ⇒ Promise
+Set the color of the LED on the Hub via a color value.
+
+**Kind**: instance method of [BoostMoveHub
](#BoostMoveHub)
+**Returns**: Promise
- Resolved upon successful issuance of command.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| color | number
| A number representing one of the LED color consts. |
+
### boostMoveHub.connect() ⇒ Promise
@@ -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) ⇒ Promise
* [.setMotorSpeed(port, speed, [time])](#PUPHub+setMotorSpeed) ⇒ Promise
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#PUPHub+rampMotorSpeed) ⇒ Promise
+ * [.setLightBrightness(port, brightness, [time])](#PUPHub+setLightBrightness) ⇒ 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
@@ -780,18 +811,6 @@ The PUPHub is emitted if the discovered device is a Powered Up Hub.
| --- | --- | --- |
| batteryLevel | number
| Battery level of the hub (Percentage between 0-100) |
-
-
-### pupHub.setLEDColor(color) ⇒ Promise
-Set the color of the LED on the Hub via a color value.
-
-**Kind**: instance method of [PUPHub
](#PUPHub)
-**Returns**: Promise
- Resolved upon successful issuance of command.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| color | number
| A number representing one of the LED color consts. |
-
### pupHub.setMotorSpeed(port, speed, [time]) ⇒ Promise
@@ -821,6 +840,20 @@ 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). |
+
+
+### pupHub.setLightBrightness(port, brightness, [time]) ⇒ Promise
+Set the light brightness on a given port.
+
+**Kind**: instance method of [PUPHub
](#PUPHub)
+**Returns**: Promise
- Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| port | string
| |
+| brightness | number
| Brightness value between 0-100 (0 is off) |
+| [time] | number
| How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
+
### pupHub.setName(name) ⇒ Promise
@@ -833,6 +866,18 @@ Set the name of the Hub.
| --- | --- | --- |
| name | string
| New name of the hub (14 characters or less, ASCII only). |
+
+
+### pupHub.setLEDColor(color) ⇒ Promise
+Set the color of the LED on the Hub via a color value.
+
+**Kind**: instance method of [PUPHub
](#PUPHub)
+**Returns**: Promise
- Resolved upon successful issuance of command.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| color | number
| A number representing one of the LED color consts. |
+
### pupHub.connect() ⇒ Promise
@@ -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 [PUPRemote
](#PUPRemote)
+**Overrides**: [setLEDColor
](#LPF2Hub+setLEDColor)
**Returns**: Promise
- Resolved upon successful issuance of command.
| Param | Type | Description |
diff --git a/README.md b/README.md
index d7710ec..3bd653e 100644
--- a/README.md
+++ b/README.md
@@ -163,6 +163,7 @@ Emits when a Powered UP Hub device is found.
* [.setMotorSpeed(port, speed, [time])](#WeDo2SmartHub+setMotorSpeed) ⇒ Promise
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#WeDo2SmartHub+rampMotorSpeed) ⇒ Promise
* [.playSound(frequency, time)](#WeDo2SmartHub+playSound) ⇒ Promise
+ * [.setLightBrightness(port, brightness, [time])](#WeDo2SmartHub+setLightBrightness) ⇒ Promise
* [.connect()](#Hub+connect) ⇒ Promise
* [.disconnect()](#Hub+disconnect) ⇒ Promise
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ Promise
@@ -306,6 +307,20 @@ Play a sound on the Hub's in-built buzzer
| frequency | number
| |
| time | number
| How long the sound should play for (in milliseconds). |
+
+
+### weDo2SmartHub.setLightBrightness(port, brightness, [time]) ⇒ Promise
+Set the light brightness on a given port.
+
+**Kind**: instance method of [WeDo2SmartHub
](#WeDo2SmartHub)
+**Returns**: Promise
- Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| port | string
| |
+| brightness | number
| Brightness value between 0-100 (0 is off) |
+| [time] | number
| How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
+
### weDo2SmartHub.connect() ⇒ Promise
@@ -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) ⇒ Promise
* [.setMotorSpeed(port, speed, [time])](#BoostMoveHub+setMotorSpeed) ⇒ Promise
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#BoostMoveHub+rampMotorSpeed) ⇒ Promise
* [.setMotorAngle(port, angle, [speed])](#BoostMoveHub+setMotorAngle) ⇒ Promise
+ * [.setLightBrightness(port, brightness, [time])](#BoostMoveHub+setLightBrightness) ⇒ 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
@@ -550,18 +566,6 @@ The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
| --- | --- | --- |
| batteryLevel | number
| Battery level of the hub (Percentage between 0-100) |
-
-
-### boostMoveHub.setLEDColor(color) ⇒ Promise
-Set the color of the LED on the Hub via a color value.
-
-**Kind**: instance method of [BoostMoveHub
](#BoostMoveHub)
-**Returns**: Promise
- Resolved upon successful issuance of command.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| color | number
| A number representing one of the LED color consts. |
-
### boostMoveHub.setMotorSpeed(port, speed, [time]) ⇒ Promise
@@ -605,6 +609,20 @@ Rotate a motor by a given angle.
| angle | number
| | How much the motor should be rotated (in degrees). |
| [speed] | number
\| Array.<number>
| 100
| For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds. |
+
+
+### boostMoveHub.setLightBrightness(port, brightness, [time]) ⇒ Promise
+Set the light brightness on a given port.
+
+**Kind**: instance method of [BoostMoveHub
](#BoostMoveHub)
+**Returns**: Promise
- Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| port | string
| |
+| brightness | number
| Brightness value between 0-100 (0 is off) |
+| [time] | number
| How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
+
### boostMoveHub.setName(name) ⇒ Promise
@@ -617,6 +635,18 @@ Set the name of the Hub.
| --- | --- | --- |
| name | string
| New name of the hub (14 characters or less, ASCII only). |
+
+
+### boostMoveHub.setLEDColor(color) ⇒ Promise
+Set the color of the LED on the Hub via a color value.
+
+**Kind**: instance method of [BoostMoveHub
](#BoostMoveHub)
+**Returns**: Promise
- Resolved upon successful issuance of command.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| color | number
| A number representing one of the LED color consts. |
+
### boostMoveHub.connect() ⇒ Promise
@@ -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) ⇒ Promise
* [.setMotorSpeed(port, speed, [time])](#PUPHub+setMotorSpeed) ⇒ Promise
* [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#PUPHub+rampMotorSpeed) ⇒ Promise
+ * [.setLightBrightness(port, brightness, [time])](#PUPHub+setLightBrightness) ⇒ 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
@@ -859,18 +890,6 @@ The PUPHub is emitted if the discovered device is a Powered Up Hub.
| --- | --- | --- |
| batteryLevel | number
| Battery level of the hub (Percentage between 0-100) |
-
-
-### pupHub.setLEDColor(color) ⇒ Promise
-Set the color of the LED on the Hub via a color value.
-
-**Kind**: instance method of [PUPHub
](#PUPHub)
-**Returns**: Promise
- Resolved upon successful issuance of command.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| color | number
| A number representing one of the LED color consts. |
-
### pupHub.setMotorSpeed(port, speed, [time]) ⇒ Promise
@@ -900,6 +919,20 @@ 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). |
+
+
+### pupHub.setLightBrightness(port, brightness, [time]) ⇒ Promise
+Set the light brightness on a given port.
+
+**Kind**: instance method of [PUPHub
](#PUPHub)
+**Returns**: Promise
- Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| port | string
| |
+| brightness | number
| Brightness value between 0-100 (0 is off) |
+| [time] | number
| How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely. |
+
### pupHub.setName(name) ⇒ Promise
@@ -912,6 +945,18 @@ Set the name of the Hub.
| --- | --- | --- |
| name | string
| New name of the hub (14 characters or less, ASCII only). |
+
+
+### pupHub.setLEDColor(color) ⇒ Promise
+Set the color of the LED on the Hub via a color value.
+
+**Kind**: instance method of [PUPHub
](#PUPHub)
+**Returns**: Promise
- Resolved upon successful issuance of command.
+
+| Param | Type | Description |
+| --- | --- | --- |
+| color | number
| A number representing one of the LED color consts. |
+
### pupHub.connect() ⇒ Promise
@@ -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 [PUPRemote
](#PUPRemote)
+**Overrides**: [setLEDColor
](#LPF2Hub+setLEDColor)
**Returns**: Promise
- Resolved upon successful issuance of command.
| Param | Type | Description |
diff --git a/boostmovehub.ts b/boostmovehub.ts
index 96e7e59..eedbd2a 100644
--- a/boostmovehub.ts
+++ b/boostmovehub.ts
@@ -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();
+ });
+ }
+
+
}
diff --git a/lpf2hub.ts b/lpf2hub.ts
index 962a805..9e09ba6 100644
--- a/lpf2hub.ts
+++ b/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);
}
diff --git a/puphub.ts b/puphub.ts
index 813402c..d07877c 100644
--- a/puphub.ts
+++ b/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();
+ });
+ }
+
+
}
diff --git a/wedo2smarthub.ts b/wedo2smarthub.ts
index d9533ab..90cd355 100644
--- a/wedo2smarthub.ts
+++ b/wedo2smarthub.ts
@@ -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);
}