mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-02-14 05:02:42 +00:00
refactor: use standard prettier formatting
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
import {get, writable} from "svelte/store"
|
||||
import {CharaDevice} from "$lib/serial/device"
|
||||
import type {Chord} from "$lib/serial/chord"
|
||||
import type {Writable} from "svelte/store"
|
||||
import type {CharaLayout} from "$lib/serialization/layout"
|
||||
import {persistentWritable} from "$lib/storage"
|
||||
import {userPreferences} from "$lib/preferences"
|
||||
import settingInfo from "$lib/assets/settings.yml"
|
||||
import { get, writable } from "svelte/store";
|
||||
import { CharaDevice } from "$lib/serial/device";
|
||||
import type { Chord } from "$lib/serial/chord";
|
||||
import type { Writable } from "svelte/store";
|
||||
import type { CharaLayout } from "$lib/serialization/layout";
|
||||
import { persistentWritable } from "$lib/storage";
|
||||
import { userPreferences } from "$lib/preferences";
|
||||
import settingInfo from "$lib/assets/settings.yml";
|
||||
|
||||
export const serialPort = writable<CharaDevice | undefined>()
|
||||
export const serialPort = writable<CharaDevice | undefined>();
|
||||
|
||||
export interface SerialLogEntry {
|
||||
type: "input" | "output" | "system"
|
||||
value: string
|
||||
type: "input" | "output" | "system";
|
||||
value: string;
|
||||
}
|
||||
|
||||
export const serialLog = writable<SerialLogEntry[]>([])
|
||||
export const serialLog = writable<SerialLogEntry[]>([]);
|
||||
|
||||
/**
|
||||
* Chords as read from the device
|
||||
@@ -23,7 +23,7 @@ export const deviceChords = persistentWritable<Chord[]>(
|
||||
"chord-library",
|
||||
[],
|
||||
() => get(userPreferences).backup,
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Layout as read from the device
|
||||
@@ -32,7 +32,7 @@ export const deviceLayout = persistentWritable<CharaLayout>(
|
||||
"layout",
|
||||
[[], [], []],
|
||||
() => get(userPreferences).backup,
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings as read from the device
|
||||
@@ -41,61 +41,66 @@ export const deviceSettings = persistentWritable<number[]>(
|
||||
"device-settings",
|
||||
[],
|
||||
() => get(userPreferences).backup,
|
||||
)
|
||||
);
|
||||
|
||||
export const syncStatus: Writable<"done" | "error" | "downloading" | "uploading"> = writable("done")
|
||||
export const syncStatus: Writable<
|
||||
"done" | "error" | "downloading" | "uploading"
|
||||
> = writable("done");
|
||||
|
||||
export interface ProgressInfo {
|
||||
max: number
|
||||
current: number
|
||||
max: number;
|
||||
current: number;
|
||||
}
|
||||
export const syncProgress = writable<ProgressInfo | undefined>(undefined)
|
||||
export const syncProgress = writable<ProgressInfo | undefined>(undefined);
|
||||
|
||||
export async function initSerial(manual = false) {
|
||||
const device = get(serialPort) ?? new CharaDevice()
|
||||
await device.init(manual)
|
||||
serialPort.set(device)
|
||||
sync()
|
||||
const device = get(serialPort) ?? new CharaDevice();
|
||||
await device.init(manual);
|
||||
serialPort.set(device);
|
||||
sync();
|
||||
}
|
||||
|
||||
export async function sync() {
|
||||
const device = get(serialPort)
|
||||
if (!device) return
|
||||
const chordCount = await device.getChordCount()
|
||||
syncStatus.set("downloading")
|
||||
const device = get(serialPort);
|
||||
if (!device) return;
|
||||
const chordCount = await device.getChordCount();
|
||||
syncStatus.set("downloading");
|
||||
|
||||
const max = Object.keys(settingInfo.settings).length + device.keyCount * 3 + chordCount
|
||||
let current = 0
|
||||
syncProgress.set({max, current})
|
||||
const max =
|
||||
Object.keys(settingInfo.settings).length + device.keyCount * 3 + chordCount;
|
||||
let current = 0;
|
||||
syncProgress.set({ max, current });
|
||||
function progressTick() {
|
||||
current++
|
||||
syncProgress.set({max, current})
|
||||
current++;
|
||||
syncProgress.set({ max, current });
|
||||
}
|
||||
|
||||
const parsedSettings: number[] = []
|
||||
const parsedSettings: number[] = [];
|
||||
for (const key in settingInfo.settings) {
|
||||
try {
|
||||
parsedSettings[Number.parseInt(key)] = await device.getSetting(Number.parseInt(key))
|
||||
parsedSettings[Number.parseInt(key)] = await device.getSetting(
|
||||
Number.parseInt(key),
|
||||
);
|
||||
} catch {}
|
||||
progressTick()
|
||||
progressTick();
|
||||
}
|
||||
deviceSettings.set(parsedSettings)
|
||||
deviceSettings.set(parsedSettings);
|
||||
|
||||
const parsedLayout: CharaLayout = [[], [], []]
|
||||
const parsedLayout: CharaLayout = [[], [], []];
|
||||
for (let layer = 1; layer <= 3; layer++) {
|
||||
for (let i = 0; i < device.keyCount; i++) {
|
||||
parsedLayout[layer - 1][i] = await device.getLayoutKey(layer, i)
|
||||
progressTick()
|
||||
parsedLayout[layer - 1][i] = await device.getLayoutKey(layer, i);
|
||||
progressTick();
|
||||
}
|
||||
}
|
||||
deviceLayout.set(parsedLayout)
|
||||
deviceLayout.set(parsedLayout);
|
||||
|
||||
const chordInfo = []
|
||||
const chordInfo = [];
|
||||
for (let i = 0; i < chordCount; i++) {
|
||||
chordInfo.push(await device.getChord(i))
|
||||
progressTick()
|
||||
chordInfo.push(await device.getChord(i));
|
||||
progressTick();
|
||||
}
|
||||
deviceChords.set(chordInfo)
|
||||
syncStatus.set("done")
|
||||
syncProgress.set(undefined)
|
||||
deviceChords.set(chordInfo);
|
||||
syncStatus.set("done");
|
||||
syncProgress.set(undefined);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user