3333 #include " ../../feature/probe_temp_comp.h"
3434#endif
3535
36+ #if HAS_MULTI_HOTEND
37+ #include " ../../module/tool_change.h"
38+ #endif
39+
3640#if ENABLED(DWIN_LCD_PROUI)
3741 #include " ../../lcd/marlinui.h"
3842#endif
4953 */
5054void GcodeSuite::G30 () {
5155
56+ #if HAS_MULTI_HOTEND
57+ const uint8_t old_tool_index = active_extruder;
58+ tool_change (0 );
59+ #endif
60+
5261 const xy_pos_t pos = { parser.linearval (' X' , current_position.x + probe.offset_xy .x ),
5362 parser.linearval (' Y' , current_position.y + probe.offset_xy .y ) };
5463
@@ -57,40 +66,43 @@ void GcodeSuite::G30() {
5766 SERIAL_ECHOLNF (GET_EN_TEXT_F (MSG_ZPROBE_OUT));
5867 LCD_MESSAGE (MSG_ZPROBE_OUT);
5968 #endif
60- return ;
6169 }
62-
63- // Disable leveling so the planner won't mess with us
64- TERN_ (HAS_LEVELING, set_bed_leveling_enabled (false ));
65-
66- remember_feedrate_scaling_off ();
67-
68- TERN_ (DWIN_LCD_PROUI, process_subcommands_now (F (" G28O" )));
69-
70- const ProbePtRaise raise_after = parser.boolval (' E' , true ) ? PROBE_PT_STOW : PROBE_PT_NONE;
71-
72- TERN_ (HAS_PTC, ptc.set_enabled (!parser.seen (' C' ) || parser.value_bool ()));
73- const float measured_z = probe.probe_at_point (pos, raise_after, 1 );
74- TERN_ (HAS_PTC, ptc.set_enabled (true ));
75- if (!isnan (measured_z)) {
76- SERIAL_ECHOLNPGM (" Bed X: " , pos.x , " Y: " , pos.y , " Z: " , measured_z);
77- #if ENABLED(DWIN_LCD_PROUI)
78- char msg[31 ], str_1[6 ], str_2[6 ], str_3[6 ];
79- sprintf_P (msg, PSTR (" X:%s, Y:%s, Z:%s" ),
80- dtostrf (pos.x , 1 , 1 , str_1),
81- dtostrf (pos.y , 1 , 1 , str_2),
82- dtostrf (measured_z, 1 , 2 , str_3)
83- );
84- ui.set_status (msg);
85- #endif
70+ else {
71+ // Disable leveling so the planner won't mess with us
72+ TERN_ (HAS_LEVELING, set_bed_leveling_enabled (false ));
73+
74+ remember_feedrate_scaling_off ();
75+
76+ TERN_ (DWIN_LCD_PROUI, process_subcommands_now (F (" G28O" )));
77+
78+ const ProbePtRaise raise_after = parser.boolval (' E' , true ) ? PROBE_PT_STOW : PROBE_PT_NONE;
79+
80+ TERN_ (HAS_PTC, ptc.set_enabled (!parser.seen (' C' ) || parser.value_bool ()));
81+ const float measured_z = probe.probe_at_point (pos, raise_after, 1 );
82+ TERN_ (HAS_PTC, ptc.set_enabled (true ));
83+ if (!isnan (measured_z)) {
84+ SERIAL_ECHOLNPGM (" Bed X: " , pos.x , " Y: " , pos.y , " Z: " , measured_z);
85+ #if ENABLED(DWIN_LCD_PROUI)
86+ char msg[31 ], str_1[6 ], str_2[6 ], str_3[6 ];
87+ sprintf_P (msg, PSTR (" X:%s, Y:%s, Z:%s" ),
88+ dtostrf (pos.x , 1 , 1 , str_1),
89+ dtostrf (pos.y , 1 , 1 , str_2),
90+ dtostrf (measured_z, 1 , 2 , str_3)
91+ );
92+ ui.set_status (msg);
93+ #endif
94+ }
95+
96+ restore_feedrate_and_scaling ();
97+
98+ if (raise_after == PROBE_PT_STOW)
99+ probe.move_z_after_probing ();
100+
101+ report_current_position ();
86102 }
87103
88- restore_feedrate_and_scaling ();
89-
90- if (raise_after == PROBE_PT_STOW)
91- probe.move_z_after_probing ();
92-
93- report_current_position ();
104+ // Restore the active tool
105+ TERN_ (HAS_MULTI_HOTEND, tool_change (old_tool_index));
94106}
95107
96108#endif // HAS_BED_PROBE
0 commit comments