diff --git a/printer_data/config/macros/fan_tach_monitor.cfg b/printer_data/config/macros/fan_tach_monitor.cfg index e69de29..40fd66d 100644 --- a/printer_data/config/macros/fan_tach_monitor.cfg +++ b/printer_data/config/macros/fan_tach_monitor.cfg @@ -0,0 +1,45 @@ +# Monitoring loop. Begins at Klipper start. +[delayed_gcode CHECK_ALL_FANS] +initial_duration: 1 +gcode: + HOTEND_FAN_CHECK + UPDATE_DELAYED_GCODE ID=CHECK_ALL_FANS DURATION=3 + +# Change min_rpm and max_consecutive_stops to your desired values. +[gcode_macro HOTEND_FAN_CHECK] +variable_he_stop_count: 0 +gcode: + {% set min_rpm = 3000|float %} + {% set max_consecutive_stops = 3 %} + {% set rpm = printer['heater_fan hotend_fan'].rpm|float %} + {% set he_target = printer[printer.toolhead.extruder].target|float %} + {% set he_temp = printer[printer.toolhead.extruder].temperature|float %} + {% set fan_on_temp = printer.configfile.settings['heater_fan hotend_fan'].heater_temp|float %} + {% set he_stop_count = printer["gcode_macro HOTEND_FAN_CHECK"].he_stop_count|int %} + + {% if (he_target >= fan_on_temp) and (rpm < min_rpm) and (he_temp >= fan_on_temp) %} + SET_GCODE_VARIABLE MACRO=HOTEND_FAN_CHECK VARIABLE=he_stop_count VALUE={he_stop_count + 1} + RESPOND PREFIX="HOTEND FAN CHECK:" MSG="Fan stoppage detected ({he_stop_count+1}/{max_consecutive_stops})." + M400 + {% if printer["gcode_macro HOTEND_FAN_CHECK"].he_stop_count|int >= max_consecutive_stops-1 %} + FAN_STOPPAGE_ROUTINE + {% endif %} + {% else %} + SET_GCODE_VARIABLE MACRO=HOTEND_FAN_CHECK VARIABLE=he_stop_count VALUE=0 + {% endif %} + +# Insert the gcode that you want to run when a fan stoppage is detected. +# This runs every ~3 seconds until the stop conditions are cleared. +[gcode_macro FAN_STOPPAGE_ROUTINE] +gcode: + # If not already paused + {% if printer['pause_resume'].is_paused|int == 0 %} + M117 !!FAN STOPPAGE!! + M118 FAN STOPPAGE DETECTED. PAUSING... + PAUSE + # Turn off the hotend. + # !! Don't forget to turn your hotend back on before resume. !! + # -- If using this guide's pause/resume macros (in useful_macros.html), the hotend will automatically reheat on resume + # -- (as long as the hotend is not turned off BEFORE pause is called) + SET_HEATER_TEMPERATURE HEATER=extruder TARGET=0 + {% endif %} \ No newline at end of file