Skip to content

Commit e85a731

Browse files
committed
feat: fetch settings from build meta
1 parent 050af56 commit e85a731

File tree

5 files changed

+279
-397
lines changed

5 files changed

+279
-397
lines changed

src/lib/assets/settings.yml

Lines changed: 154 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,154 @@
1-
settings:
2-
0x1:
3-
title: Enable Serial Header
4-
description: boolean 0 or 1, default is 0
5-
0x2:
6-
title: Enable Serial Logging
7-
description: boolean 0 or 1, default is 0
8-
0x3:
9-
title: Enable Serial Debugging
10-
description: boolean 0 or 1, default is 0
11-
0x4:
12-
title: Enable Serial Raw
13-
description: boolean 0 or 1, default is 0
14-
0x5:
15-
title: Enable Serial Chord
16-
description: boolean 0 or 1, default is 0
17-
0x6:
18-
title: Enable Serial Keyboard
19-
description: boolean 0 or 1, default is 0
20-
0x7:
21-
title: Enable Serial Mouse
22-
description: boolean 0 or 1, default is 0
23-
0x11:
24-
title: Enable USB HID Keyboard
25-
description: boolean 0 or 1, default is 1
26-
0x12:
27-
title: Enable Character Entry
28-
description: boolean 0 or 1
29-
0x13:
30-
title: GUI-CTRL Swap Mode
31-
description: boolean 0 or 1; 1 swaps keymap 0 and 1. (CCL only)
32-
0x14:
33-
title: Key Scan Duration
34-
description: scan rate described in milliseconds; default is 2ms = 500Hz
35-
0x15:
36-
title: Key Debounce Press Duration
37-
description: debounce time in milliseconds; default is 7ms on the One and 20ms on the Lite
38-
0x16:
39-
title: Key Debounce Release Duration
40-
description: debounce time in milliseconds; default is 7ms on the One and 20ms on the Lite
41-
0x17:
42-
title: Keyboard Output Character Microsecond Delays
43-
description: delay time in microseconds (one delay for press and again for release); default is 480us; max is 10240us; increments of 40us
44-
0x21:
45-
title: Enable USB HID Mouse
46-
description: boolean 0 or 1; default is 1
47-
0x22:
48-
title: Slow Mouse Speed
49-
description: pixels to move at the mouse poll rate; default for CC1 is 5 = 250px/s
50-
0x23:
51-
title: Fast Mouse Speed
52-
description: pixels to move at the mouse poll rate; default for CC1 is 25 = 1250px/s
53-
0x24:
54-
title: Enable Active Mouse
55-
description: boolean 0 or 1; moves mouse back and forth every 60s
56-
0x25:
57-
title: Mouse Scroll Speed
58-
description: default is 1; polls at 1/4th the rate of the mouse move updates
59-
0x26:
60-
title: Mouse Poll Duration
61-
description: poll rate described in milliseconds; default is 20ms = 50Hz
62-
0x31:
63-
title: Enable Chording
64-
description: boolean 0 or 1
65-
0x32:
66-
title: Enable Chording Character Counter Timeout
67-
description: boolean 0 or 1; default is 1
68-
0x33:
69-
title: Chording Character Counter Timeout Timer
70-
description: 0-255 deciseconds; default is 40 or 4.0 seconds
71-
0x34:
72-
title: Chord Detection Press Tolerance(ms)
73-
description: 1-50 milliseconds
74-
0x35:
75-
title: Chord Detection Release Tolerance(ms)
76-
description: 1-50 milliseconds
77-
0x41:
78-
title: Enable Spurring
79-
description: boolean 0 or 1; default is 1
80-
0x42:
81-
title: Enable Spurring Character Counter Timeout
82-
description: boolean 0 or 1; default is 1
83-
0x43:
84-
title: Spurring Character Counter Timeout Timer
85-
description: 0-255 seconds; default is 240
86-
0x51:
87-
title: Enable Arpeggiates
88-
description: boolean 0 or 1; default is 1
89-
0x54:
90-
title: Arpeggiate Tolerance
91-
description: in milliseconds; default 800ms
92-
0x61:
93-
title: Enable Compound Chording (coming soon)
94-
description: boolean 0 or 1; default is 0
95-
0x64:
96-
title: Compound Tolerance
97-
description: in milliseconds; default 1500ms
98-
0x81:
99-
title: LED Brightness
100-
description: 0-50 (CCL only); default is 5, which draws around 100 mA of current
101-
0x82:
102-
title: LED Color Code
103-
description: Color Codes to be listed (CCL only)
104-
0x83:
105-
title: Enable LED Key Highlight (coming soon)
106-
description: boolean 0 or 1 (CCL only)
107-
0x84:
108-
title: Enable LEDs
109-
description: boolean 0 or 1; default is 1 (CCL only)
110-
0x91:
111-
title: Operating System
112-
description: Operating system codes listed below
113-
0x92:
114-
title: Enable Realtime Feedback
115-
description: boolean 0 or 1; default is 1
116-
0x93:
117-
title: Enable CharaChorder Ready on startup
118-
description: boolean 0 or 1; default is 1
1+
- name: spurring
2+
description: |
3+
"Chording only" mode which tells your device to output chords on a press
4+
rather than a press & release. It also enables you to jump from one
5+
chord to another without releasing everything and can be activated in
6+
GTM or by chording both mirror keys. It can provide significant speed
7+
gains with chording, but also takes away the flexibility of character
8+
entry.
9+
items:
10+
- id: 0x41
11+
name: enable
12+
range: [0, 1]
13+
- id: 0x43
14+
name: character counter timeout
15+
range: [0, 240000]
16+
step: 1000
17+
scale: 0.001
18+
unit: s
19+
- name: arpeggiates
20+
description: |
21+
Allows chord modifiers to be hit after instead of with a chord,
22+
and enables select keys to be placed before auto-spaces.
23+
items:
24+
- id: 0x51
25+
name: enable
26+
range: [0, 1]
27+
- id: 0x54
28+
name: timeout
29+
range: [0, 2550]
30+
step: 10
31+
unit: ms
32+
- name: keyboard
33+
items:
34+
- id: 0x11
35+
name: enable
36+
range: [0, 1]
37+
- id: 0x12
38+
name: character entry
39+
range: [0, 1]
40+
- id: 0x13
41+
name: command option swap
42+
range: [0, 1]
43+
description: |
44+
Swaps ⌥ and ⌘ to make transitioning between Mac and other systems easier.
45+
- id: 0x14
46+
name: poll rate
47+
range: [0, 255]
48+
unit: Hz
49+
inverse: 1000
50+
- id: 0x15
51+
name: debounce press
52+
range: [0, 255]
53+
unit: ms
54+
- id: 0x16
55+
name: debounce release
56+
range: [0, 255]
57+
unit: ms
58+
- id: 0x17
59+
name: output delay
60+
range: [0, 10200]
61+
step: 40
62+
unit: µs
63+
- name: mouse
64+
items:
65+
- id: 0x21
66+
name: enable
67+
range: [0, 1]
68+
- id: 0x22
69+
name: slow speed
70+
range: [0, 255]
71+
unit: px
72+
- id: 0x23
73+
name: fast speed
74+
range: [0, 255]
75+
unit: px
76+
- id: 0x24
77+
name: caffeine
78+
range: [0, 1]
79+
description: |
80+
Keeps computer alive by moving the mouse back and forth one pixel every 60s
81+
- id: 0x25
82+
name: scroll speed
83+
range: [0, 255]
84+
unit: pg
85+
- id: 0x26
86+
name: poll rate
87+
range: [0, 255]
88+
unit: Hz
89+
inverse: 1000
90+
- name: chording
91+
items:
92+
- id: 0x31
93+
name: enable
94+
range: [0, 1]
95+
- id: 0x33
96+
name: auto delete timeout
97+
range: [0, 25500]
98+
step: 100
99+
- id: 0x34
100+
name: press tolerance
101+
description: |
102+
Scales with the number of chord inputs.
103+
range: [0, 255]
104+
unit: ms
105+
- id: 0x35
106+
name: release tolerance
107+
description: |
108+
Scales with the number of chord inputs.
109+
range: [0, 255]
110+
unit: ms
111+
- name: leds
112+
items:
113+
- id: 0x84
114+
name: enable
115+
range: [0, 1]
116+
- id: 0x81
117+
name: brightness
118+
range: [0, 50]
119+
- id: 0x82
120+
name: base color code
121+
enum:
122+
white: 0
123+
red: 1
124+
orange: 2
125+
yellow: 3
126+
charteuse: 4
127+
green: 5
128+
spring green: 6
129+
cyan: 7
130+
azure: 8
131+
blue: 9
132+
violet: 10
133+
magenta: 11
134+
rose: 12
135+
rainbow: 13
136+
- id: 0x83
137+
name: highlight
138+
range: [0, 1]
139+
- name: misc
140+
items:
141+
- id: 0x91
142+
name: operating system
143+
enum:
144+
windows: 0
145+
mac: 1
146+
linux: 2
147+
ios: 3
148+
android: 4
149+
- id: 0x92
150+
name: GTM realtime feedback
151+
range: [0, 1]
152+
- id: 0x93
153+
name: startup message
154+
range: [0, 1]

