Basic code for passing messages through to the device
This commit is contained in:
parent
8ffc60b924
commit
93a1369e84
@ -23,4 +23,8 @@ export class ColorDistanceSensor extends Device {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public receive (message: Buffer) {
|
||||||
|
// NK TODO
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,14 @@ export class Device extends EventEmitter {
|
|||||||
this._hub = hub;
|
this._hub = hub;
|
||||||
this._portId = portId;
|
this._portId = portId;
|
||||||
this._type = type;
|
this._type = type;
|
||||||
this.hub.on("detach", (device) => {
|
const detachListener = (device: Device) => {
|
||||||
if (device === this) {
|
if (device.portId === this.portId) {
|
||||||
this._connected = false;
|
this._connected = false;
|
||||||
|
this.hub.removeListener("detach", detachListener);
|
||||||
this.emit("detach");
|
this.emit("detach");
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
this.hub.on("detach", detachListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get connected () {
|
public get connected () {
|
||||||
@ -58,4 +60,8 @@ export class Device extends EventEmitter {
|
|||||||
this.send(Buffer.from([0x41, this.portId, mode, 0x01, 0x00, 0x00, 0x00, 0x01]));
|
this.send(Buffer.from([0x41, this.portId, mode, 0x01, 0x00, 0x00, 0x00, 0x01]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public receive (message: Buffer) {
|
||||||
|
this.emit("receive", message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,14 @@ export class LPF2Hub extends Hub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private _parseSensorMessage (data: Buffer) {
|
private _parseSensorMessage (message: Buffer) {
|
||||||
|
|
||||||
|
const portId = message[3];
|
||||||
|
const device = this._getDeviceByPortId(portId);
|
||||||
|
|
||||||
|
if (device) {
|
||||||
|
device.receive(message);
|
||||||
|
}
|
||||||
|
|
||||||
// if (data[3] === this._voltagePort) {
|
// if (data[3] === this._voltagePort) {
|
||||||
// const voltageRaw = data.readUInt16LE(4);
|
// const voltageRaw = data.readUInt16LE(4);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user