@openmouse/protocol 0.20.0 → 0.22.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/README.md +1 -0
- package/dist/drivers/keychron/launcher-mouse.d.ts +125 -0
- package/dist/drivers/keychron/launcher-mouse.d.ts.map +1 -0
- package/dist/drivers/keychron/launcher-mouse.js +342 -0
- package/dist/drivers/keychron/launcher-mouse.js.map +1 -0
- package/dist/drivers/keychron/mouse-1k-hid.d.ts +78 -0
- package/dist/drivers/keychron/mouse-1k-hid.d.ts.map +1 -0
- package/dist/drivers/keychron/mouse-1k-hid.js +403 -0
- package/dist/drivers/keychron/mouse-1k-hid.js.map +1 -0
- package/dist/drivers/keychron/mouse-4k-hid.d.ts +5 -1
- package/dist/drivers/keychron/mouse-4k-hid.d.ts.map +1 -1
- package/dist/drivers/keychron/mouse-4k-hid.js +8 -3
- package/dist/drivers/keychron/mouse-4k-hid.js.map +1 -1
- package/dist/drivers/keychron/mouse-8k-hid.d.ts +136 -0
- package/dist/drivers/keychron/mouse-8k-hid.d.ts.map +1 -0
- package/dist/drivers/keychron/mouse-8k-hid.js +754 -0
- package/dist/drivers/keychron/mouse-8k-hid.js.map +1 -0
- package/dist/drivers/keychron/mouse-8k-nordic-hid.d.ts +145 -0
- package/dist/drivers/keychron/mouse-8k-nordic-hid.d.ts.map +1 -0
- package/dist/drivers/keychron/mouse-8k-nordic-hid.js +639 -0
- package/dist/drivers/keychron/mouse-8k-nordic-hid.js.map +1 -0
- package/dist/drivers/ksnake/hid.d.ts +43 -10
- package/dist/drivers/ksnake/hid.d.ts.map +1 -1
- package/dist/drivers/ksnake/hid.js +223 -48
- package/dist/drivers/ksnake/hid.js.map +1 -1
- package/dist/drivers/mouse-types.d.ts +4 -2
- package/dist/drivers/mouse-types.d.ts.map +1 -1
- package/dist/drivers/rapoo/hid.d.ts +72 -0
- package/dist/drivers/rapoo/hid.d.ts.map +1 -0
- package/dist/drivers/rapoo/hid.js +389 -0
- package/dist/drivers/rapoo/hid.js.map +1 -0
- package/dist/drivers/redragon/hid.d.ts +56 -5
- package/dist/drivers/redragon/hid.d.ts.map +1 -1
- package/dist/drivers/redragon/hid.js +309 -1
- package/dist/drivers/redragon/hid.js.map +1 -1
- package/dist/drivers/registry.d.ts +5 -2
- package/dist/drivers/registry.d.ts.map +1 -1
- package/dist/drivers/registry.js +15 -2
- package/dist/drivers/registry.js.map +1 -1
- package/dist/drivers/vendors.d.ts +3 -1
- package/dist/drivers/vendors.d.ts.map +1 -1
- package/dist/drivers/vendors.js +17 -4
- package/dist/drivers/vendors.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keychron/index.d.ts +63 -0
- package/dist/keychron/index.d.ts.map +1 -1
- package/dist/keychron/index.js +103 -0
- package/dist/keychron/index.js.map +1 -1
- package/dist/ksnake/index.d.ts +88 -15
- package/dist/ksnake/index.d.ts.map +1 -1
- package/dist/ksnake/index.js +323 -26
- package/dist/ksnake/index.js.map +1 -1
- package/dist/rapoo/index.d.ts +278 -0
- package/dist/rapoo/index.d.ts.map +1 -0
- package/dist/rapoo/index.js +363 -0
- package/dist/rapoo/index.js.map +1 -0
- package/dist/redragon/index.d.ts +122 -0
- package/dist/redragon/index.d.ts.map +1 -1
- package/dist/redragon/index.js +322 -0
- package/dist/redragon/index.js.map +1 -1
- package/package.json +5 -1
- package/dist/drivers/keychron/m6-hid.d.ts +0 -81
- package/dist/drivers/keychron/m6-hid.d.ts.map +0 -1
- package/dist/drivers/keychron/m6-hid.js +0 -486
- package/dist/drivers/keychron/m6-hid.js.map +0 -1
package/dist/ksnake/index.d.ts
CHANGED
|
@@ -19,6 +19,16 @@ export declare const KSNAKE_DONGLE_VENDOR_ID = 43173;
|
|
|
19
19
|
export declare const KSNAKE_PRODUCT_ID = 8789;
|
|
20
20
|
export declare const KSNAKE_USAGE_PAGE = 65281;
|
|
21
21
|
export declare const KSNAKE_USAGE = 16;
|
|
22
|
+
/**
|
|
23
|
+
* Noir's M2-NEX is an OEM rebrand of the same control protocol used by the
|
|
24
|
+
* K-snake X11. The USB and 2.4 GHz transports keep the same PID, so the
|
|
25
|
+
* product descriptor is the only safe way to give the UI the retail identity.
|
|
26
|
+
*/
|
|
27
|
+
export declare const NOIR_M2_NEX_BRAND: "Noir Gear";
|
|
28
|
+
export declare const NOIR_M2_NEX_MODEL: "M2-NEX";
|
|
29
|
+
export declare function isNoirM2NexDevice(device: {
|
|
30
|
+
productName?: string | null;
|
|
31
|
+
}): boolean;
|
|
22
32
|
export declare const KSNAKE_REPORT_ID = 0;
|
|
23
33
|
export declare const KSNAKE_MAGIC = 85;
|
|
24
34
|
export declare const KSNAKE_REPORT_SIZE = 64;
|
|
@@ -35,6 +45,14 @@ export interface KsnakeProduct {
|
|
|
35
45
|
verified: false;
|
|
36
46
|
}
|
|
37
47
|
export declare const KSNAKE_PRODUCTS: ReadonlyMap<number, KsnakeProduct>;
|
|
48
|
+
/** The vendor stores two 2 KiB macro profiles in one 4096-byte address space. */
|
|
49
|
+
export declare const KSNAKE_MACRO_REPORT_ID = 6;
|
|
50
|
+
export declare const KSNAKE_MACRO_SLOT_COUNT = 32;
|
|
51
|
+
export declare const KSNAKE_MACRO_BYTES = 4096;
|
|
52
|
+
export declare const KSNAKE_MACRO_CHUNK_BYTES = 56;
|
|
53
|
+
export declare const KSNAKE_MACRO_POINTER_BYTES: number;
|
|
54
|
+
/** Pointer table (64 bytes) plus the vendor's four-byte profile marker. */
|
|
55
|
+
export declare const KSNAKE_MACRO_HEADER_BYTES: number;
|
|
38
56
|
/**
|
|
39
57
|
* Polling-rate index ↔ Hz.
|
|
40
58
|
* Endpoints confirmed by the X11 user manual: 1000 Hz in 2.4G/wired,
|
|
@@ -43,6 +61,13 @@ export declare const KSNAKE_PRODUCTS: ReadonlyMap<number, KsnakeProduct>;
|
|
|
43
61
|
* Default index 3 = 1000 Hz.
|
|
44
62
|
*/
|
|
45
63
|
export declare const KSNAKE_POLLING_RATES: readonly [125, 250, 500, 1000];
|
|
64
|
+
/** Auto-sleep choices exposed by the M2-NEX vendor panel, in seconds. */
|
|
65
|
+
export declare const KSNAKE_SLEEP_OPTIONS: readonly [60, 180, 300, 600, 1200, 1800, 3600];
|
|
66
|
+
/** Lighting effects exposed by the M2-NEX vendor panel (value -> label). */
|
|
67
|
+
export declare const KSNAKE_LIGHT_MODE_LABELS: readonly ["Off", "Wave", "Neon", "Cycling Flash", "YOYO Ball", "Single Flash", "Breathing Loop"];
|
|
68
|
+
export type KsnakeLightMode = typeof KSNAKE_LIGHT_MODE_LABELS[number];
|
|
69
|
+
export declare function ksnakeDecodeLightMode(value: number): KsnakeLightMode | null;
|
|
70
|
+
export declare function ksnakeEncodeLightMode(mode: string): number | null;
|
|
46
71
|
export declare function ksnakeEncodePollingRate(hz: number): number | null;
|
|
47
72
|
export declare function ksnakeDecodePollingRate(index: number): number | null;
|
|
48
73
|
/**
|
|
@@ -50,7 +75,7 @@ export declare function ksnakeDecodePollingRate(index: number): number | null;
|
|
|
50
75
|
* default 1, likely 1mm/2mm on the PAW3311); they map to the Low/High stops.
|
|
51
76
|
* Medium is not offered by the hardware.
|
|
52
77
|
*/
|
|
53
|
-
export declare function ksnakeDecodeLiftOff(value: number): "Low" | "High";
|
|
78
|
+
export declare function ksnakeDecodeLiftOff(value: number): "Low" | "High" | null;
|
|
54
79
|
export declare function ksnakeEncodeLiftOff(level: string): number | null;
|
|
55
80
|
export declare const KSNAKE_DEFAULT_CONFIG: {
|
|
56
81
|
readonly lightMode: 2;
|
|
@@ -91,6 +116,8 @@ export declare function ksnakeGetVersionRequest(): Uint8Array;
|
|
|
91
116
|
/** Vendor reply bytes [23..25] hold ASCII "x.y.z" when present. */
|
|
92
117
|
export declare function ksnakeDecodeVersion(reply: Uint8Array): string | null;
|
|
93
118
|
export declare function ksnakeGetBatteryRequest(): Uint8Array;
|
|
119
|
+
/** Immediate lighting-effect command used by the vendor panel. */
|
|
120
|
+
export declare function ksnakeEncodeSetLightMode(mode: number): Uint8Array;
|
|
94
121
|
export declare function ksnakeDecodeBattery(reply: Uint8Array): {
|
|
95
122
|
percent: number;
|
|
96
123
|
charging: number;
|
|
@@ -100,19 +127,28 @@ export declare function ksnakeGetConfigRequest(): Uint8Array;
|
|
|
100
127
|
export declare function ksnakeDecodeConfig(reply: Uint8Array): KsnakeConfig | null;
|
|
101
128
|
/** Encode a setConfig request, mirroring vendor `setMouseConfigData()`. */
|
|
102
129
|
export declare function ksnakeEncodeSetConfig(config: KsnakeConfig): Uint8Array;
|
|
103
|
-
/**
|
|
104
|
-
*
|
|
105
|
-
|
|
130
|
+
/**
|
|
131
|
+
* User-visible physical controls in the order used by the shared OpenMouse
|
|
132
|
+
* button card. The DPI button is intentionally absent: the vendor firmware
|
|
133
|
+
* exposes it as a fixed slot between Forward/Backward and the wheel actions.
|
|
134
|
+
*/
|
|
135
|
+
export declare const KSNAKE_BUTTON_NAMES: readonly ["Left", "Right", "Middle", "Forward", "Backward", "Scroll up", "Scroll down"];
|
|
136
|
+
/** Wire slots for the user-visible controls. Slot 5 is the fixed DPI button. */
|
|
137
|
+
export declare const KSNAKE_BUTTON_WIRE_INDICES: readonly [0, 1, 2, 4, 3, 6, 7];
|
|
106
138
|
/** Button function types from the vendor key catalog. */
|
|
107
139
|
export declare const KSNAKE_KEY_TYPE: {
|
|
140
|
+
readonly keyboard: 16;
|
|
108
141
|
readonly mouse: 32;
|
|
109
142
|
readonly special: 33;
|
|
110
143
|
readonly media: 48;
|
|
144
|
+
readonly macro: 112;
|
|
145
|
+
readonly control: 240;
|
|
111
146
|
};
|
|
112
147
|
/** One button slot: type 32 = mouse button (code1 = HID bitmask, 0 = disabled),
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
148
|
+
* 16 = keyboard usage (code1 = modifier bits, code2 = HID usage), 33 =
|
|
149
|
+
* special (DPI loop [85,0,0], scroll [56,1/255]), 48 = consumer/media
|
|
150
|
+
* (code1 = consumer usage), 112 = a macro slot (code1 = 0..31), and 240 = the
|
|
151
|
+
* vendor's DPI/report-rate controls. */
|
|
116
152
|
export interface KsnakeKeyBinding {
|
|
117
153
|
type: number;
|
|
118
154
|
code1: number;
|
|
@@ -132,26 +168,63 @@ export declare const KSNAKE_BUTTON_ACTIONS: ReadonlyArray<{
|
|
|
132
168
|
export declare function ksnakeBindingLabel(binding: KsnakeKeyBinding): string | null;
|
|
133
169
|
/** Catalog binding for a display label, or null for unknown labels. */
|
|
134
170
|
export declare function ksnakeFindButtonAction(label: string): KsnakeKeyBinding | null;
|
|
171
|
+
export interface KsnakeMacroChunkRequest {
|
|
172
|
+
reportId: number;
|
|
173
|
+
body: Uint8Array;
|
|
174
|
+
}
|
|
175
|
+
export interface KsnakeMacroStep {
|
|
176
|
+
/** Vendor macro type: 1 = keyboard modifier, 2 = keyboard, 3 = mouse. */
|
|
177
|
+
type: 1 | 2 | 3;
|
|
178
|
+
/** Vendor action: 1 = press, 2 = release. */
|
|
179
|
+
action: 1 | 2;
|
|
180
|
+
delayMs: number;
|
|
181
|
+
code: number;
|
|
182
|
+
}
|
|
183
|
+
export interface KsnakeMacroProfile {
|
|
184
|
+
steps: readonly KsnakeMacroStep[];
|
|
185
|
+
}
|
|
186
|
+
/** Build the vendor report-6 read request for one macro-memory chunk. */
|
|
187
|
+
export declare function ksnakeGetMacroChunkRequest(offset: number, length: number): KsnakeMacroChunkRequest;
|
|
188
|
+
/** Decode the 8-byte vendor macro-read header and return the requested data. */
|
|
189
|
+
export declare function ksnakeDecodeMacroChunk(reply: Uint8Array, length: number): Uint8Array | null;
|
|
190
|
+
/** Build one report-0 macro-memory write chunk. */
|
|
191
|
+
export declare function ksnakeEncodeMacroChunk(offset: number, data: Uint8Array): Uint8Array;
|
|
192
|
+
/** Final report-0 command that commits the previously written macro chunks. */
|
|
193
|
+
export declare function ksnakeEncodeMacroCommit(): Uint8Array;
|
|
194
|
+
/** Vendor report-6 command for clearing the macro memory. */
|
|
195
|
+
export declare function ksnakeResetMacroRequest(): KsnakeMacroChunkRequest;
|
|
196
|
+
/**
|
|
197
|
+
* Encode the vendor's pointer table plus macro action records. Empty slots are
|
|
198
|
+
* omitted exactly like the official app; the result is ready to upload in
|
|
199
|
+
* 56-byte chunks with `ksnakeEncodeMacroChunk`.
|
|
200
|
+
*/
|
|
201
|
+
export declare function ksnakeEncodeMacroData(profiles: readonly KsnakeMacroProfile[]): Uint8Array;
|
|
202
|
+
/** Decode known vendor macro records from a complete macro-memory image. */
|
|
203
|
+
export declare function ksnakeDecodeMacroData(data: Uint8Array): KsnakeMacroProfile[] | null;
|
|
135
204
|
/**
|
|
136
205
|
* Plausibility gate for decoded key maps. `exchange()` resolves with the next
|
|
137
206
|
* input report, so a stray report from another command can land here; those
|
|
138
|
-
* decode to zeroed/garbage slot types. Real maps always carry nonzero
|
|
139
|
-
* (32/33/48 catalog, plus opaque refs like macro 112).
|
|
207
|
+
* decode to zeroed/garbage slot types. Real maps always carry nonzero,
|
|
208
|
+
* non-0xff types (32/33/48/240 catalog, plus opaque refs like macro 112).
|
|
209
|
+
* Some M2-NEX firmware paths answer with an all-0xff sentinel instead of a
|
|
210
|
+
* readable map; that must not become a fake remap UI.
|
|
140
211
|
*/
|
|
141
212
|
export declare function ksnakeKeysLookPlausible(keys: readonly KsnakeKeyBinding[]): boolean;
|
|
142
213
|
/** GET_KEYS request tail observed in vendor JS: [0x55, 0x08, 0xA5, 0x0B, 0x20]. */
|
|
143
214
|
export declare function ksnakeGetKeysRequest(): Uint8Array;
|
|
144
215
|
/**
|
|
145
|
-
* Decode a getKeys reply:
|
|
146
|
-
* slices 8). Slot
|
|
147
|
-
* Verified against
|
|
148
|
-
*
|
|
216
|
+
* Decode a getKeys reply: 8 slots of 4 bytes at reply[8..39] (the vendor
|
|
217
|
+
* slices 8). Slot 5 is the fixed DPI button; slots 0-4, 6 and 7 are the
|
|
218
|
+
* user-visible controls. Verified against the installed M2-NEX application
|
|
219
|
+
* and its live 2.4 GHz receiver.
|
|
149
220
|
*/
|
|
150
221
|
export declare function ksnakeDecodeKeys(reply: Uint8Array): KsnakeKeyBinding[] | null;
|
|
151
222
|
/**
|
|
152
223
|
* Encode a setKeys request, mirroring vendor `setMouseKeys()`: head
|
|
153
|
-
* [0x55, 0x09, 0xA5, 0x22, 0x20],
|
|
154
|
-
* [
|
|
224
|
+
* [0x55, 0x09, 0xA5, 0x22, 0x20], followed by all eight four-byte slots at
|
|
225
|
+
* body[8..39]. For compatibility, a seven-entry logical map is also accepted
|
|
226
|
+
* and placed into the seven user-visible wire slots while retaining the fixed
|
|
227
|
+
* DPI binding in slot 5.
|
|
155
228
|
*/
|
|
156
229
|
export declare function ksnakeEncodeSetKeys(keys: readonly KsnakeKeyBinding[]): Uint8Array;
|
|
157
230
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ksnake/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,eAAO,MAAM,iBAAiB,OAAS,CAAC;AACxC,eAAO,MAAM,iBAAiB,QAAS,CAAC;AACxC,eAAO,MAAM,YAAY,KAAO,CAAC;AAEjC,eAAO,MAAM,gBAAgB,IAAO,CAAC;AACrC,eAAO,MAAM,YAAY,KAAO,CAAC;AACjC,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC;;uDAEuD;AACvD,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,cAAc,QAAQ,CAAC;AAEpC,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,y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D;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,SAAS,kBAAkB,EAAE,GAAG,UAAU,CA8BzF;AAED,4EAA4E;AAC5E,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,kBAAkB,EAAE,GAAG,IAAI,CAkCnF;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,SAAS,gBAAgB,EAAE,GAAG,OAAO,CAElF;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,IAAI,UAAU,CAQjD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,gBAAgB,EAAE,GAAG,IAAI,CAY7E;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,gBAAgB,EAAE,GAAG,UAAU,CAgCjF"}
|
package/dist/ksnake/index.js
CHANGED
|
@@ -19,6 +19,17 @@ export const KSNAKE_DONGLE_VENDOR_ID = 0xa8a5;
|
|
|
19
19
|
export const KSNAKE_PRODUCT_ID = 0x2255;
|
|
20
20
|
export const KSNAKE_USAGE_PAGE = 0xff01;
|
|
21
21
|
export const KSNAKE_USAGE = 0x10;
|
|
22
|
+
/**
|
|
23
|
+
* Noir's M2-NEX is an OEM rebrand of the same control protocol used by the
|
|
24
|
+
* K-snake X11. The USB and 2.4 GHz transports keep the same PID, so the
|
|
25
|
+
* product descriptor is the only safe way to give the UI the retail identity.
|
|
26
|
+
*/
|
|
27
|
+
export const NOIR_M2_NEX_BRAND = "Noir Gear";
|
|
28
|
+
export const NOIR_M2_NEX_MODEL = "M2-NEX";
|
|
29
|
+
export function isNoirM2NexDevice(device) {
|
|
30
|
+
const compactName = (device.productName ?? "").trim().toLowerCase().replace(/[\s_-]+/g, "");
|
|
31
|
+
return compactName === "m2nex";
|
|
32
|
+
}
|
|
22
33
|
export const KSNAKE_REPORT_ID = 0x00;
|
|
23
34
|
export const KSNAKE_MAGIC = 0x55;
|
|
24
35
|
export const KSNAKE_REPORT_SIZE = 64;
|
|
@@ -42,6 +53,14 @@ const CMD = {
|
|
|
42
53
|
SET_LIGHT: 0x21,
|
|
43
54
|
GET_BATTERY: 0x30,
|
|
44
55
|
};
|
|
56
|
+
/** The vendor stores two 2 KiB macro profiles in one 4096-byte address space. */
|
|
57
|
+
export const KSNAKE_MACRO_REPORT_ID = 0x06;
|
|
58
|
+
export const KSNAKE_MACRO_SLOT_COUNT = 32;
|
|
59
|
+
export const KSNAKE_MACRO_BYTES = 4096;
|
|
60
|
+
export const KSNAKE_MACRO_CHUNK_BYTES = 56;
|
|
61
|
+
export const KSNAKE_MACRO_POINTER_BYTES = KSNAKE_MACRO_SLOT_COUNT * 2;
|
|
62
|
+
/** Pointer table (64 bytes) plus the vendor's four-byte profile marker. */
|
|
63
|
+
export const KSNAKE_MACRO_HEADER_BYTES = KSNAKE_MACRO_POINTER_BYTES + 4;
|
|
45
64
|
const GET_CONFIG_TAIL = [0xa5, 0x0b, 0x2f, 0x01, 0x01, 0x00, 0x00, 0x00];
|
|
46
65
|
const SET_CONFIG_HEAD = [0xae, 0x0a, 0x2f, 0x01, 0x01, 0x00, 0x00];
|
|
47
66
|
const GET_BATTERY_TAIL = [0xa5, 0x0b, 0x2e, 0x01, 0x01, 0x00, 0x00, 0x00];
|
|
@@ -53,6 +72,27 @@ const GET_BATTERY_TAIL = [0xa5, 0x0b, 0x2e, 0x01, 0x01, 0x00, 0x00, 0x00];
|
|
|
53
72
|
* Default index 3 = 1000 Hz.
|
|
54
73
|
*/
|
|
55
74
|
export const KSNAKE_POLLING_RATES = [125, 250, 500, 1000];
|
|
75
|
+
/** Auto-sleep choices exposed by the M2-NEX vendor panel, in seconds. */
|
|
76
|
+
export const KSNAKE_SLEEP_OPTIONS = [60, 180, 300, 600, 1200, 1800, 3600];
|
|
77
|
+
/** Lighting effects exposed by the M2-NEX vendor panel (value -> label). */
|
|
78
|
+
export const KSNAKE_LIGHT_MODE_LABELS = [
|
|
79
|
+
"Off",
|
|
80
|
+
"Wave",
|
|
81
|
+
"Neon",
|
|
82
|
+
"Cycling Flash",
|
|
83
|
+
"YOYO Ball",
|
|
84
|
+
"Single Flash",
|
|
85
|
+
"Breathing Loop",
|
|
86
|
+
];
|
|
87
|
+
export function ksnakeDecodeLightMode(value) {
|
|
88
|
+
return Number.isInteger(value) && value >= 0 && value < KSNAKE_LIGHT_MODE_LABELS.length
|
|
89
|
+
? KSNAKE_LIGHT_MODE_LABELS[value]
|
|
90
|
+
: null;
|
|
91
|
+
}
|
|
92
|
+
export function ksnakeEncodeLightMode(mode) {
|
|
93
|
+
const value = KSNAKE_LIGHT_MODE_LABELS.indexOf(mode);
|
|
94
|
+
return value < 0 ? null : value;
|
|
95
|
+
}
|
|
56
96
|
export function ksnakeEncodePollingRate(hz) {
|
|
57
97
|
const index = KSNAKE_POLLING_RATES.indexOf(hz);
|
|
58
98
|
return index === -1 ? null : index;
|
|
@@ -66,7 +106,11 @@ export function ksnakeDecodePollingRate(index) {
|
|
|
66
106
|
* Medium is not offered by the hardware.
|
|
67
107
|
*/
|
|
68
108
|
export function ksnakeDecodeLiftOff(value) {
|
|
69
|
-
|
|
109
|
+
if (value === 1)
|
|
110
|
+
return "Low";
|
|
111
|
+
if (value === 2)
|
|
112
|
+
return "High";
|
|
113
|
+
return null;
|
|
70
114
|
}
|
|
71
115
|
export function ksnakeEncodeLiftOff(level) {
|
|
72
116
|
if (level === "Low")
|
|
@@ -122,6 +166,17 @@ export function ksnakeGetBatteryRequest() {
|
|
|
122
166
|
});
|
|
123
167
|
return buf;
|
|
124
168
|
}
|
|
169
|
+
/** Immediate lighting-effect command used by the vendor panel. */
|
|
170
|
+
export function ksnakeEncodeSetLightMode(mode) {
|
|
171
|
+
if (!Number.isInteger(mode) || mode < 0 || mode >= KSNAKE_LIGHT_MODE_LABELS.length) {
|
|
172
|
+
throw new RangeError(`Lighting mode must be between 0 and ${KSNAKE_LIGHT_MODE_LABELS.length - 1}.`);
|
|
173
|
+
}
|
|
174
|
+
const buf = new Uint8Array(KSNAKE_REPORT_SIZE);
|
|
175
|
+
// The vendor request includes report id 0 before this body. After WebHID
|
|
176
|
+
// strips it, the mode lands at body[10] (vendor array index 11).
|
|
177
|
+
buf.set([KSNAKE_MAGIC, CMD.SET_LIGHT, 0, 0, 3, 0, 0, 0, 0, 0, mode], 0);
|
|
178
|
+
return buf;
|
|
179
|
+
}
|
|
125
180
|
export function ksnakeDecodeBattery(reply) {
|
|
126
181
|
if (reply.length < 10)
|
|
127
182
|
return null;
|
|
@@ -200,20 +255,60 @@ export function ksnakeEncodeSetConfig(config) {
|
|
|
200
255
|
buf[54] = ((config.wakeupFlag << 4) | (config.moveLightFlag & 15)) & 0xff;
|
|
201
256
|
return buf;
|
|
202
257
|
}
|
|
203
|
-
/**
|
|
204
|
-
*
|
|
205
|
-
|
|
258
|
+
/**
|
|
259
|
+
* User-visible physical controls in the order used by the shared OpenMouse
|
|
260
|
+
* button card. The DPI button is intentionally absent: the vendor firmware
|
|
261
|
+
* exposes it as a fixed slot between Forward/Backward and the wheel actions.
|
|
262
|
+
*/
|
|
263
|
+
export const KSNAKE_BUTTON_NAMES = ["Left", "Right", "Middle", "Forward", "Backward", "Scroll up", "Scroll down"];
|
|
264
|
+
/** Wire slots for the user-visible controls. Slot 5 is the fixed DPI button. */
|
|
265
|
+
export const KSNAKE_BUTTON_WIRE_INDICES = [0, 1, 2, 4, 3, 6, 7];
|
|
266
|
+
const KSNAKE_FIXED_DPI_BINDING = { type: 33, code1: 85, code2: 0, code3: 0 };
|
|
206
267
|
/** Button function types from the vendor key catalog. */
|
|
207
268
|
export const KSNAKE_KEY_TYPE = {
|
|
269
|
+
keyboard: 16,
|
|
208
270
|
mouse: 32,
|
|
209
271
|
special: 33,
|
|
210
272
|
media: 48,
|
|
273
|
+
macro: 112,
|
|
274
|
+
control: 240,
|
|
211
275
|
};
|
|
212
276
|
export function ksnakeIsKnownKeyType(type) {
|
|
213
|
-
return type === KSNAKE_KEY_TYPE.mouse || type === KSNAKE_KEY_TYPE.special || type === KSNAKE_KEY_TYPE.media;
|
|
277
|
+
return type === KSNAKE_KEY_TYPE.keyboard || type === KSNAKE_KEY_TYPE.mouse || type === KSNAKE_KEY_TYPE.special || type === KSNAKE_KEY_TYPE.media || type === KSNAKE_KEY_TYPE.macro || type === KSNAKE_KEY_TYPE.control;
|
|
214
278
|
}
|
|
215
279
|
/** Remappable actions from the vendor key catalog (display label + bytes). */
|
|
216
280
|
export const KSNAKE_BUTTON_ACTIONS = [
|
|
281
|
+
// Keyboard usages follow the vendor catalog's type-16 encoding. The
|
|
282
|
+
// modifier byte is zero for these single-key actions; custom combinations
|
|
283
|
+
// remain lossless when they are read back as opaque bindings.
|
|
284
|
+
{ label: "Escape", type: 16, code1: 0, code2: 41, code3: 0 },
|
|
285
|
+
{ label: "Tab", type: 16, code1: 0, code2: 43, code3: 0 },
|
|
286
|
+
{ label: "Caps Lock", type: 16, code1: 0, code2: 57, code3: 0 },
|
|
287
|
+
{ label: "Enter", type: 16, code1: 0, code2: 40, code3: 0 },
|
|
288
|
+
{ label: "Space", type: 16, code1: 0, code2: 44, code3: 0 },
|
|
289
|
+
{ label: "Backspace", type: 16, code1: 0, code2: 42, code3: 0 },
|
|
290
|
+
{ label: "Insert", type: 16, code1: 0, code2: 73, code3: 0 },
|
|
291
|
+
{ label: "Delete", type: 16, code1: 0, code2: 76, code3: 0 },
|
|
292
|
+
{ label: "Home", type: 16, code1: 0, code2: 74, code3: 0 },
|
|
293
|
+
{ label: "End", type: 16, code1: 0, code2: 77, code3: 0 },
|
|
294
|
+
{ label: "Page Up", type: 16, code1: 0, code2: 75, code3: 0 },
|
|
295
|
+
{ label: "Page Down", type: 16, code1: 0, code2: 78, code3: 0 },
|
|
296
|
+
{ label: "Left Arrow", type: 16, code1: 0, code2: 80, code3: 0 },
|
|
297
|
+
{ label: "Right Arrow", type: 16, code1: 0, code2: 79, code3: 0 },
|
|
298
|
+
{ label: "Up Arrow", type: 16, code1: 0, code2: 82, code3: 0 },
|
|
299
|
+
{ label: "Down Arrow", type: 16, code1: 0, code2: 81, code3: 0 },
|
|
300
|
+
{ label: "F1", type: 16, code1: 0, code2: 58, code3: 0 },
|
|
301
|
+
{ label: "F2", type: 16, code1: 0, code2: 59, code3: 0 },
|
|
302
|
+
{ label: "F3", type: 16, code1: 0, code2: 60, code3: 0 },
|
|
303
|
+
{ label: "F4", type: 16, code1: 0, code2: 61, code3: 0 },
|
|
304
|
+
{ label: "F5", type: 16, code1: 0, code2: 62, code3: 0 },
|
|
305
|
+
{ label: "F6", type: 16, code1: 0, code2: 63, code3: 0 },
|
|
306
|
+
{ label: "F7", type: 16, code1: 0, code2: 64, code3: 0 },
|
|
307
|
+
{ label: "F8", type: 16, code1: 0, code2: 65, code3: 0 },
|
|
308
|
+
{ label: "F9", type: 16, code1: 0, code2: 66, code3: 0 },
|
|
309
|
+
{ label: "F10", type: 16, code1: 0, code2: 67, code3: 0 },
|
|
310
|
+
{ label: "F11", type: 16, code1: 0, code2: 68, code3: 0 },
|
|
311
|
+
{ label: "F12", type: 16, code1: 0, code2: 69, code3: 0 },
|
|
217
312
|
{ label: "Left click", type: 32, code1: 1, code2: 0, code3: 0 },
|
|
218
313
|
{ label: "Right click", type: 32, code1: 2, code2: 0, code3: 0 },
|
|
219
314
|
{ label: "Middle click", type: 32, code1: 4, code2: 0, code3: 0 },
|
|
@@ -221,17 +316,50 @@ export const KSNAKE_BUTTON_ACTIONS = [
|
|
|
221
316
|
{ label: "Forward", type: 32, code1: 16, code2: 0, code3: 0 },
|
|
222
317
|
{ label: "Disabled", type: 32, code1: 0, code2: 0, code3: 0 },
|
|
223
318
|
{ label: "DPI loop", type: 33, code1: 85, code2: 0, code3: 0 },
|
|
319
|
+
// These vendor-control bindings were captured from the installed M2-NEX
|
|
320
|
+
// application and read back from the live 2.4 GHz receiver.
|
|
321
|
+
{ label: "DPI +", type: 240, code1: 1, code2: 1, code3: 0 },
|
|
322
|
+
{ label: "DPI -", type: 240, code1: 1, code2: 2, code3: 0 },
|
|
323
|
+
{ label: "Report Rate +", type: 240, code1: 2, code2: 1, code3: 0 },
|
|
224
324
|
{ label: "Scroll up", type: 33, code1: 56, code2: 1, code3: 0 },
|
|
225
325
|
{ label: "Scroll down", type: 33, code1: 56, code2: 255, code3: 0 },
|
|
226
326
|
{ label: "Volume +", type: 48, code1: 233, code2: 0, code3: 0 },
|
|
227
327
|
{ label: "Volume −", type: 48, code1: 234, code2: 0, code3: 0 },
|
|
228
328
|
{ label: "Mute", type: 48, code1: 226, code2: 0, code3: 0 },
|
|
229
329
|
{ label: "Play/Pause", type: 48, code1: 205, code2: 0, code3: 0 },
|
|
330
|
+
{ label: "Stop", type: 48, code1: 183, code2: 0, code3: 0 },
|
|
230
331
|
{ label: "Prev track", type: 48, code1: 182, code2: 0, code3: 0 },
|
|
231
332
|
{ label: "Next track", type: 48, code1: 181, code2: 0, code3: 0 },
|
|
333
|
+
{ label: "Multimedia", type: 48, code1: 131, code2: 1, code3: 0 },
|
|
334
|
+
{ label: "Homepage", type: 48, code1: 35, code2: 2, code3: 0 },
|
|
335
|
+
{ label: "Web refresh", type: 48, code1: 39, code2: 2, code3: 0 },
|
|
336
|
+
{ label: "Web stop", type: 48, code1: 38, code2: 2, code3: 0 },
|
|
337
|
+
{ label: "Web forward", type: 48, code1: 37, code2: 2, code3: 0 },
|
|
338
|
+
{ label: "Web backward", type: 48, code1: 36, code2: 2, code3: 0 },
|
|
339
|
+
{ label: "Web favorites", type: 48, code1: 42, code2: 2, code3: 0 },
|
|
340
|
+
{ label: "Web search", type: 48, code1: 33, code2: 2, code3: 0 },
|
|
341
|
+
{ label: "Calculator", type: 48, code1: 146, code2: 1, code3: 0 },
|
|
342
|
+
{ label: "My Computer", type: 48, code1: 148, code2: 1, code3: 0 },
|
|
343
|
+
{ label: "Mail", type: 48, code1: 138, code2: 1, code3: 0 },
|
|
344
|
+
// Macro contents live in a separate 4096-byte store. These assignments are
|
|
345
|
+
// safe to expose independently: selecting one only changes the pointer on
|
|
346
|
+
// the button and leaves the macro buffer untouched.
|
|
347
|
+
...Array.from({ length: KSNAKE_MACRO_SLOT_COUNT }, (_, slot) => ({
|
|
348
|
+
label: `Macro ${slot + 1}`,
|
|
349
|
+
type: KSNAKE_KEY_TYPE.macro,
|
|
350
|
+
code1: slot,
|
|
351
|
+
code2: 0,
|
|
352
|
+
code3: 0,
|
|
353
|
+
})),
|
|
232
354
|
];
|
|
233
355
|
/** Display label for a binding, or null when the catalog cannot name it. */
|
|
234
356
|
export function ksnakeBindingLabel(binding) {
|
|
357
|
+
if (binding.type === KSNAKE_KEY_TYPE.macro
|
|
358
|
+
&& Number.isInteger(binding.code1)
|
|
359
|
+
&& binding.code1 >= 0
|
|
360
|
+
&& binding.code1 < KSNAKE_MACRO_SLOT_COUNT) {
|
|
361
|
+
return `Macro ${binding.code1 + 1}`;
|
|
362
|
+
}
|
|
235
363
|
return KSNAKE_BUTTON_ACTIONS.find((action) => action.type === binding.type &&
|
|
236
364
|
action.code1 === binding.code1 &&
|
|
237
365
|
action.code2 === binding.code2 &&
|
|
@@ -242,14 +370,170 @@ export function ksnakeFindButtonAction(label) {
|
|
|
242
370
|
const action = KSNAKE_BUTTON_ACTIONS.find((entry) => entry.label === label);
|
|
243
371
|
return action ? { type: action.type, code1: action.code1, code2: action.code2, code3: action.code3 } : null;
|
|
244
372
|
}
|
|
373
|
+
function assertMacroOffset(offset) {
|
|
374
|
+
if (!Number.isInteger(offset) || offset < 0 || offset >= KSNAKE_MACRO_BYTES) {
|
|
375
|
+
throw new RangeError(`Macro offset must be between 0 and ${KSNAKE_MACRO_BYTES - 1} (got ${offset}).`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
function assertMacroChunk(offset, length) {
|
|
379
|
+
assertMacroOffset(offset);
|
|
380
|
+
if (!Number.isInteger(length) || length < 1 || length > KSNAKE_MACRO_CHUNK_BYTES) {
|
|
381
|
+
throw new RangeError(`Macro chunks must contain 1-${KSNAKE_MACRO_CHUNK_BYTES} bytes (got ${length}).`);
|
|
382
|
+
}
|
|
383
|
+
if (offset + length > KSNAKE_MACRO_BYTES) {
|
|
384
|
+
throw new RangeError(`Macro chunk ends beyond ${KSNAKE_MACRO_BYTES} bytes.`);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function writeLe16(target, offset, value) {
|
|
388
|
+
target[offset] = value & 0xff;
|
|
389
|
+
target[offset + 1] = (value >> 8) & 0xff;
|
|
390
|
+
}
|
|
391
|
+
/** Build the vendor report-6 read request for one macro-memory chunk. */
|
|
392
|
+
export function ksnakeGetMacroChunkRequest(offset, length) {
|
|
393
|
+
assertMacroChunk(offset, length);
|
|
394
|
+
const body = new Uint8Array(KSNAKE_REPORT_SIZE);
|
|
395
|
+
body[0] = 0x0c;
|
|
396
|
+
body[1] = length;
|
|
397
|
+
writeLe16(body, 2, offset);
|
|
398
|
+
return { reportId: KSNAKE_MACRO_REPORT_ID, body };
|
|
399
|
+
}
|
|
400
|
+
/** Decode the 8-byte vendor macro-read header and return the requested data. */
|
|
401
|
+
export function ksnakeDecodeMacroChunk(reply, length) {
|
|
402
|
+
if (!Number.isInteger(length) || length < 1 || length > KSNAKE_MACRO_CHUNK_BYTES)
|
|
403
|
+
return null;
|
|
404
|
+
if (reply.length < 8 + length)
|
|
405
|
+
return null;
|
|
406
|
+
return reply.slice(8, 8 + length);
|
|
407
|
+
}
|
|
408
|
+
/** Build one report-0 macro-memory write chunk. */
|
|
409
|
+
export function ksnakeEncodeMacroChunk(offset, data) {
|
|
410
|
+
assertMacroChunk(offset, data.length);
|
|
411
|
+
const body = new Uint8Array(KSNAKE_REPORT_SIZE);
|
|
412
|
+
body.set([KSNAKE_MAGIC, 0x0d, 0x00, 0x00, data.length], 0);
|
|
413
|
+
writeLe16(body, 5, offset);
|
|
414
|
+
body[7] = 0;
|
|
415
|
+
body.set(data, 8);
|
|
416
|
+
return body;
|
|
417
|
+
}
|
|
418
|
+
/** Final report-0 command that commits the previously written macro chunks. */
|
|
419
|
+
export function ksnakeEncodeMacroCommit() {
|
|
420
|
+
const body = new Uint8Array(KSNAKE_REPORT_SIZE);
|
|
421
|
+
body.set([KSNAKE_MAGIC, 0x10, 0xa5, 0x22, 0x00, 0x00, 0x00, 0x00, 0x05], 0);
|
|
422
|
+
return body;
|
|
423
|
+
}
|
|
424
|
+
/** Vendor report-6 command for clearing the macro memory. */
|
|
425
|
+
export function ksnakeResetMacroRequest() {
|
|
426
|
+
const body = new Uint8Array(KSNAKE_REPORT_SIZE);
|
|
427
|
+
body.set([0x0f, 0x04], 0);
|
|
428
|
+
return { reportId: KSNAKE_MACRO_REPORT_ID, body };
|
|
429
|
+
}
|
|
430
|
+
function macroStepFlags(step, last) {
|
|
431
|
+
if (![1, 2, 3].includes(step.type))
|
|
432
|
+
throw new RangeError(`Unsupported macro step type ${step.type}.`);
|
|
433
|
+
if (![1, 2].includes(step.action))
|
|
434
|
+
throw new RangeError(`Unsupported macro action ${step.action}.`);
|
|
435
|
+
if (!Number.isInteger(step.delayMs) || step.delayMs < 0 || step.delayMs > 0xffff) {
|
|
436
|
+
throw new RangeError(`Macro delay must be an integer between 0 and 65535 ms (got ${step.delayMs}).`);
|
|
437
|
+
}
|
|
438
|
+
if (!Number.isInteger(step.code) || step.code < 0 || step.code > 0xff) {
|
|
439
|
+
throw new RangeError(`Macro code must be an integer between 0 and 255 (got ${step.code}).`);
|
|
440
|
+
}
|
|
441
|
+
let flags = step.action === 1 ? 0x40 : 0;
|
|
442
|
+
// The official configurator uses modifier=1, keyboard=2, mouse=3 in the
|
|
443
|
+
// low three bits of every four-byte action record.
|
|
444
|
+
flags |= step.type;
|
|
445
|
+
if (last)
|
|
446
|
+
flags |= 0x80;
|
|
447
|
+
return flags;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Encode the vendor's pointer table plus macro action records. Empty slots are
|
|
451
|
+
* omitted exactly like the official app; the result is ready to upload in
|
|
452
|
+
* 56-byte chunks with `ksnakeEncodeMacroChunk`.
|
|
453
|
+
*/
|
|
454
|
+
export function ksnakeEncodeMacroData(profiles) {
|
|
455
|
+
if (profiles.length > KSNAKE_MACRO_SLOT_COUNT) {
|
|
456
|
+
throw new RangeError(`The mouse has only ${KSNAKE_MACRO_SLOT_COUNT} macro slots.`);
|
|
457
|
+
}
|
|
458
|
+
const data = new Uint8Array(KSNAKE_MACRO_BYTES);
|
|
459
|
+
let cursor = KSNAKE_MACRO_HEADER_BYTES;
|
|
460
|
+
// The official M2-NEX configurator writes 0x0040 for an empty slot and a
|
|
461
|
+
// four-byte marker immediately after the pointer table. Without these
|
|
462
|
+
// bytes the firmware accepts the packet but ignores the macro table.
|
|
463
|
+
for (let slot = 0; slot < KSNAKE_MACRO_SLOT_COUNT; slot++) {
|
|
464
|
+
writeLe16(data, slot * 2, KSNAKE_MACRO_POINTER_BYTES);
|
|
465
|
+
}
|
|
466
|
+
data.set([0x00, 0x00, 0x80, 0x00], KSNAKE_MACRO_POINTER_BYTES);
|
|
467
|
+
profiles.forEach((profile, slot) => {
|
|
468
|
+
if (profile.steps.length === 0)
|
|
469
|
+
return;
|
|
470
|
+
if (profile.steps.length > Math.floor((KSNAKE_MACRO_BYTES - cursor) / 4)) {
|
|
471
|
+
throw new RangeError(`Macro ${slot + 1} is too long for the device memory.`);
|
|
472
|
+
}
|
|
473
|
+
writeLe16(data, slot * 2, cursor);
|
|
474
|
+
profile.steps.forEach((step, index) => {
|
|
475
|
+
const record = cursor + index * 4;
|
|
476
|
+
// Firmware treats a zero delay as an invalid/empty record. The vendor
|
|
477
|
+
// configurator normalizes an editor value of 0 ms to its minimum 2 ms.
|
|
478
|
+
writeLe16(data, record, step.delayMs === 0 ? 2 : step.delayMs);
|
|
479
|
+
data[record + 2] = macroStepFlags(step, index === profile.steps.length - 1);
|
|
480
|
+
data[record + 3] = step.code;
|
|
481
|
+
});
|
|
482
|
+
cursor += profile.steps.length * 4;
|
|
483
|
+
});
|
|
484
|
+
return data.slice(0, cursor);
|
|
485
|
+
}
|
|
486
|
+
/** Decode known vendor macro records from a complete macro-memory image. */
|
|
487
|
+
export function ksnakeDecodeMacroData(data) {
|
|
488
|
+
if (data.length < KSNAKE_MACRO_HEADER_BYTES || data.length > KSNAKE_MACRO_BYTES)
|
|
489
|
+
return null;
|
|
490
|
+
const profiles = Array.from({ length: KSNAKE_MACRO_SLOT_COUNT }, () => ({ steps: [] }));
|
|
491
|
+
for (let slot = 0; slot < KSNAKE_MACRO_SLOT_COUNT; slot++) {
|
|
492
|
+
const start = le16(data[slot * 2], data[slot * 2 + 1]);
|
|
493
|
+
// 0 is accepted for old captures; the M2-NEX configurator uses the
|
|
494
|
+
// pointer-table end (0x0040) for an empty slot.
|
|
495
|
+
if (start === 0 || start === KSNAKE_MACRO_POINTER_BYTES)
|
|
496
|
+
continue;
|
|
497
|
+
if (start < KSNAKE_MACRO_HEADER_BYTES || start + 4 > data.length)
|
|
498
|
+
return null;
|
|
499
|
+
const steps = [];
|
|
500
|
+
let cursor = start;
|
|
501
|
+
let terminated = false;
|
|
502
|
+
while (cursor + 4 <= data.length) {
|
|
503
|
+
const flags = data[cursor + 2];
|
|
504
|
+
const wireType = flags & 0x07;
|
|
505
|
+
const type = wireType === 0x01 ? 1 : wireType === 0x02 ? 2 : wireType === 0x03 ? 3 : null;
|
|
506
|
+
if (type === null)
|
|
507
|
+
return null;
|
|
508
|
+
const action = (flags & 0x40) !== 0 ? 1 : 2;
|
|
509
|
+
steps.push({
|
|
510
|
+
type,
|
|
511
|
+
action,
|
|
512
|
+
delayMs: le16(data[cursor], data[cursor + 1]),
|
|
513
|
+
code: data[cursor + 3],
|
|
514
|
+
});
|
|
515
|
+
cursor += 4;
|
|
516
|
+
if ((flags & 0x80) !== 0) {
|
|
517
|
+
terminated = true;
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (!terminated)
|
|
522
|
+
return null;
|
|
523
|
+
profiles[slot] = { steps };
|
|
524
|
+
}
|
|
525
|
+
return profiles;
|
|
526
|
+
}
|
|
245
527
|
/**
|
|
246
528
|
* Plausibility gate for decoded key maps. `exchange()` resolves with the next
|
|
247
529
|
* input report, so a stray report from another command can land here; those
|
|
248
|
-
* decode to zeroed/garbage slot types. Real maps always carry nonzero
|
|
249
|
-
* (32/33/48 catalog, plus opaque refs like macro 112).
|
|
530
|
+
* decode to zeroed/garbage slot types. Real maps always carry nonzero,
|
|
531
|
+
* non-0xff types (32/33/48/240 catalog, plus opaque refs like macro 112).
|
|
532
|
+
* Some M2-NEX firmware paths answer with an all-0xff sentinel instead of a
|
|
533
|
+
* readable map; that must not become a fake remap UI.
|
|
250
534
|
*/
|
|
251
535
|
export function ksnakeKeysLookPlausible(keys) {
|
|
252
|
-
return keys.length ===
|
|
536
|
+
return keys.length === 8 && keys.every((key) => key.type !== 0 && key.type !== 0xff);
|
|
253
537
|
}
|
|
254
538
|
/** GET_KEYS request tail observed in vendor JS: [0x55, 0x08, 0xA5, 0x0B, 0x20]. */
|
|
255
539
|
export function ksnakeGetKeysRequest() {
|
|
@@ -262,16 +546,16 @@ export function ksnakeGetKeysRequest() {
|
|
|
262
546
|
return buf;
|
|
263
547
|
}
|
|
264
548
|
/**
|
|
265
|
-
* Decode a getKeys reply:
|
|
266
|
-
* slices 8). Slot
|
|
267
|
-
* Verified against
|
|
268
|
-
*
|
|
549
|
+
* Decode a getKeys reply: 8 slots of 4 bytes at reply[8..39] (the vendor
|
|
550
|
+
* slices 8). Slot 5 is the fixed DPI button; slots 0-4, 6 and 7 are the
|
|
551
|
+
* user-visible controls. Verified against the installed M2-NEX application
|
|
552
|
+
* and its live 2.4 GHz receiver.
|
|
269
553
|
*/
|
|
270
554
|
export function ksnakeDecodeKeys(reply) {
|
|
271
|
-
if (reply.length <
|
|
555
|
+
if (reply.length < 40)
|
|
272
556
|
return null;
|
|
273
557
|
const bindings = [];
|
|
274
|
-
for (let i = 0; i <
|
|
558
|
+
for (let i = 0; i < 8; i++) {
|
|
275
559
|
bindings.push({
|
|
276
560
|
type: reply[8 + i * 4],
|
|
277
561
|
code1: reply[9 + i * 4],
|
|
@@ -283,8 +567,10 @@ export function ksnakeDecodeKeys(reply) {
|
|
|
283
567
|
}
|
|
284
568
|
/**
|
|
285
569
|
* Encode a setKeys request, mirroring vendor `setMouseKeys()`: head
|
|
286
|
-
* [0x55, 0x09, 0xA5, 0x22, 0x20],
|
|
287
|
-
* [
|
|
570
|
+
* [0x55, 0x09, 0xA5, 0x22, 0x20], followed by all eight four-byte slots at
|
|
571
|
+
* body[8..39]. For compatibility, a seven-entry logical map is also accepted
|
|
572
|
+
* and placed into the seven user-visible wire slots while retaining the fixed
|
|
573
|
+
* DPI binding in slot 5.
|
|
288
574
|
*/
|
|
289
575
|
export function ksnakeEncodeSetKeys(keys) {
|
|
290
576
|
const buf = new Uint8Array(KSNAKE_REPORT_SIZE);
|
|
@@ -293,21 +579,32 @@ export function ksnakeEncodeSetKeys(keys) {
|
|
|
293
579
|
buf[2] = 0xa5;
|
|
294
580
|
buf[3] = 0x22;
|
|
295
581
|
buf[4] = 0x20;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
slots.
|
|
582
|
+
let slots;
|
|
583
|
+
if (keys.length >= 8) {
|
|
584
|
+
slots = [...keys].slice(0, 8).map((key) => ({ ...key }));
|
|
585
|
+
}
|
|
586
|
+
else if (keys.length === 7) {
|
|
587
|
+
slots = Array.from({ length: 8 }, () => ({ type: 32, code1: 0, code2: 0, code3: 0 }));
|
|
588
|
+
slots[5] = { ...KSNAKE_FIXED_DPI_BINDING };
|
|
589
|
+
keys.forEach((key, index) => {
|
|
590
|
+
slots[KSNAKE_BUTTON_WIRE_INDICES[index]] = { ...key };
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
// Legacy callers supplied the first six raw slots; retain that encoding
|
|
595
|
+
// while always restoring the two fixed wheel entries at the end.
|
|
596
|
+
slots = [...keys].slice(0, 6).map((key) => ({ ...key }));
|
|
597
|
+
while (slots.length < 6)
|
|
598
|
+
slots.push({ type: 32, code1: 0, code2: 0, code3: 0 });
|
|
599
|
+
slots.push({ type: 33, code1: 56, code2: 1, code3: 0 }, { type: 33, code1: 56, code2: 255, code3: 0 });
|
|
600
|
+
}
|
|
299
601
|
// Wire offsets, NOT vendor-JS t[] indices: t[0] is the report id, so the
|
|
300
|
-
// request slots at t[9..
|
|
301
|
-
|
|
302
|
-
const key = slots[n];
|
|
602
|
+
// request slots at t[9..40] land at data[8..39].
|
|
603
|
+
slots.forEach((key, n) => {
|
|
303
604
|
buf[8 + n * 4] = key.type & 0xff;
|
|
304
605
|
buf[9 + n * 4] = key.code1 & 0xff;
|
|
305
606
|
buf[10 + n * 4] = key.code2 & 0xff;
|
|
306
607
|
buf[11 + n * 4] = key.code3 & 0xff;
|
|
307
|
-
}
|
|
308
|
-
const tail = [33, 56, 1, 0, 33, 56, 255, 0];
|
|
309
|
-
tail.forEach((b, i) => {
|
|
310
|
-
buf[32 + i] = b;
|
|
311
608
|
});
|
|
312
609
|
return buf;
|
|
313
610
|
}
|