Browse Source

Apply GRID_LOOP

Scott Lahteine 5 years ago
parent
commit
2b9d2dce16
2 changed files with 19 additions and 24 deletions
  1. 7
    8
      Marlin/src/feature/bedlevel/ubl/ubl.cpp
  2. 12
    16
      Marlin/src/gcode/bedlevel/M420.cpp

+ 7
- 8
Marlin/src/feature/bedlevel/ubl/ubl.cpp View File

49
   void unified_bed_leveling::report_current_mesh() {
49
   void unified_bed_leveling::report_current_mesh() {
50
     if (!leveling_is_valid()) return;
50
     if (!leveling_is_valid()) return;
51
     SERIAL_ECHO_MSG("  G29 I99");
51
     SERIAL_ECHO_MSG("  G29 I99");
52
-    LOOP_L_N(x, GRID_MAX_POINTS_X)
53
-      for (uint8_t y = 0;  y < GRID_MAX_POINTS_Y; y++)
54
-        if (!isnan(z_values[x][y])) {
55
-          SERIAL_ECHO_START();
56
-          SERIAL_ECHOPAIR("  M421 I", int(x), " J", int(y));
57
-          SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, z_values[x][y], 4);
58
-          serial_delay(75); // Prevent Printrun from exploding
59
-        }
52
+    GRID_LOOP(x, y)
53
+      if (!isnan(z_values[x][y])) {
54
+        SERIAL_ECHO_START();
55
+        SERIAL_ECHOPAIR("  M421 I", int(x), " J", int(y));
56
+        SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, z_values[x][y], 4);
57
+        serial_delay(75); // Prevent Printrun from exploding
58
+      }
60
   }
59
   }
61
 
60
 
62
   void unified_bed_leveling::report_state() {
61
   void unified_bed_leveling::report_state() {

+ 12
- 16
Marlin/src/gcode/bedlevel/M420.cpp View File

155
 
155
 
156
             // Get the sum and average of all mesh values
156
             // Get the sum and average of all mesh values
157
             float mesh_sum = 0;
157
             float mesh_sum = 0;
158
-            for (uint8_t x = GRID_MAX_POINTS_X; x--;)
159
-              for (uint8_t y = GRID_MAX_POINTS_Y; y--;)
160
-                mesh_sum += Z_VALUES(x, y);
158
+            GRID_LOOP(x, y) mesh_sum += Z_VALUES(x, y);
161
             const float zmean = mesh_sum / float(GRID_MAX_POINTS);
159
             const float zmean = mesh_sum / float(GRID_MAX_POINTS);
162
 
160
 
163
           #else
161
           #else
164
 
162
 
165
             // Find the low and high mesh values
163
             // Find the low and high mesh values
166
             float lo_val = 100, hi_val = -100;
164
             float lo_val = 100, hi_val = -100;
167
-            for (uint8_t x = GRID_MAX_POINTS_X; x--;)
168
-              for (uint8_t y = GRID_MAX_POINTS_Y; y--;) {
169
-                const float z = Z_VALUES(x, y);
170
-                NOMORE(lo_val, z);
171
-                NOLESS(hi_val, z);
172
-              }
165
+            GRID_LOOP(x, y) {
166
+              const float z = Z_VALUES(x, y);
167
+              NOMORE(lo_val, z);
168
+              NOLESS(hi_val, z);
169
+            }
173
             // Take the mean of the lowest and highest
170
             // Take the mean of the lowest and highest
174
             const float zmean = (lo_val + hi_val) / 2.0 + cval;
171
             const float zmean = (lo_val + hi_val) / 2.0 + cval;
175
 
172
 
179
           if (!NEAR_ZERO(zmean)) {
176
           if (!NEAR_ZERO(zmean)) {
180
             set_bed_leveling_enabled(false);
177
             set_bed_leveling_enabled(false);
181
             // Subtract the mean from all values
178
             // Subtract the mean from all values
182
-            for (uint8_t x = GRID_MAX_POINTS_X; x--;)
183
-              for (uint8_t y = GRID_MAX_POINTS_Y; y--;) {
184
-                Z_VALUES(x, y) -= zmean;
185
-                #if ENABLED(EXTENSIBLE_UI)
186
-                  ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y));
187
-                #endif
188
-              }
179
+            GRID_LOOP(x, y) {
180
+              Z_VALUES(x, y) -= zmean;
181
+              #if ENABLED(EXTENSIBLE_UI)
182
+                ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y));
183
+              #endif
184
+            }
189
             #if ENABLED(ABL_BILINEAR_SUBDIVISION)
185
             #if ENABLED(ABL_BILINEAR_SUBDIVISION)
190
               bed_level_virt_interpolate();
186
               bed_level_virt_interpolate();
191
             #endif
187
             #endif

Loading…
Cancel
Save