Skip to content

Commit 9ca3821

Browse files
committed
🔥 only save bottom out threshold on command
1 parent a1be22e commit 9ca3821

7 files changed

Lines changed: 55 additions & 15 deletions

File tree

src/lib/configurator/calibration/calibration-menu.svelte

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ this program. If not, see <https://www.gnu.org/licenses/>.
2020
import Switch from "$lib/components/switch.svelte"
2121
import { Button } from "$lib/components/ui/button"
2222
import { keyboardContext } from "$lib/keyboard"
23+
import { isFeatureAvailable } from "$lib/utils"
24+
import { toast } from "svelte-sonner"
2325
import { analogInfoQueryContext } from "../queries/analog-info-query.svelte"
2426
import { calibrationQueryContext } from "../queries/calibration.query.svelte"
2527
import { optionsQueryContext } from "../queries/options-query.svelte"
2628
29+
const keyboard = keyboardContext.get()
2730
const {
2831
demo,
32+
version,
2933
metadata: { adcResolution },
30-
} = keyboardContext.get()
34+
} = keyboard
3135
3236
const analogInfoQuery = analogInfoQueryContext.get()
3337
const calibrationQuery = calibrationQueryContext.get()
@@ -38,18 +42,22 @@ this program. If not, see <https://www.gnu.org/licenses/>.
3842

3943
<div class="grid size-full grid-cols-[minmax(0,1fr)_24rem]">
4044
<FixedScrollArea class="flex flex-col gap-4 p-4">
41-
<Switch
42-
bind:checked={
43-
() => options?.saveBottomOutThreshold ?? false,
44-
(v) =>
45-
options &&
46-
optionsQuery.set({ data: { ...options, saveBottomOutThreshold: v } })
47-
}
48-
disabled={demo || !options}
49-
id="save-bottom-out-threshold"
50-
title="Save Bottom Out Threshold"
51-
description="Periodically save the per-key bottom-out threshold values after some inactivity to be restored on next boot. The saved values will only be cleared on recalibration. This setting applies globally across all profiles."
52-
/>
45+
{#if !isFeatureAvailable("saveCalibrationThreshold", version)}
46+
<Switch
47+
bind:checked={
48+
() => options?.saveBottomOutThreshold ?? false,
49+
(v) =>
50+
options &&
51+
optionsQuery.set({
52+
data: { ...options, saveBottomOutThreshold: v },
53+
})
54+
}
55+
disabled={demo || !options}
56+
id="save-bottom-out-threshold"
57+
title="Save Bottom Out Threshold"
58+
description="Periodically save the per-key bottom-out threshold values after some inactivity to be restored on next boot. The saved values will only be cleared on recalibration. This setting applies globally across all profiles."
59+
/>
60+
{/if}
5361
<CommitSlider
5462
bind:committed={
5563
() => calibration?.initialRestValue ?? 0,
@@ -89,14 +97,27 @@ this program. If not, see <https://www.gnu.org/licenses/>.
8997
step={10}
9098
title="Initial Bottom Out Threshold"
9199
/>
92-
<div>
100+
<div class="flex gap-2">
93101
<Button
94102
disabled={demo}
95103
onclick={() => analogInfoQuery.recalibrate()}
96104
size="sm"
105+
variant="destructive"
97106
>
98107
Recalibrate
99108
</Button>
109+
{#if isFeatureAvailable("saveCalibrationThreshold", version)}
110+
<Button
111+
disabled={demo}
112+
onclick={async () => {
113+
await keyboard.saveCalibrationThreshold()
114+
toast.success("Successfully saved calibration threshold.")
115+
}}
116+
size="sm"
117+
>
118+
Save Current Threshold
119+
</Button>
120+
{/if}
100121
</div>
101122
</FixedScrollArea>
102123
<FixedScrollArea class="flex flex-col gap-4 p-4">

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export class DemoKeyboard implements Keyboard {
127127
this.#state.profiles[srcProfile],
128128
)
129129
}
130+
async saveCalibrationThreshold() {
131+
return
132+
}
130133

131134
async getKeymap({ profile }: GetKeymapParams) {
132135
return this.#state.profiles[profile].keymap

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { bootloader } from "$lib/libhmk/commands/bootloader"
3232
import {
3333
getCalibration,
3434
recalibrate,
35+
saveCalibrationThreshold,
3536
setCalibration,
3637
} from "$lib/libhmk/commands/calibration"
3738
import { factoryReset } from "$lib/libhmk/commands/factory-reset"
@@ -155,6 +156,9 @@ class HMKKeyboard implements Keyboard {
155156
duplicateProfile(params: DuplicateProfileParams) {
156157
return duplicateProfile(this.commander, params)
157158
}
159+
saveCalibrationThreshold() {
160+
return saveCalibrationThreshold(this.commander)
161+
}
158162

159163
getKeymap(params: GetKeymapParams) {
160164
return getKeymap(this.commander, this.metadata, params)

src/lib/keyboard/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export type KeyboardAction = {
7474
setOptions(params: SetOptionsParams): Promise<void>
7575
resetProfile(params: ResetProfileParams): Promise<void>
7676
duplicateProfile(params: DuplicateProfileParams): Promise<void>
77+
saveCalibrationThreshold(): Promise<void>
7778

7879
getKeymap(params: GetKeymapParams): Promise<number[][]>
7980
setKeymap(params: SetKeymapParams): Promise<void>

src/lib/libhmk/commands/calibration.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,10 @@ export async function setCalibration(
5151
],
5252
})
5353
}
54+
55+
export async function saveCalibrationThreshold(commander: Commander) {
56+
await commander.sendCommand({
57+
command: HMK_Command.SAVE_CALIBRATION_THRESHOLD,
58+
payload: [],
59+
})
60+
}

src/lib/libhmk/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export enum HMK_Command {
3232
DUPLICATE_PROFILE,
3333
GET_METADATA,
3434
GET_SERIAL,
35+
SAVE_CALIBRATION_THRESHOLD,
3536

3637
GET_KEYMAP = 128,
3738
SET_KEYMAP,

src/lib/libhmk/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import z from "zod"
1818

1919
export const HMK_FIRMWARE_MIN_VERSION = 0x0104
2020
export const HMK_FIRMWARE_MAX_VERSION = 0x0107
21-
export const featureVersionMap = { pollingRateSwitch: 0x0105 } as const
21+
export const featureVersionMap = {
22+
pollingRateSwitch: 0x0105,
23+
saveCalibrationThreshold: 0x0107,
24+
} as const
2225
export type Feature = keyof typeof featureVersionMap
2326

2427
export const HMK_DEVICE_USAGE_PAGE = 0xffab

0 commit comments

Comments
 (0)