From 05daa648cb1325c3e4bf1b73b53742c8b0b25a04 Mon Sep 17 00:00:00 2001 From: Michal Szafranski Date: Sat, 2 Nov 2019 15:16:15 +0100 Subject: [PATCH 1/3] allow RGB led control for the duplo train hub --- package-lock.json | 2 +- src/duplotrainbase.ts | 22 +++------------------- src/lpf2hub.ts | 6 ++++-- src/pupremote.ts | 42 +++--------------------------------------- 4 files changed, 11 insertions(+), 61 deletions(-) diff --git a/package-lock.json b/package-lock.json index 882e944..f09459a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "node-poweredup", - "version": "2.5.3", + "version": "3.5.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/duplotrainbase.ts b/src/duplotrainbase.ts index e09b81a..59c91eb 100644 --- a/src/duplotrainbase.ts +++ b/src/duplotrainbase.ts @@ -26,6 +26,9 @@ export class DuploTrainBase extends LPF2Hub { } + protected _ledPort = 0x11; + + constructor (device: IBLEDevice, autoSubscribe: boolean = true) { super(device, autoSubscribe); this.type = Consts.HubType.DUPLO_TRAIN_HUB; @@ -47,25 +50,6 @@ export class DuploTrainBase extends LPF2Hub { }); } - - /** - * Set the color of the LED on the train via a color value. - * @method DuploTrainBase#setLEDColor - * @param {Color} color - * @returns {Promise} Resolved upon successful issuance of command. - */ - public setLEDColor (color: number | boolean) { - return new Promise((resolve, reject) => { - if (typeof color === "boolean") { - color = 0; - } - const data = Buffer.from([0x81, 0x11, 0x11, 0x51, 0x00, color]); - this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); - return resolve(); - }); - } - - /** * Set the motor speed on a given port. * @method DuploTrainBase#setMotorSpeed diff --git a/src/lpf2hub.ts b/src/lpf2hub.ts index 28cb7dd..3a56712 100644 --- a/src/lpf2hub.ts +++ b/src/lpf2hub.ts @@ -16,6 +16,8 @@ const modeInfoDebug = Debug("lpf2hubmodeinfo"); */ export class LPF2Hub extends Hub { + protected _ledPort: number = 0x32; + private _lastTiltX: number = 0; private _lastTiltY: number = 0; private _lastTiltZ: number = 0; @@ -111,9 +113,9 @@ export class LPF2Hub extends Hub { */ public setLEDRGB (red: number, green: number, blue: number) { return new Promise((resolve, reject) => { - let data = Buffer.from([0x41, 0x32, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]); + let data = Buffer.from([0x41, this._ledPort, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); - data = Buffer.from([0x81, 0x32, 0x11, 0x51, 0x01, red, green, blue]); + data = Buffer.from([0x81, this._ledPort, 0x11, 0x51, 0x01, red, green, blue]); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); return resolve(); }); diff --git a/src/pupremote.ts b/src/pupremote.ts index 846aa00..738696e 100644 --- a/src/pupremote.ts +++ b/src/pupremote.ts @@ -26,6 +26,9 @@ export class PUPRemote extends LPF2Hub { } + protected _ledPort = 0x34; + + constructor (device: IBLEDevice, autoSubscribe: boolean = true) { super(device, autoSubscribe); this.type = Consts.HubType.POWERED_UP_REMOTE; @@ -47,43 +50,4 @@ export class PUPRemote extends LPF2Hub { } - /** - * Set the color of the LED on the Remote via a color value. - * @method PUPRemote#setLEDColor - * @param {Color} color - * @returns {Promise} Resolved upon successful issuance of command. - */ - public setLEDColor (color: number | boolean) { - return new Promise((resolve, reject) => { - let data = Buffer.from([0x41, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]); - this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); - if (typeof color === "boolean") { - color = 0; - } - data = Buffer.from([0x81, 0x34, 0x11, 0x51, 0x00, color]); - this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); - return resolve(); - }); - } - - - /** - * Set the color of the LED on the Hub via RGB values. - * @method PUPRemote#setLEDRGB - * @param {number} red - * @param {number} green - * @param {number} blue - * @returns {Promise} Resolved upon successful issuance of command. - */ - public setLEDRGB (red: number, green: number, blue: number) { - return new Promise((resolve, reject) => { - let data = Buffer.from([0x41, 0x34, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]); - this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); - data = Buffer.from([0x81, 0x34, 0x11, 0x51, 0x01, red, green, blue]); - this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); - return resolve(); - }); - } - - } From 3bbca30296af5f2ec4e9697e62cca73333d162b7 Mon Sep 17 00:00:00 2001 From: Michal Szafranski Date: Sat, 2 Nov 2019 17:37:55 +0100 Subject: [PATCH 2/3] undo version bump in package lock --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index f09459a..882e944 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "node-poweredup", - "version": "3.5.1", + "version": "2.5.3", "lockfileVersion": 1, "requires": true, "dependencies": { From 1e40bdd53710fb7914c46bc5bf9efeb03ead0387 Mon Sep 17 00:00:00 2001 From: Michal Szafranski Date: Sun, 3 Nov 2019 14:24:37 +0100 Subject: [PATCH 3/3] Fix setLEDColor regression --- src/lpf2hub.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lpf2hub.ts b/src/lpf2hub.ts index 3a56712..a6fe694 100644 --- a/src/lpf2hub.ts +++ b/src/lpf2hub.ts @@ -91,12 +91,12 @@ export class LPF2Hub extends Hub { */ public setLEDColor (color: number | boolean) { return new Promise((resolve, reject) => { - let data = Buffer.from([0x41, 0x32, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]); + let data = Buffer.from([0x41, this._ledPort, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); if (typeof color === "boolean") { color = 0; } - data = Buffer.from([0x81, 0x32, 0x11, 0x51, 0x00, color]); + data = Buffer.from([0x81, this._ledPort, 0x11, 0x51, 0x00, color]); this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data); return resolve(); });