Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Feb 21, 2021
1 parent db7767c commit 9ee7454
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
// Load / Unload
#define TOOLCHANGE_FS_LENGTH 12 // (mm) Load / Unload length
#define TOOLCHANGE_FS_EXTRA_RESUME_LENGTH 0 // (mm) Extra length for better restart, fine tune by LCD/Gcode)
#define TOOLCHANGE_FS_EXTRA_RESUME_LENGTH 0 // (mm) Extra length for better restart. Adjust with LCD or M217 B.
#define TOOLCHANGE_FS_RETRACT_SPEED (50*60) // (mm/min) (Unloading)
#define TOOLCHANGE_FS_UNRETRACT_SPEED (25*60) // (mm/min) (On SINGLENOZZLE or Bowden loading must be slowed down)

Expand All @@ -2118,11 +2118,11 @@
#define TOOLCHANGE_FS_FAN_SPEED 255 // 0-255
#define TOOLCHANGE_FS_FAN_TIME 10 // (seconds)

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

// Prime on the first T0 (If other, TOOLCHANGE_FS_INIT_BEFORE_SWAP applied)
// Prime on the first T0 (For other tools use TOOLCHANGE_FS_INIT_BEFORE_SWAP)
// Enable with M217 V1 before printing to avoid unwanted priming on host connect
//#define TOOLCHANGE_FS_PRIME_FIRST_USED

Expand Down
39 changes: 20 additions & 19 deletions Marlin/src/module/tool_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,15 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
*/
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)

// Cool down with fan
inline filament_swap_cooling() {
#if HAS_FAN && TOOLCHANGE_FS_FAN >= 0
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed;
gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time));
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0;
#endif
}

void tool_change_prime() {
if (toolchange_settings.extra_prime > 0
&& TERN(PREVENT_COLD_EXTRUSION, !thermalManager.targetTooColdToExtrude(active_extruder), 1)
Expand Down Expand Up @@ -822,11 +831,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
#endif

// Cool down with fan
#if HAS_FAN && TOOLCHANGE_FS_FAN >= 0
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed;
gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time));
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0;
#endif
filament_swap_cooling();

// Move back
#if ENABLED(TOOLCHANGE_PARK)
Expand Down Expand Up @@ -922,17 +927,17 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
TEMPORARY_BED_LEVELING_STATE(false);
#endif

// First tool priming. To prime again, reboot the machine.
#if EITHER(TOOLCHANGE_FS_PRIME_FIRST_USED, TOOLCHANGE_FS_INIT_BEFORE_SWAP)
static uint8_t toolchange_extruder_ready = 0;
static uint8_t extruder_did_first_prime = 0;
#endif

// First tool priming. To prime again, reboot the machine.
#if BOTH(TOOLCHANGE_FILAMENT_SWAP, TOOLCHANGE_FS_PRIME_FIRST_USED)
static bool first_tool_is_primed = false;
if (enable_first_prime && !first_tool_is_primed && new_tool == old_tool) {
tool_change_prime();
first_tool_is_primed = true;
SBI(toolchange_extruder_ready, old_tool); // Primed and initialized
SBI(extruder_did_first_prime, old_tool); // Primed and initialized
}
#endif

Expand All @@ -959,7 +964,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {

// Unload / Retract
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
static uint8_t extruder_primed = 0; // Flags for primed extruders
static uint8_t extruder_was_primed = 0; // Flags for primed extruders
const bool should_swap = can_move_away && toolchange_settings.swap_length,
too_cold = TERN0(PREVENT_COLD_EXTRUSION,
!DEBUGGING(DRYRUN) && (thermalManager.targetTooColdToExtrude(old_tool) || thermalManager.targetTooColdToExtrude(new_tool))
Expand All @@ -969,7 +974,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
SERIAL_ECHO_MSG(STR_ERR_HOTEND_TOO_COLD);
if (ENABLED(SINGLENOZZLE)) { active_extruder = new_tool; return; }
}
else if (TEST(extruder_primed, old_tool)) // Retract the old extruder if it was previously primed
else if (TEST(extruder_was_primed, old_tool)) // Retract the old extruder if it was previously primed
unscaled_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed));
}
#endif
Expand Down Expand Up @@ -1076,9 +1081,9 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
float fr = toolchange_settings.unretract_speed;

#if ENABLED(TOOLCHANGE_FS_INIT_BEFORE_SWAP)
if (!TEST(toolchange_extruder_ready, new_tool)) {
SBI(toolchange_extruder_ready, new_tool);
fr = toolchange_settings.prime_speed; // Next move is a prime
if (!TEST(extruder_did_first_prime, new_tool)) {
SBI(extruder_did_first_prime, new_tool);
fr = toolchange_settings.prime_speed; // Next move is a prime, not just un-retract
unscaled_e_move(0, MMM_TO_MMS(fr)); // Init planner with 0 length move
}
#endif
Expand All @@ -1090,19 +1095,15 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
unscaled_e_move(toolchange_settings.extra_prime, MMM_TO_MMS(toolchange_settings.prime_speed));

// Log that this extruder has been primed
SBI(extruder_primed, new_tool);
SBI(extruder_was_primed, new_tool);

// Cutting retraction
#if TOOLCHANGE_FS_WIPE_RETRACT
unscaled_e_move(-(TOOLCHANGE_FS_WIPE_RETRACT), MMM_TO_MMS(toolchange_settings.retract_speed));
#endif

// Cool down with fan
#if HAS_FAN && TOOLCHANGE_FS_FAN >= 0
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed;
gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time));
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0;
#endif
filament_swap_cooling();
}
#endif

Expand Down
4 changes: 0 additions & 4 deletions Marlin/src/module/tool_change.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@
extern void tool_change_prime();
#endif

#if ENABLED(TOOLCHANGE_FS_INIT_BEFORE_SWAP)
extern bool toolchange_extruder_ready[EXTRUDERS];
#endif

#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
typedef struct {
uint8_t target, last;
Expand Down

0 comments on commit 9ee7454

Please sign in to comment.