Renamed devices
This commit is contained in:
parent
225f331811
commit
df70d8a8a4
@ -16,17 +16,13 @@ export class ColorDistanceSensor extends Device {
|
||||
if (this.autoSubscribe) {
|
||||
switch (event) {
|
||||
case "color":
|
||||
if (this._isWeDo2) {
|
||||
this.subscribe(0x00);
|
||||
} else {
|
||||
this.subscribe(0x08);
|
||||
}
|
||||
this.subscribe(ColorDistanceSensor.Mode.COLOR);
|
||||
break;
|
||||
case "distance":
|
||||
this.subscribe(0x08);
|
||||
this.subscribe(ColorDistanceSensor.Mode.DISTANCE);
|
||||
break;
|
||||
case "colorAndDistance":
|
||||
this.subscribe(0x08);
|
||||
this.subscribe(ColorDistanceSensor.Mode.COLOR_AND_DISTANCE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -39,13 +35,13 @@ export class ColorDistanceSensor extends Device {
|
||||
console.log(message);
|
||||
|
||||
switch (mode) {
|
||||
case 0x00:
|
||||
case ColorDistanceSensor.Mode.COLOR:
|
||||
if (this._isWeDo2 && message[2] <= 10) {
|
||||
const color = message[2];
|
||||
this.emit("color", color);
|
||||
}
|
||||
break;
|
||||
case 0x08:
|
||||
case ColorDistanceSensor.Mode.COLOR_AND_DISTANCE:
|
||||
/**
|
||||
* Emits when a color sensor is activated.
|
||||
* @event ColorDistanceSensor#color
|
||||
@ -90,3 +86,11 @@ export class ColorDistanceSensor extends Device {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export namespace ColorDistanceSensor {
|
||||
export enum Mode {
|
||||
COLOR = 0x00,
|
||||
DISTANCE = 0x01,
|
||||
COLOR_AND_DISTANCE = 0x08
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ export class MotionSensor extends Device {
|
||||
if (this.autoSubscribe) {
|
||||
switch (event) {
|
||||
case "distance":
|
||||
this.subscribe(0x00);
|
||||
this.subscribe(MotionSensor.Mode.DISTANCE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -25,7 +25,7 @@ export class MotionSensor extends Device {
|
||||
const isWeDo2 = (this.hub.type === Consts.HubType.WEDO2_SMART_HUB);
|
||||
|
||||
switch (mode) {
|
||||
case 0x00:
|
||||
case MotionSensor.Mode.DISTANCE:
|
||||
let distance = message[isWeDo2 ? 2 : 4];
|
||||
if (message[isWeDo2 ? 3 : 5] === 1) {
|
||||
distance = distance + 255;
|
||||
@ -41,3 +41,9 @@ export class MotionSensor extends Device {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export namespace MotionSensor {
|
||||
export enum Mode {
|
||||
DISTANCE = 0x00
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ export class TachoMotor extends BasicMotor {
|
||||
if (this.autoSubscribe) {
|
||||
switch (event) {
|
||||
case "rotate":
|
||||
this.subscribe(0x02);
|
||||
this.subscribe(TachoMotor.Mode.ROTATION);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,7 @@ export class TachoMotor extends BasicMotor {
|
||||
const isWeDo2 = (this.hub.type === Consts.HubType.WEDO2_SMART_HUB);
|
||||
|
||||
switch (mode) {
|
||||
case 0x02:
|
||||
case TachoMotor.Mode.ROTATION:
|
||||
const rotation = message.readInt32LE(isWeDo2 ? 2 : 4);
|
||||
/**
|
||||
* Emits when a rotation sensor is activated.
|
||||
@ -48,7 +48,7 @@ export class TachoMotor extends BasicMotor {
|
||||
public rotateByAngle (angle: number, power: number = 100) {
|
||||
const isWeDo2 = (this.hub.type === Consts.HubType.WEDO2_SMART_HUB);
|
||||
if (isWeDo2) {
|
||||
throw new Error("Rotating by angle is not available on the WeDo 2.0 Smart Hub");
|
||||
throw new Error("Angle rotation is not available on the WeDo 2.0 Smart Hub");
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
this._busy = true;
|
||||
@ -62,3 +62,9 @@ export class TachoMotor extends BasicMotor {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export namespace TachoMotor {
|
||||
export enum Mode {
|
||||
ROTATION = 0x02
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ export class TiltSensor extends Device {
|
||||
if (this.autoSubscribe) {
|
||||
switch (event) {
|
||||
case "tilt":
|
||||
this.subscribe(0x00);
|
||||
this.subscribe(TiltSensor.Mode.TILT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -25,7 +25,7 @@ export class TiltSensor extends Device {
|
||||
const isWeDo2 = (this.hub.type === Consts.HubType.WEDO2_SMART_HUB);
|
||||
|
||||
switch (mode) {
|
||||
case 0x00:
|
||||
case TiltSensor.Mode.TILT:
|
||||
const tiltX = message.readInt8(isWeDo2 ? 2 : 4);
|
||||
const tiltY = message.readInt8(isWeDo2 ? 3 : 5);
|
||||
/**
|
||||
@ -40,3 +40,9 @@ export class TiltSensor extends Device {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export namespace TiltSensor {
|
||||
export enum Mode {
|
||||
TILT = 0x00
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user