@keyboard-hub/adapter-common
v0.0.1
Published
Shared firmware adapter contracts for Keyboard Abyss.
Readme
@keyboard-hub/adapter-common
Shared firmware adapter contracts for Keyboard Abyss.
Use this package to implement or consume firmware adapters that exchange KeyboardHub keymaps with ZMK, VIA, Vial, or custom firmware.
import {
compareKeyboardHubKeymaps,
type FirmwareAdapter,
type FirmwareLoadedConnection,
} from "@keyboard-hub/adapter-common";
export async function importFromFirmware(adapter: FirmwareAdapter) {
const connection = await adapter.connect("usb");
const loaded = await adapter.load(connection, { keyCount: 42 });
return loaded.state.preview;
}
export async function writeChangedKeys(
adapter: FirmwareAdapter,
loaded: FirmwareLoadedConnection,
target: typeof loaded.state.currentKeymap,
) {
const diff = compareKeyboardHubKeymaps(target, loaded.state.currentKeymap);
await adapter.writeKeymapDiff?.(loaded, {
...diff,
comboChanges: [],
macroChanges: [],
moduleChanges: [],
});
}Adapter Flow
- Import a firmware package adapter such as
viaAdapter,vialAdapter, orzmkAdapter, or provide a custom object implementingFirmwareAdapter. - Call
adapter.connect("usb")to open the browser/device transport. - If
adapter.load(connection)throwsFirmwareLockedError, ask the user to unlock the keyboard and calladapter.requestUnlock?.(connection). - Call
adapter.load(connection, options)to build aFirmwareLoadedConnection. - Pass
loaded.state.previewto Keyboard Abyss import UI. - For writeback, compare the target KeyboardHub keymap with
loaded.state.currentKeymap, filter the selected sections, then calladapter.writeKeymapDiff.
See HELPERS for helper function examples and ADAPTER_GUIDE for a concrete custom adapter implementation.
