diff --git a/src/duplotrainbase.ts b/src/duplotrainbase.ts index 22a0a9a..1503d1d 100644 --- a/src/duplotrainbase.ts +++ b/src/duplotrainbase.ts @@ -31,6 +31,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; @@ -52,25 +55,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 80267cc..f61bf5a 100644 --- a/src/lpf2hub.ts +++ b/src/lpf2hub.ts @@ -20,6 +20,8 @@ export class LPF2Hub extends Hub { return [t[0], t[1], t.substring(2, 4), t.substring(4)].join("."); } + protected _ledPort: number = 0x32; + private _lastTiltX: number = 0; private _lastTiltY: number = 0; private _lastTiltZ: number = 0; @@ -93,12 +95,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(); }); @@ -115,9 +117,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 a06a445..888728f 100644 --- a/src/pupremote.ts +++ b/src/pupremote.ts @@ -31,6 +31,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; @@ -52,43 +55,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(); - }); - } - - }