Fix pause/resume chain, shared print cleanup, add CLAUDE.md

- RESUME is defined only in print/pause_resume.cfg; heat_soak.cfg's
  duplicate replaced it (no unretract, no fan restore). It now runs
  HEAT_SOAK_RESUME -> _RESUME_PRINT -> RESUME_BASE.
- PAUSE runs PAUSE_BASE first, then retracts and parks once (X20 Y345);
  a parked flag makes resume undo only what PAUSE did.
- New _PRINT_CLEANUP shared by PRINT_END and CANCEL_PRINT: heaters incl.
  iHEATER_OFF, fan, M221 S100, bdwidth off, mesh and skew cleared.
  In PRINT_END it runs after RESTORE_GCODE_STATE so the flow reset sticks.
- Add CLAUDE.md and tools/effective_config.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-10-10 15:20:28 +02:00
1 parent eaf9c82617
commit 9dc733b5bb
7 files changed
+245 -85

No files matched your search

+84
View File
@@ -0,0 +1,84 @@
# klipper-macros
Klipper macros, Klipper modules and scripts for one printer, installed on
the printer's Raspberry Pi with `install.sh` and updated through Moonraker.
See README.md for the user-facing description.
## The printer
Voron 2.4 350, Klipper + Moonraker + Mainsail on a Raspberry Pi 4
(`http://mainsailos.local`, Moonraker API on port 80). AFC Box Turtle with
5 lanes, Blobifier purge bucket, Beacon (Z homing and probing), Nitehawk-SB
toolboard (USB), Leviathan mainboard as USB-CAN bridge, bd_pressure
(load-check firmware, branch `load-check-extension` in
`D:\Claude\bd_pressure-load-check\bd_pressure`), bdwidth (measures width and
motion optically with a CCD; its motion reading is unreliable, so the purge
check runs with `motion_check: False`), iHeater chamber heater.
## Working with the printer
- Read freely through Moonraker: `GET /server/files/config/<path>`,
`/server/files/logs/klippy.log`, `/printer/objects/query?...`,
`/server/gcode_store`. The merged config Klipper loaded is in klippy.log
after `===== Config file =====`.
- Do **not** change anything on the printer (upload files, edit config, send
G-code, restart services) unless the user asks for that specific action.
Prepare files here and let the user upload them.
- Never run anything that moves the printer or heats while a print may be
running; check `print_stats.state` first.
## Repo layout
- `macros/klipper-macros.cfg` is the only file `printer.cfg` includes; it
includes everything else. On the Pi, `macros/` is linked as
`~/printer_data/config/klipper-macros/`.
- `extras/*.py` are linked into `~/klipper/klippy/extras/`.
- `scripts/` MCU firmware update scripts (printer-specific IDs).
- `tools/effective_config.py` expands the includes like Klipper and compares
the result between git refs.
## Rules for macro changes
- **Never define the same `[gcode_macro X]` in two files.** Klipper merges
sections with the same name and the later file wins completely (this is
how heat_soak.cfg's RESUME silently replaced the real RESUME). Include
order in `klipper-macros.cfg` matters for this.
- `RESUME` and `PAUSE` are defined only in `print/pause_resume.cfg`. AFC
renames PAUSE/RESUME at startup and wraps them:
`PAUSE -> AFC_PAUSE -> PAUSE -> PAUSE_BASE`,
`RESUME -> AFC_RESUME -> RESUME -> HEAT_SOAK_RESUME -> _RESUME_PRINT -> RESUME_BASE`.
- Only one `[save_variables]`, in `macros/save_variables.cfg`.
- `PRINT_END` and `CANCEL_PRINT` share `_PRINT_CLEANUP` (heaters including
`iHEATER_OFF`, fan, `M221 S100`, bdwidth off). Anything that must happen
at the end of every print goes there. `RESTORE_GCODE_STATE` restores the
flow (M221), so reset flow after it, not before.
- Inside `gcode:` use `;` for comments on G-code lines; `#` lines are
stripped by the config parser.
- After a refactor run `python tools/effective_config.py HEAD` and check that
only the intended sections changed.
- Render-test macros with Jinja2 using Klipper's delimiters
(`jinja2.Environment('{%', '%}', '{', '}')`) and mocked `printer` objects.
## Rules for the Python modules (`extras/`)
- Klipper only loads changed `.py` files when the **Klipper service**
restarts (`sudo systemctl restart klipper`); `RESTART` and
`FIRMWARE_RESTART` keep the old code in memory.
- Event handlers must never raise: an exception in a handler shuts Klipper
down. Example: Beacon sends `homing:home_rails_end` with `rails=[]` and a
homing state whose `get_trigger_position` raises.
- Keep them read-only wrappers where possible (look up the other module's
object, do not patch third-party files).
## Reference values
- Purge check (150 mm Blobifier purge): good load = longest pressure
13-18 s, peak 64-181; empty nozzle about 30 ms.
- XY drift check: endstop noise about 0.01-0.02 mm; limit 0.1 mm (one motor
skipping one cycle = 0.4 mm shows as 0.2 mm in X and Y).
## Git
- LF line endings everywhere (`.gitattributes`); the files run on Linux.
- Commit only when the user says so; never push without asking. Remote:
`https://mangavalk.com/mangavalk/klipper-macros.git`.