Skip to content

Commit

Permalink
Move gcode macros to their own file, use save variable
Browse files Browse the repository at this point in the history
  • Loading branch information
bofh69 committed Mar 6, 2024
1 parent 5d37558 commit e5249fd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
38 changes: 1 addition & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,7 @@ Klipper should have two gcode macros:
* SET_ACTIVE_SPOOL ID=n


I use this configuration:
```ini
[gcode_macro SET_ACTIVE_SPOOL]
gcode:
{% if params.ID %}
{% set id = params.ID|int %}
{action_call_remote_method(
"spoolman_set_active_spool",
spool_id=id
)}
{% else %}
{action_respond_info("Parameter 'ID' is required")}
{% endif %}

[gcode_macro SET_ACTIVE_FILAMENT]
variable_active_filament: 0
gcode:
{% if params.ID %}
{% set id = params.ID|int %}
SET_GCODE_VARIABLE MACRO=SET_ACTIVE_FILAMENT VARIABLE=active_filament VALUE={id}
{% else %}
{action_respond_info("Parameter 'ID' is required")}
{% endif %}

[gcode_macro ASSERT_ACTIVE_FILAMENT]
gcode:
{% if params.ID %}
{% set id = params.ID|int %}
{% current_id = printer["gcode_macro set_active_filament"].active_filament %}
{% if id != current_id %}
{# TODO: Change to PAUSE & M117 message #}
{action_raise_error("Wrong filament is loaded, should be " + id)}
{% endif %}
{% else %}
{action_respond_info("Parameter 'ID' is required")}
{% endif %}
```
See [klipper-spoolman.cfg] for klipper config for them.

## Preparing tags

Expand Down
43 changes: 43 additions & 0 deletions klipper-spoolman.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# These are from Spoolman:
[gcode_macro SET_ACTIVE_SPOOL]
gcode:
{% if params.ID %}
{% set id = params.ID|int %}
{action_call_remote_method(
"spoolman_set_active_spool",
spool_id=id
)}
{% else %}
{action_respond_info("Parameter 'ID' is required")}
{% endif %}

[gcode_macro CLEAR_ACTIVE_SPOOL]
gcode:
{action_call_remote_method(
"spoolman_set_active_spool",
spool_id=None
)}


# This is the extension for filament handling
[gcode_macro SET_ACTIVE_FILAMENT]
gcode:
{% if params.ID %}
{% set id = params.ID|int %}
SAVE_VARIABLE VARIABLE=active_filament VALUE={id}
{% else %}
{action_respond_info("Parameter 'ID' is required")}
{% endif %}

[gcode_macro ASSERT_ACTIVE_FILAMENT]
gcode:
{% if params.ID %}
{% set id = params.ID|int %}
{% set current_id = printer.save_variables.variables["active_filament"]|int %}
{% if id != current_id %}
{action_raise_error("Wrong filament is loaded, should be " + id|string)}
{% endif %}
{% else %}
{action_respond_info("Parameter 'ID' is required")}
{% endif %}

0 comments on commit e5249fd

Please sign in to comment.