Hi everyone!
I’m planning on PRing a new [MACRO=<name>]
parameter to the SAVE_VARIABLE
command of [save_variables]
.
The new functionality would update the macro variable, create a new section [gcode_macro <macroname>]
in the variable config and save it, so gcode macro variables can persist across restarts (by reading the config file on startup and setting the gcode macro variable).
The point here is for a spool_id
to be set on a toolchanger macro to allow easy spoolman spool selections in multi-tool setups - having to set every tools associated spool every time Klipper restarts will get annoying quickly.
First time contributing to Klipper, so not sure what’s valid code-wise and what isn’t.
I’ve published a first PoC under https://github.com/matmen/klipper/tree/feat/persistent-macro-variables, but I’m not sure about the following things:
- Is it valid to modify gcode macro variables from outside of the
gcode_macro
module? - I’m concerned about automatically overriding the variable default values defined in the printer.cfg with ones saved in the
save_variables
config file. I feel like this could lead to confusion when troubleshooting.
I’ve considered simply issuing a SAVE_VARIABLE VARIABLE=<macro name>_<variable name> VALUE=<value>
command, but this could create ambiguities:
A macro with name SET_SPOOL
with variable ID
would generate a SAVE_VARIABLE VARIABLE=SET_SPOOL_ID ...
, but so would a macro with name SET
and variable SPOOL_ID
.
Also, it looks like gcode_macro
variables don’t support a Jinja2 template as default value, so I’m not sure if loading the value on startup would be possible without issuing another set of commands.
Please let me know if you have any comments, questions or concerns.