实现开门检测功能

This commit is contained in:
魏瑞鹏 2025-03-31 09:32:57 +08:00
parent 3839849aa0
commit 82b7fc8acf
5 changed files with 176 additions and 34 deletions

View File

@ -0,0 +1,32 @@
[gcode_button _door_detection]
pin: DOOR_PIN
press_gcode:
release_gcode:
{% set sv = printer.save_variables.variables %}
{% set door_function = sv.door_detect|default("Disabled") %}
{% if door_function != "Disabled" %}
M118 Printer door is opening!
{% endif %}
_DOOR_DETECTION_HANDLE STATUS='open'
[gcode_macro _DOOR_DETECTION_HANDLE]
gcode:
{% set sv = printer.save_variables.variables %}
{% set door_function = sv.door_detect|default("Disabled") %}
{% set status = params.STATUS|default("close") %}
{% set printing_state = printer.print_stats.state %}
{% if status=='open' and printing_state == 'printing' %}
{% if door_function == 'Emergency Stop' %}
M112
{% elif door_function == 'Pause Print' %}
PAUSE
{% endif %}
{% endif %}
[gcode_macro _DOOR_START_PRINT_BASE]
description: Call handle door is open when starting to print
gcode:
RESPOND TYPE=command MSG="action:prompt_begin"
RESPOND TYPE=command MSG="action:prompt_text Printer door is opened. Please close the door and then start printing."
RESPOND TYPE=command MSG="action:prompt_footer_button Ok|RESPOND TYPE=command MSG=action:prompt_end"
RESPOND TYPE=command MSG="action:prompt_show"

View File

