-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from SlimeVR/feat/tracker-emulation/user-actions
fix(firmware-protocol): Add missing user action packet
- Loading branch information
Showing
6 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@slimevr/firmware-protocol': patch | ||
--- | ||
|
||
added missing UserAction (21) packet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@slimevr/tracker-emulation': patch | ||
--- | ||
|
||
add the ability to send the UserAction (21) packet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/firmware-protocol/src/packets/ServerBoundUserActionPacket.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Packet } from './Packet'; | ||
|
||
export const UserAction = { | ||
RESET_FULL: 2, | ||
RESET_YAW: 3, | ||
RESET_MOUNTING: 4, | ||
PAUSE_TRACKING: 5 | ||
} as const; | ||
export type UserAction = (typeof UserAction)[keyof typeof UserAction]; | ||
|
||
export class ServerBoundUserActionPacket extends Packet { | ||
constructor(readonly action: number) { | ||
super(ServerBoundUserActionPacket.type); | ||
} | ||
|
||
static fromBuffer(data: Buffer) { | ||
const action = data.readUIntBE(0, 1) & (0xff as UserAction); | ||
|
||
return new ServerBoundUserActionPacket(action); | ||
} | ||
|
||
static get type() { | ||
return 21; | ||
} | ||
|
||
override toString() { | ||
return `ServerBoundUserActionPacket{action: ${this.action}}`; | ||
} | ||
|
||
encode(num: bigint): Buffer { | ||
const buf = Buffer.alloc(4 + 8 + 1); | ||
|
||
buf.writeInt32BE(ServerBoundUserActionPacket.type, 0); | ||
buf.writeBigInt64BE(num, 4); | ||
|
||
buf.writeInt8(this.action, 12); | ||
|
||
return buf; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters