Named internal ports on hubs
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Nathan Kellenicki 2019-12-22 19:02:35 -08:00
parent 579f82334c
commit 9113d22766
6 changed files with 31 additions and 14 deletions

View File

@ -28,7 +28,7 @@ export class Device extends EventEmitter {
this._modeMap = modeMap; this._modeMap = modeMap;
this._isWeDo2SmartHub = (this.hub.type === Consts.HubType.WEDO2_SMART_HUB); this._isWeDo2SmartHub = (this.hub.type === Consts.HubType.WEDO2_SMART_HUB);
const attachListener = (event: string) => { const eventAttachListener = (event: string) => {
if (event === "detach") { if (event === "detach") {
return; return;
} }
@ -39,23 +39,23 @@ export class Device extends EventEmitter {
} }
}; };
const detachListener = (device: Device) => { const deviceDetachListener = (device: Device) => {
if (device.portId === this.portId) { if (device.portId === this.portId) {
this._connected = false; this._connected = false;
this.hub.removeListener("detach", detachListener); this.hub.removeListener("detach", deviceDetachListener);
this.emit("detach"); this.emit("detach");
} }
}; };
for (let event in this._modeMap) { for (let event in this._modeMap) {
if (this.hub.listenerCount(event) > 0) { if (this.hub.listenerCount(event) > 0) {
attachListener(event); eventAttachListener(event);
} }
} }
this.hub.on("newListener", attachListener); this.hub.on("newListener", eventAttachListener);
this.on("newListener", attachListener); this.on("newListener", eventAttachListener);
this.hub.on("detach", detachListener); this.hub.on("detach", deviceDetachListener);
} }
public get connected () { public get connected () {

View File

@ -62,7 +62,10 @@ export namespace Hub {
export const PortMap: {[portName: string]: number} = { export const PortMap: {[portName: string]: number} = {
"A": 0, "A": 0,
"B": 1 "B": 1,
"HUB_LED": 50,
"CURRENT_SENSOR": 59,
"VOLTAGE_SENSOR": 60
} }
} }

View File

@ -62,7 +62,11 @@ export namespace MoveHub {
"A": 0, "A": 0,
"B": 1, "B": 1,
"C": 2, "C": 2,
"D": 3 "D": 3,
"HUB_LED": 50,
"TILT_SENSOR": 58,
"CURRENT_SENSOR": 59,
"VOLTAGE_SENSOR": 60
} }
} }

View File

@ -53,7 +53,10 @@ export namespace RemoteControl {
export const PortMap: {[portName: string]: number} = { export const PortMap: {[portName: string]: number} = {
"LEFT": 0, "LEFT": 0,
"RIGHT": 1 "RIGHT": 1,
"HUB_LED": 52,
"VOLTAGE_SENSOR": 59,
"REMOTE_CONTROL_RSSI": 60
} }
} }

View File

@ -115,9 +115,12 @@ export namespace TechnicMediumHub {
"B": 1, "B": 1,
"C": 2, "C": 2,
"D": 3, "D": 3,
"ACCEL": 97, "HUB_LED": 50,
"GYRO": 98, "CURRENT_SENSOR": 59,
"TILT": 99 "VOLTAGE_SENSOR": 60,
"ACCELEROMETER": 97,
"GYRO_SENSOR": 98,
"TILT_SENSOR": 99
} }
} }

View File

@ -232,7 +232,11 @@ export namespace WeDo2SmartHub {
export const PortMap: {[portName: string]: number} = { export const PortMap: {[portName: string]: number} = {
"A": 1, "A": 1,
"B": 2 "B": 2,
"CURRENT_SENSOR": 3,
"VOLTAGE_SENSOR": 4,
"PIEZO_BUZZER": 5,
"HUB_LED": 6
} }
} }