Skip to content

Commit cbf4a30

Browse files
committed
🔧 use board serial number as the keyboard ID
1 parent 8b148be commit cbf4a30

7 files changed

Lines changed: 152 additions & 123 deletions

File tree

bun.lock

Lines changed: 95 additions & 102 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,42 @@
1515
},
1616
"devDependencies": {
1717
"@eslint/compat": "^1.4.0",
18-
"@eslint/js": "^9.37.0",
18+
"@eslint/js": "^9.38.0",
1919
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
2020
"@internationalized/date": "^3.10.0",
2121
"@lucide/svelte": "^0.544.0",
2222
"@sveltejs/adapter-vercel": "^5.10.3",
23-
"@sveltejs/kit": "^2.43.8",
23+
"@sveltejs/kit": "^2.47.3",
2424
"@sveltejs/vite-plugin-svelte": "^6.2.1",
25-
"@tailwindcss/vite": "^4.1.14",
25+
"@tailwindcss/vite": "^4.1.16",
2626
"@types/w3c-web-hid": "^1.0.6",
27-
"bits-ui": "^2.11.4",
27+
"bits-ui": "^2.14.1",
2828
"clsx": "^2.1.1",
29-
"eslint": "^9.37.0",
29+
"eslint": "^9.38.0",
3030
"eslint-config-prettier": "^10.1.8",
3131
"eslint-plugin-prettier": "^5.5.4",
32-
"eslint-plugin-svelte": "^3.12.4",
32+
"eslint-plugin-svelte": "^3.12.5",
3333
"globals": "^16.4.0",
3434
"paneforge": "^1.0.2",
3535
"prettier": "^3.6.2",
3636
"prettier-plugin-svelte": "^3.4.0",
3737
"prettier-plugin-tailwindcss": "^0.6.14",
38-
"svelte": "^5.39.8",
39-
"svelte-check": "^4.3.2",
38+
"svelte": "^5.42.2",
39+
"svelte-check": "^4.3.3",
4040
"svelte-sonner": "^1.0.5",
4141
"tailwind-merge": "^3.3.1",
4242
"tailwind-variants": "^3.1.1",
43-
"tailwindcss": "^4.1.14",
43+
"tailwindcss": "^4.1.16",
4444
"tw-animate-css": "^1.4.0",
4545
"typescript": "^5.9.3",
46-
"typescript-eslint": "^8.45.0",
47-
"vite": "^7.1.9"
46+
"typescript-eslint": "^8.46.2",
47+
"vite": "^7.1.12"
4848
},
4949
"dependencies": {
5050
"@fontsource-variable/geist": "^5.2.8",
5151
"@fontsource-variable/geist-mono": "^5.2.7",
5252
"mode-watcher": "^1.1.0",
5353
"runed": "^0.34.0",
54-
"uuid": "^13.0.0",
55-
"zod": "^4.1.11"
54+
"zod": "^4.1.12"
5655
}
5756
}

