Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ EVENT_GCODE_BEFORE_G29 #27566

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 16 additions & 7 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading