writeDirect function on device
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
a5a9b2e880
commit
705fbd341a
@ -22,13 +22,7 @@ export class BasicMotor extends Device {
|
||||
*/
|
||||
public setPower (power: number) {
|
||||
return new Promise((resolve) => {
|
||||
if (this.isWeDo2SmartHub) {
|
||||
const data = Buffer.from([this.portId, 0x01, 0x02, mapSpeed(power)]);
|
||||
this.send(data, Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
|
||||
} else {
|
||||
const data = Buffer.from([0x81, this.portId, 0x11, 0x51, 0x00, mapSpeed(power)]);
|
||||
this.send(data);
|
||||
}
|
||||
this.writeDirect(0x00, Buffer.from([mapSpeed(power)]));
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
@ -77,6 +77,14 @@ export class Device extends EventEmitter {
|
||||
return this._isWeDo2SmartHub;
|
||||
}
|
||||
|
||||
public writeDirect (mode: number, data: Buffer, callback?: () => void) {
|
||||
if (this.isWeDo2SmartHub) {
|
||||
this.send(Buffer.concat([Buffer.from([this.portId, 0x01, 0x02]), data]), Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
|
||||
} else {
|
||||
this.send(Buffer.concat([Buffer.from([0x81, this.portId, 0x11, 0x51, mode]), data]), Consts.BLECharacteristic.LPF2_ALL, callback);
|
||||
}
|
||||
}
|
||||
|
||||
public send (data: Buffer, characteristic: string = Consts.BLECharacteristic.LPF2_ALL, callback?: () => void) {
|
||||
this._ensureConnected();
|
||||
this.hub.send(data, characteristic, callback);
|
||||
|
@ -26,7 +26,7 @@ export class HubLED extends Device {
|
||||
if (typeof color === "boolean") {
|
||||
color = 0;
|
||||
}
|
||||
this.send(Buffer.from([0x81, this.portId, 0x11, 0x51, 0x00, color]));
|
||||
this.writeDirect(0x00, Buffer.from([color]));
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
@ -45,28 +45,7 @@ export class HubLED extends Device {
|
||||
if (this.mode !== HubLED.Mode.RGB) {
|
||||
this.subscribe(HubLED.Mode.RGB);
|
||||
}
|
||||
this.send(Buffer.from([0x81, this.portId, 0x11, 0x51, 0x01, red, green, blue]));
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the light brightness.
|
||||
* @method Light#brightness
|
||||
* @param {number} brightness Brightness value between 0-100 (0 is off)
|
||||
* @returns {Promise} Resolved upon successful completion of command.
|
||||
*/
|
||||
public setBrightness (brightness: number) {
|
||||
return new Promise((resolve) => {
|
||||
if (this.isWeDo2SmartHub) {
|
||||
const data = Buffer.from([this.portId, 0x01, 0x02, brightness]);
|
||||
this.send(data, Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
|
||||
} else {
|
||||
const data = Buffer.from([0x81, this.portId, 0x11, 0x51, 0x00, brightness]);
|
||||
this.send(data);
|
||||
}
|
||||
this.writeDirect(0x00, Buffer.from([red, green, blue]));
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
@ -20,13 +20,7 @@ export class Light extends Device {
|
||||
*/
|
||||
public setBrightness (brightness: number) {
|
||||
return new Promise((resolve) => {
|
||||
if (this.isWeDo2SmartHub) {
|
||||
const data = Buffer.from([this.portId, 0x01, 0x02, brightness]);
|
||||
this.send(data, Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
|
||||
} else {
|
||||
const data = Buffer.from([0x81, this.portId, 0x11, 0x51, 0x00, brightness]);
|
||||
this.send(data);
|
||||
}
|
||||
this.writeDirect(0x00, Buffer.from([brightness]));
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import { PoweredUP } from "./poweredup-browser";
|
||||
|
||||
import { BaseHub } from "./hubs/basehub";
|
||||
import { DuploTrainBase } from "./hubs/duplotrainbase";
|
||||
import { MoveHub } from "./hubs/movehub";
|
||||
import { Hub } from "./hubs/hub";
|
||||
import { MoveHub } from "./hubs/movehub";
|
||||
import { RemoteControl } from "./hubs/remotecontrol";
|
||||
import { TechnicMediumHub } from "./hubs/technicmediumhub";
|
||||
import { WeDo2SmartHub } from "./hubs/wedo2smarthub";
|
||||
|
@ -4,8 +4,8 @@ import { PoweredUP } from "./poweredup-node";
|
||||
|
||||
import { BaseHub } from "./hubs/basehub";
|
||||
import { DuploTrainBase } from "./hubs/duplotrainbase";
|
||||
import { MoveHub } from "./hubs/movehub";
|
||||
import { Hub } from "./hubs/hub";
|
||||
import { MoveHub } from "./hubs/movehub";
|
||||
import { RemoteControl } from "./hubs/remotecontrol";
|
||||
import { TechnicMediumHub } from "./hubs/technicmediumhub";
|
||||
import { WeDo2SmartHub } from "./hubs/wedo2smarthub";
|
||||
|
@ -2,8 +2,8 @@ import { WebBLEDevice } from "./webbleabstraction";
|
||||
|
||||
import { BaseHub } from "./hubs/basehub";
|
||||
import { DuploTrainBase } from "./hubs/duplotrainbase";
|
||||
import { MoveHub } from "./hubs/movehub";
|
||||
import { Hub } from "./hubs/hub";
|
||||
import { MoveHub } from "./hubs/movehub";
|
||||
import { RemoteControl } from "./hubs/remotecontrol";
|
||||
import { TechnicMediumHub } from "./hubs/technicmediumhub";
|
||||
import { WeDo2SmartHub } from "./hubs/wedo2smarthub";
|
||||
|
@ -4,8 +4,8 @@ import { NobleDevice } from "./nobleabstraction";
|
||||
|
||||
import { BaseHub } from "./hubs/basehub";
|
||||
import { DuploTrainBase } from "./hubs/duplotrainbase";
|
||||
import { MoveHub } from "./hubs/movehub";
|
||||
import { Hub } from "./hubs/hub";
|
||||
import { MoveHub } from "./hubs/movehub";
|
||||
import { RemoteControl } from "./hubs/remotecontrol";
|
||||
import { TechnicMediumHub } from "./hubs/technicmediumhub";
|
||||
import { WeDo2SmartHub } from "./hubs/wedo2smarthub";
|
||||
|
Loading…
x
Reference in New Issue
Block a user