Skip to content

Commit

Permalink
Allow specification of G-code that is executed during tool-changes.
Browse files Browse the repository at this point in the history
Adds options EVENT_GCODE_TOOLCHANGE_T0 (executed during T0) and
EVENT_GCODE_TOOLCHANGE_T1 (executed during T1)
  • Loading branch information
DerAndere1 committed Oct 30, 2020
1 parent 8e8e2bf commit fd6efc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,12 @@
#if ENABLED(TOOLCHANGE_NO_RETURN)
//#define EVENT_GCODE_AFTER_TOOLCHANGE "G12X" // Extra G-code to run after tool-change
#endif
/**
* Extra G-code to run while executing tool-change commands. Can be used to use an additional
* stepper motor (I axis, see option LINEAR_AXES in Configuration.h) to drive the tool-changer.
*/
//#define EVENT_GCODE_TOOLCHANGE_T0 "G28 I\nG1 I0" // Extra G-code to run while executing tool-change command T0
//#define EVENT_GCODE_TOOLCHANGE_T1 "G1 I10" // Extra G-code to run while executing tool-change command T1

/**
* Retract and prime filament on tool-change to reduce
Expand Down
14 changes: 13 additions & 1 deletion Marlin/src/module/tool_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
uint8_t singlenozzle_fan_speed[EXTRUDERS];
#endif

#if ENABLED(MAGNETIC_PARKING_EXTRUDER) || defined(EVENT_GCODE_AFTER_TOOLCHANGE) || (ENABLED(PARKING_EXTRUDER) && PARKING_EXTRUDER_SOLENOIDS_DELAY > 0)
#if ENABLED(MAGNETIC_PARKING_EXTRUDER) || defined(EVENT_GCODE_TOOLCHANGE_T0) || defined(EVENT_GCODE_TOOLCHANGE_T1)|| defined(EVENT_GCODE_AFTER_TOOLCHANGE) || (ENABLED(PARKING_EXTRUDER) && PARKING_EXTRUDER_SOLENOIDS_DELAY > 0)
#include "../gcode/gcode.h"
#endif

Expand Down Expand Up @@ -1189,6 +1189,18 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {

TERN_(HAS_FANMUX, fanmux_switch(active_extruder));

#ifdef EVENT_GCODE_TOOLCHANGE_T0
if ((!no_move) && (new_tool == 0)) {
gcode.process_subcommands_now_P(PSTR(EVENT_GCODE_TOOLCHANGE_T0));
}
#endif

#ifdef EVENT_GCODE_TOOLCHANGE_T1
if ((!no_move) && (new_tool == 1)) {
gcode.process_subcommands_now_P(PSTR(EVENT_GCODE_TOOLCHANGE_T1));
}
#endif

#ifdef EVENT_GCODE_AFTER_TOOLCHANGE
if (!no_move && TERN1(DUAL_X_CARRIAGE, dual_x_carriage_mode == DXC_AUTO_PARK_MODE))
gcode.process_subcommands_now_P(PSTR(EVENT_GCODE_AFTER_TOOLCHANGE));
Expand Down

1 comment on commit fd6efc3

@tphan26363
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, I guess now this feature may be able to support by GitHub. I have made some code that works with 3 or more tools. But I did some terrible thing to the code( which I don't understand all of them so I just removed and change a bunch of code). This is can help me get to the right direction. I will try out soon enough.

Please sign in to comment.