Skip to content

Commit 3b9dbbc

Browse files
committed
Added EVENT_GCODE_PARK_Tx
1 parent 37bc552 commit 3b9dbbc

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

Marlin/Configuration_adv.h

+3
Original file line numberDiff line numberDiff line change
@@ -2798,7 +2798,10 @@
27982798
/**
27992799
* Extra G-code to run while executing tool-change commands. Can be used to use an additional
28002800
* stepper motor (e.g., I axis in Configuration.h) to drive the tool-changer.
2801+
*
28012802
*/
2803+
//#define EVENT_GCODE_PARK_T0 "G28 A\nG1 A0" // Extra G-code to run before executing tool-change command if T0 was active before the toolchange command
2804+
//#define EVENT_GCODE_PARK_T1 "G1 A10" // Extra G-code to run before executing tool-change command if T1 was active before the toolchange command
28022805
//#define EVENT_GCODE_TOOLCHANGE_T0 "G28 A\nG1 A0" // Extra G-code to run while executing tool-change command T0
28032806
//#define EVENT_GCODE_TOOLCHANGE_T1 "G1 A10" // Extra G-code to run while executing tool-change command T1
28042807
//#define EVENT_GCODE_TOOLCHANGE_ALWAYS_RUN // Always execute above G-code sequences. Use with caution!

Marlin/src/module/tool_change.cpp

+47-1
Original file line numberDiff line numberDiff line change
@@ -1436,11 +1436,57 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
14361436
TERN_(HAS_FANMUX, fanmux_switch(active_extruder));
14371437

14381438
if (ENABLED(EVENT_GCODE_TOOLCHANGE_ALWAYS_RUN) || !no_move) {
1439+
#if ANY(TC_GCODE_USE_GLOBAL_X, TC_GCODE_USE_GLOBAL_Y, TC_GCODE_USE_GLOBAL_Z,\
1440+
EVENT_GCODE_PARK_T0, EVENT_GCODE_PARK_T1, EVENT_GCODE_PARK_T2, EVENT_GCODE_PARK_T3,\
1441+
EVENT_GCODE_PARK_T4, EVENT_GCODE_PARK_T5, EVENT_GCODE_PARK_T6, EVENT_GCODE_PARK_T7)
1442+
xyz_pos_t old_workspace_offset;
1443+
#endif
1444+
1445+
#if ANY(EVENT_GCODE_PARK_T0, EVENT_GCODE_PARK_T1, EVENT_GCODE_PARK_T2, EVENT_GCODE_PARK_T3,\
1446+
EVENT_GCODE_PARK_T4, EVENT_GCODE_PARK_T5, EVENT_GCODE_PARK_T6, EVENT_GCODE_PARK_T7)
1447+
old_workspace_offset = workspace_offset;
1448+
const xyz_pos_t &ho = hotend_offset[new_tool];
1449+
TERN_(TC_GCODE_USE_GLOBAL_X, workspace_offset.x -= ho.x);
1450+
TERN_(TC_GCODE_USE_GLOBAL_Y, workspace_offset.y -= ho.y);
1451+
TERN_(TC_GCODE_USE_GLOBAL_Z, workspace_offset.z -= ho.z);
1452+
#endif
1453+
1454+
switch (old_tool) {
1455+
default: break;
1456+
#ifdef EVENT_GCODE_PARK_T0
1457+
case 0: gcode.process_subcommands_now(F(EVENT_GCODE_PARK_T0)); break;
1458+
#endif
1459+
#ifdef EVENT_GCODE_PARK_T1
1460+
case 1: gcode.process_subcommands_now(F(EVENT_GCODE_PARK_T1)); break;
1461+
#endif
1462+
#ifdef EVENT_GCODE_PARK_T2
1463+
case 2: gcode.process_subcommands_now(F(EVENT_GCODE_PARK_T2)); break;
1464+
#endif
1465+
#ifdef EVENT_GCODE_PARK_T3
1466+
case 3: gcode.process_subcommands_now(F(EVENT_GCODE_PARK_T3)); break;
1467+
#endif
1468+
#ifdef EVENT_GCODE_PARK_T4
1469+
case 4: gcode.process_subcommands_now(F(EVENT_GCODE_PARK_T4)); break;
1470+
#endif
1471+
#ifdef EVENT_GCODE_PARK_T5
1472+
case 5: gcode.process_subcommands_now(F(EVENT_GCODE_PARK_T5)); break;
1473+
#endif
1474+
#ifdef EVENT_GCODE_PARK_T6
1475+
case 6: gcode.process_subcommands_now(F(EVENT_GCODE_PARK_T6)); break;
1476+
#endif
1477+
#ifdef EVENT_GCODE_PARK_T7
1478+
case 7: gcode.process_subcommands_now(F(EVENT_GCODE_PARK_T7)); break;
1479+
#endif
1480+
}
1481+
1482+
#if ANY(EVENT_GCODE_PARK_T0, EVENT_GCODE_PARK_T1, EVENT_GCODE_PARK_T2, EVENT_GCODE_PARK_T3,\
1483+
EVENT_GCODE_PARK_T4, EVENT_GCODE_PARK_T5, EVENT_GCODE_PARK_T6, EVENT_GCODE_PARK_T7)
1484+
workspace_offset = old_workspace_offset;
1485+
#endif
14391486

14401487
#if ANY(TC_GCODE_USE_GLOBAL_X, TC_GCODE_USE_GLOBAL_Y, TC_GCODE_USE_GLOBAL_Z)
14411488
// G0/G1/G2/G3/G5 moves are relative to the active tool.
14421489
// Shift the workspace to make custom moves relative to T0.
1443-
xyz_pos_t old_workspace_offset;
14441490
if (new_tool > 0) {
14451491
old_workspace_offset = workspace_offset;
14461492
const xyz_pos_t &he = hotend_offset[new_tool];

0 commit comments

Comments
 (0)