初步添加了标定支持,需要完善和测试

This commit is contained in:
lennlouisgeek
2026-04-07 01:46:37 +08:00
parent aeb17f194c
commit 770d713d03
19 changed files with 1599 additions and 489 deletions

View File

@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<link rel="icon" href="data:," />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Tauri + SvelteKit + Typescript App</title>
%sveltekit.head%

File diff suppressed because it is too large Load Diff

View File

@@ -40,6 +40,18 @@
dtsMs: number;
}
type CalibrationMethodId = "coarse";
interface CalibrationStartPayload {
methodId: CalibrationMethodId;
rounds: number;
}
interface CalibrationInvokeResult {
success: boolean;
message: string;
}
const copyByLocale: Record<LocaleCode, HudCopy> = {
"zh-CN": {
appName: "JE-Skin",
@@ -159,6 +171,7 @@
const summaryPointsPerSeries = 42;
const signalRenderTickMs = 1200;
const replayDefaultFrameMs = 40;
const defaultCalibrationTargetFrames = 100;
const showSignalPanels = false;
const mockToneCycle: SignalTone[] = ["cyan", "lime", "orange", "violet", "gold", "rose"];
@@ -205,6 +218,7 @@
let activeConfigLinkId = "stream-on";
let isConfigPanelOpen = false;
let isPrecisionTestOpen = false;
let isCalibrationTestOpen = false;
let hasSignalData = false;
let signalPanels: HudSignalPanel[] = buildInactivePanels();
let summary: HudSummary = buildEmptySummary();
@@ -233,7 +247,7 @@
let fileExplorerFileName = "";
$: uiCopy = copyByLocale[locale];
$: configLinks = buildConfigLinks(locale, activeConfigLinkId, isConfigPanelOpen, isPrecisionTestOpen);
$: configLinks = buildConfigLinks(locale, activeConfigLinkId, isConfigPanelOpen, isPrecisionTestOpen, isCalibrationTestOpen);
$: stageStatusText = webglStatusTone === "ok" ? uiCopy.runtimeReady : uiCopy.runtimeFallback;
$: leftSignalPanels = signalPanels.filter((panel) => panel.side === "left");
$: rightSignalPanels = signalPanels.filter((panel) => panel.side === "right");
@@ -975,7 +989,8 @@
currentLocale: LocaleCode,
activeId: string,
isSettingsOpen: boolean,
isPrecisionOpen: boolean
isPrecisionOpen: boolean,
isCalibrationOpen: boolean
): HudConfigLink[] {
const labels =
currentLocale === "zh-CN"
@@ -1011,7 +1026,7 @@
id: "calibrate",
label: labels.calibrate,
tone: "cyan",
active: activeId === "calibrate"
active: isCalibrationOpen
},
{
id: "precision-test",
@@ -1460,19 +1475,80 @@
if (event.detail === "precision-test") {
isPrecisionTestOpen = !isPrecisionTestOpen;
isConfigPanelOpen = false;
isCalibrationTestOpen = false;
return;
}
if (event.detail === "calibrate") {
isCalibrationTestOpen = !isCalibrationTestOpen;
isConfigPanelOpen = false;
isPrecisionTestOpen = false;
return;
}
if (event.detail === "settings") {
isPrecisionTestOpen = false;
isCalibrationTestOpen = false;
isConfigPanelOpen = !isConfigPanelOpen;
return;
}
isPrecisionTestOpen = false;
isCalibrationTestOpen = false;
isConfigPanelOpen = false;
activeConfigLinkId = event.detail;
console.info("[hud] config link clicked:", event.detail);
}
async function handleCalibrationStart(event: CustomEvent<CalibrationStartPayload>): Promise<void> {
const targetRounds = clamp(Math.round(Number(event.detail.rounds) || 1), 1, 20);
if (!isTauriRuntime()) {
connectionNotice =
locale === "zh-CN"
? `当前运行环境不支持启动标定(目标 ${targetRounds} 轮)。`
: `Current runtime does not support calibration start (${targetRounds} rounds).`;
connectionNoticeTone = "warn";
return;
}
if (!serialPortValue) {
connectionNotice =
locale === "zh-CN" ? "请先选择串口,再启动标定。" : "Please select a serial port before starting calibration.";
connectionNoticeTone = "warn";
return;
}
if (event.detail.methodId !== "coarse") {
connectionNotice =
locale === "zh-CN" ? "当前标定方法暂未接入后端。" : "Selected calibration method is not wired to backend yet.";
connectionNoticeTone = "warn";
return;
}
try {
const result = await invoke<CalibrationInvokeResult>("serial_calibrate_with_coarse", {
port: serialPortValue,
targetFrames: defaultCalibrationTargetFrames,
maxRounds: targetRounds
});
if (result.success) {
connectionNotice =
locale === "zh-CN"
? `粗标定已启动:目标 ${targetRounds} 轮(每轮 ${defaultCalibrationTargetFrames} 帧)`
: `Coarse calibration started: ${targetRounds} rounds (${defaultCalibrationTargetFrames} frames/round)`;
connectionNoticeTone = "ok";
} else {
connectionNotice = result.message;
connectionNoticeTone = "warn";
}
} catch (error) {
const fallback =
locale === "zh-CN" ? "启动粗标定失败,请检查串口连接状态。" : "Failed to start coarse calibration.";
connectionNotice = normalizeInvokeError(error) || fallback;
connectionNoticeTone = "warn";
console.error("Calibration start failed:", error);
}
}
async function handleWindowControl(event: CustomEvent<WindowControlAction>): Promise<void> {
@@ -1623,6 +1699,7 @@
{pressureMatrix}
showConfigPanel={isConfigPanelOpen}
showPrecisionTestPanel={isPrecisionTestOpen}
showCalibrationPanel={isCalibrationTestOpen}
{summary}
on:replaytoggle={handleReplayToggle}
on:replaystop={handleReplayStop}
@@ -1630,8 +1707,10 @@
on:replayspeed={handleReplaySpeed}
on:replayclose={handleReplayClose}
on:configclose={() => (isConfigPanelOpen = false)}
on:calibrationclose={() => (isCalibrationTestOpen = false)}
on:calibrationstart={handleCalibrationStart}
>
{#if !isPrecisionTestOpen}
{#if !isPrecisionTestOpen && !isCalibrationTestOpen}
<section class="range-scale" aria-label="Signal Range">
<p class="range-label">Range</p>
<div class="range-track">