浏览代码

Fix linear/3-point manual leveling buffer overrun

Fixes #10137
Scott Lahteine 7 年前
父节点
当前提交
aa20b3ef7c
共有 1 个文件被更改,包括 30 次插入25 次删除
  1. 30
    25
      Marlin/src/gcode/bedlevel/abl/G29.cpp

+ 30
- 25
Marlin/src/gcode/bedlevel/abl/G29.cpp 查看文件

@@ -209,9 +209,9 @@ void GcodeSuite::G29() {
209 209
     #endif
210 210
 
211 211
     #if ENABLED(AUTO_BED_LEVELING_LINEAR)
212
-      ABL_VAR int abl2;
212
+      ABL_VAR int abl_points;
213 213
     #elif ENABLED(PROBE_MANUALLY) // Bilinear
214
-      int constexpr abl2 = GRID_MAX_POINTS;
214
+      int constexpr abl_points = GRID_MAX_POINTS;
215 215
     #endif
216 216
 
217 217
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
@@ -230,7 +230,7 @@ void GcodeSuite::G29() {
230 230
   #elif ENABLED(AUTO_BED_LEVELING_3POINT)
231 231
 
232 232
     #if ENABLED(PROBE_MANUALLY)
233
-      int constexpr abl2 = 3; // used to show total points
233
+      int constexpr abl_points = 3; // used to show total points
234 234
     #endif
235 235
 
236 236
     // Probe at 3 arbitrary points
@@ -342,7 +342,7 @@ void GcodeSuite::G29() {
342 342
         return;
343 343
       }
344 344
 
345
-      abl2 = abl_grid_points_x * abl_grid_points_y;
345
+      abl_points = abl_grid_points_x * abl_grid_points_y;
346 346
       mean = 0;
347 347
 
348 348
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
@@ -458,8 +458,8 @@ void GcodeSuite::G29() {
458 458
     if (verbose_level || seenQ) {
459 459
       SERIAL_PROTOCOLPGM("Manual G29 ");
460 460
       if (g29_in_progress) {
461
-        SERIAL_PROTOCOLPAIR("point ", min(abl_probe_index + 1, abl2));
462
-        SERIAL_PROTOCOLLNPAIR(" of ", abl2);
461
+        SERIAL_PROTOCOLPAIR("point ", min(abl_probe_index + 1, abl_points));
462
+        SERIAL_PROTOCOLLNPAIR(" of ", abl_points);
463 463
       }
464 464
       else
465 465
         SERIAL_PROTOCOLLNPGM("idle");
@@ -474,6 +474,11 @@ void GcodeSuite::G29() {
474 474
       #endif
475 475
     }
476 476
     else {
477
+
478
+      #if ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT)
479
+        const uint16_t index = abl_probe_index - 1;
480
+      #endif
481
+
477 482
       // For G29 after adjusting Z.
478 483
       // Save the previous Z before going to the next point
479 484
       measured_z = current_position[Z_AXIS];
@@ -481,13 +486,17 @@ void GcodeSuite::G29() {
481 486
       #if ENABLED(AUTO_BED_LEVELING_LINEAR)
482 487
 
483 488
         mean += measured_z;
484
-        eqnBVector[abl_probe_index] = measured_z;
485
-        eqnAMatrix[abl_probe_index + 0 * abl2] = xProbe;
486
-        eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe;
487
-        eqnAMatrix[abl_probe_index + 2 * abl2] = 1;
489
+        eqnBVector[index] = measured_z;
490
+        eqnAMatrix[index + 0 * abl_points] = xProbe;
491
+        eqnAMatrix[index + 1 * abl_points] = yProbe;
492
+        eqnAMatrix[index + 2 * abl_points] = 1;
488 493
 
489 494
         incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
490 495
 
496
+      #elif ENABLED(AUTO_BED_LEVELING_3POINT)
497
+
498
+        points[index].z = measured_z;
499
+
491 500
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
492 501
 
493 502
         z_values[xCount][yCount] = measured_z + zoffset;
@@ -500,10 +509,6 @@ void GcodeSuite::G29() {
500 509
           }
501 510
         #endif
502 511
 
503
-      #elif ENABLED(AUTO_BED_LEVELING_3POINT)
504
-
505
-        points[abl_probe_index].z = measured_z;
506
-
507 512
       #endif
508 513
     }
509 514
 
@@ -514,7 +519,7 @@ void GcodeSuite::G29() {
514 519
     #if ABL_GRID
515 520
 
516 521
       // Skip any unreachable points
517
-      while (abl_probe_index < abl2) {
522
+      while (abl_probe_index < abl_points) {
518 523
 
519 524
         // Set xCount, yCount based on abl_probe_index, with zig-zag
520 525
         PR_OUTER_VAR = abl_probe_index / PR_INNER_END;
@@ -541,7 +546,7 @@ void GcodeSuite::G29() {
541 546
       }
542 547
 
543 548
       // Is there a next point to move to?
544
-      if (abl_probe_index < abl2) {
549
+      if (abl_probe_index < abl_points) {
545 550
         _manual_goto_xy(xProbe, yProbe); // Can be used here too!
546 551
         #if HAS_SOFTWARE_ENDSTOPS
547 552
           // Disable software endstops to allow manual adjustment
@@ -565,7 +570,7 @@ void GcodeSuite::G29() {
565 570
     #elif ENABLED(AUTO_BED_LEVELING_3POINT)
566 571
 
567 572
       // Probe at 3 arbitrary points
568
-      if (abl_probe_index < abl2) {
573
+      if (abl_probe_index < abl_points) {
569 574
         xProbe = points[abl_probe_index].x;
570 575
         yProbe = points[abl_probe_index].y;
571 576
         _manual_goto_xy(xProbe, yProbe);
@@ -661,9 +666,9 @@ void GcodeSuite::G29() {
661 666
 
662 667
             mean += measured_z;
663 668
             eqnBVector[abl_probe_index] = measured_z;
664
-            eqnAMatrix[abl_probe_index + 0 * abl2] = xProbe;
665
-            eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe;
666
-            eqnAMatrix[abl_probe_index + 2 * abl2] = 1;
669
+            eqnAMatrix[abl_probe_index + 0 * abl_points] = xProbe;
670
+            eqnAMatrix[abl_probe_index + 1 * abl_points] = yProbe;
671
+            eqnAMatrix[abl_probe_index + 2 * abl_points] = 1;
667 672
 
668 673
             incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
669 674
 
@@ -771,7 +776,7 @@ void GcodeSuite::G29() {
771 776
       plane_equation_coefficients[1] = -lsf_results.B;  // but that is not yet tested.
772 777
       plane_equation_coefficients[2] = -lsf_results.D;
773 778
 
774
-      mean /= abl2;
779
+      mean /= abl_points;
775 780
 
776 781
       if (verbose_level) {
777 782
         SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
@@ -815,8 +820,8 @@ void GcodeSuite::G29() {
815 820
           for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) {
816 821
             int ind = indexIntoAB[xx][yy];
817 822
             float diff = eqnBVector[ind] - mean,
818
-                  x_tmp = eqnAMatrix[ind + 0 * abl2],
819
-                  y_tmp = eqnAMatrix[ind + 1 * abl2],
823
+                  x_tmp = eqnAMatrix[ind + 0 * abl_points],
824
+                  y_tmp = eqnAMatrix[ind + 1 * abl_points],
820 825
                   z_tmp = 0;
821 826
 
822 827
             apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
@@ -839,8 +844,8 @@ void GcodeSuite::G29() {
839 844
           for (int8_t yy = abl_grid_points_y - 1; yy >= 0; yy--) {
840 845
             for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) {
841 846
               int ind = indexIntoAB[xx][yy];
842
-              float x_tmp = eqnAMatrix[ind + 0 * abl2],
843
-                    y_tmp = eqnAMatrix[ind + 1 * abl2],
847
+              float x_tmp = eqnAMatrix[ind + 0 * abl_points],
848
+                    y_tmp = eqnAMatrix[ind + 1 * abl_points],
844 849
                     z_tmp = 0;
845 850
 
846 851
               apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);

正在加载...
取消
保存