src/lib/meta/meta-storage.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RawVersionMeta, VersionMeta } from "./types/meta";
1+
import type { RawVersionMeta, SettingsMeta, VersionMeta } from "./types/meta";
22
import type { Listing } from "./types/listing";
33
import type { KeymapCategory } from "./types/actions";
44
import { browser } from "$app/environment";
@@ -9,23 +9,27 @@ export async function getMeta(
99
device: string,
1010
version: string,
1111
fetch: typeof window.fetch = window.fetch,
12-
): Promise<VersionMeta | undefined> {
12+
): Promise<VersionMeta> {
1313
while (lock) await lock;
1414
let resolveLock!: () => void;
1515
lock = new Promise((resolve) => (resolveLock = resolve));
1616

1717
try {
1818
if (!browser) return fetchMeta(device, version, fetch);
1919

20-
const dbRequest = indexedDB.open("version-meta", 1);
20+
const dbRequest = indexedDB.open("version-meta", 2);
2121
const db = await new Promise<IDBDatabase>((resolve, reject) => {
2222
dbRequest.onsuccess = () => resolve(dbRequest.result);
2323
dbRequest.onerror = () => reject(dbRequest.error);
2424
dbRequest.onupgradeneeded = () => {
2525
const db = dbRequest.result;
26+
if (db.objectStoreNames.contains("meta")) {
27+
db.deleteObjectStore("meta");
28+
}
2629
db.createObjectStore("meta", { keyPath: ["device", "version"] });
2730
};
2831
});
32+
console.log("upgrading version meta db");
2933

3034
try {
3135
const readTransaction = db.transaction(["meta"], "readonly");
@@ -39,7 +43,6 @@ export async function getMeta(
3943
if (item) return item;
4044

4145
const meta = await fetchMeta(device, version);
42-
if (!meta) return undefined;
4346

4447
const putTransaction = db.transaction(["meta"], "readwrite");
4548
const putStore = putTransaction.objectStore("meta");
@@ -60,7 +63,7 @@ export async function getMeta(
6063
resolveLock();
6164
lock = undefined;
6265
}
63-
return undefined;
66+
return fetchMeta(device, version, fetch);
6467
}
6568

6669
async function fetchMeta(
@@ -69,7 +72,9 @@ async function fetchMeta(
6972
fetch: typeof window.fetch = window.fetch,
7073
): Promise<VersionMeta> {
7174
const path = `${import.meta.env.VITE_FIRMWARE_URL}/${device}/${version}`;
72-
const files: Listing[] = await fetch(`${path}/`).then((res) => res.json());
75+
const files: Listing[] = await fetch(`${path}/`)
76+
.then((res) => res.json())
77+
.catch(() => []);
7378
const meta: Partial<RawVersionMeta> | undefined = files.some(
7479
(entry) => entry.type === "file" && entry.name === "meta.json",
7580
)
@@ -105,6 +110,16 @@ async function fetchMeta(
105110
),
106111
}
107112
: undefined,
113+
settings: await (meta?.settings
114+
? fetch(`${path}/${meta.settings}`).then((it) => it.json())
115+
: import("$lib/assets/settings.yml")
116+
.then((it) => (it as any).default)
117+
.then((settings: SettingsMeta[]) => {
118+
if (!device.startsWith("lite_")) {
119+
settings = settings.filter((it) => it.name === "leds");
120+
}
121+
return settings;
122+
})),
108123
actions: await (meta?.actions
109124
? fetch(`${path}/${meta.actions}`).then((it) => it.json())
110125
: Promise.all<KeymapCategory[]>(

src/lib/meta/types/meta.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ import type {
55
} from "$lib/share/chara-file";
66
import type { KeymapCategory } from "./actions";
77

8+
export interface SettingsMeta {
9+
name: string;
10+
description?: string;
11+
items: SettingsItemMeta[];
12+
}
13+
14+
export interface SettingsItemMeta {
15+
id: number;
16+
description?: string;
17+
enum?: string[];
18+
range: [number, number];
19+
step?: number;
20+
unit?: string;
21+
inverse?: number;
22+
scale?: number;
23+
}
24+
825
export interface RawVersionMeta {
926
version: string;
1027
target: string;
@@ -14,6 +31,7 @@ export interface RawVersionMeta {
1431
public_build: boolean;
1532
development_mode: number;
1633
actions: string;
34+
settings: string;
1735
factory_defaults: {
1836
layout: string;
1937
settings: string;
@@ -38,6 +56,7 @@ export interface VersionMeta {
3856
dirty: boolean;
3957
developmentBuild: boolean;
4058
actions: KeymapCategory[];
59+
settings: SettingsMeta[];
4160
factoryDefaults?: {
4261
layout: CharaLayoutFile;
4362
settings: CharaSettingsFile;

0 commit comments

Comments
 (0)