forked from jschuh/klipper-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.cfg
452 lines (432 loc) · 19.3 KB
/
globals.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# Copyright (C) 2022 Justin Schuh <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
################################################################################
#
# Declare any of the below variables in your own [gcode_macro _km_options] to
# to override the values here.
#
# DO NOT CHANGE ANYTHING IN THIS FILE!!!
#
# This file handles the initialization for all the macros, and difficult to
# diagnose errors will result from unexpected values or code changes.
#
################################################################################
[gcode_macro _km_globals]
# Available bed surfaces for offset adjustments.
variable_bed_surface_max_name_length: 10
# Available bed surfaces for offset adjustments.
variable_bed_surfaces: ['default']
# Length (in mm) of filament to load (bowden tubes will be longer).
variable_load_length: 90.0
# Global minimum extruder temp for loading (default: min_extrude_temp + 5).
variable_load_min_temp: 0
# Length (in mm) of the filament loading that feeds at priming speed.
variable_load_priming_length: 25.0
# Filament priming speed (in mm/m).
variable_load_priming_speed: 150
# Filament loading speed (in mm/m).
variable_load_speed: 300
# Set to False to hide the Octoprint LCD menus.
variable_menu_show_octoprint: True
# Set to False to hide the SD Card LCD menus.
variable_menu_show_sdcard: True
# List up to 10 pre-heat settings in order for the LCD "Temperature" menu
variable_menu_temperature: [
{'name' : 'PLA', 'extruder' : 200, 'bed' : 60},
{'name' : 'PETG', 'extruder' : 230, 'bed' : 85},
{'name' : 'ABS', 'extruder' : 245, 'bed' : 110}]
# X position to park toolhead (set "max" or "min" to infer from stepper config).
variable_park_x: 0.0
# Y position to park toolhead (set "max" or "min" to infer from stepper config).
variable_park_y: 0.0
# Z position to park toolhead (set "max" or "min" to infer from stepper config).
variable_park_z: 20.0
# Minimum printable XY coordinate. Defaults to X and Y position_min.
variable_print_min: () # example: (0, 0)
# Maximum printable XY coordinate. Defaults to X and Y position_max.
variable_print_max: () # example: (220, 220)
# Scaling factor for M900 command (negative values make M900 a no-op).
variable_pressure_advance_scale: -1.0
# Additional padding around the specified print area for a bed mesh.
variable_probe_mesh_padding : 5.0
# Minimum number of probes for partial probing of a bed mesh.
variable_probe_min_count: 3
# Scaling factor to increase probe count for partial bed probes.
variable_probe_count_scale: 1.0
# Additional delay (in ms) during bed heating, to allow the bed to stabilize.
variable_start_bed_heat_delay: 2000
# Amount (in degrees C) to overshoot bed target temp before stabilizing.
variable_start_bed_heat_overshoot: 2.0
# Set to clear adjustments (e.g. feedrate, extrusion, heater) at end of print.
variable_start_clear_adjustments_at_end: True
# Final Y position of toolhead in PRINT_END. Defaults to print_max Y.
variable_start_end_park_y: 0.0
# Extruder scale factor during pre-warmup in PRINT_START.
variable_start_extruder_preheat_scale: 0.5
# If non-zero the extruder will stabilize at this temp before probing the bed.
variable_start_extruder_probing_temp: 0
# Set to rehome Z in PRINT_START after bed temp stabilizes; False to disable.
variable_start_home_z_at_temp: True
# Set to level bed in PRINT_START after bed temp stabilizes; False to disable.
variable_start_level_bed_at_temp: True
# Distance (in millimeters) between the purge lines and the print area.
variable_start_purge_clearance: 2.0
# Length of filament (in millimeters) to purge at print start.
variable_start_purge_length: 0.0 # 30 is a good starting point.
# Length of filament (in millimeters) to prime before drawing purge lines.
variable_start_purge_prime_length: 12.0
# Level gantry in PRINT_START after bed temp stabilizes; False to disable.
variable_start_quad_gantry_level_at_temp: True
# Skip level and load saved mesh for current sheet (if found); False to disable.
variable_start_try_saved_surface_mesh: False
# Adjust Z tilt in PRINT_START after bed temp stabilizes; False to disable.
variable_start_z_tilt_adjust_at_temp: True
# X and Y travel speed (in mm/m) for movement macros.
variable_travel_speed_xy: 3000
# Z travel speed in (mm/m) for movement macros.
variable_travel_speed_z: 600
# Value to scale acceleration by when setting ACCEL_TO_DECEL in M204, etc.
variable_velocity_decel_scale: 0.5
################################################################################
description: Initializes our globals, including any _km_options overrides.
gcode:
# Doing a shutdown here is a bit aggressive, but if we're missing required
# sections then a lot of things could go very bad later.
# To minimize the annoyance we try to identify all the fatal errors at once.
# format is:
# key = required config section
# value[0] = required field in section
# value[1] = required string in field
# A "None" value means there's no required field
{% set required_sections = {"heater_bed" : None,
"extruder" : None,
"gcode_macro _km_options" : None,
"idle_timeout" : ("gcode", "_KM_IDLE_TIMEOUT"),
"pause_resume" : None,
"respond" : None,
"save_variables" : None,
"virtual_sdcard" : None
} %}
{% set custom_error = {
"start_extruder_set_target_before_level" :
"The start_extruder_set_target_before_level option has been removed. "
"Use the start_extruder_probing_temp option instead to set a fixed "
"probing temperature.",
"start_gcode_before_print" :
"The start_gcode_before_print option has been removed. The same effect "
"can now be achieved by inserting custom gcode before the "
"_PRINT_START_PHASE_PURGE line in your slicer's start gcode, or by "
"wrapping the _PRINT_START_PHASE_PURGE macro. See the Slicer "
"Configuration section in the readme for more information."
} %}
{% set output = [] %}
{% for s in required_sections %}
{% set f = required_sections[s][0] if required_sections[s] else None %}
{% set v = required_sections[s][1] if required_sections[s] else None %}
{% if s not in printer.configfile.config %}
{% set dummy = output.append("Missing [%s] section.\n" | format(s)) %}
{% elif f and
(v not in printer.configfile.config[s][f]|default("")|upper) %}
{% set dummy = output.append("Missing %s in %s for [%s] section.\n"
| format(v, f, s)) %}
{% endif %}
{% endfor %}
{% if output %}
{ action_emergency_stop((
"required printer.cfg section(s) missing:\n"
~ output | join("\n")) ~
"See readme: https://github.com/jschuh/klipper-macros\x23klipper-setup")
}
{% endif %}
# These are all set to their defaults based on config options:
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_level_bed_at_temp VALUE="{
1 if printer.bed_mesh is defined else 0}"
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_quad_gantry_level_at_temp VALUE="{
1 if printer.quad_gantry_level is defined else 0}"
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_z_tilt_adjust_at_temp VALUE="{
1 if printer.z_tilt is defined else 0}"
{% set toolhead = printer.toolhead %}
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=print_min VALUE="{
(toolhead.axis_minimum.x, toolhead.axis_minimum.y)}"
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=print_max VALUE="{
(toolhead.axis_maximum.x, toolhead.axis_maximum.y)}"
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_end_park_y VALUE="{
toolhead.axis_maximum.y}"
{% set settings = printer.configfile.settings %}
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_home_z_at_temp VALUE="{
1 if ("stepper_z" in settings and
settings.stepper_z.endstop_pin.split()|join("")|lower ==
"probe:z_virtual_endstop") else 0}"
{% set options = printer["gcode_macro _km_options"] %}
{% set km = printer["gcode_macro _km_globals"] %}
# Allow placeholders for parking positions.
{% if options.park_x|default("")|string|lower == "min" %}
{% set dummy = options.__setitem__("park_x",
printer.configfile.settings.stepper_x.position_min) %}
{% elif options.park_x|default("")|string|lower == "max" %}
{% set dummy = options.__setitem__("park_x",
printer.configfile.settings.stepper_x.position_max) %}
{% endif %}
{% if options.park_y|default("")|string|lower == "min" %}
{% set dummy = options.__setitem__("park_y",
printer.configfile.settings.stepper_y.position_min) %}
{% elif options.park_y|default("")|string|lower == "max" %}
{% set dummy = options.__setitem__("park_y",
printer.configfile.settings.stepper_y.position_max) %}
{% endif %}
{% if options.park_z|default("")|string|lower == "min" %}
{% set dummy = options.__setitem__("park_z",
printer.configfile.settings.stepper_z.position_min) %}
{% elif options.park_z|default("")|string|lower == "max" %}
{% set dummy = options.__setitem__("park_z",
printer.configfile.settings.stepper_z.position_max) %}
{% endif %}
# Force overrides to use the original types in _KM_GLOBALS.
{% for k in options %}
{% if k not in km %}
{% if k in custom_error %}
{% set dummy = output.append(custom_error[k]) %}
{% else %}
{% set dummy = output.append("%s is not valid for _KM_OPTIONS." |
format(k)) %}
{% endif %}
{% elif km[k] is string %}
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k
} VALUE="'{options[k]|replace('\\','\\\\')|replace('\'','\\\'')
|replace('\"','\\\"')}'"
{% elif km[k] is float %}
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k
} VALUE="{options[k]|float}"
{% elif km[k] is integer or km[k] is boolean %}
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k} VALUE="{options[k]|int}"
{% elif km[k] is mapping %}
{% if options[k] is not mapping %}
{% set dummy = output.append("%s requires a mapping type." |
format(k)) %}
{% endif %}
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k
} VALUE="{options[k]|replace('\"','\\\"')}"
{% elif km[k] is sequence %}
{% if options[k] is not sequence %}
{% set dummy = output.append("%s requires a sequence type." |
format(k)) %}
{% endif %}
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k
} VALUE="{options[k]|replace('\"','\\\"')}"
{% else %}
{% set dummy = output.append("%s is not a valid type for _KM_OPTIONS." |
format(k)) %}
{% endif %}
{% endfor %}
# Defaults that can alias to a user override.
{% if "print_max" in options and "start_end_park_y" not in options %}
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_end_park_y VALUE="{
options.print_max[1] }"
{% endif %}
{% if "homing_override" in printer.configfile.config %}
{% for l in printer.configfile.config.homing_override.gcode.split("\n") %}
{% if " g28 " in (" " ~ l.split("\x23")[0].split(";")[0]|lower ~ " ") %}
{% set dummy = output.append(
"G28 in [homing_override] gcode. Replace with G28.6245197 to "
"fix recursive macro call.\n"
"See readme: https://github.com/jschuh/klipper-macros\x23g28") %}
{% endif %}
{% endfor %}
{% endif %}
SET_GCODE_VARIABLE MACRO=check_km_config VARIABLE=load_errors VALUE="{
output|replace('\"','\\\"')}"
M400
[delayed_gcode INIT_GLOBALS]
# This runs once at startup and initializes all macros.
initial_duration: 1
gcode:
_KM_GLOBALS
# This needs to be its own macro so it gets evaluated after _KM_GLOBALS runs.
CHECK_KM_CONFIG
_INIT_SURFACES
BED_MESH_CHECK
# Sets the default drawing parameters.
SET_DRAW_PARAMS WIDTH="{printer.configfile.settings.extruder.nozzle_diameter}"
# This is any end-user gcode that need to run after macro initialization.
_KM_OPTIONS
[gcode_macro check_km_config]
variable_load_errors: []
description: Checks global variables and throws an error on any invalid values.
Does nothing if the config has no errors.
gcode:
{% set km = printer["gcode_macro _km_globals"] %}
{% set toolhead = printer.toolhead %}
{% set output = load_errors %}
{% if km.park_x > toolhead.axis_maximum.x or
km.park_x < toolhead.axis_minimum.x %}
{% set dummy = output.append("park_x is invalid.") %}
{% endif %}
{% if km.park_y > toolhead.axis_maximum.y or
km.park_y < toolhead.axis_minimum.y %}
{% set dummy = output.append("park_y is invalid.") %}
{% endif %}
{% if km.park_z > toolhead.axis_maximum.z or
km.park_z < toolhead.axis_minimum.z %}
{% set dummy = output.append("park_z is invalid.") %}
{% endif %}
{% if km.print_max[0] > toolhead.axis_maximum.x or
km.print_max[1] > toolhead.axis_maximum.y %}
{% set dummy = output.append("print_max is invalid.") %}
{% endif %}
{% if km.print_min[0] < toolhead.axis_minimum.x or
km.print_min[1] < toolhead.axis_minimum.y %}
{% set dummy = output.append("print_min is invalid.") %}
{% endif %}
{% if km.start_extruder_preheat_scale > 1.0 or
km.start_extruder_preheat_scale < 0.0 %}
{% set dummy = output.append("extruder_preheat_scale is invalid.") %}
{% endif %}
{% if km.load_length >
printer.configfile.settings["extruder"].max_extrude_only_distance %}
{% set dummy = output.append(
"load_length exceeds max_extrude_only_distance.") %}
{% endif %}
{% if km.load_length < km.load_priming_length %}
{% set dummy = output.append(
"load_length is shorter than load_priming_length.") %}
{% endif %}
{% if km.load_length < 0.0 %}
{% set dummy = output.append("load_length is negative.") %}
{% endif %}
{% if km.load_priming_length < 0.0 %}
{% set dummy = output.append("load_priming_length is negative.") %}
{% endif %}
# Emit all the config errors.
{% if output %}
{ action_raise_error(output|sort|join('\nError: ')) }
{% endif %}
M400
[gcode_macro kmvars]
description: Lists global variables used by klipper-macros.
Usage: KMVARS [SEARCH=<search_string>]
gcode:
{% set SEARCH = params.SEARCH|default(params.S|default(""))|lower %}
{% set km = printer["gcode_macro _km_globals"] %}
{% set output = [] %}
{% for k in km %}
{% if SEARCH in k %}
{% set dummy = output.append(k ~ ": " ~ km[k]) %}
{% endif %}
{% endfor %}
{ action_respond_info(output|sort|join('\n')) }
[gcode_macro check_macro_docs]
description: Lists macros lacking proper documentation.
Usage: CHECK_MACRO_DOCS [USAGE=<0|1>] [HIDDEN=<1|0>] [RENAMED=<1|0>]
gcode:
{% set USAGE = params.USAGE|default(0)|int %}
{% set HIDDEN = params.HIDDEN|default(0)|int %}
{% set RENAMED = params.RENAMED|default(0)|int %}
{% set output = [] %}
{%set config = printer.configfile.config %}
{% for k in config|sort %}
{% if k.startswith("gcode_macro") %}
{% set name = k.split()[1] %}
{% set desc = config[k].description|default("") %}
{% set is_renamed = config[k].rename_existing|default("") %}
{% if (not desc or (USAGE and not "Usage: "~name.upper() in desc)) and
(HIDDEN or not name.startswith('_')) and (RENAMED or is_renamed) %}
{% set dummy = output.append("%s %s: missing %s."
| format("*" if is_renamed else " ", name,
"description" if not desc else "usage")) %}
{% endif %}
{% endif %}
{% endfor %}
{action_respond_info(output|join("\n"))}
# The below macro is a lightly edited version of the one found here:
# https://klipper.discourse.group/t/example-search-printer-objects/164
[gcode_macro listvars]
description: Lists per-macro variables with a name containing SEARCH. This is
useful for debugging macros by allowing you to probe printer state. Be very
careful, however, as an overly broad SEARCH parameter can take a long time
to process and potentially hang or crash klipper.
Usage: LISTVARS SEARCH=<search_string>
gcode:
{% if 'SEARCH' not in params and 'S' not in params %}
{ action_raise_error("Must provide a SEARCH parameter.") }
{% endif %}
{% set SEARCH = params.SEARCH|default(params.S)|lower %}
{% set ns = namespace() %}
{% set output = [] %}
{% for item in printer %}
{% if item is not string %}
{% set ns.path = ['printer', "[%s]" % (item|string), ''] %}
{% elif ' ' in item %}
{% set ns.path = ['printer', "['%s']" % (item), ''] %}
{% else %}
{% set ns.path = ['printer.', item, ''] %}
{% endif %}
{% if SEARCH in ns.path|lower %}
{% set dummy = output.append(ns.path|join) %}
{% endif %}
{% if printer[item].items() %}
{% for childkey, child in printer[item].items() recursive %}
{% set ns.path = ns.path[:loop.depth|int + 1] %}
{% if childkey is not string %}
{% set null = ns.path.append("[%s]" % (childkey|string)) %}
{% elif ' ' in childkey %}
{% set null = ns.path.append("['%s']" % (childkey)) %}
{% else %}
{% set null = ns.path.append(".%s" % (childkey)) %}
{% endif %}
{% if child is mapping %}
{loop(child.items())}
{% else %}
{% if SEARCH in ns.path|lower %}
{% set dummy = output.append("%s : %s" % (ns.path|join, child)) %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{ action_respond_info(output|join("\n")) }
[gcode_macro list_macros]
description: Lists registered macros (and optionally show variable state).
Usage: LISTVARS SEARCH=<search_string> VARS=<0|1>
variable_macros: {}
gcode:
{% set SEARCH = params.SEARCH | default(params.S) | default("") | lower %}
{% set VARS = params.VARS | default(params.V) | default(0) | int != 0 %}
# Load the config state once and save it.
{% if not macros %}
{% set renames = {} %}
{% for k in printer.configfile.config %}
{% if k.lower().startswith("gcode_macro") and
printer.configfile.config[k].rename_existing %}
{% set name = k.split(None, 1)[1] | lower %}
{% set dummy = renames.__setitem__(name,
[printer.configfile.config[k].rename_existing] +
(renames[name] if name in renames else [])) %}
{% endif %}
{% endfor %}
{% for k in printer %}
{% if k.lower().startswith("gcode_macro") %}
{% set name = k.split(None, 1)[1] | lower %}
{% set dummy = macros.__setitem__(k, renames[name] if renames[name] else
[]) %}
{% endif %}
{% endfor %}
{% endif %}
{% set output = [] %}
{% for k in macros %}
{% if SEARCH in k | lower %}
{% set line = k.split(None, 1)[1] %}
{% if macros[k] %}
{% set line = "%s (renames: %s)" % (line, macros[k] | join(",")) %}
{% endif %}
{% set outvars = [] %}
{% if VARS %}
{% for v in printer[k] | sort %}
{% set dummy = outvars.append(
"\n* %s: %s" % (v, printer[k][v]|string)) %}
{% endfor %}
{% endif %}
{% set dummy = output.append(line + outvars | join("")) %}
{% endif %}
{% endfor %}
{ action_respond_info(output | sort | join("\n")) }