Skip to content

Commit

Permalink
state: Ignore ephemeral SET_GCODE_OFFSET calls
Browse files Browse the repository at this point in the history
Tracks SAVE_GCODE_STATE and RESTORE_GCODE_STATE (issue jschuh#13 follow up).
  • Loading branch information
jschuh committed Oct 22, 2022
1 parent ed73f49 commit a252570
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bed_surface.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ description: Wraps SET_GCODE_OFFSET to update the current bed sheet offset.
rename_existing: _KM_SET_GCODE_OFFSET_BASE
gcode:
{% set surfaces = printer.save_variables.variables.bed_surfaces %}
{% if surfaces.active %}
{% if surfaces.active and
not printer["gcode_macro _km_save_state"].is_ephemeral %}
{% set Z = params.Z|default(0.0)|float %}
{% set Z_ADJUST = params.Z_ADJUST|default(0.0)|float %}
{% if 'Z' in params and
Expand Down
34 changes: 34 additions & 0 deletions state.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (C) 2022 Justin Schuh <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.

[gcode_macro _km_save_state]
description: Tracks gcode state.
variable_state_set: {}
variable_is_ephemeral: 0
gcode:
{% if params.SAVE|int %}
{% set dummy = state_set.__setitem__(params.NAME, None) %}
{% else %}
{% set dummy = state_set.__delitem__(params.NAME) %}
{% endif %}
SET_GCODE_VARIABLE MACRO=_km_save_state VARIABLE=is_ephemeral VALUE="{
1 if state_set|length > 0 else 0 }"

[gcode_macro save_gcode_state]
description: Wraps SAVE_GCODE_STATE to track persistence state.
Usage: See Klipper documentation
rename_existing: _KM_SAVE_GCODE_STATE
gcode:
_KM_SAVE_GCODE_STATE {rawparams}
{% set NAME = params.NAME|default("default") %}
_km_save_state NAME={NAME} SAVE=1

[gcode_macro restore_gcode_state]
description: Wraps RESTORE_GCODE_STATE to track persistence state.
Usage: See Klipper documentation
rename_existing: _KM_RESTORE_GCODE_STATE
gcode:
_KM_RESTORE_GCODE_STATE {rawparams}
{% set NAME = params.NAME|default("default") %}
_km_save_state NAME={NAME} SAVE=0

0 comments on commit a252570

Please sign in to comment.