@ -10,6 +10,10 @@ filename: ~/printer_data/config/config_variables.cfg
[exclude_object]
[board_pins]
aliases:
DOOR_PIN=PC5
[gcode_arcs]
resolution: 1.0
@ -803,24 +807,41 @@ gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE']|default({}) %}
{% set do_resume = False %}
{% set runout = True %}
##### end of definitions #####
_FILAMENT_UPDATE
_RESUME_EXTRUDER AUTOSHIFT={autoshift}
_EXTRUDER_TEMPERATURE_HANDLE
{% macro resume_action() %}
_FILAMENT_UPDATE
_RESUME_EXTRUDER AUTOSHIFT={autoshift}
_EXTRUDER_TEMPERATURE_HANDLE
{% set can_extrude = True if printer.toolhead.extruder == '' # no extruder defined in config
else printer[printer.toolhead.extruder].can_extrude %} # status of active extruder
#### Printer comming from timeout idle state ####
{% if printer.idle_timeout.state|upper == "IDLE" or idle_state or autoshift %}
SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=idle_state VALUE=Fals
{% set can_extrude = True if printer.toolhead.extruder == '' # no extruder defined in config
else printer[printer.toolhead.extruder].can_extrude %} # status of active extruder
#### Printer comming from timeout idle state ####
{% if printer.idle_timeout.state|upper == "IDLE" or idle_state or autoshift %}
SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=idle_state VALUE=False
{% endif %}
{% if last_extruder_temp.restore or last_extruder1_temp.restore %}
{ client.user_temp_macro|default("") }
{% set do_resume = True %}
{% elif can_extrude %}
{% set do_resume = True %}
{% endif %}
_ACT_RESUME DO_RESUME={ do_resume }
{% endmacro %}
{% if printer['gcode_button _door_detection'] %}
{% set sv = printer.save_variables.variables %}
{% set door_function = sv.door_detect|default("Disabled") %}
{% set door_state = printer['gcode_button _door_detection'].state|default('released')|lower %}
{% if door_function == 'Pause Print' and door_state == 'pressed' %}
{ resume_action() }
{% elif door_function == 'Pause Print' and door_state == 'released' %}
RESPOND TYPE=command MSG="action:prompt_begin"
RESPOND TYPE=command MSG="action:prompt_text Please close the door and click Resume to proceed."
RESPOND TYPE=command MSG="action:prompt_footer_button Ok|RESPOND TYPE=command MSG=action:prompt_end"
RESPOND TYPE=command MSG="action:prompt_show"
{% endif %}
{% else %}
{ resume_action() }
{% endif %}
{% if last_extruder_temp.restore or last_extruder1_temp.restore %}
{client.user_temp_macro|default("")}
{% set do_resume = True %}
{% elif can_extrude %}
{% set do_resume = True %}
{% endif %}
_ACT_RESUME DO_RESUME={do_resume}
[gcode_macro _ACT_RESUME]
gcode:
@ -1154,4 +1175,6 @@ gcode:
[gcode_macro _NOZZLE_XY_OFFSET_CALIBRATE]
gcode:
RUN_SHELL_COMMAND CMD=fetch_assets PARAMS="\"Gcode\" \"D1000HS\" \"NozzleAglin.zip\""
SDCARD_PRINT_FILE FILENAME=".PresetModel/NozzleAglin.gcode"
SDCARD_PRINT_FILE FILENAME=".PresetModel/NozzleAglin.gcode"
[include module/*.cfg]

View File

@ -0,0 +1,32 @@
[gcode_button _door_detection]
pin: DOOR_PIN
press_gcode:
release_gcode:
{% set sv = printer.save_variables.variables %}
{% set door_function = sv.door_detect|default("Disabled") %}
{% if door_function != "Disabled" %}
M118 Printer door is opening!
{% endif %}
_DOOR_DETECTION_HANDLE STATUS='open'
[gcode_macro _DOOR_DETECTION_HANDLE]
gcode:
{% set sv = printer.save_variables.variables %}
{% set door_function = sv.door_detect|default("Disabled") %}
{% set status = params.STATUS|default("close") %}
{% set printing_state = printer.print_stats.state %}
{% if status=='open' and printing_state == 'printing' %}
{% if door_function == 'Emergency Stop' %}
M112
{% elif door_function == 'Pause Print' %}
PAUSE
{% endif %}
{% endif %}
[gcode_macro _DOOR_START_PRINT_BASE]
description: Call handle door is open when starting to print
gcode:
RESPOND TYPE=command MSG="action:prompt_begin"
RESPOND TYPE=command MSG="action:prompt_text Printer door is opened. Please close the door and then start printing."
RESPOND TYPE=command MSG="action:prompt_footer_button Ok|RESPOND TYPE=command MSG=action:prompt_end"
RESPOND TYPE=command MSG="action:prompt_show"

View File

@ -10,6 +10,10 @@ filename: ~/printer_data/config/config_variables.cfg
[exclude_object]
[board_pins]
aliases:
DOOR_PIN=PC5
[gcode_arcs]
resolution: 1.0
@ -794,25 +798,42 @@ gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE']|default({}) %}
{% set do_resume = False %}
{% set runout = True %}
##### end of definitions #####
_FILAMENT_UPDATE
_RESUME_EXTRUDER AUTOSHIFT={autoshift}
_EXTRUDER_TEMPERATURE_HANDLE
{% macro resume_action() %}
_FILAMENT_UPDATE
_RESUME_EXTRUDER AUTOSHIFT={autoshift}
_EXTRUDER_TEMPERATURE_HANDLE
{% set can_extrude = True if printer.toolhead.extruder == '' # no extruder defined in config
else printer[printer.toolhead.extruder].can_extrude %} # status of active extruder
{% set can_extrude = True if printer.toolhead.extruder == '' # no extruder defined in config
else printer[printer.toolhead.extruder].can_extrude %} # status of active extruder
#### Printer comming from timeout idle state ####
{% if printer.idle_timeout.state|upper == "IDLE" or idle_state or autoshift %}
SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=idle_state VALUE=Fals
#### Printer comming from timeout idle state ####
{% if printer.idle_timeout.state|upper == "IDLE" or idle_state or autoshift %}
SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=idle_state VALUE=False
{% endif %}
{% if last_extruder_temp.restore or last_extruder1_temp.restore %}
{ client.user_temp_macro|default("") }
{% set do_resume = True %}
{% elif can_extrude %}
{% set do_resume = True %}
{% endif %}
_ACT_RESUME DO_RESUME={ do_resume }
{% endmacro %}
{% if printer['gcode_button _door_detection'] %}
{% set sv = printer.save_variables.variables %}
{% set door_function = sv.door_detect|default("Disabled") %}
{% set door_state = printer['gcode_button _door_detection'].state|default('released')|lower %}
{% if door_function == 'Pause Print' and door_state == 'pressed' %}
{ resume_action() }
{% elif door_function == 'Pause Print' and door_state == 'released' %}
RESPOND TYPE=command MSG="action:prompt_begin"
RESPOND TYPE=command MSG="action:prompt_text Please close the door and click Resume to proceed."
RESPOND TYPE=command MSG="action:prompt_footer_button Ok|RESPOND TYPE=command MSG=action:prompt_end"
RESPOND TYPE=command MSG="action:prompt_show"
{% endif %}
{% else %}
{ resume_action() }
{% endif %}
{% if last_extruder_temp.restore or last_extruder1_temp.restore %}
{client.user_temp_macro|default("")}
{% set do_resume = True %}
{% elif can_extrude %}
{% set do_resume = True %}
{% endif %}
_ACT_RESUME DO_RESUME={do_resume}
[gcode_macro _ACT_RESUME]
gcode:
@ -1146,4 +1167,6 @@ gcode:
[gcode_macro _NOZZLE_XY_OFFSET_CALIBRATE]
gcode:
RUN_SHELL_COMMAND CMD=fetch_assets PARAMS="\"Gcode\" \"D600Pro2HS\" \"NozzleAglin.zip\""
SDCARD_PRINT_FILE FILENAME=".PresetModel/NozzleAglin.gcode"
SDCARD_PRINT_FILE FILENAME=".PresetModel/NozzleAglin.gcode"
[include module/*.cfg]

View File

@ -0,0 +1,32 @@
[gcode_button _door_detection]
pin: DOOR_PIN
press_gcode:
release_gcode:
{% set sv = printer.save_variables.variables %}
{% set door_function = sv.door_detect|default("Disabled") %}
{% if door_function != "Disabled" %}
M118 Printer door is opening!
{% endif %}
_DOOR_DETECTION_HANDLE STATUS='open'
[gcode_macro _DOOR_DETECTION_HANDLE]
gcode:
{% set sv = printer.save_variables.variables %}
{% set door_function = sv.door_detect|default("Disabled") %}
{% set status = params.STATUS|default("close") %}
{% set printing_state = printer.print_stats.state %}
{% if status=='open' and printing_state == 'printing' %}
{% if door_function == 'Emergency Stop' %}
M112
{% elif door_function == 'Pause Print' %}
PAUSE
{% endif %}
{% endif %}
[gcode_macro _DOOR_START_PRINT_BASE]
description: Call handle door is open when starting to print
gcode:
RESPOND TYPE=command MSG="action:prompt_begin"
RESPOND TYPE=command MSG="action:prompt_text Printer door is opened. Please close the door and then start printing."
RESPOND TYPE=command MSG="action:prompt_footer_button Ok|RESPOND TYPE=command MSG=action:prompt_end"
RESPOND TYPE=command MSG="action:prompt_show"