@openmouse/protocol 0.42.3 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/drivers/registry.d.ts +13 -1
- package/dist/drivers/registry.d.ts.map +1 -1
- package/dist/drivers/registry.js +24 -0
- package/dist/drivers/registry.js.map +1 -1
- package/dist/drivers/steelseries/aerox-3-wireless-gen2-hid.d.ts +65 -0
- package/dist/drivers/steelseries/aerox-3-wireless-gen2-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/aerox-3-wireless-gen2-hid.js +205 -0
- package/dist/drivers/steelseries/aerox-3-wireless-gen2-hid.js.map +1 -0
- package/dist/drivers/steelseries/prime-mini-hid.d.ts +59 -0
- package/dist/drivers/steelseries/prime-mini-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/prime-mini-hid.js +183 -0
- package/dist/drivers/steelseries/prime-mini-hid.js.map +1 -0
- package/dist/drivers/steelseries/rival-100-hid.d.ts +57 -0
- package/dist/drivers/steelseries/rival-100-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/rival-100-hid.js +181 -0
- package/dist/drivers/steelseries/rival-100-hid.js.map +1 -0
- package/dist/drivers/steelseries/rival-110-hid.d.ts +78 -0
- package/dist/drivers/steelseries/rival-110-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/rival-110-hid.js +206 -0
- package/dist/drivers/steelseries/rival-110-hid.js.map +1 -0
- package/dist/drivers/steelseries/rival-3-v2-hid.d.ts +59 -0
- package/dist/drivers/steelseries/rival-3-v2-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/rival-3-v2-hid.js +183 -0
- package/dist/drivers/steelseries/rival-3-v2-hid.js.map +1 -0
- package/dist/drivers/steelseries/rival-3-wireless-v2-hid.d.ts +64 -0
- package/dist/drivers/steelseries/rival-3-wireless-v2-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/rival-3-wireless-v2-hid.js +199 -0
- package/dist/drivers/steelseries/rival-3-wireless-v2-hid.js.map +1 -0
- package/dist/drivers/steelseries/rival-300-hid.d.ts +78 -0
- package/dist/drivers/steelseries/rival-300-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/rival-300-hid.js +206 -0
- package/dist/drivers/steelseries/rival-300-hid.js.map +1 -0
- package/dist/drivers/steelseries/rival-5-hid.d.ts +55 -0
- package/dist/drivers/steelseries/rival-5-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/rival-5-hid.js +177 -0
- package/dist/drivers/steelseries/rival-5-hid.js.map +1 -0
- package/dist/drivers/steelseries/rival-600-hid.d.ts +65 -0
- package/dist/drivers/steelseries/rival-600-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/rival-600-hid.js +184 -0
- package/dist/drivers/steelseries/rival-600-hid.js.map +1 -0
- package/dist/drivers/steelseries/sensei-310-hid.d.ts +54 -0
- package/dist/drivers/steelseries/sensei-310-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/sensei-310-hid.js +177 -0
- package/dist/drivers/steelseries/sensei-310-hid.js.map +1 -0
- package/dist/drivers/steelseries/sensei-raw-hid.d.ts +75 -0
- package/dist/drivers/steelseries/sensei-raw-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/sensei-raw-hid.js +199 -0
- package/dist/drivers/steelseries/sensei-raw-hid.js.map +1 -0
- package/dist/drivers/steelseries/sensei-rival-pro-hid.d.ts +42 -0
- package/dist/drivers/steelseries/sensei-rival-pro-hid.d.ts.map +1 -0
- package/dist/drivers/steelseries/sensei-rival-pro-hid.js +132 -0
- package/dist/drivers/steelseries/sensei-rival-pro-hid.js.map +1 -0
- package/dist/steelseries/aerox-3-wireless-gen2.d.ts +204 -0
- package/dist/steelseries/aerox-3-wireless-gen2.d.ts.map +1 -0
- package/dist/steelseries/aerox-3-wireless-gen2.js +301 -0
- package/dist/steelseries/aerox-3-wireless-gen2.js.map +1 -0
- package/dist/steelseries/aerox3.d.ts +3 -3
- package/dist/steelseries/aerox3.js +3 -3
- package/dist/steelseries/devices.d.ts +31 -14
- package/dist/steelseries/devices.d.ts.map +1 -1
- package/dist/steelseries/devices.js +417 -13
- package/dist/steelseries/devices.js.map +1 -1
- package/dist/steelseries/index.d.ts +12 -0
- package/dist/steelseries/index.d.ts.map +1 -1
- package/dist/steelseries/index.js +12 -0
- package/dist/steelseries/index.js.map +1 -1
- package/dist/steelseries/prime-mini-wireless.d.ts +9 -14
- package/dist/steelseries/prime-mini-wireless.d.ts.map +1 -1
- package/dist/steelseries/prime-mini-wireless.js +9 -14
- package/dist/steelseries/prime-mini-wireless.js.map +1 -1
- package/dist/steelseries/prime-mini.d.ts +173 -0
- package/dist/steelseries/prime-mini.d.ts.map +1 -0
- package/dist/steelseries/prime-mini.js +273 -0
- package/dist/steelseries/prime-mini.js.map +1 -0
- package/dist/steelseries/prime-plus.d.ts +5 -4
- package/dist/steelseries/prime-plus.d.ts.map +1 -1
- package/dist/steelseries/prime-plus.js +5 -4
- package/dist/steelseries/prime-plus.js.map +1 -1
- package/dist/steelseries/rival-100.d.ts +134 -0
- package/dist/steelseries/rival-100.d.ts.map +1 -0
- package/dist/steelseries/rival-100.js +195 -0
- package/dist/steelseries/rival-100.js.map +1 -0
- package/dist/steelseries/rival-110.d.ts +134 -0
- package/dist/steelseries/rival-110.d.ts.map +1 -0
- package/dist/steelseries/rival-110.js +205 -0
- package/dist/steelseries/rival-110.js.map +1 -0
- package/dist/steelseries/rival-3-v2.d.ts +168 -0
- package/dist/steelseries/rival-3-v2.d.ts.map +1 -0
- package/dist/steelseries/rival-3-v2.js +242 -0
- package/dist/steelseries/rival-3-v2.js.map +1 -0
- package/dist/steelseries/rival-3-wireless-v2.d.ts +219 -0
- package/dist/steelseries/rival-3-wireless-v2.d.ts.map +1 -0
- package/dist/steelseries/rival-3-wireless-v2.js +270 -0
- package/dist/steelseries/rival-3-wireless-v2.js.map +1 -0
- package/dist/steelseries/rival-300.d.ts +163 -0
- package/dist/steelseries/rival-300.d.ts.map +1 -0
- package/dist/steelseries/rival-300.js +266 -0
- package/dist/steelseries/rival-300.js.map +1 -0
- package/dist/steelseries/rival-5.d.ts +165 -0
- package/dist/steelseries/rival-5.d.ts.map +1 -0
- package/dist/steelseries/rival-5.js +212 -0
- package/dist/steelseries/rival-5.js.map +1 -0
- package/dist/steelseries/rival-600.d.ts +194 -0
- package/dist/steelseries/rival-600.d.ts.map +1 -0
- package/dist/steelseries/rival-600.js +262 -0
- package/dist/steelseries/rival-600.js.map +1 -0
- package/dist/steelseries/sensei-310.d.ts +162 -0
- package/dist/steelseries/sensei-310.d.ts.map +1 -0
- package/dist/steelseries/sensei-310.js +250 -0
- package/dist/steelseries/sensei-310.js.map +1 -0
- package/dist/steelseries/sensei-raw.d.ts +169 -0
- package/dist/steelseries/sensei-raw.d.ts.map +1 -0
- package/dist/steelseries/sensei-raw.js +233 -0
- package/dist/steelseries/sensei-raw.js.map +1 -0
- package/dist/steelseries/sensei-rival-pro.d.ts +214 -0
- package/dist/steelseries/sensei-rival-pro.d.ts.map +1 -0
- package/dist/steelseries/sensei-rival-pro.js +298 -0
- package/dist/steelseries/sensei-rival-pro.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rival-300.d.ts","sourceRoot":"","sources":["../../src/steelseries/rival-300.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,eAAO,MAAM,kBAAkB,IAAO,CAAC;AAEvC,sEAAsE;AACtE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAYnB,CAAC;AAEX,8DAA8D;AAC9D,eAAO,MAAM,qBAAqB,iBAAwB,CAAC;AAE3D,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,sBAAsB,gCAAiC,CAAC;AASrE,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,eAAO,MAAM,iBAAiB,KAA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hC,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,6BAA6B,CAAC;AAE7E,kEAAkE;AAClE,wBAAgB,kCAAkC,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,mBAAmB,GAAG,UAAU,CAY5G;AAID,qCAAqC;AACrC,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;CAOsC,CAAC;AAEpE,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,gBAAgB,CAAC;AAU/D,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,kBAAkB,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,GACtB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AASzC;;;;GAIG;AACH,wBAAgB,uCAAuC,CACrD,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,kBAAkB,EAAE,oBAAoB,CAAC,CAAC,GACjE,UAAU,CAqDZ"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SteelSeries Rival 300 configuration protocol — pure encode/decode helpers.
|
|
3
|
+
*
|
|
4
|
+
* Reconstructed from the vendor's own software, not from a third-party
|
|
5
|
+
* reimplementation: SteelSeries GG 121.0.0 ships `rival_base.lisp` (the
|
|
6
|
+
* shared profile) plus `rival_300.lisp`, `dota2-rival-mouse.lisp`,
|
|
7
|
+
* `predator-mouse.lisp`, `csgo-rival-300.lisp`, `csgo-rival-300-stm32.lisp`,
|
|
8
|
+
* `fallout_4_rival_300.lisp`, `hp_omen_rival_300.lisp`,
|
|
9
|
+
* `csgo-hyperbeast-rival-300.lisp` and `eg-rival-300.lisp`, all of which
|
|
10
|
+
* `include "rival_base"`. This module transcribes that command set. Those
|
|
11
|
+
* files are OpenPGP-armored ("DESCRIPTOR" armor, SKESK/AES-128). rivalcfg's
|
|
12
|
+
* `rival300.py` (which lists the same product ids) independently
|
|
13
|
+
* corroborates every command byte.
|
|
14
|
+
*
|
|
15
|
+
* This is the original Rival / Rival 300 command set, distinct from Rival
|
|
16
|
+
* 100 (`./rival-100.ts`) and Rival 110 (`./rival-110.ts`): the DPI byte is a
|
|
17
|
+
* linear range (not a choice table), the two LED zones have independent
|
|
18
|
+
* color and effect commands, and the six buttons are remappable.
|
|
19
|
+
*
|
|
20
|
+
* Every command is an HID **output report** with report id 0x00 (33-byte
|
|
21
|
+
* reports — `HIDIO 33`).
|
|
22
|
+
*
|
|
23
|
+
* DPI uses two per-level commands (`03 01`/`03 02`) with a linear byte:
|
|
24
|
+
* rivalcfg's `input_range [50, 6500, 50]` against `output_range [0x01,
|
|
25
|
+
* 0x82, 1]`, so `byte = (dpi - 50) / 50 + 1`, range 0x01–0x82
|
|
26
|
+
* (50–6500 DPI in 50 DPI steps). The vendor struct carries a trailing
|
|
27
|
+
* `dcpi` byte (`0x00` or `0xAA`) that rivalcfg leaves at 0; this codec
|
|
28
|
+
* matches rivalcfg and does not emit it. Off-grid values are rejected.
|
|
29
|
+
*
|
|
30
|
+
* Polling (`04 00`) is write-only (1000→0x01, 500→0x02, 250→0x03,
|
|
31
|
+
* 125→0x04). Lighting is two zones — logo (`08 01`) and wheel (`08 02`) —
|
|
32
|
+
* each with its own color and effect (`07 01`/`07 02`, steady 0x01 / breath
|
|
33
|
+
* 0x03). Buttons are one 30-byte packet (6 slots × 5-byte fields),
|
|
34
|
+
* command `31 00`, as an output report.
|
|
35
|
+
*
|
|
36
|
+
* The two readable values are the firmware version (`10 00`, two bytes,
|
|
37
|
+
* `fw_minor` then `fw_major`) and the active preset index (`16 00`).
|
|
38
|
+
* Settings apply immediately; the save command (`09 00`) persists them to
|
|
39
|
+
* onboard flash. None of this has been verified on physical hardware by this
|
|
40
|
+
* project.
|
|
41
|
+
*/
|
|
42
|
+
export const RIVAL300_REPORT_ID = 0x00;
|
|
43
|
+
/** Command prefixes; the payload is the prefix plus its arguments. */
|
|
44
|
+
export const RIVAL300_COMMAND = {
|
|
45
|
+
sensitivity1: [0x03, 0x01],
|
|
46
|
+
sensitivity2: [0x03, 0x02],
|
|
47
|
+
pollingRate: [0x04, 0x00],
|
|
48
|
+
logoColor: [0x08, 0x01],
|
|
49
|
+
wheelColor: [0x08, 0x02],
|
|
50
|
+
logoEffect: [0x07, 0x01],
|
|
51
|
+
wheelEffect: [0x07, 0x02],
|
|
52
|
+
buttonsMapping: [0x31, 0x00],
|
|
53
|
+
save: [0x09, 0x00],
|
|
54
|
+
firmware: [0x10, 0x00],
|
|
55
|
+
activeCpiIndex: [0x16, 0x00],
|
|
56
|
+
};
|
|
57
|
+
/** `09 00` — commit the current settings to onboard flash. */
|
|
58
|
+
export const RIVAL300_SAVE_COMMAND = [0x09, 0x00];
|
|
59
|
+
export const RIVAL300_FIRMWARE_RESPONSE_LENGTH = 2;
|
|
60
|
+
export const RIVAL300_POLLING_RATES = [125, 250, 500, 1000];
|
|
61
|
+
const POLLING_RATE_TO_BYTE = new Map([
|
|
62
|
+
[1000, 0x01],
|
|
63
|
+
[500, 0x02],
|
|
64
|
+
[250, 0x03],
|
|
65
|
+
[125, 0x04],
|
|
66
|
+
]);
|
|
67
|
+
export const RIVAL300_DPI_MIN = 50;
|
|
68
|
+
export const RIVAL300_DPI_MAX = 6500;
|
|
69
|
+
export const RIVAL300_DPI_STEP = 50;
|
|
70
|
+
/** rivalcfg `rival300.py` defaults for the two presets. */
|
|
71
|
+
export const RIVAL300_DEFAULT_DPI_PRESET_1 = 800;
|
|
72
|
+
export const RIVAL300_DEFAULT_DPI_PRESET_2 = 1600;
|
|
73
|
+
export const RIVAL300_DEFAULT_POLLING_RATE = 1000;
|
|
74
|
+
export class Rival300ProtocolError extends Error {
|
|
75
|
+
}
|
|
76
|
+
/** The 130 DPI values the linear encoding can express, ascending. */
|
|
77
|
+
export function steelseriesRival300DpiOptions() {
|
|
78
|
+
const options = [];
|
|
79
|
+
for (let dpi = RIVAL300_DPI_MIN; dpi <= RIVAL300_DPI_MAX; dpi += RIVAL300_DPI_STEP) {
|
|
80
|
+
options.push(dpi);
|
|
81
|
+
}
|
|
82
|
+
return options;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* `input_range [50, 6500, 50]` -> `output_range [0x01, 0x82, 1]`:
|
|
86
|
+
* `byte = (dpi - 50) / 50 + 1`. Off-grid values are rejected.
|
|
87
|
+
*/
|
|
88
|
+
function encodeDpiByte(dpi) {
|
|
89
|
+
if (!Number.isInteger(dpi) ||
|
|
90
|
+
dpi < RIVAL300_DPI_MIN ||
|
|
91
|
+
dpi > RIVAL300_DPI_MAX ||
|
|
92
|
+
(dpi - RIVAL300_DPI_MIN) % RIVAL300_DPI_STEP !== 0) {
|
|
93
|
+
throw new Rival300ProtocolError(`SteelSeries Rival 300 DPI must be ${RIVAL300_DPI_MIN}–${RIVAL300_DPI_MAX.toLocaleString("en-US")} in ${RIVAL300_DPI_STEP} DPI steps.`);
|
|
94
|
+
}
|
|
95
|
+
return (dpi - RIVAL300_DPI_MIN) / RIVAL300_DPI_STEP + 1;
|
|
96
|
+
}
|
|
97
|
+
/** `03 01 <byte>` — sensitivity preset 1. */
|
|
98
|
+
export function steelseriesRival300EncodeSensitivity1(dpi) {
|
|
99
|
+
return new Uint8Array([...RIVAL300_COMMAND.sensitivity1, encodeDpiByte(dpi)]);
|
|
100
|
+
}
|
|
101
|
+
/** `03 02 <byte>` — sensitivity preset 2. */
|
|
102
|
+
export function steelseriesRival300EncodeSensitivity2(dpi) {
|
|
103
|
+
return new Uint8Array([...RIVAL300_COMMAND.sensitivity2, encodeDpiByte(dpi)]);
|
|
104
|
+
}
|
|
105
|
+
/** `04 00 <v>` with 1000→0x01, 500→0x02, 250→0x03, 125→0x04. */
|
|
106
|
+
export function steelseriesRival300EncodePollingRate(pollingRateHz) {
|
|
107
|
+
const byte = POLLING_RATE_TO_BYTE.get(pollingRateHz);
|
|
108
|
+
if (byte === undefined) {
|
|
109
|
+
throw new Rival300ProtocolError("SteelSeries Rival 300 supports 125, 250, 500, or 1000 Hz polling.");
|
|
110
|
+
}
|
|
111
|
+
return new Uint8Array([...RIVAL300_COMMAND.pollingRate, byte]);
|
|
112
|
+
}
|
|
113
|
+
/** `09 00` — commit the current settings to onboard flash. */
|
|
114
|
+
export function steelseriesRival300SaveCommand() {
|
|
115
|
+
return new Uint8Array(RIVAL300_SAVE_COMMAND);
|
|
116
|
+
}
|
|
117
|
+
/** `10 00` — the device answers with minor then major firmware bytes. */
|
|
118
|
+
export function steelseriesRival300FirmwareQuery() {
|
|
119
|
+
return new Uint8Array(RIVAL300_COMMAND.firmware);
|
|
120
|
+
}
|
|
121
|
+
/** `16 00` — read the active preset index. */
|
|
122
|
+
export function steelseriesRival300ActiveCpiQuery() {
|
|
123
|
+
return new Uint8Array(RIVAL300_COMMAND.activeCpiIndex);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Decode the active-preset reply. The specification's `resolution_level`
|
|
127
|
+
* incoming struct is `report_id` then `level`, and the reply's report id is
|
|
128
|
+
* not surfaced by WebHID, so the level is the first byte. The device reports
|
|
129
|
+
* it 1-based (values 0x01/0x02); anything else is rejected rather than
|
|
130
|
+
* guessed at.
|
|
131
|
+
*/
|
|
132
|
+
export function steelseriesRival300DecodeActivePreset(payload) {
|
|
133
|
+
const level = payload[0];
|
|
134
|
+
if (level !== 0x01 && level !== 0x02) {
|
|
135
|
+
throw new Rival300ProtocolError(`SteelSeries Rival 300 active preset reply was not 1 or 2 (got ${level === undefined ? "nothing" : `0x${level.toString(16)}`}).`);
|
|
136
|
+
}
|
|
137
|
+
return level;
|
|
138
|
+
}
|
|
139
|
+
/** Decode the two-byte firmware response (`fw_minor`, `fw_major`). */
|
|
140
|
+
export function steelseriesRival300DecodeFirmware(payload) {
|
|
141
|
+
if (payload.length < RIVAL300_FIRMWARE_RESPONSE_LENGTH) {
|
|
142
|
+
throw new Rival300ProtocolError("SteelSeries Rival 300 firmware response is shorter than two bytes.");
|
|
143
|
+
}
|
|
144
|
+
const bytes = [payload[0], payload[1]];
|
|
145
|
+
return { bytes, display: `${bytes[1]}.${bytes[0]}` };
|
|
146
|
+
}
|
|
147
|
+
const LED_COLOR_COMMAND = {
|
|
148
|
+
logo: RIVAL300_COMMAND.logoColor,
|
|
149
|
+
wheel: RIVAL300_COMMAND.wheelColor,
|
|
150
|
+
};
|
|
151
|
+
const LED_EFFECT_COMMAND = {
|
|
152
|
+
logo: RIVAL300_COMMAND.logoEffect,
|
|
153
|
+
wheel: RIVAL300_COMMAND.wheelEffect,
|
|
154
|
+
};
|
|
155
|
+
function encodeRgb(r, g, b) {
|
|
156
|
+
for (const channel of [r, g, b]) {
|
|
157
|
+
if (!Number.isInteger(channel) || channel < 0 || channel > 255) {
|
|
158
|
+
throw new Rival300ProtocolError("RGB channels must be integers 0–255.");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return [r, g, b];
|
|
162
|
+
}
|
|
163
|
+
/** `08 <zone> <r> <g> <b>` — one LED zone's color (`logo` = 0x01, `wheel` = 0x02). */
|
|
164
|
+
export function steelseriesRival300EncodeLedColor(led, r, g, b) {
|
|
165
|
+
const command = LED_COLOR_COMMAND[led];
|
|
166
|
+
if (!command) {
|
|
167
|
+
throw new Rival300ProtocolError('SteelSeries Rival 300 LEDs are "logo" and "wheel" only.');
|
|
168
|
+
}
|
|
169
|
+
return new Uint8Array([...command, ...encodeRgb(r, g, b)]);
|
|
170
|
+
}
|
|
171
|
+
export const RIVAL300_LIGHT_EFFECT_TO_BYTE = {
|
|
172
|
+
steady: 0x01,
|
|
173
|
+
breath: 0x03,
|
|
174
|
+
};
|
|
175
|
+
/** `07 <zone> <mode>` — one LED zone's effect (steady/breath). */
|
|
176
|
+
export function steelseriesRival300EncodeLedEffect(led, effect) {
|
|
177
|
+
const command = LED_EFFECT_COMMAND[led];
|
|
178
|
+
if (!command) {
|
|
179
|
+
throw new Rival300ProtocolError('SteelSeries Rival 300 LEDs are "logo" and "wheel" only.');
|
|
180
|
+
}
|
|
181
|
+
const byte = RIVAL300_LIGHT_EFFECT_TO_BYTE[effect];
|
|
182
|
+
if (byte === undefined) {
|
|
183
|
+
throw new Rival300ProtocolError(`SteelSeries Rival 300 light effect must be one of: ${Object.keys(RIVAL300_LIGHT_EFFECT_TO_BYTE).join(", ")}.`);
|
|
184
|
+
}
|
|
185
|
+
return new Uint8Array([...command, byte]);
|
|
186
|
+
}
|
|
187
|
+
// -- Button mapping --------------------------------------------------------
|
|
188
|
+
/** 6 button slots, 5-byte fields. */
|
|
189
|
+
export const RIVAL300_BUTTONS = {
|
|
190
|
+
button1: { id: 0x01, offset: 0x00 },
|
|
191
|
+
button2: { id: 0x02, offset: 0x05 },
|
|
192
|
+
button3: { id: 0x03, offset: 0x0a },
|
|
193
|
+
button4: { id: 0x04, offset: 0x0f },
|
|
194
|
+
button5: { id: 0x05, offset: 0x14 },
|
|
195
|
+
button6: { id: 0x06, offset: 0x19 },
|
|
196
|
+
};
|
|
197
|
+
const RIVAL300_BUTTON_FIELD_LENGTH = 5;
|
|
198
|
+
const RIVAL300_BUTTON_DISABLE = 0x00;
|
|
199
|
+
const RIVAL300_BUTTON_DPI_SWITCH = 0x30;
|
|
200
|
+
const RIVAL300_BUTTON_SCROLL_UP = 0x31;
|
|
201
|
+
const RIVAL300_BUTTON_SCROLL_DOWN = 0x32;
|
|
202
|
+
const RIVAL300_BUTTON_KEYBOARD = 0x51;
|
|
203
|
+
const RIVAL300_BUTTON_MULTIMEDIA = 0x61;
|
|
204
|
+
function encodeKeyCode(code, kind) {
|
|
205
|
+
if (!Number.isInteger(code) || code < 0 || code > 255) {
|
|
206
|
+
throw new Rival300ProtocolError(`${kind} codes must be integers 0–255.`);
|
|
207
|
+
}
|
|
208
|
+
return code;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* `31 00` + one 30-byte packet (6 slots × 5-byte fields), zero-filled
|
|
212
|
+
* except where a mapping is given. Pass every button explicitly — unmapped
|
|
213
|
+
* buttons stay disabled, matching this package's no-silent-defaults policy.
|
|
214
|
+
*/
|
|
215
|
+
export function steelseriesRival300EncodeButtonsMapping(mapping) {
|
|
216
|
+
for (const name of Object.keys(mapping)) {
|
|
217
|
+
if (!Object.hasOwn(RIVAL300_BUTTONS, name)) {
|
|
218
|
+
throw new Rival300ProtocolError(`Unknown SteelSeries Rival 300 button "${name}".`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const names = Object.keys(RIVAL300_BUTTONS);
|
|
222
|
+
const packet = new Array(names.length * RIVAL300_BUTTON_FIELD_LENGTH).fill(0x00);
|
|
223
|
+
for (const [name, action] of Object.entries(mapping)) {
|
|
224
|
+
const { offset } = RIVAL300_BUTTONS[name];
|
|
225
|
+
switch (action.type) {
|
|
226
|
+
case "button": {
|
|
227
|
+
if (!Object.hasOwn(RIVAL300_BUTTONS, action.target)) {
|
|
228
|
+
throw new Rival300ProtocolError(`Unknown SteelSeries Rival 300 button "${action.target}".`);
|
|
229
|
+
}
|
|
230
|
+
packet[offset] = RIVAL300_BUTTONS[action.target].id;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case "disabled": {
|
|
234
|
+
packet[offset] = RIVAL300_BUTTON_DISABLE;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
case "dpiSwitch": {
|
|
238
|
+
packet[offset] = RIVAL300_BUTTON_DPI_SWITCH;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case "scrollUp": {
|
|
242
|
+
packet[offset] = RIVAL300_BUTTON_SCROLL_UP;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "scrollDown": {
|
|
246
|
+
packet[offset] = RIVAL300_BUTTON_SCROLL_DOWN;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case "keyboard": {
|
|
250
|
+
packet[offset] = RIVAL300_BUTTON_KEYBOARD;
|
|
251
|
+
packet[offset + 1] = encodeKeyCode(action.code, "Keyboard scan");
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case "multimedia": {
|
|
255
|
+
packet[offset] = RIVAL300_BUTTON_MULTIMEDIA;
|
|
256
|
+
packet[offset + 1] = encodeKeyCode(action.code, "Multimedia key");
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
default: {
|
|
260
|
+
throw new Rival300ProtocolError("Unsupported SteelSeries Rival 300 button action.");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return new Uint8Array([...RIVAL300_COMMAND.buttonsMapping, ...packet]);
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=rival-300.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rival-300.js","sourceRoot":"","sources":["../../src/steelseries/rival-300.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEvC,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IAC1B,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IAC1B,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IACzB,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IACvB,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IACxB,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IACxB,WAAW,EAAE,CAAC,IA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AAC,CAAC;gBAChB,MAAM,CAAC,MAAM,CAAC,GAAG,uBAAuB,CAAC;gBACzC,MAAM;YACR,CAAC;YACD,KAAK,WAAW,CAAC,CAAC,CAAC;gBACjB,MAAM,CAAC,MAAM,CAAC,GAAG,0BAA0B,CAAC;gBAC5C,MAAM;YACR,CAAC;YACD,KAAK,UAAU,CAAC,CAAC,CAAC;gBAChB,MAAM,CAAC,MAAM,CAAC,GAAG,yBAAyB,CAAC;gBAC3C,MAAM;YACR,CAAC;YACD,KAAK,YAAY,CAAC,CAAC,CAAC;gBAClB,MAAM,CAAC,MAAM,CAAC,GAAG,2BAA2B,CAAC;gBAC7C,MAAM;YACR,CAAC;YACD,KAAK,UAAU,CAAC,CAAC,CAAC;gBAChB,MAAM,CAAC,MAAM,CAAC,GAAG,wBAAwB,CAAC;gBAC1C,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;gBACjE,MAAM;YACR,CAAC;YACD,KAAK,YAAY,CAAC,CAAC,CAAC;gBAClB,MAAM,CAAC,MAAM,CAAC,GAAG,0BAA0B,CAAC;gBAC5C,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;gBAClE,MAAM;YACR,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,IAAI,qBAAqB,CAAC,kDAAkD,CAAC,CAAC;YACtF,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,CAAC,GAAG,gBAAgB,CAAC,cAAc,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SteelSeries Rival 5 configuration protocol — pure encode/decode helpers.
|
|
3
|
+
*
|
|
4
|
+
* Reconstructed from public open-source implementations and the vendor's
|
|
5
|
+
* own software, not from vendor source code:
|
|
6
|
+
*
|
|
7
|
+
* - rivalcfg has no Rival 5 profile, so there is no rivalcfg corroboration
|
|
8
|
+
* for any byte here — unlike every other wired SteelSeries family in this
|
|
9
|
+
* package, which all trace to rivalcfg first.
|
|
10
|
+
* - The vendor's SteelSeries GG device specification (`rival-5.lisp`,
|
|
11
|
+
* GG 121.0.0) documents the full command set: DPI batch `0x2D`, polling
|
|
12
|
+
* `0x2B` (+ read `0xAB`), 11-slot buttons `0x2A`, lighting `0x21`–`0x27`,
|
|
13
|
+
* save `0x11`, firmware `0x90`. Those files are OpenPGP-armored
|
|
14
|
+
* ("DESCRIPTOR" armor, SKESK/AES-128); the bytes below are the documented
|
|
15
|
+
* HID report payloads.
|
|
16
|
+
* - The DPI sensor table is byte-identical to TrueMove Air (spot-checked
|
|
17
|
+
* against the vendor file's inline case table: `0x00→100`, `0x04→400`,
|
|
18
|
+
* `0x12→1600`, `0xD6→18000`), so it is imported from
|
|
19
|
+
* `./rival3-wireless.ts`'s `TRUEMOVE_AIR_DPI_TO_BYTE` rather than
|
|
20
|
+
* re-derived — the same reuse `./aerox5.ts` makes.
|
|
21
|
+
*
|
|
22
|
+
* Every command is an HID **output report** with report id 0x00 (65-byte
|
|
23
|
+
* reports throughout the specification).
|
|
24
|
+
*
|
|
25
|
+
* DPI uses a 5-preset batch (`0x2D`): `level_max` (1–5), `level_active`
|
|
26
|
+
* (0–4, 0-based — same convention as `./aerox5.ts`'s `first_preset: 0`),
|
|
27
|
+
* then five one-byte sensor values (`0x00–0xD6`). The specification always
|
|
28
|
+
* carries all five slots, so this codec requires exactly five presets
|
|
29
|
+
* rather than guessing at padding for shorter tables.
|
|
30
|
+
*
|
|
31
|
+
* Polling (`0x2B`, values 1000→0x01, 500→0x02, 250→0x03, 125→0x04) has a
|
|
32
|
+
* read-back (`0xAB`), defined but not decoded here. Buttons are one packet
|
|
33
|
+
* (11 slots × 5-byte fields: 9 physical buttons plus scroll up/down),
|
|
34
|
+
* command `0x2A`.
|
|
35
|
+
*
|
|
36
|
+
* Known but deliberately not implemented — documented so nobody re-derives
|
|
37
|
+
* them, withheld until there is hardware evidence and a reason to ship them:
|
|
38
|
+
*
|
|
39
|
+
* - The 10-zone `direct_write` (`0x21` + uint16 LED mask + 10 RGB triples),
|
|
40
|
+
* `write_all_illumination` (mask `0x3FF`), brightness (`0x23`, 0–100),
|
|
41
|
+
* reactive color (`0x26`), default lighting (`0x27`), and reset (`0x22`).
|
|
42
|
+
* The mega-strip zone addressing is not needed for DPI/polling/buttons.
|
|
43
|
+
* - `0xAB` — polling read-back.
|
|
44
|
+
* - Accelerometer/deceleration and angle snapping: driver-side (`SSE`)
|
|
45
|
+
* settings, not HID commands, out of scope for this codec.
|
|
46
|
+
*
|
|
47
|
+
* Settings apply immediately; the save command (`0x11`, one byte) persists
|
|
48
|
+
* them to onboard flash. None of this has been verified on physical
|
|
49
|
+
* hardware by this project.
|
|
50
|
+
*/
|
|
51
|
+
export declare const RIVAL5_REPORT_ID = 0;
|
|
52
|
+
/** Command prefixes; the payload is the prefix plus its arguments. */
|
|
53
|
+
export declare const RIVAL5_COMMAND: {
|
|
54
|
+
readonly dpiPresets: readonly [45];
|
|
55
|
+
readonly pollingRate: readonly [43];
|
|
56
|
+
readonly buttonsMapping: readonly [42];
|
|
57
|
+
};
|
|
58
|
+
/** `0xAB` — polling read-back; documented, not decoded here. */
|
|
59
|
+
export declare const RIVAL5_POLLING_QUERY: readonly [171];
|
|
60
|
+
/** `0x90` — firmware version (32-byte string reply, see below). */
|
|
61
|
+
export declare const RIVAL5_FIRMWARE_QUERY: readonly [144];
|
|
62
|
+
/** `0x11` — one byte; commit the current settings to onboard flash. */
|
|
63
|
+
export declare const RIVAL5_SAVE_COMMAND: readonly [17];
|
|
64
|
+
export declare const RIVAL5_POLLING_RATES: readonly [125, 250, 500, 1000];
|
|
65
|
+
export declare const RIVAL5_DPI_MIN = 100;
|
|
66
|
+
export declare const RIVAL5_DPI_MAX = 18000;
|
|
67
|
+
export declare const RIVAL5_DPI_STEP = 100;
|
|
68
|
+
export declare const RIVAL5_MAX_DPI_PRESETS = 5;
|
|
69
|
+
export declare const RIVAL5_FIRMWARE_RESPONSE_LENGTH = 32;
|
|
70
|
+
/** Factory table from the GG seed data (400/800/1200/2400/3200). */
|
|
71
|
+
export declare const RIVAL5_DEFAULT_DPI_PRESETS: readonly [400, 800, 1200, 2400, 3200];
|
|
72
|
+
export declare const RIVAL5_DEFAULT_POLLING_RATE = 1000;
|
|
73
|
+
export declare class Rival5ProtocolError extends Error {
|
|
74
|
+
}
|
|
75
|
+
/** Every DPI value the shared TrueMove Air table can express, ascending. */
|
|
76
|
+
export declare function steelseriesRival5DpiOptions(): number[];
|
|
77
|
+
/**
|
|
78
|
+
* `2D <count 1–5> <selected 0-based> <5 sensor bytes>` — replaces the
|
|
79
|
+
* mouse's whole preset table. Exactly five presets are required (see the
|
|
80
|
+
* module doc comment); DPI values must be exact TrueMove Air table keys —
|
|
81
|
+
* off-grid values are rejected rather than rounded, matching how the rest
|
|
82
|
+
* of this package validates DPI.
|
|
83
|
+
*/
|
|
84
|
+
export declare function steelseriesRival5EncodeDpiPresets(presets: readonly number[], selectedIndex: number): Uint8Array;
|
|
85
|
+
/** `2B <v>` with 1000→0x01, 500→0x02, 250→0x03, 125→0x04. */
|
|
86
|
+
export declare function steelseriesRival5EncodePollingRate(pollingRateHz: number): Uint8Array;
|
|
87
|
+
/** `11` — commit the current settings to onboard flash. */
|
|
88
|
+
export declare function steelseriesRival5SaveCommand(): Uint8Array;
|
|
89
|
+
/** `90` — the device answers with a 32-byte version string. */
|
|
90
|
+
export declare function steelseriesRival5FirmwareQuery(): Uint8Array;
|
|
91
|
+
/**
|
|
92
|
+
* Decode the 32-byte firmware version reply as ASCII, stopping at the
|
|
93
|
+
* first NUL. The string shape follows the specification's `version_str
|
|
94
|
+
* bytearray (size 32)` field; trailing padding is not part of the version.
|
|
95
|
+
*/
|
|
96
|
+
export declare function steelseriesRival5DecodeFirmware(payload: Uint8Array): string;
|
|
97
|
+
/** 9 physical buttons plus scroll up/down (11 slots, 55 bytes total). */
|
|
98
|
+
export declare const RIVAL5_BUTTONS: {
|
|
99
|
+
readonly button1: {
|
|
100
|
+
readonly id: 1;
|
|
101
|
+
readonly offset: 0;
|
|
102
|
+
};
|
|
103
|
+
readonly button2: {
|
|
104
|
+
readonly id: 2;
|
|
105
|
+
readonly offset: 5;
|
|
106
|
+
};
|
|
107
|
+
readonly button3: {
|
|
108
|
+
readonly id: 3;
|
|
109
|
+
readonly offset: 10;
|
|
110
|
+
};
|
|
111
|
+
readonly button4: {
|
|
112
|
+
readonly id: 4;
|
|
113
|
+
readonly offset: 15;
|
|
114
|
+
};
|
|
115
|
+
readonly button5: {
|
|
116
|
+
readonly id: 5;
|
|
117
|
+
readonly offset: 20;
|
|
118
|
+
};
|
|
119
|
+
readonly button6: {
|
|
120
|
+
readonly id: 6;
|
|
121
|
+
readonly offset: 25;
|
|
122
|
+
};
|
|
123
|
+
readonly button7: {
|
|
124
|
+
readonly id: 7;
|
|
125
|
+
readonly offset: 30;
|
|
126
|
+
};
|
|
127
|
+
readonly button8: {
|
|
128
|
+
readonly id: 8;
|
|
129
|
+
readonly offset: 35;
|
|
130
|
+
};
|
|
131
|
+
readonly button9: {
|
|
132
|
+
readonly id: 9;
|
|
133
|
+
readonly offset: 40;
|
|
134
|
+
};
|
|
135
|
+
readonly scrollUp: {
|
|
136
|
+
readonly id: 49;
|
|
137
|
+
readonly offset: 45;
|
|
138
|
+
};
|
|
139
|
+
readonly scrollDown: {
|
|
140
|
+
readonly id: 50;
|
|
141
|
+
readonly offset: 50;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
export type Rival5ButtonName = keyof typeof RIVAL5_BUTTONS;
|
|
145
|
+
export type Rival5ButtonAction = {
|
|
146
|
+
type: "button";
|
|
147
|
+
target: Rival5ButtonName;
|
|
148
|
+
} | {
|
|
149
|
+
type: "disabled";
|
|
150
|
+
} | {
|
|
151
|
+
type: "dpiSwitch";
|
|
152
|
+
} | {
|
|
153
|
+
type: "keyboard";
|
|
154
|
+
code: number;
|
|
155
|
+
} | {
|
|
156
|
+
type: "multimedia";
|
|
157
|
+
code: number;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* `2A` + one 55-byte packet (11 slots × 5-byte fields), zero-filled except
|
|
161
|
+
* where a mapping is given. Pass every button explicitly — unmapped buttons
|
|
162
|
+
* stay disabled, matching this package's no-silent-defaults policy.
|
|
163
|
+
*/
|
|
164
|
+
export declare function steelseriesRival5EncodeButtonsMapping(mapping: Partial<Record<Rival5ButtonName, Rival5ButtonAction>>): Uint8Array;
|
|
165
|
+
//# sourceMappingURL=rival-5.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rival-5.d.ts","sourceRoot":"","sources":["../../src/steelseries/rival-5.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAIH,eAAO,MAAM,gBAAgB,IAAO,CAAC;AAErC,sEAAsE;AACtE,eAAO,MAAM,cAAc;;;;CAIjB,CAAC;AAEX,gEAAgE;AAChE,eAAO,MAAM,oBAAoB,gBAAkB,CAAC;AAEpD,mEAAmE;AACnE,eAAO,MAAM,qBAAqB,gBAAkB,CAAC;AAErD,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,eAAkB,CAAC;AAEnD,eAAO,MAAM,oBAAoB,gCAAiC,CAAC;AASnE,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,cAAc,QAAQ,CAAC;AACpC,eAAO,MAAM,eAAe,MAAM,CAAC;AACnC,eAAO,MAAM,sBAAsB,IAAI,CAAC;AACxC,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAElD,oEAAoE;AACpE,eAAO,MAAM,0BAA0B,uCAAwC,CAAC;AAChF,eAAO,MAAM,2BAA2B,OAAO,CAAC;AA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
|
|
3
|
+
*
|
|
4
|
+
* Reconstructed from public open-source implementations and the vendor's
|
|
5
|
+
* own software, not from vendor source code:
|
|
6
|
+
*
|
|
7
|
+
* - rivalcfg has no Rival 5 profile, so there is no rivalcfg corroboration
|
|
8
|
+
* for any byte here — unlike every other wired SteelSeries family in this
|
|
9
|
+
* package, which all trace to rivalcfg first.
|
|
10
|
+
* - The vendor's SteelSeries GG device specification (`rival-5.lisp`,
|
|
11
|
+
* GG 121.0.0) documents the full command set: DPI batch `0x2D`, polling
|
|
12
|
+
* `0x2B` (+ read `0xAB`), 11-slot buttons `0x2A`, lighting `0x21`–`0x27`,
|
|
13
|
+
* save `0x11`, firmware `0x90`. Those files are OpenPGP-armored
|
|
14
|
+
* ("DESCRIPTOR" armor, SKESK/AES-128); the bytes below are the documented
|
|
15
|
+
* HID report payloads.
|
|
16
|
+
* - The DPI sensor table is byte-identical to TrueMove Air (spot-checked
|
|
17
|
+
* against the vendor file's inline case table: `0x00→100`, `0x04→400`,
|
|
18
|
+
* `0x12→1600`, `0xD6→18000`), so it is imported from
|
|
19
|
+
* `./rival3-wireless.ts`'s `TRUEMOVE_AIR_DPI_TO_BYTE` rather than
|
|
20
|
+
* re-derived — the same reuse `./aerox5.ts` makes.
|
|
21
|
+
*
|
|
22
|
+
* Every command is an HID **output report** with report id 0x00 (65-byte
|
|
23
|
+
* reports throughout the specification).
|
|
24
|
+
*
|
|
25
|
+
* DPI uses a 5-preset batch (`0x2D`): `level_max` (1–5), `level_active`
|
|
26
|
+
* (0–4, 0-based — same convention as `./aerox5.ts`'s `first_preset: 0`),
|
|
27
|
+
* then five one-byte sensor values (`0x00–0xD6`). The specification always
|
|
28
|
+
* carries all five slots, so this codec requires exactly five presets
|
|
29
|
+
* rather than guessing at padding for shorter tables.
|
|
30
|
+
*
|
|
31
|
+
* Polling (`0x2B`, values 1000→0x01, 500→0x02, 250→0x03, 125→0x04) has a
|
|
32
|
+
* read-back (`0xAB`), defined but not decoded here. Buttons are one packet
|
|
33
|
+
* (11 slots × 5-byte fields: 9 physical buttons plus scroll up/down),
|
|
34
|
+
* command `0x2A`.
|
|
35
|
+
*
|
|
36
|
+
* Known but deliberately not implemented — documented so nobody re-derives
|
|
37
|
+
* them, withheld until there is hardware evidence and a reason to ship them:
|
|
38
|
+
*
|
|
39
|
+
* - The 10-zone `direct_write` (`0x21` + uint16 LED mask + 10 RGB triples),
|
|
40
|
+
* `write_all_illumination` (mask `0x3FF`), brightness (`0x23`, 0–100),
|
|
41
|
+
* reactive color (`0x26`), default lighting (`0x27`), and reset (`0x22`).
|
|
42
|
+
* The mega-strip zone addressing is not needed for DPI/polling/buttons.
|
|
43
|
+
* - `0xAB` — polling read-back.
|
|
44
|
+
* - Accelerometer/deceleration and angle snapping: driver-side (`SSE`)
|
|
45
|
+
* settings, not HID commands, out of scope for this codec.
|
|
46
|
+
*
|
|
47
|
+
* Settings apply immediately; the save command (`0x11`, one byte) persists
|
|
48
|
+
* them to onboard flash. None of this has been verified on physical
|
|
49
|
+
* hardware by this project.
|
|
50
|
+
*/
|
|
51
|
+
import { TRUEMOVE_AIR_DPI_TO_BYTE } from "./rival3-wireless.js";
|
|
52
|
+
export const RIVAL5_REPORT_ID = 0x00;
|
|
53
|
+
/** Command prefixes; the payload is the prefix plus its arguments. */
|
|
54
|
+
export const RIVAL5_COMMAND = {
|
|
55
|
+
dpiPresets: [0x2d],
|
|
56
|
+
pollingRate: [0x2b],
|
|
57
|
+
buttonsMapping: [0x2a],
|
|
58
|
+
};
|
|
59
|
+
/** `0xAB` — polling read-back; documented, not decoded here. */
|
|
60
|
+
export const RIVAL5_POLLING_QUERY = [0xab];
|
|
61
|
+
/** `0x90` — firmware version (32-byte string reply, see below). */
|
|
62
|
+
export const RIVAL5_FIRMWARE_QUERY = [0x90];
|
|
63
|
+
/** `0x11` — one byte; commit the current settings to onboard flash. */
|
|
64
|
+
export const RIVAL5_SAVE_COMMAND = [0x11];
|
|
65
|
+
export const RIVAL5_POLLING_RATES = [125, 250, 500, 1000];
|
|
66
|
+
const POLLING_RATE_TO_BYTE = new Map([
|
|
67
|
+
[1000, 0x01],
|
|
68
|
+
[500, 0x02],
|
|
69
|
+
[250, 0x03],
|
|
70
|
+
[125, 0x04],
|
|
71
|
+
]);
|
|
72
|
+
export const RIVAL5_DPI_MIN = 100;
|
|
73
|
+
export const RIVAL5_DPI_MAX = 18000;
|
|
74
|
+
export const RIVAL5_DPI_STEP = 100;
|
|
75
|
+
export const RIVAL5_MAX_DPI_PRESETS = 5;
|
|
76
|
+
export const RIVAL5_FIRMWARE_RESPONSE_LENGTH = 32;
|
|
77
|
+
/** Factory table from the GG seed data (400/800/1200/2400/3200). */
|
|
78
|
+
export const RIVAL5_DEFAULT_DPI_PRESETS = [400, 800, 1200, 2400, 3200];
|
|
79
|
+
export const RIVAL5_DEFAULT_POLLING_RATE = 1000;
|
|
80
|
+
export class Rival5ProtocolError extends Error {
|
|
81
|
+
}
|
|
82
|
+
/** Every DPI value the shared TrueMove Air table can express, ascending. */
|
|
83
|
+
export function steelseriesRival5DpiOptions() {
|
|
84
|
+
return [...TRUEMOVE_AIR_DPI_TO_BYTE.keys()].sort((a, b) => a - b);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* `2D <count 1–5> <selected 0-based> <5 sensor bytes>` — replaces the
|
|
88
|
+
* mouse's whole preset table. Exactly five presets are required (see the
|
|
89
|
+
* module doc comment); DPI values must be exact TrueMove Air table keys —
|
|
90
|
+
* off-grid values are rejected rather than rounded, matching how the rest
|
|
91
|
+
* of this package validates DPI.
|
|
92
|
+
*/
|
|
93
|
+
export function steelseriesRival5EncodeDpiPresets(presets, selectedIndex) {
|
|
94
|
+
if (presets.length !== RIVAL5_MAX_DPI_PRESETS) {
|
|
95
|
+
throw new Rival5ProtocolError(`SteelSeries Rival 5 requires exactly ${RIVAL5_MAX_DPI_PRESETS} DPI presets.`);
|
|
96
|
+
}
|
|
97
|
+
if (!Number.isInteger(selectedIndex) || selectedIndex < 0 || selectedIndex >= presets.length) {
|
|
98
|
+
throw new Rival5ProtocolError(`Selected DPI preset must be an index into the ${presets.length} presets being written.`);
|
|
99
|
+
}
|
|
100
|
+
const encoded = presets.map((dpi) => {
|
|
101
|
+
const byte = TRUEMOVE_AIR_DPI_TO_BYTE.get(dpi);
|
|
102
|
+
if (byte === undefined) {
|
|
103
|
+
throw new Rival5ProtocolError(`SteelSeries Rival 5 DPI must be ${RIVAL5_DPI_MIN}–${RIVAL5_DPI_MAX.toLocaleString("en-US")} in ${RIVAL5_DPI_STEP} DPI steps.`);
|
|
104
|
+
}
|
|
105
|
+
return byte;
|
|
106
|
+
});
|
|
107
|
+
return new Uint8Array([...RIVAL5_COMMAND.dpiPresets, presets.length, selectedIndex, ...encoded]);
|
|
108
|
+
}
|
|
109
|
+
/** `2B <v>` with 1000→0x01, 500→0x02, 250→0x03, 125→0x04. */
|
|
110
|
+
export function steelseriesRival5EncodePollingRate(pollingRateHz) {
|
|
111
|
+
const byte = POLLING_RATE_TO_BYTE.get(pollingRateHz);
|
|
112
|
+
if (byte === undefined) {
|
|
113
|
+
throw new Rival5ProtocolError("SteelSeries Rival 5 supports 125, 250, 500, or 1000 Hz polling.");
|
|
114
|
+
}
|
|
115
|
+
return new Uint8Array([...RIVAL5_COMMAND.pollingRate, byte]);
|
|
116
|
+
}
|
|
117
|
+
/** `11` — commit the current settings to onboard flash. */
|
|
118
|
+
export function steelseriesRival5SaveCommand() {
|
|
119
|
+
return new Uint8Array(RIVAL5_SAVE_COMMAND);
|
|
120
|
+
}
|
|
121
|
+
/** `90` — the device answers with a 32-byte version string. */
|
|
122
|
+
export function steelseriesRival5FirmwareQuery() {
|
|
123
|
+
return new Uint8Array(RIVAL5_FIRMWARE_QUERY);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Decode the 32-byte firmware version reply as ASCII, stopping at the
|
|
127
|
+
* first NUL. The string shape follows the specification's `version_str
|
|
128
|
+
* bytearray (size 32)` field; trailing padding is not part of the version.
|
|
129
|
+
*/
|
|
130
|
+
export function steelseriesRival5DecodeFirmware(payload) {
|
|
131
|
+
if (payload.length < RIVAL5_FIRMWARE_RESPONSE_LENGTH) {
|
|
132
|
+
throw new Rival5ProtocolError("SteelSeries Rival 5 firmware response is shorter than 32 bytes.");
|
|
133
|
+
}
|
|
134
|
+
const bytes = payload.slice(0, RIVAL5_FIRMWARE_RESPONSE_LENGTH);
|
|
135
|
+
const nul = bytes.indexOf(0x00);
|
|
136
|
+
return new TextDecoder("ascii").decode(nul === -1 ? bytes : bytes.slice(0, nul));
|
|
137
|
+
}
|
|
138
|
+
// -- Button mapping --------------------------------------------------------
|
|
139
|
+
/** 9 physical buttons plus scroll up/down (11 slots, 55 bytes total). */
|
|
140
|
+
export const RIVAL5_BUTTONS = {
|
|
141
|
+
button1: { id: 0x01, offset: 0x00 },
|
|
142
|
+
button2: { id: 0x02, offset: 0x05 },
|
|
143
|
+
button3: { id: 0x03, offset: 0x0a },
|
|
144
|
+
button4: { id: 0x04, offset: 0x0f },
|
|
145
|
+
button5: { id: 0x05, offset: 0x14 },
|
|
146
|
+
button6: { id: 0x06, offset: 0x19 },
|
|
147
|
+
button7: { id: 0x07, offset: 0x1e },
|
|
148
|
+
button8: { id: 0x08, offset: 0x23 },
|
|
149
|
+
button9: { id: 0x09, offset: 0x28 },
|
|
150
|
+
scrollUp: { id: 0x31, offset: 0x2d },
|
|
151
|
+
scrollDown: { id: 0x32, offset: 0x32 },
|
|
152
|
+
};
|
|
153
|
+
const BUTTON_FIELD_LENGTH = 5;
|
|
154
|
+
const BUTTON_DISABLE = 0x00;
|
|
155
|
+
const BUTTON_DPI_SWITCH = 0x30;
|
|
156
|
+
const BUTTON_KEYBOARD = 0x51;
|
|
157
|
+
const BUTTON_MULTIMEDIA = 0x61;
|
|
158
|
+
function encodeKeyCode(code, kind) {
|
|
159
|
+
if (!Number.isInteger(code) || code < 0 || code > 255) {
|
|
160
|
+
throw new Rival5ProtocolError(`${kind} codes must be integers 0–255.`);
|
|
161
|
+
}
|
|
162
|
+
return code;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* `2A` + one 55-byte packet (11 slots × 5-byte fields), zero-filled except
|
|
166
|
+
* where a mapping is given. Pass every button explicitly — unmapped buttons
|
|
167
|
+
* stay disabled, matching this package's no-silent-defaults policy.
|
|
168
|
+
*/
|
|
169
|
+
export function steelseriesRival5EncodeButtonsMapping(mapping) {
|
|
170
|
+
for (const name of Object.keys(mapping)) {
|
|
171
|
+
if (!Object.hasOwn(RIVAL5_BUTTONS, name)) {
|
|
172
|
+
throw new Rival5ProtocolError(`Unknown SteelSeries Rival 5 button "${name}".`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const names = Object.keys(RIVAL5_BUTTONS);
|
|
176
|
+
const packet = new Array(names.length * BUTTON_FIELD_LENGTH).fill(0x00);
|
|
177
|
+
for (const [name, action] of Object.entries(mapping)) {
|
|
178
|
+
const { offset } = RIVAL5_BUTTONS[name];
|
|
179
|
+
switch (action.type) {
|
|
180
|
+
case "button": {
|
|
181
|
+
if (!Object.hasOwn(RIVAL5_BUTTONS, action.target)) {
|
|
182
|
+
throw new Rival5ProtocolError(`Unknown SteelSeries Rival 5 button "${action.target}".`);
|
|
183
|
+
}
|
|
184
|
+
packet[offset] = RIVAL5_BUTTONS[action.target].id;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case "disabled": {
|
|
188
|
+
packet[offset] = BUTTON_DISABLE;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case "dpiSwitch": {
|
|
192
|
+
packet[offset] = BUTTON_DPI_SWITCH;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
case "keyboard": {
|
|
196
|
+
packet[offset] = BUTTON_KEYBOARD;
|
|
197
|
+
packet[offset + 1] = encodeKeyCode(action.code, "Keyboard scan");
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
case "multimedia": {
|
|
201
|
+
packet[offset] = BUTTON_MULTIMEDIA;
|
|
202
|
+
packet[offset + 1] = encodeKeyCode(action.code, "Multimedia key");
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
default: {
|
|
206
|
+
throw new Rival5ProtocolError("Unsupported SteelSeries Rival 5 button action.");
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return new Uint8Array([...RIVAL5_COMMAND.buttonsMapping, ...packet]);
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=rival-5.js.map
|