Skip to content

Commit

Permalink
layers: Integrate SET_PRINT_STATS_INFO
Browse files Browse the repository at this point in the history
This changes layer indexing from 0 to 1 based, but that's what the
frontends expect.
  • Loading branch information
jschuh committed Nov 17, 2022
1 parent ca5abb1 commit 3f1bf61
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions layers.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.

# Insert this into your slacer's layer change section
[gcode_macro before_layer_change]
description: Add this to the "before layer change" input box in the slicer.
Usage: BEFORE_LAYER_CHANGE HEIGHT=<current_height> LAYER=<current_layer>
gcode:
{% set height = params.HEIGHT|default(printer.toolhead.position.z)|float %}
{% set layer = params.LAYER|default(-1)|int %}
{% set layer = params.LAYER|default(-1)|int + 1 %}
{% if height >= 0.0 %}
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=cur_layer VALUE="{layer}"
SET_PRINT_STATS_INFO CURRENT_LAYER="{layer}"
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=cur_height VALUE="{height}"
{% if printer["gcode_macro _km_layer_run"].clearance_z < height %}
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=clearance_z VALUE="{
Expand All @@ -21,7 +20,7 @@ gcode:

[gcode_macro after_layer_change]
description: Add this to the "after layer change" input box in the slicer.
Usage: AFTER_LAYER_CHANGE HEIGHT=<current_height> LAYER=<current_layer>
Usage: AFTER_LAYER_CHANGE
gcode:
_KM_LAYER_RUN BEFORE=0

Expand All @@ -32,7 +31,7 @@ description: Schedules the specified g-code command to be run at the specified
[BEFORE=<0|1>] [ALLOW_DUPLICATE=<0|1>]
gcode:
{% set commands = printer["gcode_macro _km_layer_run"].commands %}
{% set tot_layers = printer["gcode_macro _km_layer_run"].tot_layers %}
{% set tot_layers = printer.print_stats.info.total_layer %}
{% if params|length > 0 %}
{% if not printer.pause_resume.is_paused and
printer.idle_timeout.state|string != "Printing" %}
Expand All @@ -42,7 +41,7 @@ gcode:
{% set when = "before" if (params.BEFORE|default(0)|int) else "after" %}

{% if "LAYER" in params %}
{% set cur_layer = printer["gcode_macro _km_layer_run"].cur_layer %}
{% set cur_layer = printer.print_stats.info.current_layer %}
{% if "HEIGHT" in params %}
{action_raise_error("Conflicting HEIGHT and LAYER arguments provided.")}
{% elif params.LAYER|string|lower == "next" %}
Expand All @@ -53,7 +52,7 @@ gcode:
{% if LAYER <= cur_layer %}
{action_raise_error("LAYER[%i] must be above current print layer[%i]."
| format(LAYER, cur_layer))}
{% elif tot_layers and LAYER > tot_layers %}
{% elif tot_layers and LAYER >= tot_layers %}
{action_raise_error("LAYER[%i] must be below top layer[%i]."
| format(LAYER, tot_layers))}
{% endif %}
Expand Down Expand Up @@ -122,20 +121,17 @@ gcode:
description: Clears scheduled gcode commands and state for all layers.
Usage: INIT_LAYER_GCODE LAYERS=<num>
gcode:
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=cur_layer VALUE="{-1}"
SET_PRINT_STATS_INFO TOTAL_LAYER="{params.LAYERS|int}"
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=cur_height VALUE="{0.0}"
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=tot_layers VALUE="{
params.LAYERS|int}"
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=clearance_z VALUE="{0.0}"
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=commands VALUE="{{}}"

[gcode_macro _reset_layer_gcode]
description: Clears scheduled gcode commands and state for all layers.
Usage: _RESET_LAYER_GCODE
gcode:
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=cur_layer VALUE="{-1}"
SET_PRINT_STATS_INFO TOTAL_LAYER="0"
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=cur_height VALUE="{0.0}"
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=tot_layers VALUE="{0}"
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=clearance_z VALUE="{0.0}"
SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=commands VALUE="{{}}"

Expand All @@ -158,13 +154,12 @@ gcode:
[gcode_macro _km_layer_run]
description: Runs pending commands for the current layer change.
Usage: _KM_LAYER_RUN BEFORE=<0|1>
variable_cur_layer: -1
variable_cur_height: 0.0
variable_tot_layers: 0
variable_clearance_z: 0.0
variable_commands: {}
gcode:
{% set BEFORE = params.BEFORE|int %}
{% set cur_layer = printer.print_stats.info.current_layer %}
{% for k in commands | list | sort %}
{% set args = k.split('_') %}
{% set cmd_pos = args[0]|float %}
Expand Down

0 comments on commit 3f1bf61

Please sign in to comment.