Added buzzer support to the WeDo 2.0 Smart Hub
This commit is contained in:
parent
490117f36e
commit
137929607f
30
wedo2hub.ts
30
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user