This commit is contained in:
Nathan Kellenicki 2018-08-29 10:14:21 -07:00
parent ef69af5c5f
commit 52c4accaf5
3 changed files with 17 additions and 3 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);