From 137929607f3a2b5908db4a5d2220515bb12b39ac Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Thu, 26 Jul 2018 17:59:59 +0100 Subject: [PATCH] Added buzzer support to the WeDo 2.0 Smart Hub --- wedo2hub.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/wedo2hub.ts b/wedo2hub.ts index 92909c3..cb65de4 100644 --- a/wedo2hub.ts +++ b/wedo2hub.ts @@ -90,6 +90,21 @@ export class WeDo2Hub extends Hub { } + /** + * Set the motor speed on a given port. + * @method WeDo2Hub#setMotorSpeed + * @param {string} port + * @param {number} speed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. + * @returns {Promise} Resolved upon successful issuance of command. + */ + public setMotorSpeed (port: string, speed: number) { + return new Promise((resolve, reject) => { + this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, Buffer.from([this._ports[port].value, 0x01, 0x02, this._mapSpeed(speed)])); + return resolve(); + }); + } + + /** * Play a sound on the Hub's in-built buzzer * @method WeDo2Hub#playSound @@ -108,21 +123,6 @@ export class WeDo2Hub extends Hub { } - /** - * Set the motor speed on a given port. - * @method WeDo2Hub#setMotorSpeed - * @param {string} port - * @param {number} speed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. - * @returns {Promise} Resolved upon successful issuance of command. - */ - public setMotorSpeed (port: string, speed: number) { - return new Promise((resolve, reject) => { - this._writeMessage(Consts.BLECharacteristics.WEDO2_MOTOR_VALUE_WRITE, Buffer.from([this._ports[port].value, 0x01, 0x02, this._mapSpeed(speed)])); - return resolve(); - }); - } - - protected _activatePortDevice (port: number, type: number, mode: number, format: number, callback: () => void) { this._writeMessage(Consts.BLECharacteristics.WEDO2_PORT_TYPE_WRITE, Buffer.from([0x01, 0x02, port, type, mode, 0x01, 0x00, 0x00, 0x00, format, 0x01]), callback); }