Skip to content

Commit

Permalink
initial code for suicide switch
Browse files Browse the repository at this point in the history
  • Loading branch information
strayr committed Dec 10, 2023
1 parent c22742f commit b6a5966
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 65 deletions.
46 changes: 46 additions & 0 deletions M84.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
####
# Improved M84 turns of individual axis.
#
# Will work for upto 4 Z steppers automaticly. Intended for use with idle_timeout.cfg
#
###
[gcode_macro M84]
description: Can disable a subset of steppers, M84 X Y E leaves Z enabled. M84 XY (no spaces) is invalid and disables all steppers.
rename_existing: M84.1
gcode:
{% if 'X' in params %}
{action_respond_info("Stepper X turned off")}
SET_STEPPER_ENABLE stepper=stepper_x enable=0
{% endif %}

{% if 'Y' in params %}
{action_respond_info("Stepper Y turned off")}
SET_STEPPER_ENABLE stepper=stepper_y enable=0
{% endif %}

{% if 'E' in params %}
{action_respond_info("Extruder turned off")}
SET_STEPPER_ENABLE stepper=extruder enable=0
{% endif %}

{% if 'Z' in params %}
SET_STEPPER_ENABLE stepper=stepper_z enable=0
{action_respond_info("Stepper Z turned off")}
{% if printer.configfile.settings.stepper_z1 %}
{action_respond_info("Stepper Z1 turned off")}
SET_STEPPER_ENABLE stepper=stepper_z1 enable=0
{% endif %}
{% if printer.configfile.settings.stepper_z2 %}
{action_respond_info("Stepper Z2 turned off")}
SET_STEPPER_ENABLE stepper=stepper_z2 enable=0
{% endif %}
{% if printer.configfile.settings.stepper_z3 %}
{action_respond_info("Stepper Z3 turned off")}
SET_STEPPER_ENABLE stepper=stepper_z3 enable=0
{% endif %}
{% endif %}

{% if 'X' not in params and 'Y' not in params and 'E' not in params and 'Z' not in params%}
{action_respond_info("All steppers turned off")}
M84.1
{% endif %}
20 changes: 10 additions & 10 deletions auto_mesh.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#https://klipper.info/macro-examples-1/dutchdudes-automatic-bed-selection


[gcode_macro LOAD_MESH_TEMP]
[gcode_macro _LOAD_MESH_TEMP]
variable_version: 0.2
gcode:
# TODO use SVV
{% set svv = printer.save_variables.variables %}
{% set version = printer["gcode_macro LOAD_MESH_TEMP"].version %}
{% if svv.setup_version|float < version|float %}
Expand All @@ -33,13 +32,13 @@ gcode:
{% endif %}
{ action_respond_info("bed_mesh not defined, your bed temperature will go up!")}
{ action_respond_info("We will probe the bed and save the mesh as bed_mesh "+ BED_TEMP|string)}
ADD_BED_MESH TARGET_TEMP={BED_TEMP}
_ADD_BED_MESH TARGET_TEMP={BED_TEMP}
SAVE_AT_END
{% endif %}
{% endif %}

[gcode_macro ADD_BED_MESH]
#default_parameter_TARGET_TEMP: 30
[gcode_macro _ADD_BED_MESH]
description: Use in start print to add a bed mesh.
gcode:
# TODO use SVV
{% set svv = printer.save_variables.variables %}
Expand All @@ -62,13 +61,14 @@ gcode:
_SOUND_YES

[gcode_macro FORCE_MESH_REBUILD]
description: Expires the previous mesh lifespan, persistent.
gcode:
SAVE_VARIABLE VARIABLE=setup_mesh_lifespan VALUE=0
{ action_respond_info("The mesh will be rebuit")}
# SAVE_AT_END # not needed we do this automatically

#[gcode_macro FORCE_MESH_LOAD]
#description: Adds another ten uses to the life of the mesh
#gcode:
# SET_GCODE_VARIABLE MACRO=LOAD_MESH_TEMP VARIABLE=force VALUE=10
# { action_respond_info("The mesh will not be rebuilt unless it does not exist")}
[gcode_macro FORCE_MESH_LOAD]
description: Adds another use to the life ofthe mesh. USE WITH CARE
gcode:
SAVE_VARIABLE VARIABLE=setup_mesh_lifespan VALUE=1
{ action_respond_info("The mesh will not be rebuilt unless it does not exist")}
61 changes: 15 additions & 46 deletions idle_timeout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,28 @@

