Created
January 4, 2023 00:21
-
-
Save GarthSnyder/8a4e76cb7ebee2f35eaab29acd948b58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[gcode_macro limit_toolhead_temp_for_tap] | |
gcode: | |
{% set stack_level = printer["gcode_macro restore_toolhead_temp"].stack_level|int > 0 %} | |
{% set already_limited = stack_level > 0 %} | |
{% set probe_temp = 150 %} | |
{% set max_temp = probe_temp + 3 %} | |
{% set actual_temp = printer.extruder.temperature %} | |
{% set target_temp = printer.extruder.target %} | |
{% set target_too_high = target_temp > probe_temp %} | |
{% set actual_too_high = actual_temp > max_temp %} | |
{% set overheated = target_too_high or actual_too_high %} | |
SET_GCODE_VARIABLE MACRO=restore_toolhead_temp VARIABLE=stack_level VALUE={stack_level + 1} | |
{% if already_limited and overheated %} | |
{ action_respond_info('Unexpectedly high extruder temperature while in nested LIMIT') } | |
STATUS_HEATING | |
M109 S{probe_temp} | |
{% elif target_temp > probe_temp %} | |
SET_GCODE_VARIABLE MACRO=restore_toolhead_temp VARIABLE=previous_target VALUE={target_temp} | |
{ action_respond_info('Extruder temperature target of %.1fC is too high, lowering to %.1fC' % (target_temp, probe_temp)) } | |
STATUS_HEATING | |
M109 S{ probe_temp } | |
{% elif actual_temp > max_temp %} | |
# Temperature target is already low enough, but nozzle may still be too hot. | |
{ action_respond_info('Extruder temperature %.1fC is still too high, waiting until below %.1fC' % (actual_temp, probe_temp)) } | |
TEMPERATURE_WAIT SENSOR=extruder MAXIMUM={ probe_temp } | |
{% endif %} | |
[gcode_macro restore_toolhead_temp] | |
variable_stack_level: 0 | |
variable_previous_target: None | |
gcode: | |
{% set level = stack_level|int %} | |
{% if level <= 0 %} | |
{ action_respond_info('Unnested RESTORE_TOOLHEAD_TEMP') } | |
SET_GCODE_VARIABLE MACRO=restore_toolhead_temp VARIABLE=stack_level VALUE=0 | |
{% else %} | |
{% set level = level - 1 %} | |
SET_GCODE_VARIABLE MACRO=restore_toolhead_temp VARIABLE=stack_level VALUE={level} | |
{% if level == 0 and previous_target %} | |
{ action_respond_info('Restoring previous temperature target of %.1fC' % (previous_target)) } | |
SET_GCODE_VARIABLE MACRO=restore_toolhead_temp VARIABLE=previous_target VALUE=None | |
STATUS_HEATING | |
M104 S{previous_target} | |
{% endif %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment