← Back to Config Store
📄 mainsail.conf
FILE: mainsail.conf
•
LINES: 314
•
SIZE: 16.11 KB
•
SYNTAX: INI / Klipper G-Code
1 ## Client klipper macro definitions
2 ##
3 ## Copyright (C) 2022 Alex Zellner <alexander.zellner@googlemail.com>
4 ##
5 ## This file may be distributed under the terms of the GNU GPLv3 license
6 ##
7 ## !!! This file is read-only. Maybe the used editor indicates that. !!!
8 ##
9 ## Customization:
10 ## 1) copy the gcode_macro _CLIENT_VARIABLE (see below) to your printer.cfg
11 ## 2) remove the comment mark (#) from all lines
12 ## 3) change any value in there to your needs
13 ##
14 ## Use the PAUSE macro direct in your M600:
15 ## e.g. with a different park position front left and a minimal height of 50
16 ## [gcode_macro M600]
17 ## description: Filament change
18 ## gcode: PAUSE X=10 Y=10 Z_MIN=50
19 ## Z_MIN will park the toolhead at a minimum of 50 mm above to bed to make it easier for you to swap filament.
20 ##
21 ## Client variable macro for your printer.cfg
22 #[gcode_macro _CLIENT_VARIABLE]
23 #variable_use_custom_pos : False ; use custom park coordinates for x,y [True/False]
24 #variable_custom_park_x : 0.0 ; custom x position; value must be within your defined min and max of X
25 #variable_custom_park_y : 0.0 ; custom y position; value must be within your defined min and max of Y
26 #variable_custom_park_dz : 2.0 ; custom dz value; the value in mm to lift the nozzle when move to park position
27 #variable_retract : 1.0 ; the value to retract while PAUSE
28 #variable_cancel_retract : 5.0 ; the value to retract while CANCEL_PRINT
29 #variable_speed_retract : 35.0 ; retract speed in mm/s
30 #variable_unretract : 1.0 ; the value to unretract while RESUME
31 #variable_speed_unretract : 35.0 ; unretract speed in mm/s
32 #variable_speed_hop : 15.0 ; z move speed in mm/s
33 #variable_speed_move : 100.0 ; move speed in mm/s
34 #variable_park_at_cancel : False ; allow to move the toolhead to park while execute CANCEL_PRINT [True/False]
35 #variable_park_at_cancel_x : None ; different park position during CANCEL_PRINT [None/Position as Float]; park_at_cancel must be True
36 #variable_park_at_cancel_y : None ; different park position during CANCEL_PRINT [None/Position as Float]; park_at_cancel must be True
37 ## !!! Caution [firmware_retraction] must be defined in the printer.cfg if you set use_fw_retract: True !!!
38 #variable_use_fw_retract : False ; use fw_retraction instead of the manual version [True/False]
39 #variable_idle_timeout : 0 ; time in sec until idle_timeout kicks in. Value 0 means that no value will be set or restored
40 #variable_runout_sensor : "" ; If a sensor is defined, it will be used to cancel the execution of RESUME in case no filament is detected.
41 ## Specify the config name of the runout sensor e.g "filament_switch_sensor runout". Hint use the same as in your printer.cfg
42 ## !!! Custom macros, please use with care and review the section of the corresponding macro.
43 ## These macros are for simple operations like setting a status LED. Please make sure your macro does not interfere with the basic macro functions.
44 ## Only single line commands are supported, please create a macro if you need more than one command.
45 #variable_user_pause_macro : "" ; Everything inside the "" will be executed after the klipper base pause (PAUSE_BASE) function
46 #variable_user_resume_macro: "" ; Everything inside the "" will be executed before the klipper base resume (RESUME_BASE) function
47 #variable_user_cancel_macro: "" ; Everything inside the "" will be executed before the klipper base cancel (CANCEL_PRINT_BASE) function
48 #gcode:
49
50 [virtual_sdcard]
51 path: ~/printer_data/gcodes
52 on_error_gcode: CANCEL_PRINT
53
54 [pause_resume]
55 #recover_velocity: 50.
56 # When capture/restore is enabled, the speed at which to return to
57 # the captured position (in mm/s). Default is 50.0 mm/s.
58
59 [display_status]
60
61 [respond]
62
63 [gcode_macro CANCEL_PRINT]
64 description: Cancel the actual running print
65 rename_existing: CANCEL_PRINT_BASE
66 gcode:
67 ##### get user parameters or use default #####
68 {% set client = printer['gcode_macro _CLIENT_VARIABLE']|default({}) %}
69 {% set allow_park = client.park_at_cancel|default(false)|lower == 'true' %}
70 {% set retract = client.cancel_retract|default(5.0)|abs %}
71 ##### define park position #####
72 {% set park_x = "" if (client.park_at_cancel_x|default(none) is none)
73 else "X=" ~ client.park_at_cancel_x %}
74 {% set park_y = "" if (client.park_at_cancel_y|default(none) is none)
75 else "Y=" ~ client.park_at_cancel_y %}
76 {% set custom_park = park_x|length > 0 or park_y|length > 0 %}
77 ##### end of definitions #####
78 # restore idle_timeout time if needed
79 {% if printer['gcode_macro RESUME'].restore_idle_timeout > 0 %}
80 SET_IDLE_TIMEOUT TIMEOUT={printer['gcode_macro RESUME'].restore_idle_timeout}
81 {% endif %}
82 {% if (custom_park or not printer.pause_resume.is_paused) and allow_park %} _TOOLHEAD_PARK_PAUSE_CANCEL {park_x} {park_y} {% endif %}
83 _CLIENT_RETRACT LENGTH={retract}
84 TURN_OFF_HEATERS
85 M106 S0
86 {client.user_cancel_macro|default("")}
87 SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=idle_state VALUE=False
88 # clear pause_next_layer and pause_at_layer as preparation for next print
89 SET_PAUSE_NEXT_LAYER ENABLE=0
90 SET_PAUSE_AT_LAYER ENABLE=0 LAYER=0
91 CANCEL_PRINT_BASE
92
93 [gcode_macro PAUSE]
94 description: Pause the actual running print
95 rename_existing: PAUSE_BASE
96 gcode:
97 ##### get user parameters or use default #####
98 {% set client = printer['gcode_macro _CLIENT_VARIABLE']|default({}) %}
99 {% set idle_timeout = client.idle_timeout|default(0) %}
100 {% set temp = printer[printer.toolhead.extruder].target if printer.toolhead.extruder != '' else 0 %}
101 {% set restore = False if printer.toolhead.extruder == ''
102 else True if params.RESTORE|default(1)|int == 1 else False %}
103 ##### end of definitions #####
104 SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=last_extruder_temp VALUE="{{'restore': restore, 'temp': temp}}"
105 # set a new idle_timeout value
106 {% if idle_timeout > 0 %}
107 SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=restore_idle_timeout VALUE={printer.configfile.settings.idle_timeout.timeout}
108 SET_IDLE_TIMEOUT TIMEOUT={idle_timeout}
109 {% endif %}
110 PAUSE_BASE
111 {client.user_pause_macro|default("")}
112 _TOOLHEAD_PARK_PAUSE_CANCEL {rawparams}
113
114 [gcode_macro RESUME]
115 description: Resume the actual running print
116 rename_existing: RESUME_BASE
117 variable_last_extruder_temp: {'restore': False, 'temp': 0}
118 variable_restore_idle_timeout: 0
119 variable_idle_state: False
120 gcode:
121 ##### get user parameters or use default #####
122 {% set client = printer['gcode_macro _CLIENT_VARIABLE']|default({}) %}
123 {% set velocity = printer.configfile.settings.pause_resume.recover_velocity %}
124 {% set sp_move = client.speed_move|default(velocity) %}
125 {% set runout_resume = True if client.runout_sensor|default("") == "" # no runout
126 else True if not printer[client.runout_sensor].enabled # sensor is disabled
127 else printer[client.runout_sensor].filament_detected %} # sensor status
128 {% set can_extrude = True if printer.toolhead.extruder == '' # no extruder defined in config
129 else printer[printer.toolhead.extruder].can_extrude %} # status of active extruder
130 {% set do_resume = False %}
131 {% set prompt_txt = [] %}
132 ##### end of definitions #####
133 #### Printer comming from timeout idle state ####
134 {% if printer.idle_timeout.state|upper == "IDLE" or idle_state %}
135 SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=idle_state VALUE=False
136 {% if last_extruder_temp.restore %}
137 # we need to use the unicode (\u00B0) for the ° as py2 env's would throw an error otherwise
138 RESPOND TYPE=echo MSG='{"Restoring \"%s\" temperature to %3.1f\u00B0C, this may take some time" % (printer.toolhead.extruder, last_extruder_temp.temp) }'
139 M109 S{last_extruder_temp.temp}
140 {% set do_resume = True %}
141 {% elif can_extrude %}
142 {% set do_resume = True %}
143 {% else %}
144 RESPOND TYPE=error MSG='{"Resume aborted !!! \"%s\" not hot enough, please heat up again and press RESUME" % printer.toolhead.extruder}'
145 {% set _d = prompt_txt.append("\"%s\" not hot enough, please heat up again and press RESUME" % printer.toolhead.extruder) %}
146 {% endif %}
147 #### Printer comming out of regular PAUSE state ####
148 {% elif can_extrude %}
149 {% set do_resume = True %}
150 {% else %}
151 RESPOND TYPE=error MSG='{"Resume aborted !!! \"%s\" not hot enough, please heat up again and press RESUME" % printer.toolhead.extruder}'
152 {% set _d = prompt_txt.append("\"%s\" not hot enough, please heat up again and press RESUME" % printer.toolhead.extruder) %}
153 {% endif %}
154 {% if runout_resume %}
155 {% if do_resume %}
156 {% if restore_idle_timeout > 0 %} SET_IDLE_TIMEOUT TIMEOUT={restore_idle_timeout} {% endif %} # restore idle_timeout time
157 {client.user_resume_macro|default("")}
158 _CLIENT_EXTRUDE
159 RESUME_BASE VELOCITY={params.VELOCITY|default(sp_move)}
160 {% endif %}
161 {% else %}
162 RESPOND TYPE=error MSG='{"Resume aborted !!! \"%s\" detects no filament, please load filament and press RESUME" % (client.runout_sensor.split(" "))[1]}'
163 {% set _d = prompt_txt.append("\"%s\" detects no filament, please load filament and press RESUME" % (client.runout_sensor.split(" "))[1]) %}
164 {% endif %}
165 ##### Generate User Information box in case of abort #####
166 {% if not (runout_resume and do_resume) %}
167 RESPOND TYPE=command MSG="action:prompt_begin RESUME aborted !!!"
168 {% for element in prompt_txt %}
169 RESPOND TYPE=command MSG='{"action:prompt_text %s" % element}'
170 {% endfor %}
171 RESPOND TYPE=command MSG="action:prompt_footer_button Ok|RESPOND TYPE=command MSG=action:prompt_end|info"
172 RESPOND TYPE=command MSG="action:prompt_show"
173 {% endif %}
174
175 # Usage: SET_PAUSE_NEXT_LAYER [ENABLE=[0|1]] [MACRO=<name>]
176 [gcode_macro SET_PAUSE_NEXT_LAYER]
177 description: Enable a pause if the next layer is reached
178 gcode:
179 {% set pause_next_layer = printer['gcode_macro SET_PRINT_STATS_INFO'].pause_next_layer %}
180 {% set ENABLE = params.ENABLE|default(1)|int != 0 %}
181 {% set MACRO = params.MACRO|default(pause_next_layer.call, True) %}
182 SET_GCODE_VARIABLE MACRO=SET_PRINT_STATS_INFO VARIABLE=pause_next_layer VALUE="{{ 'enable': ENABLE, 'call': MACRO }}"
183
184 # Usage: SET_PAUSE_AT_LAYER [ENABLE=[0|1]] [LAYER=<number>] [MACRO=<name>]
185 [gcode_macro SET_PAUSE_AT_LAYER]
186 description: Enable/disable a pause if a given layer number is reached
187 gcode:
188 {% set pause_at_layer = printer['gcode_macro SET_PRINT_STATS_INFO'].pause_at_layer %}
189 {% set ENABLE = params.ENABLE|int != 0 if params.ENABLE is defined
190 else params.LAYER is defined %}
191 {% set LAYER = params.LAYER|default(pause_at_layer.layer)|int %}
192 {% set MACRO = params.MACRO|default(pause_at_layer.call, True) %}
193 SET_GCODE_VARIABLE MACRO=SET_PRINT_STATS_INFO VARIABLE=pause_at_layer VALUE="{{ 'enable': ENABLE, 'layer': LAYER, 'call': MACRO }}"
194
195 # Usage: SET_PRINT_STATS_INFO [TOTAL_LAYER=<total_layer_count>] [CURRENT_LAYER= <current_layer>]
196 [gcode_macro SET_PRINT_STATS_INFO]
197 rename_existing: SET_PRINT_STATS_INFO_BASE
198 description: Overwrite, to get pause_next_layer and pause_at_layer feature
199 variable_pause_next_layer: { 'enable': False, 'call': "PAUSE" }
200 variable_pause_at_layer : { 'enable': False, 'layer': 0, 'call': "PAUSE" }
201 gcode:
202 {% if pause_next_layer.enable %}
203 RESPOND TYPE=echo MSG='{"%s, forced by pause_next_layer" % pause_next_layer.call}'
204 {pause_next_layer.call} ; execute the given gcode to pause, should be either M600 or PAUSE
205 SET_PAUSE_NEXT_LAYER ENABLE=0
206 {% elif pause_at_layer.enable and params.CURRENT_LAYER is defined and params.CURRENT_LAYER|int == pause_at_layer.layer %}
207 RESPOND TYPE=echo MSG='{"%s, forced by pause_at_layer [%d]" % (pause_at_layer.call, pause_at_layer.layer)}'
208 {pause_at_layer.call} ; execute the given gcode to pause, should be either M600 or PAUSE
209 SET_PAUSE_AT_LAYER ENABLE=0
210 {% endif %}
211 SET_PRINT_STATS_INFO_BASE {rawparams}
212
213 ##### internal use #####
214 [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
215 description: Helper: park toolhead used in PAUSE and CANCEL_PRINT
216 gcode:
217 ##### get user parameters or use default #####
218 {% set client = printer['gcode_macro _CLIENT_VARIABLE']|default({}) %}
219 {% set velocity = printer.configfile.settings.pause_resume.recover_velocity %}
220 {% set use_custom = client.use_custom_pos|default(false)|lower == 'true' %}
221 {% set custom_park_x = client.custom_park_x|default(0.0) %}
222 {% set custom_park_y = client.custom_park_y|default(0.0) %}
223 {% set park_dz = client.custom_park_dz|default(2.0)|abs %}
224 {% set sp_hop = client.speed_hop|default(15) * 60 %}
225 {% set sp_move = client.speed_move|default(velocity) * 60 %}
226 ##### get config and toolhead values #####
227 {% set origin = printer.gcode_move.homing_origin %}
228 {% set act = printer.gcode_move.gcode_position %}
229 {% set max = printer.toolhead.axis_maximum %}
230 {% set cone = printer.toolhead.cone_start_z|default(max.z) %} ; height as long the toolhead can reach max and min of an delta
231 {% set round_bed = True if printer.configfile.settings.printer.kinematics is in ['delta','polar','rotary_delta','winch']
232 else False %}
233 ##### define park position #####
234 {% set z_min = params.Z_MIN|default(0)|float %}
235 {% set z_park = [[(act.z + park_dz), z_min]|max, (max.z - origin.z)]|min %}
236 {% set x_park = params.X if params.X is defined
237 else custom_park_x if use_custom
238 else 0.0 if round_bed
239 else (max.x - 5.0) %}
240 {% set y_park = params.Y if params.Y is defined
241 else custom_park_y if use_custom
242 else (max.y - 5.0) if round_bed and z_park < cone
243 else 0.0 if round_bed
244 else (max.y - 5.0) %}
245 ##### end of definitions #####
246 _CLIENT_RETRACT
247 {% if "xyz" in printer.toolhead.homed_axes %}
248 G90
249 G1 Z{z_park} F{sp_hop}
250 G1 X{x_park} Y{y_park} F{sp_move}
251 {% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %}
252 {% else %}
253 RESPOND TYPE=echo MSG='Printer not homed'
254 {% endif %}
255
256 [gcode_macro _CLIENT_EXTRUDE]
257 description: Extrudes, if the extruder is hot enough
258 gcode:
259 ##### get user parameters or use default #####
260 {% set client = printer['gcode_macro _CLIENT_VARIABLE']|default({}) %}
261 {% set use_fw_retract = (client.use_fw_retract|default(false)|lower == 'true') and (printer.firmware_retraction is defined) %}
262 {% set length = params.LENGTH|default(client.unretract)|default(1.0)|float %}
263 {% set speed = params.SPEED|default(client.speed_unretract)|default(35) %}
264 {% set absolute_extrude = printer.gcode_move.absolute_extrude %}
265 ##### end of definitions #####
266 {% if printer.toolhead.extruder != '' %}
267 {% if printer[printer.toolhead.extruder].can_extrude %}
268 {% if use_fw_retract %}
269 {% if length < 0 %}
270 G10
271 {% else %}
272 G11
273 {% endif %}
274 {% else %}
275 M83
276 G1 E{length} F{(speed|float|abs) * 60}
277 {% if absolute_extrude %}
278 M82
279 {% endif %}
280 {% endif %}
281 {% else %}
282 RESPOND TYPE=echo MSG='{"\"%s\" not hot enough" % printer.toolhead.extruder}'
283 {% endif %}
284 {% endif %}
285
286 [gcode_macro _CLIENT_RETRACT]
287 description: Retracts, if the extruder is hot enough
288 gcode:
289 {% set client = printer['gcode_macro _CLIENT_VARIABLE']|default({}) %}
290 {% set length = params.LENGTH|default(client.retract)|default(1.0)|float %}
291 {% set speed = params.SPEED|default(client.speed_retract)|default(35) %}
292
293 _CLIENT_EXTRUDE LENGTH=-{length|float|abs} SPEED={speed|float|abs}
294
295 [gcode_macro _CLIENT_LINEAR_MOVE]
296 description: Linear move with save and restore of the gcode state
297 gcode:
298 {% set x_move = "X" ~ params.X if params.X is defined else "" %}
299 {% set y_move = "Y" ~ params.Y if params.Y is defined else "" %}
300 {% set z_move = "Z" ~ params.Z if params.Z is defined else "" %}
301 {% set e_move = "E" ~ params.E if params.E is defined else "" %}
302 {% set rate = "F" ~ params.F if params.F is defined else "" %}
303 {% set ABSOLUTE = params.ABSOLUTE | default(0) | int != 0 %}
304 {% set ABSOLUTE_E = params.ABSOLUTE_E | default(0) | int != 0 %}
305 SAVE_GCODE_STATE NAME=_client_movement
306 {% if x_move or y_move or z_move %}
307 G9{ 0 if ABSOLUTE else 1 }
308 {% endif %}
309 {% if e_move %}
310 M8{ 2 if ABSOLUTE_E else 3 }
311 {% endif %}
312 G1 { x_move } { y_move } { z_move } { e_move } { rate }
313 RESTORE_GCODE_STATE NAME=_client_movement
314