Skip to content
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ filters, the driver registry, and shared status types live under
| ATK (Hall-effect and RS series) | `@openmouse/keyboard-protocol/atk` |
| Glorious (stock firmware) | `@openmouse/keyboard-protocol/glorious` |
| VIA (QMK/VIA firmware, any vendor) | `@openmouse/keyboard-protocol/via` |
| MCHOSE (Ace 68 Air, Mix 87 III) | `@openmouse/keyboard-protocol/mchose` |
| MCHOSE (Ace 68 Air, Ace 68 V2 III, Mix 87 III) | `@openmouse/keyboard-protocol/mchose` |

The VIA driver matches the raw-HID collection (`0xFF60:0x61`) on any board and
covers keymaps, keycode names, encoders, macros and custom-menu lighting. Layout
Expand Down Expand Up @@ -146,6 +146,14 @@ confirmed by read-back. It was tested on an Air III with firmware 116; the
ledger lists exactly which reads and writes were exercised on hardware. The
Air II (`0x2120`) is catalogued from the same bundle and is untested.

The Ace 68 V2 III (`0x3837:0x3024`, firmware 116) is the same `glw` command set
under MCHOSE's other vendor id, with the Air's 68-key layout and lighting bytes
but no light box. Through the driver its identity, profile table, function
config, lighting, key travel, keymap and key colours were read on hardware, and
a lighting and a per-key colour write were confirmed by read-back and restored.
It is catalogued as unverified until the rest is exercised. The bootloader
enumerates as `0x3837:0x3025` and is not claimed.

The Mix 87 III (`0x3837:0x300D`) is the same `glw` command set under MCHOSE's
other vendor id; its identity, profile table, function config, key travel,
profile names and default keymap were read on firmware 1.22, and its 90-key
Expand Down
49 changes: 46 additions & 3 deletions docs/mchose-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ configurator (`https://www.mchose.com.cn/cizhou/CZ_SHARED_DATA/`,
`main.7d734adfcc65efb81c4d.js`, fetched 2026-10-31), which calls this command
set the `glw` family, and checked against an **Ace 68 Air III**
(`0x41E4:0x2132`, firmware 116, controller `GL8KH-PRO`) and a **Mix 87 III**
(`0x3837:0x300D`, firmware 1.22, controller `GL8KH-PRO`) over USB on Windows.
(`0x3837:0x300D`, firmware 1.22, controller `GL8KH-PRO`) over USB on Windows, and
an **Ace 68 V2 III** (`0x3837:0x3024`, firmware 116) over USB on Linux (hidraw).

Most MCHOSE `0x3837` boards speak a different protocol (`qhw`, report id
`0x4D`) and are not covered. The Mix 87 III is the exception: it answers the
same `glw` frames on the same usage-`0x0001:0x0000` collection.
same `glw` frames on the same usage-`0x0001:0x0000` collection, and so does the
Ace 68 V2 III.

| Model | Vendor:product | Status |
| --- | --- | --- |
| Ace 68 Air III | `0x41E4:0x2132` | Verified on hardware (firmware 116); "Hardware checks" lists what was exercised |
| Ace 68 Air II | `0x41E4:0x2120` | Same layout, keymap and command set in the vendor bundle; not tested |
| Mix 87 III | `0x3837:0x300D` | Identity, profile table, function config, key travel, profile names and default keymap read on firmware 1.22; writes not exercised |
| Ace 68 V2 III | `0x3837:0x3024` | Identity, profile table, function config, lighting, key travel, keymap and key colours read on firmware 116; a lighting and a key-colour write confirmed and restored; the rest not exercised |

## Transport

Expand Down Expand Up @@ -116,14 +119,21 @@ read, then compare all 64 bytes on read-back.
| Byte | Field |
| --- | --- |
| 0 | High nibble `0xA` on every captured key (kept as read), low nibble switch type |
| 1 | Low nibble key mode (0 normal, 1 rapid trigger), high nibble priority |
| 1 | Low nibble key mode, high nibble priority |
| 2, 3 bit 0 | Actuation, 9 bits, stored minus one |
| 3 bits 3-4 / 1-2 | Press / release rapid-trigger precision |
| 4, 5 bit 0 | Rapid-trigger press, 9 bits, stored minus one |
| 5 bits 1-7 | Press dead zone |
| 6, 7 bit 0 | Rapid-trigger release, 9 bits, stored minus one |
| 7 bits 1-7 | Release dead zone |

