mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-04-23 14:49:00 +00:00
feat: use progress api
This commit is contained in:
@@ -8,6 +8,7 @@ import { userPreferences } from "$lib/preferences";
|
||||
import { getMeta } from "$lib/meta/meta-storage";
|
||||
import type { VersionMeta } from "$lib/meta/types/meta";
|
||||
import { serial as serialPolyfill } from "web-serial-polyfill";
|
||||
import semverGte from "semver/functions/gte";
|
||||
|
||||
export const serialPort = writable<CharaDevice | undefined>();
|
||||
|
||||
@@ -91,6 +92,20 @@ export async function initSerial(port: SerialPortLike, withSync: boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function waitForDevice(device: CharaDevice) {
|
||||
if (semverGte(device.version, "3.1.0")) {
|
||||
const startProgress = await device.getProgress();
|
||||
let total = startProgress;
|
||||
while (total < 1.0) {
|
||||
total = await device.getProgress();
|
||||
syncProgress.set({
|
||||
max: 1.0 - startProgress,
|
||||
current: total - startProgress,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function sync() {
|
||||
const device = get(serialPort);
|
||||
if (!device) return;
|
||||
@@ -100,6 +115,9 @@ export async function sync() {
|
||||
device.version.toString(),
|
||||
);
|
||||
deviceMeta.set(meta);
|
||||
|
||||
await waitForDevice(device);
|
||||
|
||||
const chordCount = await device.getChordCount();
|
||||
|
||||
const maxSettings = meta.settings
|
||||
|
||||
@@ -143,7 +143,7 @@ export class CharaDevice {
|
||||
|
||||
constructor(
|
||||
readonly port: SerialPortLike,
|
||||
public baudRate = 115200,
|
||||
public baudRate = 921600,
|
||||
) {}
|
||||
|
||||
async init() {
|
||||
@@ -390,6 +390,11 @@ export class CharaDevice {
|
||||
if (status !== "0") throw new Error(`Failed with status ${status}`);
|
||||
}
|
||||
|
||||
async getProgress() {
|
||||
const [status] = await this.send(1, ["CML", "C5"]);
|
||||
return Number.parseFloat(status);
|
||||
}
|
||||
|
||||
async deleteChord(chord: Pick<Chord, "actions">) {
|
||||
const status = await this.send(1, [
|
||||
"CML",
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
sync,
|
||||
syncProgress,
|
||||
syncStatus,
|
||||
waitForDevice,
|
||||
} from "$lib/serial/connection";
|
||||
import ProgressButton from "$lib/ProgressButton.svelte";
|
||||
import { tick } from "svelte";
|
||||
@@ -136,6 +137,7 @@
|
||||
empty.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
changes.update((changes) => {
|
||||
changes.push([
|
||||
...empty.keys().map(
|
||||
@@ -242,6 +244,8 @@
|
||||
|
||||
let progressCurrent = 0;
|
||||
|
||||
await waitForDevice(port);
|
||||
|
||||
function updateProgress() {
|
||||
syncProgress.set({
|
||||
max: progressMax,
|
||||
|
||||
Reference in New Issue
Block a user