Repository navigation
Native Attack Shark X3 support #312
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # Attack Shark X3 testing notes | ||
|
|
||
| Native X3 support (2.4 GHz receiver `1d57:fa60`, wired `1d57:fa61`). The | ||
| protocol is taken from the MIT licensed repo enthonyaraujo/attacksharkx3-linux, | ||
| read only. **No part of it has been run against our own X3 hardware yet.** | ||
| Settings are HID feature reports on the config collection (usage page `0x000B`, | ||
| interface MI_02), which browsers cannot reach, so this runs through OpenMouse | ||
| Bridge or the desktop app. | ||
|
|
||
| ## Identity | ||
|
|
||
| | Path | VID:PID | Config collection | Battery collection | | ||
| |---|---|---|---| | ||
| | Receiver | `1d57:fa60` | usage page `0x000B`, MI_02 | usage page `0x000A`, input report `0x03` | | ||
| | Wired | `1d57:fa61` | same | same | | ||
|
|
||
| The X3 path is gated on the receiver message naming model id `0x4d` | ||
| (`03 <model> 40 01 <pct>`) plus the X3 product ids. Any other model id keeps | ||
| today's behaviour. | ||
|
|
||
| ## Reports (all feature reports, report id first) | ||
|
|
||
| | Id | Length | Content | | ||
| |---|---|---| | ||
| | `0x0C` | 10 | commit lead `0C 0A 01 FE 01 FE 00 00 00 00` | | ||
| | `0x04` | 56 | LOD, ripple, stage mask, angle snap, motion sync, 8 DPI slots (raw = dpi/50 - 1), active stage, 8 RGB colours, checksum at 50..51 | | ||
| | `0x05` | 15 | deep sleep, sleep (half minutes), debounce (2 ms units), checksum at 11..12 | | ||
| | `0x06` | 9 | polling code and complement | | ||
| | `0x08` | 59 | 18 button slots of 3 bytes, checksum at 57..58 | | ||
| | `0x09` | 64, 64, 12 | macro upload chunks, slot 2, checksum over the 128 byte block from offset 0 | | ||
|
|
||
| The X3 has no read-back. The library keeps the full settings per product id and | ||
| every change sends the whole burst in the order `0C, 04, 05, 06, 08`. The UI | ||
| therefore shows defaults until the first write, and the first write overwrites | ||
| settings changed elsewhere (this matches the reference). | ||
|
|
||
| ## Pacing | ||
|
|
||
| 500 ms after every report of a burst on the receiver, 15 ms on wired, as in the | ||
| reference, which saw polling changes ignored on the receiver at 15 ms. A burst | ||
| takes about 2.5 s on the receiver. The wired 15 ms value was not validated, and | ||
| the reference's own analysis of the vendor app suggests it may use 500 ms on | ||
| wired too. Macro chunks use 15 ms on both. | ||
|
|
||
| ## Buttons, macros, profiles | ||
|
|
||
| - Remappable: Left, Right, Middle, Forward (slot 6), Back (slot 7). Actions: | ||
| clicks, Forward/Backward, double click, fire, scroll, DPI cycle/+/-, Easy Aim, | ||
| media, My Computer, Browser Home, Off, Macro, and keyboard shortcuts typed as | ||
| `Ctrl+Shift+Alt+Win+<key>` (A-Z, 0-9, F1-F12, Enter, Esc, Backspace, Tab, Space). | ||
| - Slots 3, 4, 5 and 8 (factory `0D`, `3C`, `0F`, `3C`) are never touched; their | ||
| physical buttons are unknown. At least one slot must stay Left Click. | ||
| - Macros: key press and release events, up to 50, slot 2 only. | ||
| `uploadMacro({events})`, then `setButtonMapping(button, "Macro")`. The | ||
| protocol has no delays, mouse-button events or repeat modes. | ||
| - Profiles: not supported. The protocol has one profile (byte `0x01`) and no | ||
| select report. | ||
|
|
||
| ## Battery | ||
|
|
||
| Battery is derived from the reference (`03 10 [raw] 01 09` on usage page | ||
| `0x000A`, voltage = raw/16, reference lithium curve, charging = flag bit 1) and | ||
| is not yet confirmed on our hardware. | ||
|
|
||
| ## Model id question: 0x4d versus 0x10 | ||
|
|
||
| The `DeviceId` table names `0x4d` as X3, but the battery packet starts | ||
| `03 10`, the same shape as an R1 message (`0x10`). Once `0x4d` has been learned | ||
| the library routes `03 10 xx 01 09` to the X3 battery parser. Before that, such | ||
| a packet still reads as an R1. If a real X3 never sends a `0x4d` message, the | ||
| X3 path never activates. Wired `fa61` receives no receiver messages, so it can | ||
| not be named `0x4d` and stays read-only until the maintainer picks an | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Distinguish the disabled X3 path from read-only mode. A native
|
||
| identification source. | ||
|
|
||
| ## Unknowns | ||
|
|
||
| Wired identification, factory `0x3C` slots, byte 49 `0x01` and trailing zeros of | ||
| `0x04`, power byte 8 `0xFF`, whether a commit is needed after a macro upload, | ||
| LOD naming (Low = 1 mm, High = 2 mm), battery scale and charging bit. | ||
|
|
||
| ## Steps for a tester with a real X3 (through Bridge) | ||
|
|
||
| 1. Plug in the receiver, open OpenMouse through Bridge, export the diagnostic | ||
| and confirm the collections include `0x000B` and `0x000A`, and the device is | ||
| named Attack Shark X3 (model id `0x4d`). If it is named R1 or unnamed, stop | ||
| and report the receiver message bytes. | ||
| 2. Change polling to 500, 250, 125 and 1000, waiting about 3 s each, and check | ||
| with a polling-rate tool (evhz) that it applies. | ||
| 3. Change DPI stage values, active stage, stage count and colours; confirm the | ||
| cursor speed and LED colour follow. | ||
| 4. Toggle lift-off, ripple, angle snapping and motion sync; set sleep and | ||
| debounce. Confirm a polling change afterwards did not reset them. | ||
| 5. Remap Forward to `Ctrl+X`, Back to DPI Cycle, Middle to Play/Pause; verify | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. List every action the X3 accepts in
Make the advertised list cover the shortcut actions the codec accepts. Choose the representation that fits the shared contract. Other drivers list shortcuts such as
|
||
| each, and that Left cannot be set to Off. | ||
| 6. Upload a macro (7 taps of key `0x06`), bind it with `Macro` and press the | ||
| button. Report whether it plays or needs a follow-up commit. | ||
| 7. Watch the battery value for a while, then plug in charging, and report the | ||
| raw bytes of `03 10 xx 01 09` against a known charge level. | ||
| 8. If you own a wired `fa61` unit, report what the diagnostic shows. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
|
|
||
| import { | ||
| buildX3Burst, | ||
| buildX3Buttons, | ||
| buildX3Commit, | ||
| buildX3MacroChunks, | ||
| buildX3Polling, | ||
| buildX3Power, | ||
| buildX3Sensor, | ||
| defaultX3Settings, | ||
| parseX3Battery, | ||
| x3DpiToRaw, | ||
| x3EnabledMask, | ||
| x3KeyboardAction, | ||
| x3MacroAction, | ||
| x3RawToDpi, | ||
| X3_MOD, | ||
| } from "./x3-config.ts"; | ||
|
|
||
| const hex = (s: string) => Uint8Array.from(s.split(" ").map((b) => parseInt(b, 16))); | ||
| const h = (u: Uint8Array) => [...u].map((b) => b.toString(16).padStart(2, "0").toUpperCase()).join(" "); | ||
|
|
||
| test("commit", () => { | ||
| assert.equal(h(buildX3Commit()), "0C 0A 01 FE 01 FE 00 00 00 00"); | ||
| }); | ||
|
|
||
| test("default sensor golden", () => { | ||
| assert.equal( | ||
| h(buildX3Sensor(defaultX3Settings())), | ||
| "04 38 01 01 00 3F 00 00 0F 1F 2F 3F 63 07 00 00 00 00 00 00 00 02 00 00 01 FF 00 00 00 FF 00 00 00 FF FF FF 00 00 FF FF FF 00 FF FF 40 00 FF FF FF 01 0E 7D 00 00 00 00", | ||
| ); | ||
| }); | ||
|
|
||
| test("default power golden", () => { | ||
| assert.equal(h(buildX3Power(defaultX3Settings())), "05 0F 01 00 13 E8 00 00 FF 0A 02 02 06 00 00"); | ||
| }); | ||
|
|
||
| test("polling goldens", () => { | ||
| assert.equal(h(buildX3Polling(1000)), "06 09 01 01 FE 00 00 00 00"); | ||
| assert.equal(h(buildX3Polling(500)), "06 09 01 02 FD 00 00 00 00"); | ||
| assert.equal(h(buildX3Polling(250)), "06 09 01 04 FB 00 00 00 00"); | ||
| assert.equal(h(buildX3Polling(125)), "06 09 01 08 F7 00 00 00 00"); | ||
| assert.throws(() => buildX3Polling(100 as 125)); | ||
| }); | ||
|
|
||
| const DEFAULT_BUTTONS = | ||
| "08 3B 01 02 00 00 03 00 00 04 00 00 0D 00 00 3C 00 00 0F 00 00 06 00 00 05 00 00 3C 00 00 01 00 00 01 00 00 01 00 00 01 00 00 01 00 00 01 00 00 01 00 00 0A 00 00 09 00 00 00 C2"; | ||
|
|
||
| test("default buttons golden", () => { | ||
| assert.equal(h(buildX3Buttons(defaultX3Settings().buttons)), DEFAULT_BUTTONS); | ||
| }); | ||
|
|
||
| test("forward = Ctrl+X golden", () => { | ||
| const s = defaultX3Settings(); | ||
| s.buttons[6] = x3KeyboardAction(X3_MOD.ctrl, 0x1b); | ||
| assert.equal( | ||
| h(buildX3Buttons(s.buttons)), | ||
| "08 3B 01 02 00 00 03 00 00 04 00 00 0D 00 00 3C 00 00 0F 00 00 11 01 1B 05 00 00 3C 00 00 01 00 00 01 00 00 01 00 00 01 00 00 01 00 00 01 00 00 01 00 00 0A 00 00 09 00 00 00 E9", | ||
| ); | ||
| }); | ||
|
|
||
| test("buttons need a left click and 18 slots", () => { | ||
| const s = defaultX3Settings(); | ||
| s.buttons[0] = [0x01, 0, 0]; | ||
| assert.throws(() => buildX3Buttons(s.buttons)); | ||
| assert.throws(() => buildX3Buttons(s.buttons.slice(1))); | ||
| assert.deepEqual([...x3MacroAction(2)], [0x12, 0, 2]); | ||
| }); | ||
|
|
||
| test("burst order and lengths", () => { | ||
| const b = buildX3Burst(defaultX3Settings()); | ||
| assert.deepEqual(b.map((r) => r[0]), [0x0c, 0x04, 0x05, 0x06, 0x08]); | ||
| assert.deepEqual(b.map((r) => r.length), [10, 56, 15, 9, 59]); | ||
| }); | ||
|
|
||
| test("macro golden", () => { | ||
| const events = Array.from({ length: 7 }, () => [ | ||
| { usage: 6, down: true }, | ||
| { usage: 6, down: false }, | ||
| ]).flat(); | ||
| const [c0, c1, c2] = buildX3MacroChunks(events, 2); | ||
| assert.deepEqual([c0.length, c1.length, c2.length], [64, 64, 12]); | ||
| assert.deepEqual([...c0.subarray(0, 4)], [9, 0x40, 8, 0]); | ||
| assert.deepEqual([...c1.subarray(0, 4)], [9, 0x40, 8, 1]); | ||
| assert.deepEqual([...c2.subarray(0, 4)], [9, 0x0c, 8, 2]); | ||
| const block = new Uint8Array(128); | ||
| block.set(c0.subarray(4), 0); | ||
| block.set(c1.subarray(4), 60); | ||
| block.set(c2.subarray(4), 120); | ||
| assert.deepEqual([...block.subarray(0, 5)], [2, 0, 0, 0, 1]); | ||
| assert.equal(block[25], 14); | ||
| assert.deepEqual([...block.subarray(26, 30)], [1, 6, 0x81, 6]); | ||
| assert.deepEqual([...block.subarray(126)], [0x03, 0xf3]); | ||
| assert.throws(() => buildX3MacroChunks(events, 0)); | ||
| assert.throws(() => buildX3MacroChunks(Array(51).fill({ usage: 4, down: true }))); | ||
| }); | ||
|
|
||
| test("dpi conversion", () => { | ||
| assert.equal(x3DpiToRaw(800), 15); | ||
| assert.equal(x3DpiToRaw(26000), 0x207); | ||
| for (let d = 50; d <= 26000; d += 50) assert.equal(x3RawToDpi(x3DpiToRaw(d)), d); | ||
| for (const bad of [0, 49, 75, 26050, 800.5]) assert.throws(() => x3DpiToRaw(bad)); | ||
| }); | ||
|
|
||
| test("sensor active stage, mask, validation", () => { | ||
| const s = defaultX3Settings(); | ||
| s.dpiStages = [800, 1600, 12850]; | ||
| s.activeStage = 4; | ||
| assert.equal(x3EnabledMask(s), 0x07); | ||
| const r = buildX3Sensor(s); | ||
| assert.equal(r[5], 0x07); | ||
| assert.equal(r[24], 2); | ||
| assert.equal(r[18], 1); | ||
| assert.equal(r[10], 0xff & (12850 / 50 - 1)); | ||
| s.enabledMask = 0x05; | ||
| assert.equal(buildX3Sensor(s)[5], 0x05); | ||
| s.dpiStages = []; | ||
| assert.throws(() => buildX3Sensor(s)); | ||
| }); | ||
|
|
||
| test("power validation", () => { | ||
| const p = defaultX3Settings(); | ||
| assert.throws(() => buildX3Power({ ...p, sleepMinutes: 0 })); | ||
| assert.throws(() => buildX3Power({ ...p, sleepMinutes: 31 })); | ||
| assert.throws(() => buildX3Power({ ...p, deepSleepMinutes: 0 })); | ||
| assert.throws(() => buildX3Power({ ...p, deepSleepMinutes: 61 })); | ||
| assert.throws(() => buildX3Power({ ...p, debounceMs: 1 })); | ||
| assert.throws(() => buildX3Power({ ...p, debounceMs: 52 })); | ||
| assert.equal(buildX3Power({ ...p, sleepMinutes: 0.5 })[9], 1); | ||
| assert.equal(buildX3Power({ ...p, sleepMinutes: 30, debounceMs: 50 })[10], 25); | ||
| }); | ||
|
|
||
| test("checksum unchanged bytes verify", () => { | ||
| const r = buildX3Sensor(defaultX3Settings()); | ||
| let s = 0; | ||
| for (let i = 3; i <= 49; i++) s += r[i]; | ||
| assert.equal((r[50] << 8) | r[51], s); | ||
| assert.deepEqual(hex("0E 7D"), r.subarray(50, 52)); | ||
| }); | ||
|
|
||
| test("battery sample and curve", () => { | ||
| const b = parseX3Battery(hex("03 10 40 01 09"))!; | ||
| assert.equal(b.voltage, 4); | ||
| assert.equal(b.percent, 77); | ||
| assert.equal(b.charging, false); | ||
| assert.equal(parseX3Battery(hex("03 10 40 02 09"))!.charging, true); | ||
| const want: Record<number, number> = { 0x36: 0, 0x37: 1, 0x38: 3, 0x39: 6, 0x3a: 13, 0x3b: 21, 0x3c: 33, 0x3d: 46, 0x3e: 59, 0x3f: 68, 0x41: 87, 0x42: 94, 0x43: 100, 0xff: 100 }; | ||
| for (const [raw, pct] of Object.entries(want)) { | ||
| const got = parseX3Battery(Uint8Array.of(3, 0x10, Number(raw), 1, 9))!.percent; | ||
| assert.ok(Math.abs(got - pct) <= 1, `raw ${raw}: ${got} vs ${pct}`); | ||
| } | ||
| assert.equal(parseX3Battery(hex("03 10 40 01")), null); | ||
| assert.equal(parseX3Battery(hex("04 10 40 01 09")), null); | ||
| assert.equal(parseX3Battery(hex("03 11 40 01 09")), null); | ||
| }); | ||
|
|
||
| test("X3 action labels round trip and match the reference codes", async () => { | ||
| const { x3ActionLabel, x3ParseActionLabel } = await import("./x3-config.ts"); | ||
| assert.deepEqual([...x3ParseActionLabel("Ctrl+X")!], [0x11, 0x01, 0x1b]); | ||
| assert.deepEqual([...x3ParseActionLabel("Ctrl+Shift+Alt+Win+F12")!], [0x11, 0x0f, 0x45]); | ||
| assert.deepEqual([...x3ParseActionLabel("Mute")!], [0x1a, 0, 0]); | ||
| assert.deepEqual([...x3ParseActionLabel("Macro", 2)!], [0x12, 0, 2]); | ||
| for (const l of ["Ctrl+X", "Alt+Tab", "Win+0", "Space", "DPI-", "Volume Up", "Macro", "Browser Home"]) { | ||
| assert.equal(x3ActionLabel(x3ParseActionLabel(l)!), l); | ||
| } | ||
| assert.equal(x3ParseActionLabel("Ctrl+Ctrl+X"), null); | ||
| assert.equal(x3ParseActionLabel("Bogus"), null); | ||
| assert.equal(x3ActionLabel([0x3c, 0, 0]), null); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify the macro checksum range.
The builder sums block bytes 0–125 and writes the big-endian checksum at bytes 126–127. The table describes a sum over the full 128-byte block, which includes the checksum itself. State both ranges so a tester can independently validate a capture.