推进 INI 面板快照 G-code 运行选择
This commit is contained in:
@@ -110,6 +110,7 @@ const fields = {
|
||||
let iniSdk = null;
|
||||
let interpSdk = null;
|
||||
let loadedSession = null;
|
||||
let restoredSessionSnapshot = null;
|
||||
let canonicalEventText = "";
|
||||
let runPlaybackTimer = null;
|
||||
|
||||
@@ -310,6 +311,26 @@ function syncEditorToWasmFs() {
|
||||
requireIniSdk().writeTextFile(WASM_FILE, editor.value);
|
||||
}
|
||||
|
||||
function gcodeFilenameFromSnapshotPath(path) {
|
||||
const prefix = "linuxcnc/gcode/";
|
||||
if (typeof path !== "string" || !path.startsWith(prefix)) {
|
||||
return GCODE_FILENAME;
|
||||
}
|
||||
const filename = path.slice(prefix.length);
|
||||
return filename || GCODE_FILENAME;
|
||||
}
|
||||
|
||||
async function loadSelectedGcodeProgram() {
|
||||
const opfsPath = restoredSessionSnapshot?.payload?.files?.gcode;
|
||||
const filename = gcodeFilenameFromSnapshotPath(opfsPath);
|
||||
return {
|
||||
filename,
|
||||
opfsPath: opfsPath ?? `linuxcnc/gcode/${filename}`,
|
||||
wasmPath: GCODE_WASM_FILE,
|
||||
text: await loadGcodeProgram(filename),
|
||||
};
|
||||
}
|
||||
|
||||
async function restoreSessionSnapshotToEditor() {
|
||||
const snapshot = await loadMachineSessionSnapshot(
|
||||
SESSION_SNAPSHOT_ID,
|
||||
@@ -323,6 +344,7 @@ async function restoreSessionSnapshotToEditor() {
|
||||
setField("sessionToolTable", snapshot.payload.files.toolTable);
|
||||
setField("sessionGcode", snapshot.payload.files.gcode);
|
||||
setField("sessionSnapshot", `${snapshot.sessionId}/${SESSION_SNAPSHOT_FILENAME}`);
|
||||
restoredSessionSnapshot = snapshot;
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
@@ -556,21 +578,21 @@ document.getElementById("run-gcode").addEventListener("click", async () => {
|
||||
throw new Error("Load a machine session before running G-code.");
|
||||
}
|
||||
const interp = requireInterpSdk();
|
||||
const programText = await loadGcodeProgram(GCODE_FILENAME);
|
||||
interp.writeTextFile(GCODE_WASM_FILE, programText);
|
||||
const program = await loadSelectedGcodeProgram();
|
||||
interp.writeTextFile(program.wasmPath, program.text);
|
||||
clearRunPlayback();
|
||||
setField("runStatus", "running");
|
||||
setRunMonitor(5, "running", {}, "running");
|
||||
await nextFrame();
|
||||
const result = interp.runFileWithIni(GCODE_WASM_FILE, loadedSession.ini.wasmPath);
|
||||
setField("sessionGcode", GCODE_WASM_FILE);
|
||||
const result = interp.runFileWithIni(program.wasmPath, loadedSession.ini.wasmPath);
|
||||
setField("sessionGcode", program.opfsPath);
|
||||
setField("runStatus", "ok");
|
||||
setCanonicalEvents(result.trim());
|
||||
playRunMotion(result.trim(), programText);
|
||||
playRunMotion(result.trim(), program.text);
|
||||
setLog(
|
||||
[
|
||||
"Ran G-code through LinuxCNC interpreter WASM.",
|
||||
`Program: ${GCODE_WASM_FILE}`,
|
||||
`Program: ${program.opfsPath} -> ${program.wasmPath}`,
|
||||
`INI: ${loadedSession.ini.wasmPath}`,
|
||||
result.trim(),
|
||||
].join("\n"),
|
||||
|
||||
Reference in New Issue
Block a user