Skip to content
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

feat: add _CLIENT_LINEAR_MOVE macro #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion client.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,23 @@ gcode:
{% set speed = params.SPEED|default(client.speed_retract)|default(35) %}

_CLIENT_EXTRUDE LENGTH=-{length|float|abs} SPEED={speed|float|abs}


[gcode_macro _CLIENT_LINEAR_MOVE]
description: Linear move with save and restore of the gcode state
gcode:
{% set x_move = "X" ~ params.X if params.X is defined else "" %}
{% set y_move = "Y" ~ params.Y if params.Y is defined else "" %}
{% set z_move = "Z" ~ params.Z if params.Z is defined else "" %}
{% set e_move = "E" ~ params.E if params.E is defined else "" %}
{% set rate = "F" ~ params.F if params.F is defined else "" %}
{% set ABSOLUTE = params.ABSOLUTE | default(0) | int != 0 %}
{% set ABSOLUTE_E = params.ABSOLUTE_E | default(0) | int != 0 %}
SAVE_GCODE_STATE NAME=_client_movement
{% if 'X' in params or 'Y' in params or 'Z' in params %}
G9{ 0 if ABSOLUTE else 1 }
{% endif %}
{% if 'E' in params %}
M8{ 2 if ABSOLUTE_E else 3 }
{% endif %}
Comment on lines +306 to +311
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just checking if the parameter exists or not, not if it is empty (we can do _CLIENT_LINEAR_MOVE X= and Klipper will be just fine with that, so this is not correct)

So we need to check for param exists AND ensure that the value is NOT empty.

I took it a step further and just checked for the movement parts we are sending.

Suggested change
{% if 'X' in params or 'Y' in params or 'Z' in params %}
G9{ 0 if ABSOLUTE else 1 }
{% endif %}
{% if 'E' in params %}
M8{ 2 if ABSOLUTE_E else 3 }
{% endif %}
{% if x_move or y_move or z_move %}
G9{ 0 if ABSOLUTE else 1 }
{% endif %}
{% if e_move %}
M8{ 2 if ABSOLUTE_E else 3 }
{% endif %}

G1 { x_move } { y_move } { z_move } { e_move } { rate }
RESTORE_GCODE_STATE NAME=_client_movement