Start of hub refactor

This commit is contained in:
Nathan Kellenicki 2019-12-10 07:23:33 +09:00
parent f9cea9a6bf
commit 7fdc754084
13 changed files with 78 additions and 234 deletions

View File

@ -8,7 +8,7 @@ import { mapSpeed } from "./utils";
export class BasicMotor extends Device { export class BasicMotor extends Device {
constructor (hub: Hub, portId: number, type: number = Consts.DeviceType.UNKNOWN) { constructor (hub: Hub, portId: number, type: Consts.DeviceType = Consts.DeviceType.UNKNOWN) {
super(hub, portId, type); super(hub, portId, type);
} }

View File

@ -34,9 +34,8 @@ export class BoostMoveHub extends LPF2Hub {
protected _currentPort = 0x3b; protected _currentPort = 0x3b;
protected _voltagePort = 0x3c; protected _voltagePort = 0x3c;
constructor (device: IBLEAbstraction, autoSubscribe: boolean = true) { constructor (device: IBLEAbstraction) {
super(device, autoSubscribe); super(device, Consts.HubType.BOOST_MOVE_HUB);
this._type = Consts.HubType.BOOST_MOVE_HUB;
this._portNames = { this._portNames = {
"A": 0, "A": 0,
"B": 1, "B": 1,

View File

@ -36,9 +36,8 @@ export class ControlPlusHub extends LPF2Hub {
protected _voltageMaxRaw = 4095; protected _voltageMaxRaw = 4095;
protected _voltageMaxV = 9.615; protected _voltageMaxV = 9.615;
constructor (device: IBLEAbstraction, autoSubscribe: boolean = true) { constructor (device: IBLEAbstraction) {
super(device, autoSubscribe); super(device, Consts.HubType.CONTROL_PLUS_HUB);
this._type = Consts.HubType.CONTROL_PLUS_HUB;
this._portNames = { this._portNames = {
"A": 0, "A": 0,
"B": 1, "B": 1,

View File

@ -14,9 +14,9 @@ export class Device extends EventEmitter {
private _hub: Hub; private _hub: Hub;
private _portId: number; private _portId: number;
private _connected: boolean = true; private _connected: boolean = true;
private _type: number; private _type: Consts.DeviceType;
constructor (hub: Hub, portId: number, type: number = Consts.DeviceType.UNKNOWN) { constructor (hub: Hub, portId: number, type: Consts.DeviceType = Consts.DeviceType.UNKNOWN) {
super(); super();
this._hub = hub; this._hub = hub;
this._portId = portId; this._portId = portId;
@ -61,7 +61,7 @@ export class Device extends EventEmitter {
public subscribe (mode: number) { public subscribe (mode: number) {
if (mode !== this._mode) { if (mode !== this._mode) {
this._mode = mode; this._mode = mode;
this.send(Buffer.from([0x41, this.portId, mode, 0x01, 0x00, 0x00, 0x00, 0x01])); this.hub.subscribe(this.portId, mode);
} }
} }

View File

@ -35,9 +35,8 @@ export class DuploTrainBase extends LPF2Hub {
protected _voltageMaxV = 6.4; protected _voltageMaxV = 6.4;
protected _voltageMaxRaw = 3047; protected _voltageMaxRaw = 3047;
constructor (device: IBLEAbstraction, autoSubscribe: boolean = true) { constructor (device: IBLEAbstraction) {
super(device, autoSubscribe); super(device, Consts.HubType.DUPLO_TRAIN_HUB);
this._type = Consts.HubType.DUPLO_TRAIN_HUB;
this._portNames = { this._portNames = {
"MOTOR": 0, "MOTOR": 0,
"COLOR": 18, "COLOR": 18,

View File

@ -15,10 +15,7 @@ const debug = Debug("hub");
*/ */
export class Hub extends EventEmitter { export class Hub extends EventEmitter {
public autoSubscribe: boolean = true;
public useSpeedMap: boolean = true; public useSpeedMap: boolean = true;
protected _type: Consts.HubType = Consts.HubType.UNKNOWN;
protected _attachedDevices: {[portId: number]: Device} = {}; protected _attachedDevices: {[portId: number]: Device} = {};
@ -39,9 +36,11 @@ export class Hub extends EventEmitter {
private _isConnecting = false; private _isConnecting = false;
private _isConnected = false; private _isConnected = false;
constructor (device: IBLEAbstraction, autoSubscribe: boolean = true) { private _type: Consts.HubType;
constructor (device: IBLEAbstraction, type: Consts.HubType = Consts.HubType.UNKNOWN) {
super(); super();
this.autoSubscribe = !!autoSubscribe; this._type = type;
this._bleDevice = device; this._bleDevice = device;
device.on("disconnect", () => { device.on("disconnect", () => {
/** /**
@ -183,41 +182,6 @@ export class Hub extends EventEmitter {
} }
// /**
// * Subscribe to sensor notifications on a given port.
// * @method Hub#subscribe
// * @param {string} port
// * @param {number} [mode] The sensor mode to activate. If no mode is provided, the default for that sensor will be chosen.
// * @returns {Promise} Resolved upon successful issuance of command.
// */
// public subscribe (port: string, mode?: number) {
// return new Promise((resolve, reject) => {
// let newMode = this._getModeForDeviceType(this._portLookup(port).type);
// if (mode !== undefined) {
// newMode = mode;
// }
// this._activatePortDevice(this._portLookup(port).value, this._portLookup(port).type, newMode, 0x00, () => {
// return resolve();
// });
// });
// }
// /**
// * Unsubscribe to sensor notifications on a given port.
// * @method Hub#unsubscribe
// * @param {string} port
// * @returns {Promise} Resolved upon successful issuance of command.
// */
// public unsubscribe (port: string) {
// return new Promise((resolve, reject) => {
// const mode = this._getModeForDeviceType(this._portLookup(port).type);
// this._deactivatePortDevice(this._portLookup(port).value, this._portLookup(port).type, mode, 0x00, () => {
// return resolve();
// });
// });
// }
/** /**
* Sleep a given amount of time. * Sleep a given amount of time.
* *
@ -246,17 +210,6 @@ export class Hub extends EventEmitter {
} }
// /**
// * Get the device type for a given port.
// * @method Hub#getPortDeviceType
// * @param {string} port
// * @returns {DeviceType}
// */
// public getPortDeviceType (port: string) {
// return this._portLookup(port).type;
// }
public send (message: Buffer, uuid: string, callback?: () => void) { public send (message: Buffer, uuid: string, callback?: () => void) {
if (callback) { if (callback) {
callback(); callback();
@ -264,60 +217,19 @@ export class Hub extends EventEmitter {
} }
// protected _getCharacteristic (uuid: string) { public subscribe (portId: number, mode: number) {
// return this._characteristics[uuid.replace(/-/g, "")]; // NK Do nothing here
// } }
// protected _subscribeToCharacteristic (characteristic: Characteristic, callback: (data: Buffer) => void) {
// characteristic.on("data", (data: Buffer) => {
// return callback(data);
// });
// characteristic.subscribe((err) => {
// if (err) {
// this.emit("error", err);
// }
// });
// }
protected _attachDevice (device: Device) { protected _attachDevice (device: Device) {
this._attachedDevices[device.portId] = device; this._attachedDevices[device.portId] = device;
/** /**
* Emits when a device is attached to the Hub. * Emits when a device is attached to the Hub.
* @event Hub#attach * @event Hub#attach
* @param {Device} device * @param {Device} device
*/ */
this.emit("attach", device); this.emit("attach", device);
// if (port.connected) {
// port.type = type;
// if (this.autoSubscribe) {
// this._activatePortDevice(port.value, type, this._getModeForDeviceType(type), 0x00);
// }
// /**
// * Emits when a motor or sensor is attached to the Hub.
// * @event Hub#attach
// * @param {string} port
// * @param {DeviceType} type
// */
// this.emit("attach", port.id, type);
// } else {
// port.type = Consts.DeviceType.UNKNOWN;
// debug(`Port ${port.id} disconnected`);
// /**
// * Emits when an attached motor or sensor is detached from the Hub.
// * @event Hub#detach
// * @param {string} port
// */
// if (this._virtualPorts[port.id]) {
// delete this._virtualPorts[port.id];
// }
// this.emit("detach", port.id);
// }
} }
@ -337,44 +249,6 @@ export class Hub extends EventEmitter {
} }
// protected _getPortForPortNumber (num: number) {
// for (const key of Object.keys(this._ports)) {
// if (this._ports[key].value === num) {
// return this._ports[key];
// }
// }
// for (const key of Object.keys(this._virtualPorts)) {
// if (this._virtualPorts[key].value === num) {
// return this._virtualPorts[key];
// }
// }
// return false;
// }
// protected _mapSpeed (speed: number) { // Speed range of -100 to 100 is supported unless speed mapping is turned off, in which case, you're on your own!
// if (!this.useSpeedMap) {
// return speed;
// }
// if (speed === 127) {
// return 127; // Hard stop
// }
// if (speed > 100) {
// speed = 100;
// } else if (speed < -100) {
// speed = -100;
// }
// return speed;
// }
// protected _calculateRamp (fromSpeed: number, toSpeed: number, time: number, port: Port) { // protected _calculateRamp (fromSpeed: number, toSpeed: number, time: number, port: Port) {
// const emitter = new EventEmitter(); // const emitter = new EventEmitter();
// const steps = Math.abs(toSpeed - fromSpeed); // const steps = Math.abs(toSpeed - fromSpeed);
@ -406,15 +280,6 @@ export class Hub extends EventEmitter {
// } // }
// protected _portLookup (portName: string) {
// const portNameUpper = portName.toUpperCase();
// const port = this._ports[portNameUpper] || this._virtualPorts[portNameUpper];
// if (!port) {
// throw new Error(`Port ${portNameUpper} does not exist on this Hub type`);
// }
// return port;
// }
// private _getModeForDeviceType (type: Consts.DeviceType) { // private _getModeForDeviceType (type: Consts.DeviceType) {
// switch (type) { // switch (type) {
// case Consts.DeviceType.SIMPLE_MEDIUM_LINEAR_MOTOR: // case Consts.DeviceType.SIMPLE_MEDIUM_LINEAR_MOTOR:

View File

@ -46,7 +46,7 @@ export class LPF2Hub extends Hub {
if (this._currentPort !== undefined) { if (this._currentPort !== undefined) {
this.send(Buffer.from([0x41, this._currentPort, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01]), Consts.BLECharacteristic.LPF2_ALL); // Activate current reports this.send(Buffer.from([0x41, this._currentPort, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01]), Consts.BLECharacteristic.LPF2_ALL); // Activate current reports
} }
if (this._type === Consts.HubType.DUPLO_TRAIN_HUB) { if (this.type === Consts.HubType.DUPLO_TRAIN_HUB) {
this.send(Buffer.from([0x41, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01]), Consts.BLECharacteristic.LPF2_ALL); this.send(Buffer.from([0x41, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01]), Consts.BLECharacteristic.LPF2_ALL);
} }
await this.sleep(100); await this.sleep(100);
@ -137,15 +137,6 @@ export class LPF2Hub extends Hub {
} }
public sendRaw (message: Buffer) {
return new Promise((resolve, reject) => {
this.send(message, Consts.BLECharacteristic.LPF2_ALL, () => {
return resolve();
});
});
}
public send (message: Buffer, uuid: string, callback?: () => void) { public send (message: Buffer, uuid: string, callback?: () => void) {
message = Buffer.concat([Buffer.alloc(2), message]); message = Buffer.concat([Buffer.alloc(2), message]);
message[0] = message.length; message[0] = message.length;
@ -154,14 +145,14 @@ export class LPF2Hub extends Hub {
} }
// protected _activatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) { public subscribe (portId: number, mode: number) {
// this.send(Buffer.from([0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x01]), Consts.BLECharacteristic.LPF2_ALL, callback); this.send(Buffer.from([0x41, portId, mode, 0x01, 0x00, 0x00, 0x00, 0x01]), Consts.BLECharacteristic.LPF2_ALL);
// } }
// protected _deactivatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) { public unsubscribe (portId: number, mode: number) {
// this.send(Buffer.from([0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x00]), Consts.BLECharacteristic.LPF2_ALL, callback); this.send(Buffer.from([0x41, portId, mode, 0x01, 0x00, 0x00, 0x00, 0x00]), Consts.BLECharacteristic.LPF2_ALL);
// } }
// protected _combinePorts (port: string, type: number) { // protected _combinePorts (port: string, type: number) {
@ -238,11 +229,11 @@ export class LPF2Hub extends Hub {
} }
private _parseDeviceInfo (data: Buffer) { private _parseDeviceInfo (message: Buffer) {
// Button press reports // Button press reports
if (data[3] === 0x02) { if (message[3] === 0x02) {
if (data[5] === 1) { if (message[5] === 1) {
/** /**
* Emits when a button is pressed. * Emits when a button is pressed.
* @event LPF2Hub#button * @event LPF2Hub#button
@ -251,35 +242,35 @@ export class LPF2Hub extends Hub {
*/ */
this.emit("button", "GREEN", Consts.ButtonState.PRESSED); this.emit("button", "GREEN", Consts.ButtonState.PRESSED);
return; return;
} else if (data[5] === 0) { } else if (message[5] === 0) {
this.emit("button", "GREEN", Consts.ButtonState.RELEASED); this.emit("button", "GREEN", Consts.ButtonState.RELEASED);
return; return;
} }
// Firmware version // Firmware version
} else if (data[3] === 0x03) { } else if (message[3] === 0x03) {
this._firmwareVersion = decodeVersion(data.readInt32LE(5)); this._firmwareVersion = decodeVersion(message.readInt32LE(5));
this._checkFirmware(this._firmwareVersion); this._checkFirmware(this._firmwareVersion);
// Hardware version // Hardware version
} else if (data[3] === 0x04) { } else if (message[3] === 0x04) {
this._hardwareVersion = decodeVersion(data.readInt32LE(5)); this._hardwareVersion = decodeVersion(message.readInt32LE(5));
// RSSI update // RSSI update
} else if (data[3] === 0x05) { } else if (message[3] === 0x05) {
const rssi = data.readInt8(5); const rssi = message.readInt8(5);
if (rssi !== 0) { if (rssi !== 0) {
this._rssi = rssi; this._rssi = rssi;
this.emit("rssiChange", this._rssi); this.emit("rssiChange", this._rssi);
} }
// primary MAC Address // primary MAC Address
} else if (data[3] === 0x0d) { } else if (message[3] === 0x0d) {
this._primaryMACAddress = decodeMACAddress(data.slice(5)); this._primaryMACAddress = decodeMACAddress(message.slice(5));
// Battery level reports // Battery level reports
} else if (data[3] === 0x06) { } else if (message[3] === 0x06) {
this._batteryLevel = data[5]; this._batteryLevel = message[5];
} }
} }
@ -361,19 +352,19 @@ export class LPF2Hub extends Hub {
} }
private _parsePortInformationResponse (data: Buffer) { private _parsePortInformationResponse (message: Buffer) {
const port = data[3]; const port = message[3];
if (data[4] === 2) { if (message[4] === 2) {
const modeCombinationMasks: number[] = []; const modeCombinationMasks: number[] = [];
for (let i = 5; i < data.length; i += 2) { for (let i = 5; i < message.length; i += 2) {
modeCombinationMasks.push(data.readUInt16LE(i)); modeCombinationMasks.push(message.readUInt16LE(i));
} }
modeInfoDebug(`Port ${toHex(port)}, mode combinations [${modeCombinationMasks.map((c) => toBin(c, 0)).join(", ")}]`); modeInfoDebug(`Port ${toHex(port)}, mode combinations [${modeCombinationMasks.map((c) => toBin(c, 0)).join(", ")}]`);
return; return;
} }
const count = data[6]; const count = message[6];
const input = toBin(data.readUInt16LE(7), count); const input = toBin(message.readUInt16LE(7), count);
const output = toBin(data.readUInt16LE(9), count); const output = toBin(message.readUInt16LE(9), count);
modeInfoDebug(`Port ${toHex(port)}, total modes ${count}, input modes ${input}, output modes ${output}`); modeInfoDebug(`Port ${toHex(port)}, total modes ${count}, input modes ${input}, output modes ${output}`);
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
@ -392,31 +383,31 @@ export class LPF2Hub extends Hub {
} }
private _parseModeInformationResponse (data: Buffer) { private _parseModeInformationResponse (message: Buffer) {
const port = toHex(data[3]); const port = toHex(message[3]);
const mode = data[4]; const mode = message[4];
const type = data[5]; const type = message[5];
switch (type) { switch (type) {
case 0x00: // Mode Name case 0x00: // Mode Name
modeInfoDebug(`Port ${port}, mode ${mode}, name ${data.slice(6, data.length).toString()}`); modeInfoDebug(`Port ${port}, mode ${mode}, name ${message.slice(6, message.length).toString()}`);
break; break;
case 0x01: // RAW Range case 0x01: // RAW Range
modeInfoDebug(`Port ${port}, mode ${mode}, RAW min ${data.readFloatLE(6)}, max ${data.readFloatLE(10)}`); modeInfoDebug(`Port ${port}, mode ${mode}, RAW min ${message.readFloatLE(6)}, max ${message.readFloatLE(10)}`);
break; break;
case 0x02: // PCT Range case 0x02: // PCT Range
modeInfoDebug(`Port ${port}, mode ${mode}, PCT min ${data.readFloatLE(6)}, max ${data.readFloatLE(10)}`); modeInfoDebug(`Port ${port}, mode ${mode}, PCT min ${message.readFloatLE(6)}, max ${message.readFloatLE(10)}`);
break; break;
case 0x03: // SI Range case 0x03: // SI Range
modeInfoDebug(`Port ${port}, mode ${mode}, SI min ${data.readFloatLE(6)}, max ${data.readFloatLE(10)}`); modeInfoDebug(`Port ${port}, mode ${mode}, SI min ${message.readFloatLE(6)}, max ${message.readFloatLE(10)}`);
break; break;
case 0x04: // SI Symbol case 0x04: // SI Symbol
modeInfoDebug(`Port ${port}, mode ${mode}, SI symbol ${data.slice(6, data.length).toString()}`); modeInfoDebug(`Port ${port}, mode ${mode}, SI symbol ${message.slice(6, message.length).toString()}`);
break; break;
case 0x80: // Value Format case 0x80: // Value Format
const numValues = data[6]; const numValues = message[6];
const dataType = ["8bit", "16bit", "32bit", "float"][data[7]]; const dataType = ["8bit", "16bit", "32bit", "float"][message[7]];
const totalFigures = data[8]; const totalFigures = message[8];
const decimals = data[9]; const decimals = message[9];
modeInfoDebug(`Port ${port}, mode ${mode}, Value ${numValues} x ${dataType}, Decimal format ${totalFigures}.${decimals}`); modeInfoDebug(`Port ${port}, mode ${mode}, Value ${numValues} x ${dataType}, Decimal format ${totalFigures}.${decimals}`);
} }
} }

View File

@ -23,9 +23,6 @@ const debug = Debug("poweredup");
export class PoweredUP extends EventEmitter { export class PoweredUP extends EventEmitter {
public autoSubscribe: boolean = true;
private _connectedHubs: {[uuid: string]: Hub} = {}; private _connectedHubs: {[uuid: string]: Hub} = {};
@ -184,22 +181,22 @@ export class PoweredUP extends EventEmitter {
switch (hubType) { switch (hubType) {
case Consts.HubType.WEDO2_SMART_HUB: case Consts.HubType.WEDO2_SMART_HUB:
hub = new WeDo2SmartHub(device, this.autoSubscribe); hub = new WeDo2SmartHub(device);
break; break;
case Consts.HubType.BOOST_MOVE_HUB: case Consts.HubType.BOOST_MOVE_HUB:
hub = new BoostMoveHub(device, this.autoSubscribe); hub = new BoostMoveHub(device);
break; break;
case Consts.HubType.POWERED_UP_HUB: case Consts.HubType.POWERED_UP_HUB:
hub = new PUPHub(device, this.autoSubscribe); hub = new PUPHub(device);
break; break;
case Consts.HubType.POWERED_UP_REMOTE: case Consts.HubType.POWERED_UP_REMOTE:
hub = new PUPRemote(device, this.autoSubscribe); hub = new PUPRemote(device);
break; break;
case Consts.HubType.DUPLO_TRAIN_HUB: case Consts.HubType.DUPLO_TRAIN_HUB:
hub = new DuploTrainBase(device, this.autoSubscribe); hub = new DuploTrainBase(device);
break; break;
case Consts.HubType.CONTROL_PLUS_HUB: case Consts.HubType.CONTROL_PLUS_HUB:
hub = new ControlPlusHub(device, this.autoSubscribe); hub = new ControlPlusHub(device);
break; break;
default: default:
return; return;

View File

@ -44,9 +44,6 @@ noble.on("stateChange", (state: string) => {
export class PoweredUP extends EventEmitter { export class PoweredUP extends EventEmitter {
public autoSubscribe: boolean = true;
private _connectedHubs: {[uuid: string]: Hub} = {}; private _connectedHubs: {[uuid: string]: Hub} = {};
@ -144,17 +141,17 @@ export class PoweredUP extends EventEmitter {
let hub: Hub; let hub: Hub;
if (await WeDo2SmartHub.IsWeDo2SmartHub(peripheral)) { if (await WeDo2SmartHub.IsWeDo2SmartHub(peripheral)) {
hub = new WeDo2SmartHub(device, this.autoSubscribe); hub = new WeDo2SmartHub(device);
} else if (await BoostMoveHub.IsBoostMoveHub(peripheral)) { } else if (await BoostMoveHub.IsBoostMoveHub(peripheral)) {
hub = new BoostMoveHub(device, this.autoSubscribe); hub = new BoostMoveHub(device);
} else if (await PUPHub.IsPUPHub(peripheral)) { } else if (await PUPHub.IsPUPHub(peripheral)) {
hub = new PUPHub(device, this.autoSubscribe); hub = new PUPHub(device);
} else if (await PUPRemote.IsPUPRemote(peripheral)) { } else if (await PUPRemote.IsPUPRemote(peripheral)) {
hub = new PUPRemote(device, this.autoSubscribe); hub = new PUPRemote(device);
} else if (await DuploTrainBase.IsDuploTrainBase(peripheral)) { } else if (await DuploTrainBase.IsDuploTrainBase(peripheral)) {
hub = new DuploTrainBase(device, this.autoSubscribe); hub = new DuploTrainBase(device);
} else if (await ControlPlusHub.IsControlPlusHub(peripheral)) { } else if (await ControlPlusHub.IsControlPlusHub(peripheral)) {
hub = new ControlPlusHub(device, this.autoSubscribe); hub = new ControlPlusHub(device);
} else { } else {
return; return;
} }

View File

@ -34,9 +34,8 @@ export class PUPHub extends LPF2Hub {
protected _currentPort = 0x3b; protected _currentPort = 0x3b;
protected _voltagePort = 0x3c; protected _voltagePort = 0x3c;
constructor (device: IBLEAbstraction, autoSubscribe: boolean = true) { constructor (device: IBLEAbstraction) {
super(device, autoSubscribe); super(device, Consts.HubType.POWERED_UP_HUB);
this._type = Consts.HubType.POWERED_UP_HUB;
this._portNames = { this._portNames = {
"A": 0, "A": 0,
"B": 1 "B": 1

View File

@ -37,9 +37,8 @@ export class PUPRemote extends LPF2Hub {
protected _voltageMaxRaw = 3200; protected _voltageMaxRaw = 3200;
constructor (device: IBLEAbstraction, autoSubscribe: boolean = true) { constructor (device: IBLEAbstraction) {
super(device, autoSubscribe); super(device, Consts.HubType.POWERED_UP_REMOTE);
this._type = Consts.HubType.POWERED_UP_REMOTE;
this._portNames = { this._portNames = {
"LEFT": 0, "LEFT": 0,
"RIGHT": 1 "RIGHT": 1

View File

@ -6,7 +6,7 @@ import { mapSpeed } from "./utils";
export class TachoMotor extends BasicMotor { export class TachoMotor extends BasicMotor {
constructor (hub: Hub, portId: number, type: number = Consts.DeviceType.UNKNOWN) { constructor (hub: Hub, portId: number, type: Consts.DeviceType = Consts.DeviceType.UNKNOWN) {
super(hub, portId, type); super(hub, portId, type);
this.on("newListener", (event) => { this.on("newListener", (event) => {

View File

@ -38,9 +38,8 @@ export class WeDo2SmartHub extends Hub {
private _lastTiltY: number = 0; private _lastTiltY: number = 0;
constructor (device: IBLEAbstraction, autoSubscribe: boolean = true) { constructor (device: IBLEAbstraction) {
super(device, autoSubscribe); super(device, Consts.HubType.WEDO2_SMART_HUB);
this._type = Consts.HubType.WEDO2_SMART_HUB;
this._portNames = { this._portNames = {
"A": 1, "A": 1,
"B": 2 "B": 2