diff --git a/native-hid/src/registry.mjs b/native-hid/src/registry.mjs index c70f033..ce2a3a4 100644 --- a/native-hid/src/registry.mjs +++ b/native-hid/src/registry.mjs @@ -14,8 +14,24 @@ import { DescribedDeviceAdapter } from "./hid-device-adapter.mjs"; /** Receivers that stop answering while a sibling collection is read: only - * the collection on this usage page is opened (see candidateDevices()). */ -const ONLY_USAGE_PAGE = { scyrox: 0xff02 }; + * the collection on this usage page is opened (see candidateDevices()). A + * rule with a vendor id applies only to that brand's devices on it. + * + * Lamzu's Atlantis generation sits on CompX's 0x3554: a Maya behind its 4K + * receiver (0x3554:0xf510) answered 0 of 3 status reads on Windows with every + * vendor collection open and 3 of 3 with only 0xff02. Lamzu's 0x373e and + * 0x37b0 models talk through feature reports and are opened whole. */ +const ONLY_USAGE_PAGE = [ + { brand: "scyrox", usagePage: 0xff02 }, + { brand: "lamzu", vendorId: 0x3554, usagePage: 0xff02 }, +]; + +/** The usage page to narrow `described` to for `driver`, if any. */ +export function onlyUsagePageFor(driver, described) { + const brand = brandKey(driver.brand); + return ONLY_USAGE_PAGE.find((rule) => rule.brand === brand && (rule.vendorId === undefined || rule.vendorId === described.vendorId)) + ?.usagePage; +} export async function loadRegistry() { const [{ DEVICE_DRIVERS }, { SUPPORTED_HID_FILTERS }] = await Promise.all([ @@ -88,7 +104,7 @@ export function registryPairs(drivers, devices, brand, { matchStatusBrand = fals const driver = driverFor(drivers, view(described)); if (!driver) continue; if (!matchStatusBrand && brandKey(driver.brand) !== wanted) continue; - const device = new Adapter(described, { onlyUsagePage: ONLY_USAGE_PAGE[brandKey(driver.brand)] }); + const device = new Adapter(described, { onlyUsagePage: onlyUsagePageFor(driver, described) }); const client = driver.create(device); pairs.push({ device, diff --git a/native-hid/src/registry.test.mjs b/native-hid/src/registry.test.mjs index 680fc27..f240bd9 100644 --- a/native-hid/src/registry.test.mjs +++ b/native-hid/src/registry.test.mjs @@ -3,7 +3,7 @@ import assert from "node:assert/strict"; import { EventEmitter } from "node:events"; import { DescribedDeviceAdapter } from "./hid-device-adapter.mjs"; -import { identify, knowsBrand, registryPairs } from "./registry.mjs"; +import { identify, knowsBrand, onlyUsagePageFor, registryPairs } from "./registry.mjs"; /** A node-hid handle that records what is sent through it. */ function fakeHandles({ failWrites = [] } = {}) { @@ -207,6 +207,27 @@ test("matching on the status brand offers every claimed device", () => { assert.ok(pairs.every(({ candidate }) => candidate.requireBrand === "attack shark")); }); +test("only CompX-id Lamzu receivers and Scyrox are narrowed to their config collection", () => { + const lamzu = { brand: "Lamzu" }; + assert.equal(onlyUsagePageFor(lamzu, { vendorId: 0x3554 }), 0xff02); + assert.equal(onlyUsagePageFor(lamzu, { vendorId: 0x373e }), undefined); + assert.equal(onlyUsagePageFor(lamzu, { vendorId: 0x37b0 }), undefined); + assert.equal(onlyUsagePageFor({ brand: "Scyrox" }, { vendorId: 0x3554 }), 0xff02); + assert.equal(onlyUsagePageFor({ brand: "Keychron" }, { vendorId: 0x3434 }), undefined); +}); + +test("a Lamzu receiver on CompX's id opens only its 0xff02 collection", () => { + const { Handle } = fakeHandles(); + class Adapter extends DescribedDeviceAdapter { + constructor(device, options) { + super(device, { ...options, Handle }); + } + } + const lamzuDrivers = [{ brand: "Lamzu", supports: (device) => device.vendorId === 0x3554, create: (device) => new FakeClient(device) }]; + const [{ device }] = registryPairs(lamzuDrivers, [described({ key: "maya", vendorId: 0x3554 })], "lamzu", { Adapter }); + assert.deepEqual(device._paths.map((path) => path.path), ["notify"]); +}); + test("every helper script parses", async () => { // apply.mjs and the other entry points run main() on import, so no test // loads them; a syntax error there would otherwise only show in Bridge.