From 7a3878ff7aaa60be5ba4a478847ecfa54335bbe7 Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Thu, 16 Aug 2018 14:59:34 +0100 Subject: [PATCH] Lights working --- boostmovehub.ts | 13 ++++++++----- consts.ts | 1 + puphub.ts | 13 ++++++++----- wedo2smarthub.ts | 13 ++++++++----- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/boostmovehub.ts b/boostmovehub.ts index eedbd2a..cc03636 100644 --- a/boostmovehub.ts +++ b/boostmovehub.ts @@ -182,12 +182,15 @@ export class BoostMoveHub extends LPF2Hub { 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); + if (time) { + setTimeout(() => { + const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]); + this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); + return resolve(); + }, time); + } else { return resolve(); - }, time); - return resolve(); + } }); } diff --git a/consts.ts b/consts.ts index 876655d..2ed1d74 100644 --- a/consts.ts +++ b/consts.ts @@ -10,6 +10,7 @@ export enum Devices { UNKNOWN = 0, BASIC_MOTOR = 1, TRAIN_MOTOR = 2, + LED_LIGHTS = 8, BOOST_LED = 22, WEDO2_TILT = 34, WEDO2_DISTANCE = 35, diff --git a/puphub.ts b/puphub.ts index d07877c..09d8c34 100644 --- a/puphub.ts +++ b/puphub.ts @@ -142,12 +142,15 @@ export class PUPHub extends LPF2Hub { 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); + if (time) { + setTimeout(() => { + const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]); + this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); + return resolve(); + }, time); + } else { return resolve(); - }, time); - return resolve(); + } }); } diff --git a/wedo2smarthub.ts b/wedo2smarthub.ts index 991efb0..168e2b3 100644 --- a/wedo2smarthub.ts +++ b/wedo2smarthub.ts @@ -187,12 +187,15 @@ export class WeDo2SmartHub extends Hub { return new Promise((resolve, reject) => { const data = Buffer.from([portObj.value, 0x01, 0x02, this._mapSpeed(brightness)]); this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); - setTimeout(() => { - const data = Buffer.from([portObj.value, 0x01, 0x02, 0x00]); - this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); + if (time) { + setTimeout(() => { + const data = Buffer.from([portObj.value, 0x01, 0x02, 0x00]); + this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); + return resolve(); + }, time); + } else { return resolve(); - }, time); - return resolve(); + } }); }