Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change device mode after feedback only #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/devices/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export class Device extends EventEmitter {
public subscribe (mode: number) {
this._ensureConnected();
if (mode !== this._mode) {
this._mode = mode;
this.hub.subscribe(this.portId, this.type, mode);
}
}
Expand Down Expand Up @@ -178,6 +177,10 @@ export class Device extends EventEmitter {
}
}

public setMode (message: number) {
this._mode = message;
}

public setEventTimer (timer: NodeJS.Timeout) {
this._eventTimer = timer;
}
Expand Down
17 changes: 12 additions & 5 deletions src/hubs/lpf2hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,14 @@ export class LPF2Hub extends BaseHub {
this._parseSensorMessage(message);
break;
}
case Consts.MessageType.PORT_INPUT_FORMAT_SINGLE: {
this._parsePortInputFormatMessage(message);
break;
}
case Consts.MessageType.PORT_OUTPUT_COMMAND_FEEDBACK: {
this._parsePortAction(message);
break;
}
}
}

if (this._messageBuffer.length > 0) {
Expand Down Expand Up @@ -346,7 +350,6 @@ export class LPF2Hub extends BaseHub {
}
}


private _parsePortAction (message: Buffer) {
for (let offset = 3; offset < message.length; offset += 2) {
const device = this._getDeviceByPortId(message[offset]);
Expand All @@ -357,17 +360,21 @@ export class LPF2Hub extends BaseHub {
}
}


private _parseSensorMessage (message: Buffer) {

const portId = message[3];
const device = this._getDeviceByPortId(portId);

if (device) {
device.receive(message);
}

}

private _parsePortInputFormatMessage (message: Buffer) {
const portId = message[3];
const device = this._getDeviceByPortId(portId);

if (device) {
device.setMode(message[4]);
}
}
}