From 63000d0d91b4e74c2860d0e8360e7ca9a6d488d2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 3 Dec 2024 17:44:20 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20EVENT=5FGCODE=5FBEFORE=5FG29?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/Configuration.h | 6 ++++++ Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp | 23 ++++++++++++++------- Marlin/src/gcode/bedlevel/abl/G29.cpp | 7 ++++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c45c75a39d96..2f5b8a6c5418 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2104,6 +2104,12 @@ //#define AUTO_BED_LEVELING_UBL //#define MESH_BED_LEVELING +/** + * Commands to execute at the start of G29 probing, + * after switching to the PROBING_TOOL. + */ +//#define EVENT_GCODE_BEFORE_G29 "M300 P440 S200" + /** * Commands to execute at the end of G29 probing. * Useful to retract or move the Z probe out of the way. diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index 4637bf87e828..2cea4968b785 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -297,7 +297,13 @@ G29_parameters_t unified_bed_leveling::param; void unified_bed_leveling::G29() { - bool probe_deployed = false; + #ifdef EVENT_GCODE_AFTER_G29 + bool probe_deployed = false; + #define SET_PROBE_DEPLOYED(N) probe_deployed = N + #else + #define SET_PROBE_DEPLOYED(N) + #endif + if (G29_parse_parameters()) return; // Abort on parameter error const uint8_t p_val = parser.byteval('P'); @@ -316,6 +322,11 @@ void unified_bed_leveling::G29() { #endif probe.use_probing_tool(); + #ifdef EVENT_GCODE_BEFORE_G29 + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Before G29 G-code: ", EVENT_GCODE_BEFORE_G29); + gcode.process_subcommands_now(F(EVENT_GCODE_BEFORE_G29)); + #endif + // Position bed horizontally and Z probe vertically. #if HAS_SAFE_BED_LEVELING xyze_pos_t safe_position = current_position; @@ -430,7 +441,7 @@ void unified_bed_leveling::G29() { do_blocking_move_to_xy(0.5f * ((MESH_MIN_X) + (MESH_MAX_X)), 0.5f * ((MESH_MIN_Y) + (MESH_MAX_Y))); #endif report_current_position(); - probe_deployed = true; + SET_PROBE_DEPLOYED(true); } #endif // HAS_BED_PROBE @@ -465,7 +476,7 @@ void unified_bed_leveling::G29() { probe_entire_mesh(param.XY_pos, parser.seen_test('T'), parser.seen_test('E'), parser.seen_test('U')); report_current_position(); - probe_deployed = true; + SET_PROBE_DEPLOYED(true); } break; #endif // HAS_BED_PROBE @@ -503,7 +514,7 @@ void unified_bed_leveling::G29() { SERIAL_ECHOLNPGM("?Error in Business Card measurement."); return; } - probe_deployed = true; + SET_PROBE_DEPLOYED(true); } if (!position_is_reachable(param.XY_pos)) { @@ -681,13 +692,11 @@ void unified_bed_leveling::G29() { #endif #ifdef EVENT_GCODE_AFTER_G29 - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Probe End Script: ", EVENT_GCODE_AFTER_G29); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("After G29 G-code: ", EVENT_GCODE_AFTER_G29); if (probe_deployed) { planner.synchronize(); gcode.process_subcommands_now(F(EVENT_GCODE_AFTER_G29)); } - #else - UNUSED(probe_deployed); #endif probe.use_probing_tool(false); diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 7c8289b7de80..0f31b6e1cfd7 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -287,6 +287,11 @@ G29_TYPE GcodeSuite::G29() { probe.use_probing_tool(); + #ifdef EVENT_GCODE_BEFORE_G29 + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Before G29 G-code: ", EVENT_GCODE_BEFORE_G29); + gcode.process_subcommands_now(F(EVENT_GCODE_BEFORE_G29)); + #endif + #if ANY(PROBE_MANUALLY, AUTO_BED_LEVELING_LINEAR) abl.abl_probe_index = -1; #endif @@ -1002,7 +1007,7 @@ G29_TYPE GcodeSuite::G29() { TERN_(HAS_BED_PROBE, probe.move_z_after_probing()); #ifdef EVENT_GCODE_AFTER_G29 - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Probe End Script: ", EVENT_GCODE_AFTER_G29); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("After G29 G-code: ", EVENT_GCODE_AFTER_G29); planner.synchronize(); process_subcommands_now(F(EVENT_GCODE_AFTER_G29)); #endif