|
30 | 30 | #include "temperature.h"
|
31 | 31 |
|
32 | 32 | #include "../MarlinCore.h"
|
| 33 | +#include "../gcode/gcode.h" |
33 | 34 |
|
34 | 35 | //#define DEBUG_TOOL_CHANGE
|
35 | 36 | //#define DEBUG_TOOLCHANGE_FILAMENT_SWAP
|
|
49 | 50 | Flags<EXTRUDERS> toolchange_extruder_ready;
|
50 | 51 | #endif
|
51 | 52 |
|
52 |
| -#if EITHER(MAGNETIC_PARKING_EXTRUDER, TOOL_SENSOR) \ |
53 |
| - || defined(EVENT_GCODE_TOOLCHANGE_T0) || defined(EVENT_GCODE_TOOLCHANGE_T1) || defined(EVENT_GCODE_AFTER_TOOLCHANGE) \ |
54 |
| - || (ENABLED(PARKING_EXTRUDER) && PARKING_EXTRUDER_SOLENOIDS_DELAY > 0) |
55 |
| - #include "../gcode/gcode.h" |
56 |
| -#endif |
57 |
| - |
58 | 53 | #if ENABLED(TOOL_SENSOR)
|
59 | 54 | #include "../lcd/marlinui.h"
|
60 | 55 | #endif
|
|
98 | 93 | #endif
|
99 | 94 |
|
100 | 95 | #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
|
101 |
| - #include "../gcode/gcode.h" |
102 | 96 | #if TOOLCHANGE_FS_WIPE_RETRACT <= 0
|
103 | 97 | #undef TOOLCHANGE_FS_WIPE_RETRACT
|
104 | 98 | #define TOOLCHANGE_FS_WIPE_RETRACT 0
|
@@ -986,7 +980,7 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0.
|
986 | 980 | }
|
987 | 981 | #endif
|
988 | 982 |
|
989 |
| - //Calculate and perform the priming distance |
| 983 | + // Calculate and perform the priming distance |
990 | 984 | if (toolchange_settings.extra_prime >= 0) {
|
991 | 985 | // Positive extra_prime value
|
992 | 986 | // - Return filament at speed (fr) then extra_prime at prime speed
|
@@ -1409,14 +1403,61 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
|
1409 | 1403 | TERN_(HAS_FANMUX, fanmux_switch(active_extruder));
|
1410 | 1404 |
|
1411 | 1405 | if (ENABLED(EVENT_GCODE_TOOLCHANGE_ALWAYS_RUN) || !no_move) {
|
1412 |
| - #ifdef EVENT_GCODE_TOOLCHANGE_T0 |
1413 |
| - if (new_tool == 0) |
1414 |
| - gcode.process_subcommands_now(F(EVENT_GCODE_TOOLCHANGE_T0)); |
| 1406 | + |
| 1407 | + #if ANY(TC_GCODE_USE_GLOBAL_X, TC_GCODE_USE_GLOBAL_Y, TC_GCODE_USE_GLOBAL_Z) |
| 1408 | + // G0/G1/G2/G3/G5 moves are relative to the active tool. |
| 1409 | + // Shift the workspace to make custom moves relative to T0. |
| 1410 | + xyz_pos_t old_position_shift; |
| 1411 | + if (new_tool > 0) { |
| 1412 | + old_position_shift = position_shift; |
| 1413 | + const xyz_pos_t &he = hotend_offset[new_tool]; |
| 1414 | + #if ENABLED(TC_GCODE_USE_GLOBAL_X) |
| 1415 | + position_shift.x -= he.x; update_workspace_offset(X_AXIS); |
| 1416 | + #endif |
| 1417 | + #if ENABLED(TC_GCODE_USE_GLOBAL_Y) |
| 1418 | + position_shift.y -= he.y; update_workspace_offset(Y_AXIS); |
| 1419 | + #endif |
| 1420 | + #if ENABLED(TC_GCODE_USE_GLOBAL_Z) |
| 1421 | + position_shift.z -= he.z; update_workspace_offset(Z_AXIS); |
| 1422 | + #endif |
| 1423 | + } |
1415 | 1424 | #endif
|
1416 | 1425 |
|
1417 |
| - #ifdef EVENT_GCODE_TOOLCHANGE_T1 |
1418 |
| - if (new_tool == 1) |
1419 |
| - gcode.process_subcommands_now(F(EVENT_GCODE_TOOLCHANGE_T1)); |
| 1426 | + switch (new_tool) { |
| 1427 | + default: break; |
| 1428 | + #ifdef EVENT_GCODE_TOOLCHANGE_T0 |
| 1429 | + case 0: gcode.process_subcommands_now(F(EVENT_GCODE_TOOLCHANGE_T0)); break; |
| 1430 | + #endif |
| 1431 | + #ifdef EVENT_GCODE_TOOLCHANGE_T1 |
| 1432 | + case 1: gcode.process_subcommands_now(F(EVENT_GCODE_TOOLCHANGE_T1)); break; |
| 1433 | + #endif |
| 1434 | + #ifdef EVENT_GCODE_TOOLCHANGE_T2 |
| 1435 | + case 2: gcode.process_subcommands_now(F(EVENT_GCODE_TOOLCHANGE_T2)); break; |
| 1436 | + #endif |
| 1437 | + #ifdef EVENT_GCODE_TOOLCHANGE_T3 |
| 1438 | + case 3: gcode.process_subcommands_now(F(EVENT_GCODE_TOOLCHANGE_T3)); break; |
| 1439 | + #endif |
| 1440 | + #ifdef EVENT_GCODE_TOOLCHANGE_T4 |
| 1441 | + case 4: gcode.process_subcommands_now(F(EVENT_GCODE_TOOLCHANGE_T4)); break; |
| 1442 | + #endif |
| 1443 | + #ifdef EVENT_GCODE_TOOLCHANGE_T5 |
| 1444 | + case 5: gcode.process_subcommands_now(F(EVENT_GCODE_TOOLCHANGE_T5)); break; |
| 1445 | + #endif |
| 1446 | + #ifdef EVENT_GCODE_TOOLCHANGE_T6 |
| 1447 | + case 6: gcode.process_subcommands_now(F(EVENT_GCODE_TOOLCHANGE_T6)); break; |
| 1448 | + #endif |
| 1449 | + #ifdef EVENT_GCODE_TOOLCHANGE_T7 |
| 1450 | + case 7: gcode.process_subcommands_now(F(EVENT_GCODE_TOOLCHANGE_T7)); break; |
| 1451 | + #endif |
| 1452 | + } |
| 1453 | + |
| 1454 | + #if ANY(TC_GCODE_USE_GLOBAL_X, TC_GCODE_USE_GLOBAL_Y, TC_GCODE_USE_GLOBAL_Z) |
| 1455 | + if (new_tool > 0) { |
| 1456 | + position_shift = old_position_shift; |
| 1457 | + TERN_(TC_GCODE_USE_GLOBAL_X, update_workspace_offset(X_AXIS)); |
| 1458 | + TERN_(TC_GCODE_USE_GLOBAL_Y, update_workspace_offset(Y_AXIS)); |
| 1459 | + TERN_(TC_GCODE_USE_GLOBAL_Z, update_workspace_offset(Z_AXIS)); |
| 1460 | + } |
1420 | 1461 | #endif
|
1421 | 1462 |
|
1422 | 1463 | #ifdef EVENT_GCODE_AFTER_TOOLCHANGE
|
|
0 commit comments