2 * Marlin 3D Printer Firmware
3 * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5 * Based on Sprinter and grbl.
6 * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 #include "../../../inc/MarlinConfig.h"
25 #if ENABLED(ADVANCED_PAUSE_FEATURE)
27 #include "../../gcode.h"
28 #include "../../../feature/pause.h"
29 #include "../../../module/motion.h"
30 #include "../../../module/printcounter.h"
33 #include "../../../module/tool_change.h"
37 #include "../../../lcd/ultralcd.h"
40 #if ENABLED(MMU2_MENUS)
41 #include "../../../lcd/menu/menu_mmu2.h"
44 #if ENABLED(MIXING_EXTRUDER)
45 #include "../../../feature/mixing.h"
48 #if HAS_FILAMENT_SENSOR
49 #include "../../../feature/runout.h"
53 * M600: Pause for filament change
55 * E[distance] - Retract the filament this far
56 * Z[distance] - Move the Z axis by this distance
57 * X[position] - Move to this X position, with Y
58 * Y[position] - Move to this Y position, with X
59 * U[distance] - Retract distance for removal (manual reload)
60 * L[distance] - Extrude distance for insertion (manual reload)
61 * B[count] - Number of times to beep, -1 for indefinite (if equipped with a buzzer)
62 * T[toolhead] - Select extruder for filament change
63 * R[temp] - Resume temperature (in current units)
65 * Default values are used for omitted arguments.
67 void GcodeSuite::M600() {
69 #if ENABLED(MIXING_EXTRUDER)
70 const int8_t target_e_stepper
= get_target_e_stepper_from_command();
71 if (target_e_stepper
< 0) return;
73 const uint8_t old_mixing_tool
= mixer
.get_current_vtool();
74 mixer
.T(MIXER_DIRECT_SET_TOOL
);
76 MIXER_STEPPER_LOOP(i
) mixer
.set_collector(i
, i
== uint8_t(target_e_stepper
) ? 1.0 : 0.0);
79 const int8_t target_extruder
= active_extruder
;
81 const int8_t target_extruder
= get_target_extruder_from_command();
82 if (target_extruder
< 0) return;
85 #if ENABLED(DUAL_X_CARRIAGE)
86 int8_t DXC_ext
= target_extruder
;
87 if (!parser
.seen('T')) { // If no tool index is specified, M600 was (probably) sent in response to filament runout.
88 // In this case, for duplicating modes set DXC_ext to the extruder that ran out.
89 #if HAS_FILAMENT_SENSOR && NUM_RUNOUT_SENSORS > 1
90 if (dxc_is_duplicating())
91 DXC_ext
= (READ(FIL_RUNOUT2_PIN
) == FIL_RUNOUT_STATE
) ? 1 : 0;
93 DXC_ext
= active_extruder
;
98 // Show initial "wait for start" message
99 #if HAS_LCD_MENU && DISABLED(MMU2_MENUS)
100 lcd_pause_show_message(PAUSE_MESSAGE_CHANGING
, PAUSE_MODE_PAUSE_PRINT
, target_extruder
);
103 #if ENABLED(HOME_BEFORE_FILAMENT_CHANGE)
104 // If needed, home before parking for filament change
105 if (!all_axes_known()) home_all_axes();
109 // Change toolhead if specified
110 const uint8_t active_extruder_before_filament_change
= active_extruder
;
111 if (active_extruder
!= target_extruder
&& TERN1(DUAL_X_CARRIAGE
, !dxc_is_duplicating()))
112 tool_change(target_extruder
, false);
115 // Initial retract before move to filament change position
116 const float retract
= -ABS(parser
.seen('E') ? parser
.value_axis_units(E_AXIS
) : (PAUSE_PARK_RETRACT_LENGTH
));
118 xyz_pos_t park_point NOZZLE_PARK_POINT
;
121 if (parser
.seenval('Z')) park_point
.z
= parser
.linearval('Z');
123 // Move XY axes to filament change position or given position
124 if (parser
.seenval('X')) park_point
.x
= parser
.linearval('X');
125 if (parser
.seenval('Y')) park_point
.y
= parser
.linearval('Y');
127 #if HAS_HOTEND_OFFSET && NONE(DUAL_X_CARRIAGE, DELTA)
128 park_point
+= hotend_offset
[active_extruder
];
131 #if ENABLED(MMU2_MENUS)
132 // For MMU2 reset retract and load/unload values so they don't mess with MMU filament handling
133 constexpr float unload_length
= 0.5f
,
134 slow_load_length
= 0.0f
,
135 fast_load_length
= 0.0f
;
138 const float unload_length
= -ABS(parser
.seen('U') ? parser
.value_axis_units(E_AXIS
)
139 : fc_settings
[active_extruder
].unload_length
);
141 // Slow load filament
142 constexpr float slow_load_length
= FILAMENT_CHANGE_SLOW_LOAD_LENGTH
;
144 // Fast load filament
145 const float fast_load_length
= ABS(parser
.seen('L') ? parser
.value_axis_units(E_AXIS
)
146 : fc_settings
[active_extruder
].load_length
);
149 const int beep_count
= parser
.intval('B', -1
150 #ifdef FILAMENT_CHANGE_ALERT_BEEPS
151 + 1 + FILAMENT_CHANGE_ALERT_BEEPS
155 if (pause_print(retract
, park_point
, unload_length
, true DXC_PASS
)) {
156 #if ENABLED(MMU2_MENUS)
158 resume_print(slow_load_length
, fast_load_length
, 0, beep_count DXC_PASS
);
160 wait_for_confirmation(true, beep_count DXC_PASS
);
161 resume_print(slow_load_length
, fast_load_length
, ADVANCED_PAUSE_PURGE_LENGTH
,
162 beep_count
, (parser
.seenval('R') ? parser
.value_celsius() : 0) DXC_PASS
);
166 TERN_(HAS_FILAMENT_SENSOR
, runout
.reset());
170 // Restore toolhead if it was changed
171 if (active_extruder_before_filament_change
!= active_extruder
)
172 tool_change(active_extruder_before_filament_change
, false);
175 TERN_(MIXING_EXTRUDER
, mixer
.T(old_mixing_tool
)); // Restore original mixing tool
178 #endif // ADVANCED_PAUSE_FEATURE