diff --git a/boostmovehub.ts b/boostmovehub.ts index 1e7d9be..49012ad 100644 --- a/boostmovehub.ts +++ b/boostmovehub.ts @@ -61,12 +61,16 @@ export class BoostMoveHub extends LPF2Hub { if (portObj.id !== "AB" && speed instanceof Array) { throw new Error(`Port ${portObj.id} can only accept a single speed`); } + let cancelEventTimer = true; if (typeof time === "boolean") { if (time === true) { - portObj.cancelEventTimer(); + cancelEventTimer = false; } time = undefined; } + if (cancelEventTimer) { + portObj.cancelEventTimer(); + } return new Promise((resolve, reject) => { if (time && typeof time === "number") { @@ -190,6 +194,7 @@ export class BoostMoveHub extends LPF2Hub { */ public setLightBrightness (port: string, brightness: number, time?: number) { const portObj = this._portLookup(port); + portObj.cancelEventTimer(); return new Promise((resolve, reject) => { const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]); this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); diff --git a/puphub.ts b/puphub.ts index 7ee7b25..7f15370 100644 --- a/puphub.ts +++ b/puphub.ts @@ -74,12 +74,16 @@ export class PUPHub extends LPF2Hub { throw new Error(`Port ${portObj.id} requires both motors be of the same type`); } } + let cancelEventTimer = true; if (typeof time === "boolean") { if (time === true) { - portObj.cancelEventTimer(); + cancelEventTimer = false; } time = undefined; } + if (cancelEventTimer) { + portObj.cancelEventTimer(); + } return new Promise((resolve, reject) => { if (time && typeof time === "number") { let data = null; diff --git a/wedo2smarthub.ts b/wedo2smarthub.ts index 19a3e11..1600426 100644 --- a/wedo2smarthub.ts +++ b/wedo2smarthub.ts @@ -126,12 +126,16 @@ export class WeDo2SmartHub extends Hub { */ public setMotorSpeed (port: string, speed: number, time?: number | boolean) { const portObj = this._portLookup(port); + let cancelEventTimer = true; if (typeof time === "boolean") { if (time === true) { - portObj.cancelEventTimer(); + cancelEventTimer = false; } time = undefined; } + if (cancelEventTimer) { + portObj.cancelEventTimer(); + } return new Promise((resolve, reject) => { this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, Buffer.from([portObj.value, 0x01, 0x02, this._mapSpeed(speed)])); if (time && typeof time === "number") { @@ -197,6 +201,7 @@ export class WeDo2SmartHub extends Hub { */ public setLightBrightness (port: string, brightness: number, time?: number) { const portObj = this._portLookup(port); + portObj.cancelEventTimer(); return new Promise((resolve, reject) => { const data = Buffer.from([portObj.value, 0x01, 0x02, brightness]); this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, data);