forked from jschuh/klipper-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.cfg
319 lines (303 loc) · 13.2 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
# 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. Don't change them in this file (or things may
# break). See README.md for more information.
#
################################################################################
[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']
# Default beep frequency (in Hz) for M300 command.
variable_beep_frequency: 1000
# Default beep duration (in ms) for M300 command.
variable_beep_duration: 100
# Length (in mm) of filament to load (bowden tubes will be longer).
variable_load_length: 90.0
# Filament loading speed (in mm/m).
variable_load_speed: 300
# 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
# 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 the toolhead.
variable_park_x: 0.0
# Y position to park the toolhead.
variable_park_y: 0.0
# Z position to park the toolhead.
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
# Extruder scale factor during pre-warmup in PRINT_START.
variable_start_extruder_preheat_scale: 0.5
# 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 level bed in PRINT_START after stabilizing at temp; set 0 to disable.
variable_start_level_bed_at_temp: True
# Set to rehome the Z in PRINT_START after the bed temperature stabilizes.
variable_start_home_z_at_temp: True
# Set to clear adjustments (e.g. feedrate, extrusion, heater) at end of print.
variable_start_clear_adjustments_at_end: True
# Length of filament (in millimeters) to purge at print start.
variable_start_purge_length: 0.0 # 30 is a good starting point.
# Distance (in millimeters) between the purge lines and the print area.
variable_start_purge_clearance: 5.0
# 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 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 %}
# Bed leveling behavior is 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}"
BED_MESH_CHECK
# Use config to set default printable area.
{% set settings = printer.configfile.settings %}
{% if "stepper_x" in settings and "stepper_y" in settings %}
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=print_min VALUE="{
(settings.stepper_x.position_min, settings.stepper_y.position_min)}"
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=print_max VALUE="{
(settings.stepper_x.position_max, settings.stepper_y.position_max)}"
{% endif %}
{% set options = printer["gcode_macro _km_options"] %}
{% set km = printer["gcode_macro _km_globals"] %}
# Force overrides to use the original types in _KM_GLOBALS.
{% for k in options %}
{% if k not in km %}
{action_raise_error("%s is not valid for _KM_OPTIONS." | format(k))}
{% endif %}
{% if 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 %}
{action_raise_error("%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 %}
{action_raise_error("%s requires a sequence type." | format(k))}
{% endif %}
SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k
} VALUE="{options[k]|replace('\"','\\\"')}"
{% else %}
{action_raise_error("%s is not a valid type for _KM_OPTIONS."|format(k))}
{% endif %}
{% endfor %}
{% 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 ~ " ") %}
{ action_raise_error(
"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 %}
M400
[delayed_gcode INIT_GLOBALS]
# This runs once at startup and initializes all macros.
initial_duration: 0.0001
gcode:
_KM_GLOBALS
# This needs to be its own macro so it gets evaluated after _KM_GLOBALS runs.
_CHECK_GLOBALS
_INIT_SURFACES
# 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_globals]
description: Checks global variables and stops printer on an invalid value.
gcode:
{% set km = printer["gcode_macro _km_globals"] %}
{% set toolhead = printer.toolhead %}
{% set output = [] %}
{% 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.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('\n')) }
{% 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 ' ' 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 ' ' 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")) }