forked from jschuh/klipper-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filament.cfg
132 lines (120 loc) · 5.19 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
# Copyright (C) 2022 Justin Schuh <code@justinschuh.com>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
[gcode_macro _load_unload]
variable_is_printing: 1
gcode:
# Klipper think we're printing if parking homed first, so this is a hack to
# prevent that from happening. The caller sets the value and we clear it.
SET_GCODE_VARIABLE MACRO=_load_unload VARIABLE=is_printing VALUE="{1}"
{% set saved_extruder = printer.toolhead.extruder %}
{% set EXTRUDER = params.EXTRUDER|default(saved_extruder)|lower %}
{% set MINIMUM = params.MINIMUM|default(
printer.configfile.settings[EXTRUDER].min_extrude_temp + 5.0) %}
{% 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}"
{% elif printer.idle_timeout.state == "Printing" and is_printing %}
{ action_raise_error("Command not valid during printing.") }
{% endif %}
{% set km = printer["gcode_macro _km_globals"] %}
{% set SPEED = params.SPEED|default(km.load_speed) %}
{% 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=_LOAD_UNLOAD
{% if EXTRUDER != saved_extruder%}
ACTIVATE_EXTRUDER EXTRUDER={EXTRUDER}
{% endif %}
{% if printer[EXTRUDER].target < MINIMUM %}
M109 S{MINIMUM}
{% endif %}
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=_LOAD_UNLOAD
[gcode_macro load_filament]
description: Loads filament to the extruder.
Usage: LOAD_FILAMENT [LENGTH=<distance>] [SPEED=<speed>]
[EXTRUDER=<extruder>] [MINIMUM=<temperature>]
gcode:
_LOAD_UNLOAD LOAD=1{% for k in params
%}{' '~k~'="'~params[k]~'"'}{% endfor %}
# Dummy argument block for Mainsail
{% set dummy = None if True else "
{% 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 %}
" %} # End argument block for Mainsail
[gcode_macro unload_filament]
description: Unloads filament from the extruder.
Usage: UNLOAD_FILAMENT [LENGTH=<distance>] [SPEED=<speed>]
[EXTRUDER=<extruder>] [MINIMUM=<temperature>]
gcode:
_LOAD_UNLOAD LOAD=0{% for k in params
%}{' '~k~'="'~params[k]~'"'}{% endfor %}
# Dummy argument block for Mainsail
{% set dummy = None if True else "
{% 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 %}
" %} # End argument block for Mainsail
[gcode_macro _pause_inner_m700]
gcode:
{% set extruder = printer["extruder" ~ params.T|int]
if params.T|default(0)|int != 0 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 P=2{z_param}
{% elif not printer.pause_resume.is_paused%}
SET_GCODE_VARIABLE MACRO=_load_unload VARIABLE=is_printing VALUE="{0}"
PARK 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 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 LENGTH={
params.U|default(printer["gcode_macro _km_globals"].load_length)|float}