What's new
VORON Design

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members!

User code modifications in Python without restart / loss of homing

endstop

Member
Hi,
posting this here as I wrote it for my 2.4/350 Voron Stealthchanger.
I'll have to implement quite a bit of custom functionality for my envisioned "workflow" but found that code - both Klipper modules in Python and GCODE - can't be changed without Klipper reload and loss of homing.
Add Quad Gantry Leveling for toolchanges, possibly bed mesh, and this gets old real quick.

Enter "KlipperHotload" - my project - to (re)compile Python code on the fly. For what I need, it's a gamechanger, I will probably stop using GCODE files and code everything I need in Python.

In a nutshell (see README in above link) it provides one macro - I picked the letter "U" as it's not used in GCODE -
U PATH={CONFIG}/myCodeDir FILE=myCodeFile.py FUN=myFunction SOME_ARG_TO_FUN=123 SOME_OTHER_ARG=456 ...

to run a given function from a given file, passing arguments (where {CONFIG} interpolates to the directory of printer.cfg). There are a few tricks built in to assist with keeping GCODE concise, e.g. PATH and FILE may need to be set only once, the last value becomes default.
If only a single function is required, it collapses to
U SOME_ARG_TO_FUN=123 SOME_OTHER_ARG=456 ...

or if I don't need arguments just
U

which is about as short as it gets :)
Speaking of "short", it's just a single ~200 line file in klipper/klippy/extras plus tests directory.

I hope someone will find it useful.
 
Last edited:
Top