src/lib/configurator/lib/advanced-keys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
ArrowDownToLineIcon,
1919
ArrowUpFromLineIcon,
2020
ArrowUpToLineIcon,
21-
FileQuestionIcon,
21+
FileQuestionMarkIcon,
2222
LayersIcon,
2323
LayoutTemplateIcon,
2424
MoveHorizontalIcon,
@@ -90,7 +90,7 @@ export function getAdvancedKeyMetadata(type: HMK_AKType): AdvancedKeyMetadata {
9090
return (
9191
metadata ?? {
9292
type,
93-
icon: FileQuestionIcon,
93+
icon: FileQuestionMarkIcon,
9494
title: `Unknown ${displayUInt8(type)}`,
9595
description: "This Advanced Key type is not recognized.",
9696
numKeys: 0,

src/lib/configurator/performance/performance-keyboard.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ this program. If not, see <https://www.gnu.org/licenses/>.
4242
>
4343
{#snippet child({ props })}
4444
<AreaSelect
45-
bind:selections={performanceState.keys}
45+
bind:selections={
46+
() => performanceState.keys, (v) => (performanceState.keys = v)
47+
}
4648
class="flex flex-1 flex-col"
4749
{...props}
4850
>

src/lib/keyboard/hmk-keyboard.svelte.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* this program. If not, see <https://www.gnu.org/licenses/>.
1414
*/
1515

16+
import { displayUInt16 } from "$lib/integer"
1617
import {
1718
HMK_DEVICE_USAGE_ID,
1819
HMK_DEVICE_USAGE_PAGE,
@@ -52,9 +53,9 @@ import {
5253
resetProfile,
5354
} from "$lib/libhmk/commands/profile"
5455
import { reboot } from "$lib/libhmk/commands/reboot"
56+
import { getSerial } from "$lib/libhmk/commands/serial"
5557
import { getTickRate, setTickRate } from "$lib/libhmk/commands/tick-rate"
5658
import { displayVersion, isWebHIDSSupported } from "$lib/utils"
57-
import { v4 as uuidv4 } from "uuid"
5859
import type {
5960
DuplicateProfileParams,
6061
GetActuationMapParams,
@@ -78,6 +79,7 @@ import { Commander } from "./commander"
7879
import type { KeyboardMetadata } from "./metadata"
7980

8081
type HMKKeyboardProps = {
82+
id: string
8183
metadata: KeyboardMetadata
8284
commander: Commander
8385
onDisconnect?: (keyboard: Keyboard) => void
@@ -90,8 +92,8 @@ class HMKKeyboard implements Keyboard {
9092
commander: Commander
9193
onDisconnect?: (keyboard: Keyboard) => void
9294

93-
constructor({ metadata, commander, onDisconnect }: HMKKeyboardProps) {
94-
this.id = uuidv4()
95+
constructor({ id, metadata, commander, onDisconnect }: HMKKeyboardProps) {
96+
this.id = id
9597
this.metadata = metadata
9698
this.commander = commander
9799
this.onDisconnect = onDisconnect
@@ -224,9 +226,14 @@ export async function connect(
224226
)
225227
}
226228

229+
const serial = await getSerial(commander)
227230
const metadata = await getMetadata(commander)
228-
console.log(metadata)
229-
const keyboard = new HMKKeyboard({ metadata, commander, onDisconnect })
231+
const keyboard = new HMKKeyboard({
232+
id: `${displayUInt16(commander.hidDevice.vendorId)}-${displayUInt16(commander.hidDevice.productId)}-${serial}`,
233+
metadata,
234+
commander,
235+
onDisconnect,
236+
})
230237

231238
navigator.hid.addEventListener("disconnect", async function handler() {
232239
navigator.hid.removeEventListener("disconnect", handler)

src/lib/libhmk/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export enum HMK_Command {
3131
RESET_PROFILE,
3232
DUPLICATE_PROFILE,
3333
GET_METADATA,
34+
GET_SERIAL,
3435

3536
GET_KEYMAP = 128,
3637
SET_KEYMAP,

src/lib/libhmk/commands/serial.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* This program is free software: you can redistribute it and/or modify it under
3+
* the terms of the GNU General Public License as published by the Free Software
4+
* Foundation, either version 3 of the License, or (at your option) any later
5+
* version.
6+
*
7+
* This program is distributed in the hope that it will be useful, but WITHOUT
8+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10+
* details.
11+
*
12+
* You should have received a copy of the GNU General Public License along with
13+
* this program. If not, see <https://www.gnu.org/licenses/>.
14+
*/
15+
16+
import type { Commander } from "$lib/keyboard/commander"
17+
import { HMK_Command } from "."
18+
19+
const SERIAL_MAX_LENGTH = 32
20+
21+
export async function getSerial(commander: Commander) {
22+
const decoder = new TextDecoder("utf-8")
23+
const view = await commander.sendCommand({ command: HMK_Command.GET_SERIAL })
24+
return decoder
25+
.decode(view.buffer.slice(0, SERIAL_MAX_LENGTH))
26+
.replace(/\0/g, "")
27+
}

0 commit comments

Comments
 (0)