# Idle timeout. An idle timeout is automatically enabled - add an
# explicit idle_timeout config section to change the default settings.

# Adds a check to see if the printer should shutdown on idle

[idle_timeout]
gcode:
#{action_respond_info("Timeout, X Y E disabled")}
#M84 X Y E

{action_respond_info("Timeout, Extruder Heater Disabled")}
SET_HEATER_TEMPERATURE HEATER=extruder TARGET=0
timeout: 600
# Idle time (in seconds) to wait before running the above G-Code
# commands. The default is 600 seconds.

####
# Improved M84 turns of individual axis.
#
# Will work for upto 4 Z steppers automaticly. Intended for use with idle_timeout.cfg
#
###
[gcode_macro M84]
description: Can disable a subset of steppers, M84 X Y E leaves Z enabled. M84 XY (no spaces) is invalid and disables all steppers.
rename_existing: M84.1
gcode:
{% if 'X' in params %}
{action_respond_info("Stepper X turned off")}
SET_STEPPER_ENABLE stepper=stepper_x enable=0
{% endif %}

{% if 'Y' in params %}
{action_respond_info("Stepper Y turned off")}
SET_STEPPER_ENABLE stepper=stepper_y enable=0
#TODO check if pause state is active, don't timeout the motors on a pause.
#TODO check if pause state acive and if not turn the bed off unless we set a preheat
{% if printer.save_variables.variables.idle_gantry_power == 0 %}
{action_respond_info("Timeout, Extruder Heater Disabled")}
M84
{% elif printer.save_variables.variables.idle_gantry_power == 1 %}
#TODO i mean this works, but...
#M84 X Y E # only works if extended M84 enabled
{% endif %}
_SHUTDOWN_IF_SET
# Idle time (in seconds) to wait before running the above G-Code
# commands. The default is 600 seconds.

{% if 'E' in params %}
{action_respond_info("Extruder turned off")}
SET_STEPPER_ENABLE stepper=extruder enable=0
{% endif %}

{% if 'Z' in params %}
SET_STEPPER_ENABLE stepper=stepper_z enable=0
{action_respond_info("Stepper Z turned off")}
{% if printer.configfile.settings.stepper_z1 %}
{action_respond_info("Stepper Z1 turned off")}
SET_STEPPER_ENABLE stepper=stepper_z1 enable=0
{% endif %}
{% if printer.configfile.settings.stepper_z2 %}
{action_respond_info("Stepper Z2 turned off")}
SET_STEPPER_ENABLE stepper=stepper_z2 enable=0
{% endif %}
{% if printer.configfile.settings.stepper_z3 %}
{action_respond_info("Stepper Z3 turned off")}
SET_STEPPER_ENABLE stepper=stepper_z3 enable=0
{% endif %}
{% endif %}

{% if 'X' not in params and 'Y' not in params and 'E' not in params and 'Z' not in params%}
{action_respond_info("All steppers turned off")}
M84.1
{% endif %}
60 changes: 56 additions & 4 deletions save_at_end.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# From makatos
# This can save the config at the end of a print, automesh enables this when it makes a new mesh
# It can also shutdown the printer in idle after a print


# Based on makatos' save at end
# https://klipper.info/macro-examples-1/makotos-conditional-config-saving

[delayed_gcode delay_save]
[delayed_gcode delay_end]
gcode:
# IF we made a mesh save the temperature and set lifespan
{% if printer["gcode_macro SAVE_AT_END"].mesh_temp > 1 %}
Expand All @@ -17,7 +21,7 @@ gcode:
SET_GCODE_VARIABLE MACRO=SAVE_AT_END VARIABLE=save VALUE=1
{action_respond_info("SAVE_AT_END is armed")}

[gcode_macro SAVE_IF_SET]
[gcode_macro _SAVE_IF_SET]
gcode:
{% if printer["gcode_macro SAVE_AT_END"].save == 1 %}
{action_respond_info("SAVE_AT_END requested save")}
Expand All @@ -26,4 +30,52 @@ gcode:
{% else %}
_SOUND_NO
{action_respond_info("SAVE_AT_END did not request save")}
{% endif %}
{% endif %}
{% if printer["gcode_macro SHUTDOWN_AT_END"].halt == 1 %}
{action_respond_info("SHUTDOWN_AT_END requested halt")}
_SOUND_YES
SAVE_VARIABLE VARIABLE=idle_shutdown VALUE=1
{% else %}
_SOUND_NO
{action_respond_info("SAVE_AT_END did not request save")}
{% endif %}


