Skip to content

Commit 2a66a05

Browse files
committed
misc. updates
1 parent b899a96 commit 2a66a05

4 files changed

Lines changed: 59 additions & 60 deletions

File tree

Marlin/Configuration_adv.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@
21042104
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
21052105
// Load / Unload
21062106
#define TOOLCHANGE_FS_LENGTH 12 // (mm) Load / Unload length
2107-
#define TOOLCHANGE_FS_EXTRA_RESUME_LENGTH 0 // (mm) Extra length for better restart, fine tune by LCD/Gcode)
2107+
#define TOOLCHANGE_FS_EXTRA_RESUME_LENGTH 0 // (mm) Extra length for better restart. Adjust with LCD or M217 B.
21082108
#define TOOLCHANGE_FS_RETRACT_SPEED (50*60) // (mm/min) (Unloading)
21092109
#define TOOLCHANGE_FS_UNRETRACT_SPEED (25*60) // (mm/min) (On SINGLENOZZLE or Bowden loading must be slowed down)
21102110

@@ -2118,12 +2118,12 @@
21182118
#define TOOLCHANGE_FS_FAN_SPEED 255 // 0-255
21192119
#define TOOLCHANGE_FS_FAN_TIME 10 // (seconds)
21202120

2121-
// Swap uninitialized extruder with TOOLCHANGE_FS_PRIME_SPEED for all lengths (recover + prime)
2121+
// Swap uninitialized extruder (using TOOLCHANGE_FS_PRIME_SPEED feedrate)
21222122
// (May break filament if not retracted beforehand.)
21232123
//#define TOOLCHANGE_FS_INIT_BEFORE_SWAP
21242124

2125-
// Prime on the first T0 (If other, TOOLCHANGE_FS_INIT_BEFORE_SWAP applied)
2126-
// Enable it (M217 V[0/1]) before printing, to avoid unwanted priming on host connect
2125+
// Prime on the first T0 (For other tools use TOOLCHANGE_FS_INIT_BEFORE_SWAP)
2126+
// Enable with M217 V1 before printing to avoid unwanted priming on host connect
21272127
//#define TOOLCHANGE_FS_PRIME_FIRST_USED
21282128

