WeDo 2.0 unsubscribing

This commit is contained in:
Nathan Kellenicki 2020-01-06 09:49:38 -08:00
parent c5146bd315
commit 077a7376c0
3 changed files with 12 additions and 3 deletions

View File

@ -107,11 +107,15 @@ export class Device extends EventEmitter {
} }
} }
public unsubscribe (mode: number) {
this._ensureConnected();
}
public receive (message: Buffer) { public receive (message: Buffer) {
this.emitGlobal("receive", message); this.emitGlobal("receive", message);
} }
public emitGlobal (event: string, ...args: any) { public emitGlobal (event: string, ...args: any[]) {
this.emit(event, ...args); this.emit(event, ...args);
if (this.hub.listenerCount(event) > 0) { if (this.hub.listenerCount(event) > 0) {
this.hub.emit(event, this, ...args); this.hub.emit(event, this, ...args);

View File

@ -289,6 +289,11 @@ export class BaseHub extends EventEmitter {
} }
public unsubscribe (portId: number, deviceType: number, mode: number) {
// NK Do nothing here
}
protected _attachDevice (device: Device) { protected _attachDevice (device: Device) {
this._attachedDevices[device.portId] = device; this._attachedDevices[device.portId] = device;
/** /**

View File

@ -141,8 +141,8 @@ export class WeDo2SmartHub extends BaseHub {
} }
protected _deactivatePortDevice (port: number, type: number, mode: number, format: number, callback?: () => void) { public unsubscribe (portId: number, deviceType: number, mode: number) {
this.send(Buffer.from([0x01, 0x02, port, type, mode, 0x01, 0x00, 0x00, 0x00, format, 0x00]), Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE, callback); this.send(Buffer.from([0x01, 0x02, portId, deviceType, mode, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]), Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE);
} }