[gcode_macro SHUTDOWN_AT_END]
variable_halt: 0
gcode:
SET_GCODE_VARIABLE MACRO=SHUTDOWN_AT_END VARIABLE=halt VALUE=1
{action_respond_info("SAVE_AT_END is armed")}



[gcode_macro _SHUTDOWN_IF_SET]
description: checks to see if the printer was marked for shutdown on idle
variable_version: 0.4
gcode:
G4
{% set svv = printer.save_variables.variables %}
{% set version = printer["gcode_macro _SHUTDOWN_IF_SET"].version %}
{% if svv.idle_version|float < version|float %}
{ action_raise_error("Setup data is older than macro version \
You should check the values in INIT_SETUP and run it to update \
")}

{% endif %}
{% if svv.idle_shutdown == 1 %}
# {% if printer["gcode_macro POWER_OFF_PRINTER"] %}
# SAVE_VARIABLE VARIABLE=idle_shutdown VALUE=0
# POWER_OFF_PRINTER
# {action_respond_info("Trying to shutdown")}
# {% else %}
# {action_respond_info("POWER_OFF_PRINTER macro does not exist")}
# {% endif %}
SAVE_VARIABLE VARIABLE=idle_shutdown VALUE=0
G4
{action_respond_info("Trying to shutdown")}
{action_call_remote_method("set_device_power",
device="printer",
state="off")}
{% endif %}
{action_respond_info("Printer still running")}

14 changes: 11 additions & 3 deletions save_variables.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ gcode:
_INIT_SETUP
_INIT_FILAMENT
_INIT_BED
_INIT_IDLE

[gcode_macro _INIT_SETUP]
description: Initialise the parameters used by START_PRINT including nozzle offset.
variable_version: 0.1
variable_version: 0.4
gcode:
# After you run probe calibrate, this is the z-offset you need to apply
# in order to get a good first layer height on your default bed. This should
Expand All @@ -43,7 +44,7 @@ gcode:

[gcode_macro _INIT_FILAMENT]
description: Initialise the values used to change filament
variable_version: 0.1
variable_version: 0.4
gcode:
# This is the length down to the metlzone. It can be measured by making a
# mark on the loaded filament where it leaves the extruder or reverse
Expand Down Expand Up @@ -86,11 +87,18 @@ gcode:

[gcode_macro _INIT_BED]
description: Initialise the values used to for the bed
variable_version: 0.1
variable_version: 0.4
gcode:
SAVE_VARIABLE VARIABLE=bed_slot VALUE=0
# This is the difference between the bed in use and the reference surface.
SAVE_VARIABLE VARIABLE=bed_offset VALUE=0.0
#this is the bed we set out nozzle height with
SAVE_VARIABLE VARIABLE=bed_reference VALUE=0
SAVE_VARIABLE VARIABLE=bed_version VALUE={version}

[gcode_macro _INIT_IDLE]
description: Initialise the parameters used by START_PRINT including nozzle offset.
variable_version: 0.4
gcode:
SAVE_VARIABLE VARIABLE=idle_version VALUE={version}
SAVE_VARIABLE VARIABLE=idle_shutdown VALUE=0
4 changes: 2 additions & 2 deletions setup_macros.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ gcode:


[gcode_macro START_PRINT]
variable_version: 0.1
variable_version: 0.4
description: Does everythin to go from a cold printer to a successful print except a purge line.
gcode:
{% set svv = printer.save_variables.variables %}
Expand Down Expand Up @@ -123,7 +123,7 @@ gcode:
SET_GCODE_OFFSET Z_ADJUST={-(svv.setup_nozzle_offset)} ;+ve is UP
M117 Print Done
#FORCE_MESH_LOAD #removed becasue not needed
SAVE_IF_SET
_SAVE_IF_SET

[gcode_macro CANCEL_PRINT]
rename_existing: BASE_CANCEL_PRINT
Expand Down

0 comments on commit b6a5966

Please sign in to comment.