Code cleanup
This commit is contained in:
parent
f9b99e0481
commit
5efc38b213
@ -34,8 +34,8 @@ export class BoostMoveHub extends LPF2Hub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constructor (peripheral: BLEDevice, autoSubscribe: boolean = true) {
|
constructor (device: BLEDevice, autoSubscribe: boolean = true) {
|
||||||
super(peripheral, autoSubscribe);
|
super(device, autoSubscribe);
|
||||||
this.type = Consts.HubType.BOOST_MOVE_HUB;
|
this.type = Consts.HubType.BOOST_MOVE_HUB;
|
||||||
this._ports = {
|
this._ports = {
|
||||||
"A": new Port("A", 55),
|
"A": new Port("A", 55),
|
||||||
|
@ -64,8 +64,8 @@ export class DuploTrainBase extends LPF2Hub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constructor (peripheral: BLEDevice, autoSubscribe: boolean = true) {
|
constructor (device: BLEDevice, autoSubscribe: boolean = true) {
|
||||||
super(peripheral, autoSubscribe);
|
super(device, autoSubscribe);
|
||||||
this.type = Consts.HubType.DUPLO_TRAIN_HUB;
|
this.type = Consts.HubType.DUPLO_TRAIN_HUB;
|
||||||
this._ports = {
|
this._ports = {
|
||||||
"MOTOR": new Port("MOTOR", 0),
|
"MOTOR": new Port("MOTOR", 0),
|
||||||
|
56
src/hub.ts
56
src/hub.ts
@ -119,70 +119,14 @@ export class Hub extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
public connect () {
|
public connect () {
|
||||||
return new Promise(async (connectResolve, connectReject) => {
|
return new Promise(async (connectResolve, connectReject) => {
|
||||||
|
|
||||||
const self = this;
|
|
||||||
|
|
||||||
if (this._isConnecting) {
|
if (this._isConnecting) {
|
||||||
return connectReject("Already connecting");
|
return connectReject("Already connecting");
|
||||||
} else if (this._isConnected) {
|
} else if (this._isConnected) {
|
||||||
return connectReject("Already connected");
|
return connectReject("Already connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
this._isConnecting = true;
|
this._isConnecting = true;
|
||||||
await this._bleDevice.connect();
|
await this._bleDevice.connect();
|
||||||
return connectResolve();
|
return connectResolve();
|
||||||
// this._peripheral.connect((err: string) => {
|
|
||||||
|
|
||||||
// this._rssi = this._peripheral.rssi;
|
|
||||||
// const rssiUpdateInterval = setInterval(() => {
|
|
||||||
// this._peripheral.updateRssi((err: string, rssi: number) => {
|
|
||||||
// if (!err) {
|
|
||||||
// if (this._rssi !== rssi) {
|
|
||||||
// this._rssi = rssi;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }, 2000);
|
|
||||||
|
|
||||||
// self._peripheral.on("disconnect", () => {
|
|
||||||
// clearInterval(rssiUpdateInterval);
|
|
||||||
// this._isConnecting = false;
|
|
||||||
// this._isConnected = false;
|
|
||||||
// this.emit("disconnect");
|
|
||||||
// });
|
|
||||||
|
|
||||||
// self._peripheral.discoverServices([], (err: string, services: Service[]) => {
|
|
||||||
|
|
||||||
// if (err) {
|
|
||||||
// this.emit("error", err);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// debug("Service/characteristic discovery started");
|
|
||||||
// const servicePromises: Array<Promise<null>> = [];
|
|
||||||
// services.forEach((service) => {
|
|
||||||
// servicePromises.push(new Promise((resolve, reject) => {
|
|
||||||
// service.discoverCharacteristics([], (err, characteristics) => {
|
|
||||||
// characteristics.forEach((characteristic) => {
|
|
||||||
// this._characteristics[characteristic.uuid] = characteristic;
|
|
||||||
// });
|
|
||||||
// return resolve();
|
|
||||||
// });
|
|
||||||
// }));
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Promise.all(servicePromises).then(() => {
|
|
||||||
// debug("Service/characteristic discovery finished");
|
|
||||||
// this._isConnecting = false;
|
|
||||||
// this._isConnected = true;
|
|
||||||
// this.emit("connect");
|
|
||||||
// return connectResolve();
|
|
||||||
// });
|
|
||||||
|
|
||||||
// });
|
|
||||||
|
|
||||||
// });
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ export class PUPHub extends LPF2Hub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constructor (peripheral: BLEDevice, autoSubscribe: boolean = true) {
|
constructor (device: BLEDevice, autoSubscribe: boolean = true) {
|
||||||
super(peripheral, autoSubscribe);
|
super(device, autoSubscribe);
|
||||||
this.type = Consts.HubType.POWERED_UP_HUB;
|
this.type = Consts.HubType.POWERED_UP_HUB;
|
||||||
this._ports = {
|
this._ports = {
|
||||||
"A": new Port("A", 0),
|
"A": new Port("A", 0),
|
||||||
|
@ -64,8 +64,8 @@ export class PUPRemote extends LPF2Hub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constructor (peripheral: BLEDevice, autoSubscribe: boolean = true) {
|
constructor (device: BLEDevice, autoSubscribe: boolean = true) {
|
||||||
super(peripheral, autoSubscribe);
|
super(device, autoSubscribe);
|
||||||
this.type = Consts.HubType.POWERED_UP_REMOTE;
|
this.type = Consts.HubType.POWERED_UP_REMOTE;
|
||||||
this._ports = {
|
this._ports = {
|
||||||
"LEFT": new Port("LEFT", 0),
|
"LEFT": new Port("LEFT", 0),
|
||||||
|
@ -37,8 +37,8 @@ export class WeDo2SmartHub extends Hub {
|
|||||||
private _lastTiltY: number = 0;
|
private _lastTiltY: number = 0;
|
||||||
|
|
||||||
|
|
||||||
constructor (peripheral: BLEDevice, autoSubscribe: boolean = true) {
|
constructor (device: BLEDevice, autoSubscribe: boolean = true) {
|
||||||
super(peripheral, autoSubscribe);
|
super(device, autoSubscribe);
|
||||||
this.type = Consts.HubType.WEDO2_SMART_HUB;
|
this.type = Consts.HubType.WEDO2_SMART_HUB;
|
||||||
this._ports = {
|
this._ports = {
|
||||||
"A": new Port("A", 1),
|
"A": new Port("A", 1),
|
||||||
@ -312,7 +312,6 @@ export class WeDo2SmartHub extends Hub {
|
|||||||
|
|
||||||
private _parseHighCurrentAlert (data: Buffer) {
|
private _parseHighCurrentAlert (data: Buffer) {
|
||||||
debug("Received Message (WEDO2_HIGH_CURRENT_ALERT)", data);
|
debug("Received Message (WEDO2_HIGH_CURRENT_ALERT)", data);
|
||||||
// console.log(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user