Exported hub PortMap
This commit is contained in:
parent
36c34a9743
commit
ffd3cceab8
@ -35,14 +35,7 @@ export class BoostMoveHub extends LPF2Hub {
|
|||||||
protected _voltagePort = 0x3c;
|
protected _voltagePort = 0x3c;
|
||||||
|
|
||||||
constructor (device: IBLEAbstraction) {
|
constructor (device: IBLEAbstraction) {
|
||||||
super(device, Consts.HubType.BOOST_MOVE_HUB);
|
super(device, BoostMoveHub.PortMap, Consts.HubType.BOOST_MOVE_HUB);
|
||||||
this._portNames = {
|
|
||||||
"A": 0,
|
|
||||||
"B": 1,
|
|
||||||
"C": 2,
|
|
||||||
"D": 3,
|
|
||||||
"TILT": 58
|
|
||||||
};
|
|
||||||
debug("Discovered Boost Move Hub");
|
debug("Discovered Boost Move Hub");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,3 +58,15 @@ export class BoostMoveHub extends LPF2Hub {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export namespace BoostMoveHub {
|
||||||
|
|
||||||
|
export const PortMap: {[port: string]: number} = {
|
||||||
|
"A": 0,
|
||||||
|
"B": 1,
|
||||||
|
"C": 2,
|
||||||
|
"D": 3,
|
||||||
|
"TILT": 58
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -37,16 +37,7 @@ export class ControlPlusHub extends LPF2Hub {
|
|||||||
protected _voltageMaxV = 9.615;
|
protected _voltageMaxV = 9.615;
|
||||||
|
|
||||||
constructor (device: IBLEAbstraction) {
|
constructor (device: IBLEAbstraction) {
|
||||||
super(device, Consts.HubType.CONTROL_PLUS_HUB);
|
super(device, ControlPlusHub.PortMap, Consts.HubType.CONTROL_PLUS_HUB);
|
||||||
this._portNames = {
|
|
||||||
"A": 0,
|
|
||||||
"B": 1,
|
|
||||||
"C": 2,
|
|
||||||
"D": 3,
|
|
||||||
"ACCEL": 97,
|
|
||||||
"GYRO": 98,
|
|
||||||
"TILT": 99
|
|
||||||
};
|
|
||||||
debug("Discovered Control+ Hub");
|
debug("Discovered Control+ Hub");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,3 +113,17 @@ export class ControlPlusHub extends LPF2Hub {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export namespace ControlPlusHub {
|
||||||
|
|
||||||
|
export const PortMap: {[port: string]: number} = {
|
||||||
|
"A": 0,
|
||||||
|
"B": 1,
|
||||||
|
"C": 2,
|
||||||
|
"D": 3,
|
||||||
|
"ACCEL": 97,
|
||||||
|
"GYRO": 98,
|
||||||
|
"TILT": 99
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -36,12 +36,7 @@ export class DuploTrainBase extends LPF2Hub {
|
|||||||
protected _voltageMaxRaw = 3047;
|
protected _voltageMaxRaw = 3047;
|
||||||
|
|
||||||
constructor (device: IBLEAbstraction) {
|
constructor (device: IBLEAbstraction) {
|
||||||
super(device, Consts.HubType.DUPLO_TRAIN_HUB);
|
super(device, DuploTrainBase.PortMap, Consts.HubType.DUPLO_TRAIN_HUB);
|
||||||
this._portNames = {
|
|
||||||
"MOTOR": 0,
|
|
||||||
"COLOR": 18,
|
|
||||||
"SPEEDOMETER": 19
|
|
||||||
};
|
|
||||||
debug("Discovered Duplo Train Base");
|
debug("Discovered Duplo Train Base");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,3 +68,13 @@ export class DuploTrainBase extends LPF2Hub {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export namespace DuploTrainBase {
|
||||||
|
|
||||||
|
export const PortMap: {[port: string]: number} = {
|
||||||
|
"MOTOR": 0,
|
||||||
|
"COLOR": 18,
|
||||||
|
"SPEEDOMETER": 19
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -27,8 +27,6 @@ const debug = Debug("hub");
|
|||||||
export class Hub extends EventEmitter {
|
export class Hub extends EventEmitter {
|
||||||
|
|
||||||
protected _attachedDevices: {[portId: number]: Device} = {};
|
protected _attachedDevices: {[portId: number]: Device} = {};
|
||||||
|
|
||||||
protected _portNames: {[port: string]: number} = {};
|
|
||||||
// protected _virtualPorts: {[port: string]: Port} = {};
|
// protected _virtualPorts: {[port: string]: Port} = {};
|
||||||
|
|
||||||
protected _name: string = "";
|
protected _name: string = "";
|
||||||
@ -43,11 +41,13 @@ export class Hub extends EventEmitter {
|
|||||||
protected _bleDevice: IBLEAbstraction;
|
protected _bleDevice: IBLEAbstraction;
|
||||||
|
|
||||||
private _type: Consts.HubType;
|
private _type: Consts.HubType;
|
||||||
|
private _portMap: {[port: string]: number} = {};
|
||||||
|
|
||||||
constructor (device: IBLEAbstraction, type: Consts.HubType = Consts.HubType.UNKNOWN) {
|
constructor (device: IBLEAbstraction, portMap: {[port: string]: number} = {}, type: Consts.HubType = Consts.HubType.UNKNOWN) {
|
||||||
super();
|
super();
|
||||||
this._type = type;
|
this._type = type;
|
||||||
this._bleDevice = device;
|
this._bleDevice = device;
|
||||||
|
this._portMap = portMap;
|
||||||
device.on("disconnect", () => {
|
device.on("disconnect", () => {
|
||||||
/**
|
/**
|
||||||
* Emits when the hub is disconnected.
|
* Emits when the hub is disconnected.
|
||||||
@ -76,6 +76,15 @@ export class Hub extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @readonly
|
||||||
|
* @property {string[]} ports Array of port names
|
||||||
|
*/
|
||||||
|
public get ports () {
|
||||||
|
return Object.keys(this._portMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @readonly
|
* @readonly
|
||||||
* @property {string} firmwareVersion Firmware version of the hub
|
* @property {string} firmwareVersion Firmware version of the hub
|
||||||
@ -178,7 +187,7 @@ export class Hub extends EventEmitter {
|
|||||||
|
|
||||||
|
|
||||||
public getDeviceAtPort (portName: string) {
|
public getDeviceAtPort (portName: string) {
|
||||||
const portId = this._portNames[portName];
|
const portId = this._portMap[portName];
|
||||||
if (portId) {
|
if (portId) {
|
||||||
return this._attachedDevices[portId];
|
return this._attachedDevices[portId];
|
||||||
} else {
|
} else {
|
||||||
@ -198,8 +207,8 @@ export class Hub extends EventEmitter {
|
|||||||
|
|
||||||
|
|
||||||
public getPortNameForPortId (portId: number) {
|
public getPortNameForPortId (portId: number) {
|
||||||
for (const port of Object.keys(this._portNames)) {
|
for (const port of Object.keys(this._portMap)) {
|
||||||
if (this._portNames[port] === portId) {
|
if (this._portMap[port] === portId) {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,11 +35,7 @@ export class PUPHub extends LPF2Hub {
|
|||||||
protected _voltagePort = 0x3c;
|
protected _voltagePort = 0x3c;
|
||||||
|
|
||||||
constructor (device: IBLEAbstraction) {
|
constructor (device: IBLEAbstraction) {
|
||||||
super(device, Consts.HubType.POWERED_UP_HUB);
|
super(device, PUPHub.PortMap, Consts.HubType.POWERED_UP_HUB);
|
||||||
this._portNames = {
|
|
||||||
"A": 0,
|
|
||||||
"B": 1
|
|
||||||
};
|
|
||||||
debug("Discovered Powered UP Hub");
|
debug("Discovered Powered UP Hub");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,3 +58,12 @@ export class PUPHub extends LPF2Hub {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export namespace PUPHub {
|
||||||
|
|
||||||
|
export const PortMap: {[port: string]: number} = {
|
||||||
|
"A": 0,
|
||||||
|
"B": 1
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -38,11 +38,7 @@ export class PUPRemote extends LPF2Hub {
|
|||||||
|
|
||||||
|
|
||||||
constructor (device: IBLEAbstraction) {
|
constructor (device: IBLEAbstraction) {
|
||||||
super(device, Consts.HubType.POWERED_UP_REMOTE);
|
super(device, PUPRemote.PortMap, Consts.HubType.POWERED_UP_REMOTE);
|
||||||
this._portNames = {
|
|
||||||
"LEFT": 0,
|
|
||||||
"RIGHT": 1
|
|
||||||
};
|
|
||||||
debug("Discovered Powered UP Remote");
|
debug("Discovered Powered UP Remote");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,3 +54,12 @@ export class PUPRemote extends LPF2Hub {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export namespace PUPRemote {
|
||||||
|
|
||||||
|
export const PortMap: {[port: string]: number} = {
|
||||||
|
"LEFT": 0,
|
||||||
|
"RIGHT": 1
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -34,11 +34,7 @@ export class WeDo2SmartHub extends Hub {
|
|||||||
|
|
||||||
|
|
||||||
constructor (device: IBLEAbstraction) {
|
constructor (device: IBLEAbstraction) {
|
||||||
super(device, Consts.HubType.WEDO2_SMART_HUB);
|
super(device, WeDo2SmartHub.PortMap, Consts.HubType.WEDO2_SMART_HUB);
|
||||||
this._portNames = {
|
|
||||||
"A": 1,
|
|
||||||
"B": 2
|
|
||||||
};
|
|
||||||
debug("Discovered WeDo 2.0 Smart Hub");
|
debug("Discovered WeDo 2.0 Smart Hub");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,3 +349,12 @@ export class WeDo2SmartHub extends Hub {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export namespace WeDo2SmartHub {
|
||||||
|
|
||||||
|
export const PortMap: {[port: string]: number} = {
|
||||||
|
"A": 1,
|
||||||
|
"B": 2
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user