-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
macros.cfg
332 lines (290 loc) · 13.3 KB
/
macros.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
# 3MS Macros
# Copyright (C) 2024 3dcoded
# This file may be distributed under the terms of the GNU GPLv3 license.
# ██████╗ ██████╗ ██████╗ ███╗ ███╗██████╗ ████████╗███████╗
# ██╔══██╗██╔══██╗██╔═══██╗████╗ ████║██╔══██╗╚══██╔══╝██╔════╝
# ██████╔╝██████╔╝██║ ██║██╔████╔██║██████╔╝ ██║ ███████╗
# ██╔═══╝ ██╔══██╗██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ╚════██║
# ██║ ██║ ██║╚██████╔╝██║ ╚═╝ ██║██║ ██║ ███████║
# ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══════╝
# Notifications/Prompts
# Displays a prompt on Mainsail/Fluidd/KS
[gcode_macro WEB_PROMPT]
gcode:
{% set p = printer.save_variables.variables.p|int %}
RESPOND TYPE=command MSG="action:prompt_begin {params.TITLE}"
RESPOND TYPE=command MSG="action:prompt_text {params.MESSAGE}"
RESPOND TYPE=command MSG="action:prompt_text See {params.LINK}"
RESPOND TYPE=command MSG="action:prompt_button_group_start"
RESPOND TYPE=command MSG="action:prompt_button Sync T{p}|SYNC_TOOL TOOL={p}|info"
RESPOND TYPE=command MSG="action:prompt_button Sync T{params.T}|SYNC_TOOL TOOL={params.T}|info"
RESPOND TYPE=command MSG="action:prompt_button_group_end"
RESPOND TYPE=command MSG="action:prompt_button_group_start"
RESPOND TYPE=command MSG="action:prompt_button Resume|RESUME|warning"
RESPOND TYPE=command MSG="action:prompt_button_group_end"
RESPOND TYPE=command MSG="action:prompt_show"
# Displays a notification on mobile devies via Mobileraker
[gcode_macro MOBILE_NOTIFY]
gcode:
MR_NOTIFY TITLE="{params.TITLE}" MESSAGE="{params.MESSAGE} {params.LINK}"
# Uses both WEB_PROMPT and MOBILE_NOTIFY
[gcode_macro MMMS_NOTIFY]
gcode:
{% set t = params.T|string %}
{% set p = printer.save_variables.variables.p|string %}
{% set fail_type = params.TYPE %}
{% if fail_type == "UNLOAD" %}
{% set title = "3MS Unload Fail" %}
{% set message = "Please unload T"+p+", load T"+t+", and resume." %}
{% set link = "https://is.gd/3msunload" %}
{% elif fail_type == "LOAD" %}
{% set title = "3MS Load Fail" %}
{% set message = "Please load T"+t+" and resume." %}
{% set link = "https://is.gd/3msload" %}
{% else %}
{% set title = "3MS Error" %}
{% set message = "Unknown error" %}
{% set link = "https://is.gd/3mstrouble" %}
{% endif %}
MOBILE_NOTIFY TITLE="{title}" MESSAGE="{message}" LINK="{link}"
WEB_PROMPT TITLE="{title}" MESSAGE="{message}" LINK="{link}" T={t}
# ██████╗ ██████╗ ██╗ ██╗████████╗██╗███╗ ██╗███████╗███████╗
# ██╔══██╗██╔═══██╗██║ ██║╚══██╔══╝██║████╗ ██║██╔════╝██╔════╝
# ██████╔╝██║ ██║██║ ██║ ██║ ██║██╔██╗ ██║█████╗ ███████╗
# ██╔══██╗██║ ██║██║ ██║ ██║ ██║██║╚██╗██║██╔══╝ ╚════██║
# ██║ ██║╚██████╔╝╚██████╔╝ ██║ ██║██║ ╚████║███████╗███████║
# ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚══════╝
# 3MS Routines
# MMMS_START: Initializes the 3MS to the provided INITIAL_TOOL. Use in your PRINT_START macro.
[gcode_macro MMMS_START]
gcode:
CLEAR_TOOL
{% set initial_tool = params.INITIAL_TOOL|int %}
{% set fsensor_delay = printer["gcode_macro MMMS_SETTINGS"].fsensor_delay|int %}
M118 3MS Start
M118 Initial Tool: T{initial_tool}
CHECK_FSENSOR V=0 T={initial_tool} P=-1
SYNC_TOOL TOOL={initial_tool}
DISABLE_FSENSOR
MMMS_LOAD
G4 P{fsensor_delay}
ENABLE_FSENSOR
G4 P{fsensor_delay}
CHECK_FSENSOR V=1 T={initial_tool} P=-1
SAVE_VARIABLE VARIABLE=p VALUE={initial_tool}
# MMMS_END: Unloads the 3MS. Use in your PRINT_END macro.
[gcode_macro MMMS_END]
gcode:
{% set current_tool = printer.save_variables.variables.p|default(-1)|int %}
{% set fsensor_delay = printer["gcode_macro MMMS_SETTINGS"].fsensor_delay|int %}
CLEAR_TOOL
M118 3MS End
{% if current_tool > -1 %}
SYNC_TOOL TOOL={current_tool}
G4 P{fsensor_delay/2}
DISABLE_FSENSOR
MMMS_UNLOAD
G4 P{fsensor_delay}
{% endif %}
ENABLE_FSENSOR
G4 P{fsensor_delay}
CHECK_FSENSOR V=0 T=-1 P={current_tool}
ENABLE_FSENSOR
# ██████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝██╔═══██╗██╔══██╗██╔════╝
# ██║ ██║ ██║██████╔╝█████╗
# ██║ ██║ ██║██╔══██╗██╔══╝
# ╚██████╗╚██████╔╝██║ ██║███████╗
# ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
# 3MS Core Macros
# Unloads 3MS by provided/default DISTANCE, SPEED, in 50mm increments
[gcode_macro MMMS_UNLOAD]
gcode:
{% set distance = params.DISTANCE|default(printer["gcode_macro MMMS_SETTINGS"].unload_distance)|int %}
{% set speed = params.SPEED|default(printer["gcode_macro MMMS_SETTINGS"].unload_speed)|int %}
{% set step_size = printer["gcode_macro MMMS_SETTINGS"].step_size %}
{% set times = (distance // step_size)|int %}
{% if "gcode_macro CUT_FILAMENT" in printer %}
CUT_FILAMENT
{% endif %}
M83
{% for _ in range(times) %}
G1 E-{step_size} F{speed}
{% endfor %}
G1 E-{distance - (times * step_size)} F{speed}
# Loads 3MS by provided/default DISTANCE, SPEED, in 50mm incremenents
[gcode_macro MMMS_LOAD]
gcode:
{% set distance = params.DISTANCE|default(printer["gcode_macro MMMS_SETTINGS"].load_distance)|int %}
{% set speed = params.SPEED|default(printer["gcode_macro MMMS_SETTINGS"].load_speed)|int %}
{% set step_size = printer["gcode_macro MMMS_SETTINGS"].step_size %}
{% set times = (distance // step_size)|int %}
M83
{% for _ in range(times) %}
G1 E{step_size} F{speed}
{% endfor %}
G1 E{distance - (times * step_size)} F{speed}
[gcode_macro Toolchange]
gcode:
{% set p = printer.save_variables.variables.p|default(-1)|int %}
{% set fsensor_delay = printer["gcode_macro MMMS_SETTINGS"].fsensor_delay|int %}
{% set t = params.T|int %}
M118 T{p} -> T{t}
{% if p != t %}
{% if p > -1 %}
{% if "gcode_macro FORM_TIP" in printer %}
{% set tip_settings = get_macro_variables("FORM_TIP_SETTINGS") %}
{% set start_x = printer.toolhead.position.x %}
{% set start_y = printer.toolhead.position.y %}
G1 X{tip_settings.park_x} Y{tip_settings.park_y} F{(tip_settings.park_speed|int)*60}
FORM_TIP
{% else %}
DISABLE_FSENSOR
G4 P{fsensor_delay}
{% endif %}
MMMS_UNLOAD
DESYNC_TOOL TOOL={p}
G4 P{fsensor_delay}
ENABLE_FSENSOR
G4 P{fsensor_delay}
CHECK_FSENSOR V=0 T={t} P={p}
{% endif %}
SYNC_TOOL TOOL={t}
MMMS_LOAD
G4 P{fsensor_delay}
ENABLE_FSENSOR
DISABLE_FSENSOR
G4 P{fsensor_delay}
ENABLE_FSENSOR
G4 P{fsensor_delay}
CHECK_FSENSOR V=1 T={t} P={p} R=4
{% if "gcode_macro LOAD_TIP" in printer and p > -1 %}
LOAD_TIP
G1 X{start_x} Y{start_y} F{(tip_settings.park_speed|int)*60}
{% endif %}
{% endif %}
SAVE_VARIABLE VARIABLE=p VALUE={t}
# ███████╗███████╗███╗ ██╗███████╗ ██████╗ ██████╗ ███████╗
# ██╔════╝██╔════╝████╗ ██║██╔════╝██╔═══██╗██╔══██╗██╔════╝
# ███████╗█████╗ ██╔██╗ ██║███████╗██║ ██║██████╔╝███████╗
# ╚════██║██╔══╝ ██║╚██╗██║╚════██║██║ ██║██╔══██╗╚════██║
# ███████║███████╗██║ ╚████║███████║╚██████╔╝██║ ██║███████║
# ╚══════╝╚══════╝╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
# Filament sensor macros
[gcode_macro ENABLE_FSENSOR]
gcode:
{% set fsensor = printer["gcode_macro MMMS_SETTINGS"].fsensor_name %}
SET_FILAMENT_SENSOR SENSOR={fsensor} ENABLE=1
[gcode_macro DISABLE_FSENSOR]
gcode:
{% set fsensor = printer["gcode_macro MMMS_SETTINGS"].fsensor_name %}
SET_FILAMENT_SENSOR SENSOR={fsensor} ENABLE=0
# Check filament sensor "fsensor" to match with provided V. Else notify the user and PAUSE.
[gcode_macro CHECK_FSENSOR]
gcode:
{% set v = params.V|int %}
{% set msg = params.MSG|string %}
{% set r = params.R|default(0)|int %}
{% set retry_dist = printer["gcode_macro MMMS_SETTINGS"].retry_dist %}
{% set retry_speed = printer["gcode_macro MMMS_SETTINGS"].retry_speed %}
{% set fsensor_delay = printer["gcode_macro MMMS_SETTINGS"].fsensor_delay %}
{% set fsensor = printer["gcode_macro MMMS_SETTINGS"].fsensor_name %}
{% set t = params.T %}
{% set p = params.P %}
{% if v == 1 %}
{% set type="LOAD" %}
{% else %}
{% set type="UNLOAD" %}
{% endif %}
{% if (printer["filament_switch_sensor "+(fsensor|string)].filament_detected|int) != v %}
{% if r != 0 %}
M117 Retry
M83
{% if r > 0 %}
G1 E{retry_dist} F{retry_speed}
{% set new_r = r - 1 %}
{% else %}
G1 E-{retry_dist} F{retry_speed}
{% set new_r = r + 1 %}
{% endif %}
ENABLE_FSENSOR
DISABLE_FSENSOR
ENABLE_FSENSOR
G4 P{fsensor_delay}
CHECK_FSENSOR V={v} T={t} P={p} R={new_r}
{% else %}
MMMS_NOTIFY T={t} P={p} TYPE={type}
PAUSE
{% endif %}
{% endif %}
# ███████╗██╗ ██╗███╗ ██╗ ██████╗
# ██╔════╝╚██╗ ██╔╝████╗ ██║██╔════╝
# ███████╗ ╚████╔╝ ██╔██╗ ██║██║
# ╚════██║ ╚██╔╝ ██║╚██╗██║██║
# ███████║ ██║ ██║ ╚████║╚██████╗
# ╚══════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═════╝
# 3MS tool synchronization macros
# Set the sync of provided TOOL to SYNC with extruder
### --- Comment if using the 3MS instead of your printer's extruder --- ###
[gcode_macro SET_TOOL_SYNC]
gcode:
{% set tool = params.TOOL|int %}
{% set sync = params.SYNC|int %}
{% set motion_queue = "extruder" if sync == 1 else "" %}
SYNC_EXTRUDER_MOTION EXTRUDER=3ms{ tool } MOTION_QUEUE={ motion_queue }
{% if sync == 1 %}
SAVE_VARIABLE VARIABLE=synced VALUE={tool}
{% endif %}
### --- Uncomment if using the 3MS instead of your printer's extruder --- ###
#[gcode_macro SET_TOOL_SYNC]
#gcode:
# {% set tool = params.TOOL|int %}
# {% set sync = params.SYNC|int %}
# {% set ext_name = "3ms"+(tool|string) %}
# {% if tool == 0 %}
# {% set ext_name = "extruder" %}
# {% endif %}
# {% set motion_queue = "extruder" if sync == 1 else "" %}
# SYNC_EXTRUDER_MOTION EXTRUDER={ext_name} MOTION_QUEUE={ motion_queue }
# {% if sync == 1 %}
# SAVE_VARIABLE VARIABLE=synced VALUE={tool}
# {% endif %}
# Desync all tools, then sync provided TOOL to extruder
[gcode_macro SYNC_TOOL]
gcode:
{% set tool = params.TOOL|int %}
{% set num_tools = printer["gcode_macro MMMS_SETTINGS"].num_tools|int %}
{% for t in range(num_tools) %}
{% if t != tool %}
DESYNC_TOOL TOOL={t}
{% endif %}
{% endfor %}
SET_TOOL_SYNC TOOL={tool} SYNC=1
# Sync to current tool on Klipper startup
[delayed_gcode sync_startup]
initial_duration: 1.
gcode:
{% set p = printer.save_variables.variables.p|default(-1)|int %}
{% if p > -1 %}
SYNC_TOOL TOOL={p}
{% else %}
DESYNC_ALL_TOOLS
{% endif %}
# Desync provided TOOL from the extruder
[gcode_macro DESYNC_TOOL]
gcode:
{% set tool = params.TOOL|int %}
SET_TOOL_SYNC TOOL={tool} SYNC=0
SAVE_VARIABLE VARIABLE=synced VALUE=-1
# Set previous to -1 (no filament loaded)
[gcode_macro CLEAR_TOOL]
gcode:
SAVE_VARIABLE VARIABLE=p VALUE=-1
# Desync all tools from the extruder
[gcode_macro DESYNC_ALL_TOOLS]
gcode:
{% set num_tools = printer["gcode_macro MMMS_SETTINGS"].num_tools|int %}
{% for tool in range(num_tools) %}
DESYNC_TOOL TOOL={tool}
{% endfor %}
SAVE_VARIABLE VARIABLE=synced VALUE=-1