Browse Source

🐛 Fix M_State_grbl when G29 calls G28

Scott Lahteine 3 years ago
parent
commit
b07a34eb6b

+ 23
- 10
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

@@ -77,7 +77,12 @@
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 @@ public:
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
 }

+ 2
- 2
Marlin/src/gcode/bedlevel/mbl/G29.cpp View File

@@ -75,8 +75,6 @@ void GcodeSuite::G29() {
75 75
     }
76 76
   #endif
77 77
 
78
-  TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE));
79
-
80 78
   static int mbl_probe_index = -1;
81 79
 
82 80
   MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport);
@@ -85,6 +83,8 @@ void GcodeSuite::G29() {
85 83
     return;
86 84
   }
87 85
 
86
+  TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE));
87
+
88 88
   int8_t ix, iy;
89 89
   ix = iy = 0;
90 90
 

+ 6
- 3
Marlin/src/gcode/calibrate/G28.cpp View File

@@ -213,8 +213,6 @@ void GcodeSuite::G28() {
213 213
 
214 214
   TERN_(LASER_MOVE_G28_OFF, cutter.set_inline_enabled(false));  // turn off laser
215 215
 
216
-  TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_HOMING));
217
-
218 216
   #if ENABLED(DUAL_X_CARRIAGE)
219 217
     bool IDEX_saved_duplication_state = extruder_duplication_enabled;
220 218
     DualXMode IDEX_saved_mode = dual_x_carriage_mode;
@@ -236,6 +234,11 @@ void GcodeSuite::G28() {
236 234
     return;
237 235
   }
238 236
 
237
+  #if ENABLED(FULL_REPORT_TO_HOST_FEATURE)
238
+    const M_StateEnum old_grblstate = M_State_grbl;
239
+    set_and_report_grblstate(M_HOMING);
240
+  #endif
241
+
239 242
   TERN_(HAS_DWIN_E3V2_BASIC, DWIN_StartHoming());
240 243
   TERN_(EXTENSIBLE_UI, ExtUI::onHomingStart());
241 244
 
@@ -557,7 +560,7 @@ void GcodeSuite::G28() {
557 560
   if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))
558 561
     SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP);
559 562
 
560
-  TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
563
+  TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(old_grblstate));
561 564
 
562 565
   #if HAS_L64XX
563 566
     // Set L6470 absolute position registers to counts

+ 5
- 3
Marlin/src/module/motion.h View File

@@ -265,9 +265,11 @@ void report_current_position_projected();
265 265
   void report_current_position_moving();
266 266
 
267 267
   #if ENABLED(FULL_REPORT_TO_HOST_FEATURE)
268
-    inline void set_and_report_grblstate(const M_StateEnum state) {
269
-      M_State_grbl = state;
270
-      report_current_grblstate_moving();
268
+    inline void set_and_report_grblstate(const M_StateEnum state, const bool force=true) {
269
+      if (force || M_State_grbl != state) {
270
+        M_State_grbl = state;
271
+        report_current_grblstate_moving();
272
+      }
271 273
     }
272 274
   #endif
273 275
 

Loading…
Cancel
Save