feat: settings wip

This commit is contained in:
2023-07-24 22:58:10 +02:00
parent e64082d578
commit 2130b6c7b9
10 changed files with 338 additions and 164 deletions

View File

@@ -2,6 +2,7 @@ import {LineBreakTransformer} from "$lib/serial/line-break-transformer"
import {serialLog} from "$lib/serial/connection"
import type {Chord} from "$lib/serial/chord"
import {parseChordActions, parsePhrase, stringifyChordActions, stringifyPhrase} from "$lib/serial/chord"
import {dev} from "$app/environment"
export const VENDOR_ID = 0x239a
@@ -24,8 +25,10 @@ export class CharaDevice {
private lock?: Promise<true>
version!: string
deviceId!: string
version!: [number, number, number]
company!: "CHARACHORDER"
device!: "ONE" | "LITE"
chipset!: "M0" | "S2"
constructor(private readonly baudRate = 115200) {}
@@ -58,8 +61,12 @@ export class CharaDevice {
})
.getReader()
this.version = await this.send("VERSION").then(it => it[0])
this.deviceId = await this.send("ID").then(it => it[0])
const [version] = await this.send("VERSION")
this.version = version.split(".").map(Number) as [number, number, number]
const [company, device, chipset] = await this.send("ID")
this.company = company as "CHARACHORDER"
this.device = device as "ONE" | "LITE"
this.chipset = chipset as "M0" | "S2"
}
private async internalRead() {

View File

@@ -1,41 +0,0 @@
export interface DeviceSettings {
enableSerialLog: boolean
enableSerialRaw: boolean
enableSerialChord: boolean
enableSerialKeyboard: boolean
enableSerialMouse: boolean
enableSerialDebug: boolean
enableSerialHeader: boolean
enableHidKeyboard: boolean
pressThreshold: number
releaseThreshold: number
enableHidMouse: number
scrollDelay: number
enableSpurring: boolean
spurKillerToggle: number
spurKiller: number
enableChording: boolean
charKillerToggle: number
charCounterKiller: number
}
export const SETTING_IDS: Record<keyof DeviceSettings, number> = {
enableSerialLog: 0x01,
enableSerialRaw: 0x02,
enableSerialChord: 0x03,
enableSerialKeyboard: 0x04,
enableSerialMouse: 0x05,
enableSerialDebug: 0x06,
enableSerialHeader: 0x07,
enableHidKeyboard: 0x0a,
pressThreshold: 0x0b,
releaseThreshold: 0x0c,
enableHidMouse: 0x14,
scrollDelay: 0x15,
enableSpurring: 0x1e,
spurKillerToggle: 0x1f,
spurKiller: 0x20,
enableChording: 0x28,
charKillerToggle: 0x29,
charCounterKiller: 0x2a,
}