Fix Read .grbl

This commit is contained in:
chk
2026-06-14 13:57:02 +02:00
parent c68ce406a6
commit 551dded4dc
3 changed files with 28 additions and 3 deletions

View File

@@ -47,7 +47,8 @@ class ActiveState {
}
}
/** API-Repräsentation (ActiveState). currentLine = driver-nativ (Radian). */
/** API-Repräsentation (ActiveState). currentLine = driver-nativ (Radian);
* lines = volle Programmliste in GRAD (wie gespeichert) — für die Anzeige (FShow). */
getState() {
const currentLine = this.lines.length ? units.toExecutable(this.lines[this.cursor]) : null;
return {
@@ -55,11 +56,19 @@ class ActiveState {
cursor: this.cursor,
lineCount: this.lines.length,
currentLine,
lines: this.lines,
playing: this.playing,
version: this.version,
};
}
/** FShow: lädt bei Bedarf das Default-Programm (Lesen mit implizitem log) und
* liefert den vollen Zustand inkl. Zeilenliste. */
async show() {
await this._ensureActive();
return this.getState();
}
/**
* Setzt ein Programm aktiv (FLoad). Existiert es nicht, wird es leer angelegt
* (nötig für Teaching). Ein vorher aktives Programm wird zuvor persistiert.

View File

@@ -9,8 +9,8 @@ const { ApiError } = require('../errors');
const router = express.Router();
const asyncH = (fn) => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
// GET /api/active
router.get('/', (req, res) => res.json(active.getState()));
// GET /api/active (FShow) — lädt bei Bedarf das Default-Programm, liefert volle Liste
router.get('/', asyncH(async (req, res) => res.json(await active.show())));
// PUT /api/active (FLoad) — existiert nicht → leer anlegen (für Teaching)
router.put(