From 19c70ebeb8480c34c85b6c7b168085da819944a3 Mon Sep 17 00:00:00 2001 From: MangaValk Date: Fri, 6 Nov 2026 20:58:17 +0100 Subject: [PATCH] Purge check: stop an infinite spool swap when the check fails An AFC swap pauses and resumes the file without the PAUSE and RESUME macros and only stops on AFC's own error state. A failed check called PAUSE, so the swap went on and restarted the print while the printer counted as paused. During a swap (file paused, pause_resume not paused) the check now raises an error at the end of BLOBIFIER_CHECKED, after the temperature and sensor cleanup. CHANGE_TOOL catches it and pauses through AFC_error. AFC's remap is skipped, so the message names the SET_MAP command. Other failed checks still call PAUSE. Read from AFC 5ea84ea and Klipper 0cee841; render tests only, not yet run on the printer. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 4 ++++ macros/afc/purge_check.cfg | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index a108c07..8b4e70d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -62,6 +62,10 @@ detection, `filament_error_sensitivity`), iHeater chamber heater. calls `_BED_CHECK_RETRY`, which sets the print file back to the `PRINT_START` line (`M26`) and resumes. Everything after the check belongs in `_PRINT_START_FINISH`: a pause does not stop a running macro. +- An AFC infinite spool swap pauses and resumes the file without the PAUSE and + RESUME macros and only stops on AFC's own error state, so PAUSE cannot stop it. + During a swap `print_stats.state` is paused with `pause_resume.is_paused` False; + a failed purge check then raises an error (`_PURGE_CHECK_SWAP_STOP`). - Only one `[save_variables]`, in `macros/save_variables.cfg`. - PA values are saved per nozzle and spool (`pa_value_0_4_spool_`), the fitted size in `pa_nozzle` (`SET_NOZZLE`). The slicer's `NOZZLE=` on `PRINT_WARMUP` must diff --git a/macros/afc/purge_check.cfg b/macros/afc/purge_check.cfg index 935d676..7e93d59 100644 --- a/macros/afc/purge_check.cfg +++ b/macros/afc/purge_check.cfg @@ -53,6 +53,7 @@ variable_bdwidth_warmup_ms: 15000 variable_start_counts: 0 variable_start_e: 0.0 variable_last_failed: False # last check failed in enforce mode (read by _RESUME_PURGE_VERIFY) +variable_swap_failed: False # failed during an infinite spool swap (read by _PURGE_CHECK_SWAP_STOP) variable_ignore_missing_sensor: False # set by PURGE_CHECK_IGNORE_SENSOR, cleared at print end # Hotter purge: the leftover of the previous filament (the piece below the # cutter) has to melt to be pushed out. When the filament that last went @@ -117,6 +118,7 @@ gcode: {% endif %} {% endif %} _PURGE_FLUSH_DONE + _PURGE_CHECK_SWAP_STOP # Separate macros so the status is read when they run, not when # BLOBIFIER_CHECKED is rendered @@ -205,10 +207,39 @@ gcode: {% if failed and cfg.mode == "enforce" %} _WARN MSG="PURGE_CHECK: {lane} {failed|join(', ')} - check extruder and lane" DISPLAY="Purge check failed: {lane}, paused" SET_GCODE_VARIABLE MACRO=_PURGE_CHECK_CFG VARIABLE=last_failed VALUE=True - PAUSE ; no effect while already paused (resume purge): see _RESUME_PURGE_VERIFY + # Infinite spool swap: AFC paused the file itself, without PAUSE + {% if printer.print_stats.state == "paused" and not printer.pause_resume.is_paused %} + SET_GCODE_VARIABLE MACRO=_PURGE_CHECK_CFG VARIABLE=swap_failed VALUE=True + {% else %} + PAUSE ; no effect while already paused (resume purge): see _RESUME_PURGE_VERIFY + {% endif %} {% endif %} {% endif %} +# A failed check during an infinite spool swap. PAUSE alone would not stop it: +# AFC only looks at its own error state, so it would remap, go back to the print +# and restart the file while the printer counts as paused. An error reaches AFC's +# CHANGE_TOOL, which then pauses through AFC_error and sets that state, so the +# swap stops. Last in BLOBIFIER_CHECKED: the error skips everything after it. It +# also skips the rest of AFC's TOOL_LOAD, so the buffer's fault detection may stay +# off until the next tool load, and AFC's remap, which the message asks for. +[gcode_macro _PURGE_CHECK_SWAP_STOP] +description: Helper for BLOBIFIER_CHECKED: stop an infinite spool swap after a failed check +gcode: + {% if printer["gcode_macro _PURGE_CHECK_CFG"].swap_failed %} + SET_GCODE_VARIABLE MACRO=_PURGE_CHECK_CFG VARIABLE=swap_failed VALUE=False + {% set lane = printer.AFC.current_load|default("", true) %} + {% set ns = namespace(tool="") %} + {% for name in printer.AFC.lanes %} + {% set obj = printer["AFC_stepper " ~ name] if ("AFC_stepper " ~ name) in printer else {} %} + {% if lane and obj.runout_lane|default("", true) == lane and not ns.tool %} + {% set ns.tool = obj.map %} + {% endif %} + {% endfor %} + {% set remap = "SET_MAP LANE=%s MAP=%s, then " % (lane, ns.tool) if ns.tool else "set the tool map with SET_MAP, then " %} + _ERROR MSG="Spool swap stopped: the purge check failed on {lane}. Check the extruder and lane, run {remap}RESUME. AFC also reports an unexpected CHANGE_TOOL error: that is this stop." DISPLAY="Swap stopped: purge check failed on {lane}" + {% endif %} + [gcode_macro PURGE_CHECK_IGNORE_SENSOR] description: Let purges pass without bd_pressure until the print ends (ENABLE=0 to undo) gcode: