Skip to content

Commit d7fefcd

Browse files
thinkyheadEvilGremlin
authored andcommitted
✨ EVENT_GCODE_BEFORE_G29 (MarlinFirmware#27566)
1 parent 588840c commit d7fefcd

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

Marlin/Configuration.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,12 @@
21842184
// #define AUTO_BED_LEVELING_UBL
21852185
//#define MESH_BED_LEVELING
21862186

2187+
/**
2188+
* Commands to execute at the start of G29 probing,
2189+
* after switching to the PROBING_TOOL.
2190+
*/
2191+
//#define EVENT_GCODE_BEFORE_G29 "M300 P440 S200"
2192+
21872193
/**
21882194
* Commands to execute at the end of G29 probing.
21892195
* Useful to retract or move the Z probe out of the way.

Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,13 @@ G29_parameters_t unified_bed_leveling::param;
297297

298298
void unified_bed_leveling::G29() {
299299

300-
bool probe_deployed = false;
300+
#ifdef EVENT_GCODE_AFTER_G29
301+
bool probe_deployed = false;
302+
#define SET_PROBE_DEPLOYED(N) probe_deployed = N
303+
#else
304+
#define SET_PROBE_DEPLOYED(N)
305+
#endif
306+
301307
if (G29_parse_parameters()) return; // Abort on parameter error
302308

303309
const uint8_t p_val = parser.byteval('P');
@@ -316,6 +322,11 @@ void unified_bed_leveling::G29() {
316322
#endif
317323
probe.use_probing_tool();
318324

325+
#ifdef EVENT_GCODE_BEFORE_G29
326+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Before G29 G-code: ", EVENT_GCODE_BEFORE_G29);
327+
gcode.process_subcommands_now(F(EVENT_GCODE_BEFORE_G29));
328+
#endif
329+
319330
// Position bed horizontally and Z probe vertically.
320331
#if HAS_SAFE_BED_LEVELING
321332
xyze_pos_t safe_position = current_position;
@@ -430,7 +441,7 @@ void unified_bed_leveling::G29() {
430441
do_blocking_move_to_xy(0.5f * ((MESH_MIN_X) + (MESH_MAX_X)), 0.5f * ((MESH_MIN_Y) + (MESH_MAX_Y)));
431442
#endif
432443
report_current_position();
433-
probe_deployed = true;
444+
SET_PROBE_DEPLOYED(true);
434445
}
435446

436447
#endif // HAS_BED_PROBE
@@ -465,7 +476,7 @@ void unified_bed_leveling::G29() {
465476
probe_entire_mesh(param.XY_pos, parser.seen_test('T'), parser.seen_test('E'), parser.seen_test('U'));
466477

467478
report_current_position();
468-
probe_deployed = true;
479+
SET_PROBE_DEPLOYED(true);
469480
} break;
470481

471482
#endif // HAS_BED_PROBE
@@ -503,7 +514,7 @@ void unified_bed_leveling::G29() {
503514
SERIAL_ECHOLNPGM("?Error in Business Card measurement.");
504515
return;
505516
}
506-
probe_deployed = true;
517+
SET_PROBE_DEPLOYED(true);
507518
}
508519

509520
if (!position_is_reachable(param.XY_pos)) {
@@ -681,13 +692,11 @@ void unified_bed_leveling::G29() {
681692
#endif
682693

683694
#ifdef EVENT_GCODE_AFTER_G29
684-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Probe End Script: ", EVENT_GCODE_AFTER_G29);
695+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("After G29 G-code: ", EVENT_GCODE_AFTER_G29);
685696
if (probe_deployed) {
686697
planner.synchronize();
687698
gcode.process_subcommands_now(F(EVENT_GCODE_AFTER_G29));
688699
}
689-
#else
690-
UNUSED(probe_deployed);
691700
#endif
692701

693702
probe.use_probing_tool(false);

Marlin/src/gcode/bedlevel/abl/G29.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ G29_TYPE GcodeSuite::G29() {
287287

288288
probe.use_probing_tool();
289289

290+
#ifdef EVENT_GCODE_BEFORE_G29
291+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Before G29 G-code: ", EVENT_GCODE_BEFORE_G29);
292+
gcode.process_subcommands_now(F(EVENT_GCODE_BEFORE_G29));
293+
#endif
294+
290295
#if ANY(PROBE_MANUALLY, AUTO_BED_LEVELING_LINEAR)
291296
abl.abl_probe_index = -1;
292297
#endif
@@ -1007,7 +1012,7 @@ G29_TYPE GcodeSuite::G29() {
10071012
TERN_(HAS_BED_PROBE, probe.move_z_after_probing());
10081013

10091014
#ifdef EVENT_GCODE_AFTER_G29
1010-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Probe End Script: ", EVENT_GCODE_AFTER_G29);
1015+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("After G29 G-code: ", EVENT_GCODE_AFTER_G29);
10111016
planner.synchronize();
10121017
process_subcommands_now(F(EVENT_GCODE_AFTER_G29));
10131018
#endif

0 commit comments

Comments
 (0)