From cfc14643d2c07523ddb0331ae5744c5f5c580a14 Mon Sep 17 00:00:00 2001 From: muehe Date: Fri, 1 May 2026 16:16:51 +0200 Subject: [PATCH] control: home W last in 'Home All' Previously XYZ and W homing dispatched in parallel. Wait for the main AVR homing cycle to return to idle before kicking off the W auxcnc home so they never run simultaneously. --- src/js/control-view.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/js/control-view.js b/src/js/control-view.js index 3603216..c9b53b8 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -255,19 +255,32 @@ module.exports = { }); }, - // Home every enabled axis at once (legacy Onefinity behavior). - // The XYZ home is fired first via the standard /api/home endpoint, - // then the W axis is homed if it is enabled. The two cycles run - // in parallel — W is on the auxcnc ESP and doesn't share motors - // with the AVR — so the user sees one click homing everything. - home_all: function () { + // Home every enabled axis (legacy Onefinity "Home All"). Sequence: + // 1. Z, X, Y (and A/B/C if enabled) via /api/home on the AVR + // 2. W axis via /api/aux/home on the ESP + // The two cycles are dispatched serially: we wait for the main + // homing cycle to drop back to idle before kicking off W so the + // gantry never moves while the W spindle is also homing. + home_all: async function () { this.ask_home = false; - api.put("home"); - if (this.w && this.w.enabled) { - api.put("aux/home").catch(function (err) { - console.error("W home failed:", err); - }); + try { + await api.put("home"); + } catch (e) { + console.error("Home all (XYZ) failed:", e); + return; } + if (!this.w || !this.w.enabled) return; + // Poll state.cycle until the main homing cycle finishes. The + // homing cycle leaves state.cycle as 'homing' until done, then + // returns to 'idle'. + const start = Date.now(); + while (Date.now() - start < 120000) { + if (this.state && this.state.cycle == "idle") break; + await new Promise(r => setTimeout(r, 200)); + } + api.put("aux/home").catch(function (err) { + console.error("W home failed:", err); + }); }, aux_jog: function (delta_mm) {