This commit is contained in:
parent
579f82334c
commit
9113d22766
@ -28,7 +28,7 @@ export class Device extends EventEmitter {
|
||||
this._modeMap = modeMap;
|
||||
this._isWeDo2SmartHub = (this.hub.type === Consts.HubType.WEDO2_SMART_HUB);
|
||||
|
||||
const attachListener = (event: string) => {
|
||||
const eventAttachListener = (event: string) => {
|
||||
if (event === "detach") {
|
||||
return;
|
||||
}
|
||||
@ -39,23 +39,23 @@ export class Device extends EventEmitter {
|
||||
}
|
||||
};
|
||||
|
||||
const detachListener = (device: Device) => {
|
||||
const deviceDetachListener = (device: Device) => {
|
||||
if (device.portId === this.portId) {
|
||||
this._connected = false;
|
||||
this.hub.removeListener("detach", detachListener);
|
||||
this.hub.removeListener("detach", deviceDetachListener);
|
||||
this.emit("detach");
|
||||
}
|
||||
};
|
||||
|
||||
for (let event in this._modeMap) {
|
||||
if (this.hub.listenerCount(event) > 0) {
|
||||
attachListener(event);
|
||||
eventAttachListener(event);
|
||||
}
|
||||
}
|
||||
|
||||
this.hub.on("newListener", attachListener);
|
||||
this.on("newListener", attachListener);
|
||||
this.hub.on("detach", detachListener);
|
||||
this.hub.on("newListener", eventAttachListener);
|
||||
this.on("newListener", eventAttachListener);
|
||||
this.hub.on("detach", deviceDetachListener);
|
||||
}
|
||||
|
||||
public get connected () {
|
||||
|
@ -62,7 +62,10 @@ export namespace Hub {
|
||||
|
||||
export const PortMap: {[portName: string]: number} = {
|
||||
"A": 0,
|
||||
"B": 1
|
||||
"B": 1,
|
||||
"HUB_LED": 50,
|
||||
"CURRENT_SENSOR": 59,
|
||||
"VOLTAGE_SENSOR": 60
|
||||
}
|
||||
|
||||
}
|
@ -62,7 +62,11 @@ export namespace MoveHub {
|
||||
"A": 0,
|
||||
"B": 1,
|
||||
"C": 2,
|
||||
"D": 3
|
||||
"D": 3,
|
||||
"HUB_LED": 50,
|
||||
"TILT_SENSOR": 58,
|
||||
"CURRENT_SENSOR": 59,
|
||||
"VOLTAGE_SENSOR": 60
|
||||
}
|
||||
|
||||
}
|
@ -53,7 +53,10 @@ export namespace RemoteControl {
|
||||
|
||||
export const PortMap: {[portName: string]: number} = {
|
||||
"LEFT": 0,
|
||||
"RIGHT": 1
|
||||
"RIGHT": 1,
|
||||
"HUB_LED": 52,
|
||||
"VOLTAGE_SENSOR": 59,
|
||||
"REMOTE_CONTROL_RSSI": 60
|
||||
}
|
||||
|
||||
}
|
@ -115,9 +115,12 @@ export namespace TechnicMediumHub {
|
||||
"B": 1,
|
||||
"C": 2,
|
||||
"D": 3,
|
||||
"ACCEL": 97,
|
||||
"GYRO": 98,
|
||||
"TILT": 99
|
||||
"HUB_LED": 50,
|
||||
"CURRENT_SENSOR": 59,
|
||||
"VOLTAGE_SENSOR": 60,
|
||||
"ACCELEROMETER": 97,
|
||||
"GYRO_SENSOR": 98,
|
||||
"TILT_SENSOR": 99
|
||||
}
|
||||
|
||||
}
|
@ -232,7 +232,11 @@ export namespace WeDo2SmartHub {
|
||||
|
||||
export const PortMap: {[portName: string]: number} = {
|
||||
"A": 1,
|
||||
"B": 2
|
||||
"B": 2,
|
||||
"CURRENT_SENSOR": 3,
|
||||
"VOLTAGE_SENSOR": 4,
|
||||
"PIEZO_BUZZER": 5,
|
||||
"HUB_LED": 6
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user