ソースを参照

Signal an invalid mesh for M420 enable / load

Scott Lahteine 6年前
コミット
b7e38ea249
1個のファイルの変更50行の追加38行の削除
  1. 50
    38
      Marlin/src/gcode/bedlevel/M420.cpp

+ 50
- 38
Marlin/src/gcode/bedlevel/M420.cpp ファイルの表示

@@ -126,61 +126,71 @@ void GcodeSuite::M420() {
126 126
 
127 127
   #endif // AUTO_BED_LEVELING_UBL
128 128
 
129
+  const bool seenV = parser.seen('V');
130
+
129 131
   #if HAS_MESH
130 132
 
131
-    // Subtract the given value or the mean from all mesh values
132
-    if (leveling_is_valid() && parser.seen('C')) {
133
-      const float cval = parser.value_float();
134
-      #if ENABLED(AUTO_BED_LEVELING_UBL)
133
+    if (leveling_is_valid()) {
135 134
 
136
-        set_bed_leveling_enabled(false);
137
-        ubl.adjust_mesh_to_mean(true, cval);
135
+      // Subtract the given value or the mean from all mesh values
136
+      if (parser.seen('C')) {
137
+        const float cval = parser.value_float();
138
+        #if ENABLED(AUTO_BED_LEVELING_UBL)
138 139
 
139
-      #else
140
+          set_bed_leveling_enabled(false);
141
+          ubl.adjust_mesh_to_mean(true, cval);
140 142
 
141
-        #if ENABLED(M420_C_USE_MEAN)
143
+        #else
142 144
 
143
-          // Get the sum and average of all mesh values
144
-          float mesh_sum = 0;
145
-          for (uint8_t x = GRID_MAX_POINTS_X; x--;)
146
-            for (uint8_t y = GRID_MAX_POINTS_Y; y--;)
147
-              mesh_sum += Z_VALUES(x, y);
148
-          const float zmean = mesh_sum / float(GRID_MAX_POINTS);
145
+          #if ENABLED(M420_C_USE_MEAN)
149 146
 
150
-        #else
147
+            // Get the sum and average of all mesh values
148
+            float mesh_sum = 0;
149
+            for (uint8_t x = GRID_MAX_POINTS_X; x--;)
150
+              for (uint8_t y = GRID_MAX_POINTS_Y; y--;)
151
+                mesh_sum += Z_VALUES(x, y);
152
+            const float zmean = mesh_sum / float(GRID_MAX_POINTS);
151 153
 
152
-          // Find the low and high mesh values
153
-          float lo_val = 100, hi_val = -100;
154
-          for (uint8_t x = GRID_MAX_POINTS_X; x--;)
155
-            for (uint8_t y = GRID_MAX_POINTS_Y; y--;) {
156
-              const float z = Z_VALUES(x, y);
157
-              NOMORE(lo_val, z);
158
-              NOLESS(hi_val, z);
159
-            }
160
-          // Take the mean of the lowest and highest
161
-          const float zmean = (lo_val + hi_val) / 2.0 + cval;
154
+          #else
162 155
 
163
-        #endif
156
+            // Find the low and high mesh values
157
+            float lo_val = 100, hi_val = -100;
158
+            for (uint8_t x = GRID_MAX_POINTS_X; x--;)
159
+              for (uint8_t y = GRID_MAX_POINTS_Y; y--;) {
160
+                const float z = Z_VALUES(x, y);
161
+                NOMORE(lo_val, z);
162
+                NOLESS(hi_val, z);
163
+              }
164
+            // Take the mean of the lowest and highest
165
+            const float zmean = (lo_val + hi_val) / 2.0 + cval;
164 166
 
165
-        // If not very close to 0, adjust the mesh
166
-        if (!NEAR_ZERO(zmean)) {
167
-          set_bed_leveling_enabled(false);
168
-          // Subtract the mean from all values
169
-          for (uint8_t x = GRID_MAX_POINTS_X; x--;)
170
-            for (uint8_t y = GRID_MAX_POINTS_Y; y--;)
171
-              Z_VALUES(x, y) -= zmean;
172
-          #if ENABLED(ABL_BILINEAR_SUBDIVISION)
173
-            bed_level_virt_interpolate();
174 167
           #endif
175
-        }
176 168
 
177
-      #endif
169
+          // If not very close to 0, adjust the mesh
170
+          if (!NEAR_ZERO(zmean)) {
171
+            set_bed_leveling_enabled(false);
172
+            // Subtract the mean from all values
173
+            for (uint8_t x = GRID_MAX_POINTS_X; x--;)
174
+              for (uint8_t y = GRID_MAX_POINTS_Y; y--;)
175
+                Z_VALUES(x, y) -= zmean;
176
+            #if ENABLED(ABL_BILINEAR_SUBDIVISION)
177
+              bed_level_virt_interpolate();
178
+            #endif
179
+          }
180
+
181
+        #endif
182
+      }
183
+
184
+    }
185
+    else if (to_enable || seenV) {
186
+      SERIAL_ERROR_MSG("Invalid mesh.");
187
+      goto EXIT_M420;
178 188
     }
179 189
 
180 190
   #endif // HAS_MESH
181 191
 
182 192
   // V to print the matrix or mesh
183
-  if (parser.seen('V')) {
193
+  if (seenV) {
184 194
     #if ABL_PLANAR
185 195
       planner.bed_level_matrix.debug(PSTR("Bed Level Correction Matrix:"));
186 196
     #else
@@ -205,6 +215,8 @@ void GcodeSuite::M420() {
205 215
   // Enable leveling if specified, or if previously active
206 216
   set_bed_leveling_enabled(to_enable);
207 217
 
218
+  EXIT_M420:
219
+
208 220
   // Error if leveling failed to enable or reenable
209 221
   if (to_enable && !planner.leveling_active)
210 222
     SERIAL_ERROR_MSG(MSG_ERR_M420_FAILED);

読み込み中…
キャンセル
保存