Key mode, from the M HUB trigger page on an Ace 68 V2 III (each switch was
turned on a key and the frames it wrote were read): 0 is a fixed actuation point
(Quick Trigger off), 1 is Quick Trigger (RT) with the page's "Rapid trigger"
switch off, and 2 is Quick Trigger with that switch on, which is how the
keyboard ships. In the page's "Key Deadzone" the Top value is the press dead
zone (byte 5) and Bottom is the release dead zone (byte 7).

Units, from the vendor app's conversions:

- Actuation and dead zones are 0.01 mm. The app allows actuation from
Expand All @@ -147,6 +157,11 @@ key with a deeper factory actuation, 2.50 mm, and sits in slot 46).
`mchoseLayoutFromDefaults` resolves the slots from the connected keyboard;
`MCHOSE_ACE68_LAYOUT` is the same table read from an Air III on firmware 116.

The Ace 68 V2 III uses the same 68-key drawing and slot numbers as the Air: all
68 keys resolved from its own default keymap (firmware 116) match
`MCHOSE_ACE68_LAYOUT` slot for slot. It has no light box, so its model lists no
side effects.

The Mix 87 III uses the vendor's 90-key drawing (87 keys plus the G1/RT/Light
function keys). Its default keymap on firmware 1.22 places every ordinary key;
the three function keys are `0xF0` actions the usage join cannot name, so the
Expand Down Expand Up @@ -205,6 +220,20 @@ The delay follows the step; under 5 ms is written as 4, meaning none.
Writing the first frame takes a flash erase (180 ms measured); the driver
resends a frame that gets no answer, twice at most, as the vendor app does.

### Profiles on the keyboard

