forked from jschuh/klipper-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filament.cfg
160 lines (147 loc) · 6.28 KB
/
filament.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
# Copyright (C) 2022 Justin Schuh <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
[gcode_macro _load_unload]
gcode:
{% set saved_extruder = printer.toolhead.extruder %}
{% set EXTRUDER = params.EXTRUDER|default(saved_extruder)|lower %}
{% set km = printer["gcode_macro _km_globals"] %}
# Use the global min as default if provided, else use per extruder min + 5.
{% set BEEPS = params.BEEPS|default(8)|int if "output_pin beeper" in printer
else 0 %}
{% set default_minimum = km.load_min_temp if km.load_min_temp else
(printer.configfile.settings[EXTRUDER].min_extrude_temp + 5) %}
{% if 'MINIMUM' in params %}
{% set MINIMUM = params.MINIMUM|int %}
# This is the special case for a filament change after an idle timeout.
{% elif printer.pause_resume.is_paused and printer[EXTRUDER].target == 0 and
printer["gcode_macro resume"].saved_extruder_temp %}
{% set MINIMUM = printer["gcode_macro resume"].saved_extruder_temp %}
# Use the target temp if higher than the default.
{% elif printer[EXTRUDER].target > default_minimum %}
{% set MINIMUM = printer[EXTRUDER].target %}
{% else %}
{% set MINIMUM = default_minimum %}
{% endif %}
{% if MINIMUM < printer.configfile.settings[EXTRUDER].min_extrude_temp %}
{ action_raise_error("Extrude below minimum temp.") }
{% elif printer.pause_resume.is_paused %}
# Clear the saved E if we're (un-)loading while paused.
SET_GCODE_VARIABLE MACRO=resume VARIABLE=saved_e VALUE="{0.0}"
{% endif %}
{% set SPEED = params.SPEED|default(km.load_speed)|int %}
{% set priming_length = km.load_priming_length %}
{% set LENGTH = params.LENGTH|default(km.load_length)|float - priming_length%}
{% if LENGTH < 0 %}
{% set priming_length = (priming_length + LENGTH, 0)|max %}
{% set LENGTH = 0 %}
{% endif %}
SAVE_GCODE_STATE NAME=_KM_LOAD_UNLOAD
{% if EXTRUDER != saved_extruder%}
ACTIVATE_EXTRUDER EXTRUDER={EXTRUDER}
{% endif %}
_KM_PRINT_STATUS ACTION=PUSH_STATUS
{% if not printer.extruder.can_extrude or
printer[EXTRUDER].target < default_minimum %}
{action_respond_info("Preheating %s to %d" | format(EXTRUDER, MINIMUM))}
M109 S{MINIMUM}
{% endif %}
_KM_PRINT_STATUS ACTION=CHANGE STATUS={"filament_load"
if params.LOAD|int else "filament_unload"}
M83
{% if params.LOAD|int %}
G1 E{LENGTH} F{SPEED}
G1 E{priming_length} F{(km.load_priming_speed, SPEED)|min}
G1 E{'%.4f' % -printer["gcode_macro resume"].saved_e} F{km.load_speed}
{% else %}
G1 E3.0 F{SPEED}
G4 P500
G1 E{'%.4f' % -priming_length} F{(km.load_priming_speed, SPEED)|min}
G1 E{'%.4f' % -LENGTH} F{SPEED}
{% endif %}
RESTORE_GCODE_STATE NAME=_KM_LOAD_UNLOAD
# Beep on completion
{% for i in range(BEEPS) %}
M300 P100
G4 P200
{% endfor %}
_KM_PRINT_STATUS ACTION=CHANGE STATUS=pop_status
# TODO: Fix casing after front-ends get fixed
[gcode_macro LOAD_FILAMENT]
description: Loads filament to the extruder.
Usage: LOAD_FILAMENT [LENGTH=<distance>] [SPEED=<speed>]
[EXTRUDER=<extruder>] [MINIMUM=<temperature>]
[BEEPS=<beep count on completion>]
gcode:
_LOAD_UNLOAD LOAD=1{% for k in params
%}{' '~k~'="'~params[k]~'"'}{% endfor %}
# Dummy argument block for Mainsail
{% set dummy = None if True else "
M109
{% set dummy = params.LENGTH|default(variable_load_length)|float %}
{% set dummy = params.SPEED|default(variable_load_speed)|float %}
{% set dummy = params.EXTRUDER|default(current extruder) %}
{% set dummy = params.MINIMUM|default(min_extrude_temp)|int %}
{% set dummy = params.BEEPS|default(10)|int %}
" %} # End argument block for Mainsail
# TODO: Fix casing after front-ends get fixed
[gcode_macro UNLOAD_FILAMENT]
description: Unloads filament from the extruder.
Usage: UNLOAD_FILAMENT [LENGTH=<distance>] [SPEED=<speed>]
[EXTRUDER=<extruder>] [MINIMUM=<temperature>]
[BEEPS=<beep count on completion>]
gcode:
_LOAD_UNLOAD LOAD=0{% for k in params
%}{' '~k~'="'~params[k]~'"'}{% endfor %}
# Dummy argument block for Mainsail
{% set dummy = None if True else "
M109
{% set dummy = params.LENGTH|default(variable_load_length)|float %}
{% set dummy = params.SPEED|default(variable_load_speed)|float %}
{% set dummy = params.EXTRUDER|default(default extruder) %}
{% set dummy = params.MINIMUM|default(min_extrude_temp)|int %}
{% set dummy = params.BEEPS|default(10)|int %}
" %} # End argument block for Mainsail
[gcode_macro _pause_inner_m700]
gcode:
{% set extruder = "extruder" ~ params.T|replace('0', '')
if "T" in params else printer.toolhead.extruder %}
{% if extruder != printer.toolhead.extruder%}
ACTIVATE_EXTRUDER EXTRUDER={extruder}
{% endif %}
{% set z_param = (' Z="%f"' % params.Z) if 'Z' in params else "" %}
{% if printer.idle_timeout.state|string == "Printing" %}
PAUSE B="{0}" P=2{z_param}
{% elif not printer.pause_resume.is_paused%}
PARK B="{0}" P=2{z_param}
{% endif %}
[gcode_macro m701]
description: Pauses/parks the toolhead then loads filament to the extruder.
Usage: M701 [L<distance>] [Z<pos>] [T<extruder>]
gcode:
{% if 'U' in params %}
{% if not 'L' in params %}
RESPOND TYPE=error MSG="Argument \"U\" substituted for missing \"L\"."
{% set dummy = params.__setitem__("L", params.U) %}
{% else %}
RESPOND TYPE=error MSG="Invalid argument \"U\" ignored."
{% endif %}
{% endif %}
_PAUSE_INNER_M700 {% for k in params %}{' '~k~'="'~params[k]~'"'}{% endfor %}
LOAD_FILAMENT BEEPS="{10}" LENGTH={
params.L|default(printer["gcode_macro _km_globals"].load_length)|float}
[gcode_macro m702]
description: Pauses/parks the toolhead then unloads filament from the extruder.
Usage: M702 [U<distance>] [Z<pos>] [T<extruder>]
gcode:
{% if 'L' in params %}
{% if not 'U' in params %}
RESPOND TYPE=error MSG="Argument \"L\" substituted for missing \"U\"."
{% set dummy = params.__setitem__("U", params.L) %}
{% else %}
RESPOND TYPE=error MSG="Invalid argument \"L\" ignored."
{% endif %}
{% endif %}
_PAUSE_INNER_M700 {% for k in params %}{' '~k~'="'~params[k]~'"'}{% endfor %}
UNLOAD_FILAMENT BEEPS="{10}" LENGTH={
params.U|default(printer["gcode_macro _km_globals"].load_length)|float}