diff --git a/unleashed-x-kaos/config/kaos-ams-bridge.cfg b/unleashed-x-kaos/config/kaos-ams-bridge.cfg index bbb8a17..bf299f7 100644 --- a/unleashed-x-kaos/config/kaos-ams-bridge.cfg +++ b/unleashed-x-kaos/config/kaos-ams-bridge.cfg @@ -118,6 +118,10 @@ gcode: description: magic_ams tool-change entry - arms the ORCA_PURGE handoff and hands over to the spit tail gcode: {% set ams = printer.save_variables.variables.ams|default(0)|int %} + # Read the caller's extrusion mode once, before either branch touches it. Jinja renders the whole + # body before the first command runs, so this is the mode on entry -- which is what both branches + # need to hand back. + {% set was_abs_e = printer.gcode_move.absolute_extrude %} {% if ams == 1 %} # ALWAYS drop a stale handoff first. A leftover active=1 from a tool change that # never reached its spit tail would otherwise fire ORCA_PURGE at the wrong moment. @@ -149,6 +153,10 @@ gcode: # standing "G1 E-1 before M83" latent defect on this path. M83 G1 E-1 F3600 + # ...and hand the mode back. Setting M83 and keeping it would be worse than the defect it + # fixes: a slicer running absolute E would have every extrusion after the first tool change + # reinterpreted as relative, for the rest of the print. + {% if was_abs_e %}M82{% endif %} # --- Stage 3: hand the purge to ORCA_PURGE -------------------- # Refresh the fan/temp mirrors ORCA_PURGE restores at the end. Runs as a @@ -174,8 +182,11 @@ gcode: # is sticky per klippy session, so it MUST be re-sent on every change. P10 S2 {% else %} - # No AMS attached: the kit's manual-swap fallback (byte-identical to stock). + # No AMS attached: the kit's manual-swap fallback. It used to be byte-identical to stock, + # which is why it carried the bare retract; the kit has since fixed that, so this follows. + M83 G1 E-1 F3600 + {% if was_abs_e %}M82{% endif %} M118 No AMS -> manual filament change (M600: unload -> swap -> load -> purge -> resume) M600 {% endif %} diff --git a/unleashed-x-kaos/scripts/kaos-guard.sh b/unleashed-x-kaos/scripts/kaos-guard.sh index f82b034..f58106f 100755 --- a/unleashed-x-kaos/scripts/kaos-guard.sh +++ b/unleashed-x-kaos/scripts/kaos-guard.sh @@ -77,6 +77,28 @@ restore_stock_dev_py() { # printer.cfg, a Phrozen update replacing one file but not the other); the include line is # ground truth for which macro set is loading. This is what makes every half-state # self-heal on the next boot instead of persisting silently. +# Our own bridge configs are copied into printer_data/config when KAOS is ACTIVATED, and never +# again. A kit update refreshes $SELF_DIR/config (it is inside the kit clone) but not the copies, +# so a printer that has had KAOS on since before an update keeps running the old ones -- the same +# "the correction never reaches the printer" shape this project keeps meeting. Keyed on the include +# line actually present in printer.cfg, like sync_spit_patch above: a file whose include is gone is +# not put back, so KAOS_OFF stays off. KAOS's OWN files come from $CACHE and are not touched here. +sync_bridge_configs() { + [ -d "$SELF_DIR/config" ] && [ -f "$PRINTER_CFG" ] || return 0 + local src name + for src in "$SELF_DIR"/config/*.cfg; do + [ -f "$src" ] || continue + name="$(basename "$src")" + grep -qE "^[[:space:]]*\[include[[:space:]]+${name//./\.}\]" "$PRINTER_CFG" 2>/dev/null || continue + cmp -s "$src" "$CONFIG_DIR/$name" && continue + if cp -f "$src" "$CONFIG_DIR/$name"; then + log "refreshed $name from the kit — the installed copy was older than this kit" + else + log "WARNING - could not refresh $name" + fi + done +} + sync_spit_patch() { [ -f "$SPIT_PATCH" ] && [ -f "$PGM" ] && [ -f "$PRINTER_CFG" ] || return 0 local want r @@ -141,7 +163,11 @@ sync_home_hook() { # --------------------------------------------------------------------------- [ -d "$EXTRAS" ] || exit 0 # not an Arco / nothing to guard -# Both run on EVERY path, including the two early exits below. +# All three run on EVERY path, including the two early exits below. +# Refresh our own bridge configs BEFORE the spit patch reconciles: that patch renames a macro in +# printer_gcode_macro.cfg to match what the bridge declares, so the bridge has to be the current +# one first or the two describe different files. +sync_bridge_configs sync_spit_patch sync_home_hook