`createProfile(from, name, activate)` adds a profile as a copy of another: its
data goes into the first free slot, then the name, and the profile table last,
so the keyboard never lists a half-written profile (three at most).
`deleteProfile(profile)` takes a profile off the table and clears its name; the
active and the last profile stay. `factoryReset(profile | "all")` is the vendor
app's restore (the keyboard reboots). `exportProfile` and `importProfile` move a
profile's settings, lighting, colours, travel, keymap layers and advanced keys
as hex strings (format `openmouse-mchose-profile-1`, not the vendor's JSON);
the target keeps its own name and layer number, and macros are not included.
Table writes made soon after a settings write can come out garbled, so every
block is read back and rewritten after a pause if it differs.

### Lighting

In the function config: backlight effect, brightness (0-100), `4 - speed`,
Expand Down Expand Up @@ -259,3 +288,17 @@ change written, read back and then restored:

Not exercised: how advanced keys and macros behave when typed, the Air II,
wireless models.

On the Ace 68 V2 III (`0x3837:0x3024`, firmware 116), through
`MchoseKeyboardHidClient` over `/dev/hidraw` on Linux:

- Info, profile table, function config, lighting, key travel, keymap and key
colour reads decode; the layout resolved from the default keymap matches the
static Ace 68 table.
- Backlight brightness written and read back, and one per-key colour written
straight after that settings write and again 2.5 s later, each confirmed by
read-back; then both restored, byte-identical to a dump taken first.

Not exercised: polling rate (the supported list is copied from the Air),
actuation and rapid-trigger writes, keymaps, macros, advanced keys, calibration
and factory reset on this model.
113 changes: 111 additions & 2 deletions src/drivers/mchose/hid.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
import test from "node:test";
import { MCHOSE_COMMAND, mchoseChecksum } from "../../mchose/index.ts";
import { MCHOSE_COMMAND, MCHOSE_CUSTOM_AREA_SIZE, MCHOSE_PROFILE_NAMES_OFFSET, MCHOSE_PROFILE_NAMES_SIZE, encodeMchoseJson, mchoseChecksum } from "../../mchose/index.ts";
import { MchoseKeyboardHidClient } from "./hid.ts";
import { createSupportedClient, deviceBrand } from "../registry.ts";
import { MCHOSE_HID_FILTERS, SUPPORTED_HID_FILTERS, VENDOR_ID } from "../vendors.ts";
Expand Down Expand Up @@ -144,6 +144,25 @@ test("recognises the Mix 87 III on MCHOSE's other vendor id", async () => {
assert.ok(!MchoseKeyboardHidClient.isSupported(other.hid), "another product on the Mix vendor id is not a Mix 87");
});

test("recognises the Ace 68 V2 III on MCHOSE's other vendor id", async () => {
const fake = new FakeMchoseKeyboard();
fake.vendorId = 0x3837;
fake.productId = 0x3024;
assert.ok(MchoseKeyboardHidClient.isSupported(fake.hid));
assert.equal(deviceBrand(createSupportedClient(fake.hid)!), "MCHOSE");
assert.ok(MCHOSE_HID_FILTERS.some((filter) =>
filter.vendorId === 0x3837 && filter.productId === 0x3024 && filter.usagePage === 1 && filter.usage === 0));
const status = await new MchoseKeyboardHidClient(fake.hid).readStatus();
assert.equal(status.name, "Ace 68 V2 III");
assert.equal(status.mchose?.layout?.length, 68);
assert.equal(status.mchose?.layout?.find((key) => key.label === "E")?.index, 0);
// The bootloader enumerates as 0x3025 and is not a configuration interface.
const boot = new FakeMchoseKeyboard();
boot.vendorId = 0x3837;
boot.productId = 0x3025;
assert.ok(!MchoseKeyboardHidClient.isSupported(boot.hid));
});

test("readStatus reads identity, the active profile, performance and key travel", async () => {
const fake = new FakeMchoseKeyboard();
const status = await new MchoseKeyboardHidClient(fake.hid).readStatus();
Expand Down Expand Up @@ -284,7 +303,9 @@ test("advanced-key slots, colours, names and calibration", async () => {
assert.deepEqual(colors[3], { r: 1, g: 2, b: 3 });
const names = await client.setProfileName(2, "Aim");
assert.equal(names[2], "Aim");
assert.deepEqual(fake.writes(MCHOSE_COMMAND.setCustomData).map((frame) => frame[4]), [56], "only the frames the JSON needs");
assert.deepEqual(fake.writes(MCHOSE_COMMAND.setCustomData).map((frame) => frame[4]), [56, 56, 56, 56], "only the frames the JSON needs, once per profile's copy");
const copies = [0, 1, 2, 3].map((slot) => fake.custom.slice(1024 * slot + 336, 1024 * slot + 336 + 56).join(","));
assert.ok(copies.every((copy) => copy === copies[0]), "every profile holds the same list");
await client.calibrate("start");
await client.calibrate("end");
assert.deepEqual(fake.calibration, [MCHOSE_COMMAND.startCalibration, MCHOSE_COMMAND.endCalibration]);
Expand Down Expand Up @@ -361,3 +382,91 @@ test("closing while the device is still opening leaves it closed", async () => {
fake.open = async () => { fake.opened = true; };
assert.ok((await client.readBase()).profileCount > 0, "a later open starts a new session");
});

test("a profile is added as a copy and removed again, in the order the page writes", async () => {
const fake = new FakeMchoseKeyboard();
fake.base = [0, 2, 0, 2, 1, 3, 0xaa, 0xbb, ...new Array(48).fill(0xa2)];
// Give profile 0 recognisable data in every block that is copied.
fake.config[0]![20] = 9;
fake.config[0]![1] = 0x50 | 0x01; // the Windows Fn layer is showing
fake.colors.splice(0, 3, 1, 2, 3);
fake.travel[0]!.splice(8, 8, 0xa1, 0x02, 0x4a, 0x00, 0x4a, 0x1e, 0x4a, 0x1e);
fake.keymap.splice(3, 3, 0x10, 0x00, 0x14);
fake.keymap.splice(512 * 3 + 6, 3, 0x10, 0x00, 0x15);
fake.dks.splice(0, 2, 7, 8);
fake.modTap.splice(0, 2, 5, 6);
fake.toggle.splice(0, 2, 3, 4);
fake.custom.splice(700, 2, 0x41, 0x42);
const client = new MchoseKeyboardHidClient(fake.hid);

const created = await client.createProfile(0, "Copy");
assert.deepEqual([created.activeProfile, created.profileCount], [1, 3], "slot 1 is the first free one and becomes active");
assert.equal(fake.config[1]![20], 9, "settings are copied");
assert.equal(fake.config[1]![1] & 0x0f, 4, "the layer nibble follows the slot and the copy starts on its base layer");
assert.deepEqual(fake.colors.slice(512, 515), [1, 2, 3]);
assert.deepEqual(fake.travel[1]!.slice(8, 16), fake.travel[0]!.slice(8, 16));
assert.deepEqual(fake.keymap.slice(2048 + 3, 2048 + 6), [0x10, 0x00, 0x14], "layer 0 of the new slot");
assert.deepEqual(fake.keymap.slice(2048 + 512 * 3 + 6, 2048 + 512 * 3 + 9), [0x10, 0x00, 0x15], "layer 3 of the new slot");
assert.deepEqual([fake.dks[768], fake.modTap[256], fake.toggle[128]], [7, 5, 3]);
assert.deepEqual(fake.custom.slice(1024 + 700, 1024 + 702), [0x41, 0x42]);
assert.equal((await client.readProfileNames())[1], "Copy");
// The profile table is written last.
const order = fake.sent.filter((frame) => frame[0] === 0x55).map((frame) => frame[1]);
assert.equal(order.lastIndexOf(MCHOSE_COMMAND.setBase) > order.lastIndexOf(MCHOSE_COMMAND.setKeyTravel), true);
await assert.rejects(client.createProfile(0, "Fourth"), RangeError, "three is the most");
await assert.rejects(client.createProfile(0, ""), RangeError);
await assert.rejects(client.createProfile(0, "x".repeat(16)), RangeError);

// Removing a profile other than the active one.
await assert.rejects(client.deleteProfile(1), RangeError, "the active profile stays");
await client.setActiveProfile(0);
const left = await client.deleteProfile(2);
assert.deepEqual([left.activeProfile, left.profileCount, [...left.order]], [0, 2, [0, 1, 2, 3]]);
assert.equal((await client.readProfileNames())[2], null, "its name is cleared");
});

test("a profile is exported and imported into another profile, keeping that profile's own layer", async () => {
const fake = new FakeMchoseKeyboard();
fake.base = [0, 2, 0, 2, 1, 3, 0xaa, 0xbb, ...new Array(48).fill(0xa2)];
fake.config[0]![20] = 9;
fake.config[1]![1] = 0x50 | 0x04;
fake.colors.splice(0, 3, 1, 2, 3);
fake.keymap.splice(3, 3, 0x10, 0x00, 0x14);
fake.dks.splice(0, 2, 7, 8);
fake.modTap.splice(0, 2, 5, 6);
fake.toggle.splice(0, 2, 3, 4);
const client = new MchoseKeyboardHidClient(fake.hid);
const snapshot = await client.exportProfile(0);
// A saved file goes through JSON.
await client.importProfile(1, JSON.parse(JSON.stringify(snapshot)));
assert.equal(fake.config[1]![20], 9);
assert.equal(fake.config[1]![1] & 0x0f, 4, "profile 1 keeps its own layer");
assert.deepEqual(fake.colors.slice(512, 515), [1, 2, 3]);
assert.deepEqual(fake.keymap.slice(2048 + 3, 2048 + 6), [0x10, 0x00, 0x14]);
assert.deepEqual([fake.dks[768], fake.modTap[256], fake.toggle[128]], [7, 5, 3]);
await assert.rejects(client.importProfile(1, { ...snapshot, format: "other" }), RangeError);
await assert.rejects(client.importProfile(1, { ...snapshot, travel: "zz" }), RangeError);
});

test("a new profile keeps the other names from profile 0's list, not from the copied profile's", async () => {
const fake = new FakeMchoseKeyboard();
fake.base = [0, 1, 2, 0, 1, 3, 0xaa, 0xbb, ...new Array(48).fill(0xa2)];
const names = (list: string[], slot: number) =>
fake.custom.splice(MCHOSE_CUSTOM_AREA_SIZE * slot + MCHOSE_PROFILE_NAMES_OFFSET, MCHOSE_PROFILE_NAMES_SIZE, ...encodeMchoseJson(list, MCHOSE_PROFILE_NAMES_SIZE));
names(["", "", "Game", ""], 0);
names(["", "", "Old", ""], 2);
const client = new MchoseKeyboardHidClient(fake.hid);

await client.createProfile(2, "New");
assert.deepEqual((await client.readProfileNames()).slice(0, 3), ["New", null, "Game"]);
});

test("an import with a missing keymap layer is refused before anything is written", async () => {
const fake = new FakeMchoseKeyboard();
fake.base = [0, 2, 0, 2, 1, 3, 0xaa, 0xbb, ...new Array(48).fill(0xa2)];
const client = new MchoseKeyboardHidClient(fake.hid);
const snapshot = await client.exportProfile(0);
const sent = fake.sent.length;
await assert.rejects(client.importProfile(1, { ...snapshot, keymap: new Array(4) }), RangeError);
assert.equal(fake.sent.slice(sent).filter((frame) => frame[0] === 0x55 && frame[1] !== MCHOSE_COMMAND.getFuncConfig).length, 0);
});
Loading