New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gcode_macro: Add "rawparams" pseudo-variable #4727
gcode_macro: Add "rawparams" pseudo-variable #4727
Conversation
Thanks. In general, it looks fine. However, one issue is that the example is subtly broken if the command includes g-code line numbers (eg, We may need to abstract that logic so that it can be used here and in -Kevin |
I did see that line with the For that specific example, I would just write the jinja code like this: [gcode_macro M117]
rename_existing: M117.1
gcode:
{% set message = commandline[5:] %}
{% set index = message.rfind('*') %}
{% if index >= 0 %}
{% set message = message[:index] %}
{% endif%}
M117.1 { message }
M118 { message } My question right now is if we should just make the |
Took me a while to get the whole "line number" thing, but I think I understand now! Something like Given that, this is how one could code it in a template: [gcode_macro M117]
rename_existing: M117.1
gcode:
{% set message = commandline %}
{% if not message.startswith("M117") %}
{% set start = message.find("M117") %}
{% set end = message.rfind('*') %}
{% if end >= 0 %}
{% set message = message[:end] %}
{% endif%}
{% set message = message[start:] %}
{% endif %}
M117.1 { message }
M118 { message } But that does seem way to much verbose to me, so I think something better should be done on Klipper side... I will follow up on your comments and see how I can improve this! |
5294f3d
to
a0be333
Compare
@KevinOConnor I've added a new I considered changing the existing |
a0be333
to
6464e3b
Compare
Thanks. I agree with adding a new method and not changing -Kevin |
Given that, I changed approach: instead of having the full command line as a variable, I'm just adding a |
ea29618
to
d6eb5c0
Compare
I've updated the PR title and description to match these changes. |
d6eb5c0
to
3eda30d
Compare
Thanks. I'm fine with adding a -Kevin |
3eda30d
to
47a6c6e
Compare
I've moved all the logic to the Having said that, I think as it stands it will still invoke the logic for any macro... should I convert the current |
47a6c6e
to
68598c2
Compare
@KevinOConnor just wanted to check if you think this needs more work or even a different approach to the current way I've implemented it? |
ebd5dd0
to
d861954
Compare
Hmm, turns out I didn’t see this when making #4883. I went for the least intrusive way by not adding any extra functions and just passing the whole command line in, leaving it to the macro to sanitise the params |
@whi-tw that was actually my initial approach but after some discussion, @KevinOConnor pointed out some problems with that as the commandline (gcode) can include line numbers and checksums, hence why I ended with the proposed implementation in this PR. |
@pedrolamas for sure, makes sense, although it depends where the responsibility for parsing the variable lies. I went for the responsibility being on the macro author, vs Klipper itself, as it’s feasible the line number could be helpful to someone? |
Thanks. Looks fine to me. One question - is there a reason that -Kevin |
|
I'd say always returning a string would be preferable (and add the additional None logic to the M117 code). Otherwise, we'd need to document that Thanks, |
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
d861954
to
d7b6499
Compare
No worries, I just pushed the necessary changes to make |
Thanks. -Kevin |
This adds a new
rawparams
pseudo-variable to thegcode_macro
template context.The main usage for this is to allow easier override of an existing G-Code like
M117
, where we don't have any parameters (soparams
is useless) but instead take the whole message after the gcode.Here's an example of it:
In the above example, any message sent via
M117
would also be mirrored withM118
.Signed-off-by: Pedro Lamas pedrolamas@gmail.com