From 8614e646fb53cdbd976b473b7204f034f030a215 Mon Sep 17 00:00:00 2001 From: HelgeKeck Date: Thu, 25 Jan 2024 01:33:29 +0100 Subject: [PATCH] prevent the user from calling the _select_toolchange macro if not in idex mdoe --- macros/toolheads.cfg | 140 ++++++++++++++++++++++--------------------- 1 file changed, 71 insertions(+), 69 deletions(-) diff --git a/macros/toolheads.cfg b/macros/toolheads.cfg index b4338291..15f84e4e 100644 --- a/macros/toolheads.cfg +++ b/macros/toolheads.cfg @@ -3,84 +3,86 @@ #### [gcode_macro _SELECT_TOOL] gcode: - {% if params.T is defined %} - {% set idex_mode = '' %} - {% if printer["dual_carriage"] is defined %} - {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} - {% if "xyz" not in printer.toolhead.homed_axes and (idex_mode == "copy" or idex_mode == "mirror") %} - _IDEX_SINGLE - {% set idex_mode = 'reset' %} - {% endif %} - {% endif %} - {% if idex_mode != "copy" and idex_mode != "mirror" %} - {% set act_t = 1 if idex_mode == 'primary' else 0 %} - {% set new_t = params.T|int %} - {% set act_extruder = 'extruder%s' % ('' if new_t == 0 else new_t) %} - {% if new_t != act_t or printer.toolhead.extruder != act_extruder or idex_mode == 'reset' %} - - RATOS_ECHO PREFIX="IDEX" MSG="Selecting T{new_t}.." - - # reset any speed override from the purge tower - M220 S100 - - # parameters - {% set new_x = params.X|default(-1)|float %} - {% set new_y = params.Y|default(-1)|float %} - {% set z_hop = params.Z|default(0.0)|float %} - {% set toolshift = true if params.TOOLSHIFT|default(1)|int == 1 else false %} - - # deactivate toolshifting if printer is not homed - {% if "xyz" not in printer.toolhead.homed_axes %} - {% set toolshift = false %} + {% if printer["dual_carriage"] is defined %} + {% if params.T is defined %} + {% set idex_mode = '' %} + {% if printer["dual_carriage"] is defined %} + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% if "xyz" not in printer.toolhead.homed_axes and (idex_mode == "copy" or idex_mode == "mirror") %} + _IDEX_SINGLE + {% set idex_mode = 'reset' %} {% endif %} + {% endif %} + {% if idex_mode != "copy" and idex_mode != "mirror" %} + {% set act_t = 1 if idex_mode == 'primary' else 0 %} + {% set new_t = params.T|int %} + {% set act_extruder = 'extruder%s' % ('' if new_t == 0 else new_t) %} + {% if new_t != act_t or printer.toolhead.extruder != act_extruder or idex_mode == 'reset' %} + + RATOS_ECHO PREFIX="IDEX" MSG="Selecting T{new_t}.." + + # reset any speed override from the purge tower + M220 S100 + + # parameters + {% set new_x = params.X|default(-1)|float %} + {% set new_y = params.Y|default(-1)|float %} + {% set z_hop = params.Z|default(0.0)|float %} + {% set toolshift = true if params.TOOLSHIFT|default(1)|int == 1 else false %} + + # deactivate toolshifting if printer is not homed + {% if "xyz" not in printer.toolhead.homed_axes %} + {% set toolshift = false %} + {% endif %} - # swap part cooling fans - {% set fan_speed = printer["fan_generic part_fan_t%s" % act_t].speed %} - {% set sync_fans = true if printer["gcode_macro RatOS"].toolchange_sync_fans|default(false)|lower == 'true' else false %} - {% if fan_speed > 0 %} - SET_FAN_SPEED FAN=part_fan_t0 SPEED={fan_speed if (new_t == 0 or sync_fans) else 0} - SET_FAN_SPEED FAN=part_fan_t1 SPEED={fan_speed if (new_t == 1 or sync_fans) else 0} - # Update core Klipper's fan speed to the fan speed of the active toolhead - # Only do this if you have a sacrificial [fan] section - M106.1 S{fan_speed} - {% endif %} + # swap part cooling fans + {% set fan_speed = printer["fan_generic part_fan_t%s" % act_t].speed %} + {% set sync_fans = true if printer["gcode_macro RatOS"].toolchange_sync_fans|default(false)|lower == 'true' else false %} + {% if fan_speed > 0 %} + SET_FAN_SPEED FAN=part_fan_t0 SPEED={fan_speed if (new_t == 0 or sync_fans) else 0} + SET_FAN_SPEED FAN=part_fan_t1 SPEED={fan_speed if (new_t == 1 or sync_fans) else 0} + # Update core Klipper's fan speed to the fan speed of the active toolhead + # Only do this if you have a sacrificial [fan] section + M106.1 S{fan_speed} + {% endif %} - # change toolhead - _TOOLCHANGE T={new_t} X={new_x} Y={new_y} TOOLSHIFT={toolshift} Z_HOP={z_hop} - - # set input shaper - {% set shaper_x_freq = printer["gcode_macro RatOS"].shaper_x_freq %} - {% set shaper_y_freq = printer["gcode_macro RatOS"].shaper_y_freq %} - {% set shaper_x_type = printer["gcode_macro RatOS"].shaper_x_type %} - {% set shaper_y_type = printer["gcode_macro RatOS"].shaper_y_type %} - SET_INPUT_SHAPER SHAPER_FREQ_X={(shaper_x_freq[new_t]|float)} SHAPER_FREQ_Y={(shaper_y_freq[new_t]|float)} SHAPER_TYPE_X={(shaper_x_type[new_t]|lower)} SHAPER_TYPE_Y={(shaper_y_type[new_t]|lower)} - - # update mainsail UI - SET_GCODE_VARIABLE MACRO=T0 VARIABLE=active VALUE={True if new_t == 0 else False} - SET_GCODE_VARIABLE MACRO=T1 VARIABLE=active VALUE={True if new_t == 1 else False} - - # this is a very basic sanity check for the klipper idex_mode.py bug - # a randomly apearing bug in idex_mode.py leads to switched modes for the dual carriage state - {% if 'x' in printer.toolhead.homed_axes %} - {% set sanity_check_idex_mode = printer["dual_carriage"].carriage_1|lower %} - {% if new_t == 0 %} - {% if printer.toolhead.extruder == 'extruder' %} - {% if sanity_check_idex_mode == 'primary' %} - { action_emergency_stop("Switched states detected in idex_mode.py. Please restart the host controller.") } + # change toolhead + _TOOLCHANGE T={new_t} X={new_x} Y={new_y} TOOLSHIFT={toolshift} Z_HOP={z_hop} + + # set input shaper + {% set shaper_x_freq = printer["gcode_macro RatOS"].shaper_x_freq %} + {% set shaper_y_freq = printer["gcode_macro RatOS"].shaper_y_freq %} + {% set shaper_x_type = printer["gcode_macro RatOS"].shaper_x_type %} + {% set shaper_y_type = printer["gcode_macro RatOS"].shaper_y_type %} + SET_INPUT_SHAPER SHAPER_FREQ_X={(shaper_x_freq[new_t]|float)} SHAPER_FREQ_Y={(shaper_y_freq[new_t]|float)} SHAPER_TYPE_X={(shaper_x_type[new_t]|lower)} SHAPER_TYPE_Y={(shaper_y_type[new_t]|lower)} + + # update mainsail UI + SET_GCODE_VARIABLE MACRO=T0 VARIABLE=active VALUE={True if new_t == 0 else False} + SET_GCODE_VARIABLE MACRO=T1 VARIABLE=active VALUE={True if new_t == 1 else False} + + # this is a very basic sanity check for the klipper idex_mode.py bug + # a randomly apearing bug in idex_mode.py leads to switched modes for the dual carriage state + {% if 'x' in printer.toolhead.homed_axes %} + {% set sanity_check_idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% if new_t == 0 %} + {% if printer.toolhead.extruder == 'extruder' %} + {% if sanity_check_idex_mode == 'primary' %} + { action_emergency_stop("Switched states detected in idex_mode.py. Please restart the host controller.") } + {% endif %} {% endif %} - {% endif %} - {% elif new_t == 1 %} - {% if printer.toolhead.extruder == 'extruder1' %} - {% if sanity_check_idex_mode == 'inactive' %} - { action_emergency_stop("Switched states detected in idex_mode.py. Please restart the host controller.") } + {% elif new_t == 1 %} + {% if printer.toolhead.extruder == 'extruder1' %} + {% if sanity_check_idex_mode == 'inactive' %} + { action_emergency_stop("Switched states detected in idex_mode.py. Please restart the host controller.") } + {% endif %} {% endif %} {% endif %} {% endif %} - {% endif %} - # absolute positioning - G90 + # absolute positioning + G90 + {% endif %} {% endif %} {% endif %} {% endif %}