21292129
/**

Marlin/src/gcode/config/M217.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void M217_report(const bool eeprom=false) {
4444
SERIAL_ECHOPAIR(" R", LINEAR_UNIT(toolchange_settings.retract_speed),
4545
" U", LINEAR_UNIT(toolchange_settings.unretract_speed),
4646
" F", toolchange_settings.fan_speed,
47-
" G", toolchange_settings.fan_time);
47+
" D", toolchange_settings.fan_time);
4848

4949
#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
5050
SERIAL_ECHOPAIR(" A", migration.automode);
@@ -72,25 +72,25 @@ void M217_report(const bool eeprom=false) {
7272
}
7373

7474
/**
75-
* M217 - Set SINGLENOZZLE toolchange parameters
75+
* M217 - Set toolchange parameters
7676
*
7777
* // Tool change command
7878
* Q Prime active tool and exit
7979
*
8080
* // Tool change settings
81-
* S[linear] Swap length
82-
* B[linear] Extra Swap length
83-
* E[linear] Prime length
84-
* P[linear/m] Prime speed
85-
* R[linear/m] Retract speed
86-
* U[linear/m] UnRetract speed
87-
* V[linear] 0/1 Enable auto prime first extruder used
88-
* W[linear] 0/1 Enable park & Z Raise
89-
* X[linear] Park X (Requires TOOLCHANGE_PARK)
90-
* Y[linear] Park Y (Requires TOOLCHANGE_PARK)
91-
* Z[linear] Z Raise
92-
* F[linear] Fan Speed 0-255
93-
* G[linear/s] Fan time
81+
* S[linear] Swap length
82+
* B[linear] Extra Swap resume length
83+
* E[linear] Extra Prime length (as used by M217 Q)
84+
* P[linear/min] Prime speed
85+
* R[linear/min] Retract speed
86+
* U[linear/min] UnRetract speed
87+
* V[linear] 0/1 Enable auto prime first extruder used
88+
* W[linear] 0/1 Enable park & Z Raise
89+
* X[linear] Park X (Requires TOOLCHANGE_PARK)
90+
* Y[linear] Park Y (Requires TOOLCHANGE_PARK)
91+
* Z[linear] Z Raise
92+
* F[speed] Fan Speed 0-255
93+
* D[seconds] Fan time
9494
*
9595
* Tool migration settings
9696
* A[0|1] Enable auto-migration on runout
@@ -115,7 +115,7 @@ void GcodeSuite::M217() {
115115
if (parser.seenval('U')) { const int16_t v = parser.value_linear_units(); toolchange_settings.unretract_speed = constrain(v, 10, 5400); }
116116
#if TOOLCHANGE_FS_FAN >= 0 && HAS_FAN
117117
if (parser.seenval('F')) { const int16_t v = parser.value_linear_units(); toolchange_settings.fan_speed = constrain(v, 0, 255); }
118-
if (parser.seenval('G')) { const int16_t v = parser.value_linear_units(); toolchange_settings.fan_time = constrain(v, 1, 30); }
118+
if (parser.seenval('D')) { const int16_t v = parser.value_linear_units(); toolchange_settings.fan_time = constrain(v, 1, 30); }
119119
#endif
120120
#endif
121121

Marlin/src/module/tool_change.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@
4242

4343
#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
4444
migration_settings_t migration = migration_defaults;
45-
bool enable_first_prime;
46-
#endif
47-
48-
#if ENABLED(TOOLCHANGE_FS_INIT_BEFORE_SWAP)
49-
bool toolchange_extruder_ready[EXTRUDERS];
45+
bool enable_first_prime; // As set by M217 V
5046
#endif
5147

5248
#if ENABLED(MAGNETIC_PARKING_EXTRUDER) || defined(EVENT_GCODE_AFTER_TOOLCHANGE) || (ENABLED(PARKING_EXTRUDER) && PARKING_EXTRUDER_SOLENOIDS_DELAY > 0)
@@ -93,7 +89,6 @@
9389

9490
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
9591
#include "../gcode/gcode.h"
96-
bool extruder_primed[EXTRUDERS]; // Log that extruders have been primed
9792
#if TOOLCHANGE_FS_WIPE_RETRACT <= 0
9893
#undef TOOLCHANGE_FS_WIPE_RETRACT
9994
#define TOOLCHANGE_FS_WIPE_RETRACT 0
@@ -784,6 +779,15 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
784779
*/
785780
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
786781

782+
// Cool down with fan
783+
inline void filament_swap_cooling() {
784+
#if HAS_FAN && TOOLCHANGE_FS_FAN >= 0
785+
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed;
786+
gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time));
787+
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0;
788+
#endif
789+
}
790+
787791
void tool_change_prime() {
788792
if (toolchange_settings.extra_prime > 0
789793
&& TERN(PREVENT_COLD_EXTRUSION, !thermalManager.targetTooColdToExtrude(active_extruder), 1)
@@ -827,11 +831,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
827831
#endif
828832

829833
// Cool down with fan
830-
#if HAS_FAN && TOOLCHANGE_FS_FAN >= 0
831-
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed;
832-
gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time));
833-
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0;
834-
#endif
834+
filament_swap_cooling();
835835

836836
// Move back
837837
#if ENABLED(TOOLCHANGE_PARK)
@@ -927,13 +927,17 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
927927
TEMPORARY_BED_LEVELING_STATE(false);
928928
#endif
929929

