77
77
#endif
78
78
#endif
79
79
80
- #define G29_RETURN (b ) return TERN_(G29_RETRY_AND_RECOVER, b)
80
+ #define G29_RETURN (retry ) do { \
81
+ if (TERN (G29_RETRY_AND_RECOVER, !retry, true )) { \
82
+ TERN_ (FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate (M_IDLE, false )); \
83
+ } \
84
+ return TERN_ (G29_RETRY_AND_RECOVER, retry); \
85
+ }while (0 )
81
86
82
87
// For manual probing values persist over multiple G29
83
88
class G29_State {
@@ -218,12 +223,13 @@ class G29_State {
218
223
G29_TYPE GcodeSuite::G29 () {
219
224
DEBUG_SECTION (log_G29, " G29" , DEBUGGING (LEVELING));
220
225
226
+ // Leveling state is persistent when done manually with multiple G29 commands
221
227
TERN_ (PROBE_MANUALLY, static ) G29_State abl;
222
228
223
- TERN_ (FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate (M_PROBE));
224
-
229
+ // Keep powered steppers from timing out
225
230
reset_stepper_timeout ();
226
231
232
+ // Q = Query leveling and G29 state
227
233
const bool seenQ = EITHER (DEBUG_LEVELING_FEATURE, PROBE_MANUALLY) && parser.seen_test (' Q' );
228
234
229
235
// G29 Q is also available if debugging
@@ -232,11 +238,14 @@ G29_TYPE GcodeSuite::G29() {
232
238
if (DISABLED (PROBE_MANUALLY) && seenQ) G29_RETURN (false );
233
239
#endif
234
240
241
+ // A = Abort manual probing
242
+ // C<bool> = Generate fake probe points (DEBUG_LEVELING_FEATURE)
235
243
const bool seenA = TERN0 (PROBE_MANUALLY, parser.seen_test (' A' )),
236
244
no_action = seenA || seenQ,
237
245
faux = ENABLED (DEBUG_LEVELING_FEATURE) && DISABLED (PROBE_MANUALLY) ? parser.boolval (' C' ) : no_action;
238
246
239
- if (!no_action && planner.leveling_active && parser.boolval (' O' )) { // Auto-level only if needed
247
+ // O = Don't level if leveling is already active
248
+ if (!no_action && planner.leveling_active && parser.boolval (' O' )) {
240
249
if (DEBUGGING (LEVELING)) DEBUG_ECHOLNPGM (" > Auto-level not needed, skip" );
241
250
G29_RETURN (false );
242
251
}
@@ -248,15 +257,20 @@ G29_TYPE GcodeSuite::G29() {
248
257
// Don't allow auto-leveling without homing first
249
258
if (homing_needed_error ()) G29_RETURN (false );
250
259
260
+ // 3-point leveling gets points from the probe class
251
261
#if ENABLED(AUTO_BED_LEVELING_3POINT)
252
262
vector_3 points[3 ];
253
263
probe.get_three_points (points);
254
264
#endif
255
265
266
+ // Storage for ABL Linear results
256
267
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
257
268
struct linear_fit_data lsf_results;
258
269
#endif
259
270
271
+ // Set and report "probing" state to host
272
+ TERN_ (FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate (M_PROBE, false ));
273
+
260
274
/* *
261
275
* On the initial G29 fetch command parameters.
262
276
*/
@@ -429,10 +443,10 @@ G29_TYPE GcodeSuite::G29() {
429
443
if (!no_action) set_bed_leveling_enabled (false );
430
444
431
445
// Deploy certain probes before starting probing
432
- #if HAS_BED_PROBE
433
- if ( ENABLED (BLTOUCH))
434
- do_z_clearance (Z_CLEARANCE_DEPLOY_PROBE);
435
- else if (probe.deploy ()) {
446
+ #if ENABLED(BLTOUCH)
447
+ do_z_clearance (Z_CLEARANCE_DEPLOY_PROBE);
448
+ # elif HAS_BED_PROBE
449
+ if (probe.deploy ()) { // (returns true on deploy failure)
436
450
set_bed_leveling_enabled (abl.reenable );
437
451
G29_RETURN (false );
438
452
}
@@ -483,6 +497,7 @@ G29_TYPE GcodeSuite::G29() {
483
497
SERIAL_ECHOLNPGM (" idle" );
484
498
}
485
499
500
+ // For 'A' or 'Q' exit with success state
486
501
if (no_action) G29_RETURN (false );
487
502
488
503
if (abl.abl_probe_index == 0 ) {
@@ -893,8 +908,6 @@ G29_TYPE GcodeSuite::G29() {
893
908
894
909
report_current_position ();
895
910
896
- TERN_ (FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate (M_IDLE));
897
-
898
911
G29_RETURN (isnan (abl.measured_z ));
899
912
900
913
}
0 commit comments