930+
#if EITHER(TOOLCHANGE_FS_PRIME_FIRST_USED, TOOLCHANGE_FS_INIT_BEFORE_SWAP)
931+
static uint8_t extruder_did_first_prime = 0;
932+
#endif
933+
930934
// First tool priming. To prime again, reboot the machine.
931935
#if BOTH(TOOLCHANGE_FILAMENT_SWAP, TOOLCHANGE_FS_PRIME_FIRST_USED)
932936
static bool first_tool_is_primed = false;
933-
if (new_tool == old_tool && !first_tool_is_primed && enable_first_prime) {
937+
if (enable_first_prime && !first_tool_is_primed && new_tool == old_tool) {
934938
tool_change_prime();
935939
first_tool_is_primed = true;
936-
toolchange_extruder_ready[old_tool] = true; // Primed and initialized
940+
SBI(extruder_did_first_prime, old_tool); // Primed and initialized
937941
}
938942
#endif
939943

@@ -960,6 +964,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
960964

961965
// Unload / Retract
962966
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
967+
static uint8_t extruder_was_primed = 0; // Flags for primed extruders
963968
const bool should_swap = can_move_away && toolchange_settings.swap_length,
964969
too_cold = TERN0(PREVENT_COLD_EXTRUSION,
965970
!DEBUGGING(DRYRUN) && (thermalManager.targetTooColdToExtrude(old_tool) || thermalManager.targetTooColdToExtrude(new_tool))
@@ -969,12 +974,8 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
969974
SERIAL_ECHO_MSG(STR_ERR_HOTEND_TOO_COLD);
970975
if (ENABLED(SINGLENOZZLE)) { active_extruder = new_tool; return; }
971976
}
972-
else {
973-
//Only perform retraction for this nozzle if it has been primed
974-
if (extruder_primed[old_tool]){
975-
unscaled_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed));
976-
}
977-
}
977+
else if (TEST(extruder_was_primed, old_tool)) // Retract the old extruder if it was previously primed
978+
unscaled_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed));
978979
}
979980
#endif
980981

@@ -1080,9 +1081,9 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
10801081
float fr = toolchange_settings.unretract_speed;
10811082

10821083
#if ENABLED(TOOLCHANGE_FS_INIT_BEFORE_SWAP)
1083-
if (!toolchange_extruder_ready[new_tool]) {
1084-
toolchange_extruder_ready[new_tool] = true;
1085-
fr = toolchange_settings.prime_speed; // Next move is a prime
1084+
if (!TEST(extruder_did_first_prime, new_tool)) {
1085+
SBI(extruder_did_first_prime, new_tool);
1086+
fr = toolchange_settings.prime_speed; // Next move is a prime, not just un-retract
10861087
unscaled_e_move(0, MMM_TO_MMS(fr)); // Init planner with 0 length move
10871088
}
10881089
#endif
@@ -1094,19 +1095,15 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
10941095
unscaled_e_move(toolchange_settings.extra_prime, MMM_TO_MMS(toolchange_settings.prime_speed));
10951096

10961097
// Log that this extruder has been primed
1097-
extruder_primed[new_tool] = true;
1098+
SBI(extruder_was_primed, new_tool);
10981099

10991100
// Cutting retraction
11001101
#if TOOLCHANGE_FS_WIPE_RETRACT
11011102
unscaled_e_move(-(TOOLCHANGE_FS_WIPE_RETRACT), MMM_TO_MMS(toolchange_settings.retract_speed));
11021103
#endif
11031104

11041105
// Cool down with fan
1105-
#if HAS_FAN && TOOLCHANGE_FS_FAN >= 0
1106-
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed;
1107-
gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time));
1108-
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0;
1109-
#endif
1106+
filament_swap_cooling();
11101107
}
11111108
#endif
11121109

Marlin/src/module/tool_change.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,30 @@
3030

3131
typedef struct {
3232
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
33-
float swap_length, extra_prime, extra_resume;
34-
int16_t prime_speed, retract_speed, unretract_speed, fan, fan_speed, fan_time;
33+
float swap_length, // M217 S
34+
extra_prime, // M217 E
35+
extra_resume; // M217 B
36+
int16_t prime_speed, // M217 P
37+
retract_speed, // M217 R
38+
unretract_speed, // M217 U
39+
fan_speed, // M217 F
40+
fan_time; // M217 D
3541
#endif
3642
#if ENABLED(TOOLCHANGE_PARK)
37-
bool enable_park;
38-
xy_pos_t change_point;
43+
bool enable_park; // M217 W
44+
xy_pos_t change_point; // M217 X Y
3945
#endif
40-
float z_raise;
46+
float z_raise; // M217 Z
4147
} toolchange_settings_t;
4248

4349
extern toolchange_settings_t toolchange_settings;
4450

45-
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
46-
extern void tool_change_prime();
47-
#endif
48-
4951
#if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED)
50-
extern bool enable_first_prime;
52+
extern bool enable_first_prime; // M217 V
5153
#endif
5254

53-
#if ENABLED(TOOLCHANGE_FS_INIT_BEFORE_SWAP)
54-
extern bool toolchange_extruder_ready[EXTRUDERS];
55+
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
56+
extern void tool_change_prime();
5557
#endif
5658

5759
#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)

0 commit comments

Comments
 (0)