瀏覽代碼

Reduce code size (40b, or 166b with bilinear subdivision)

jes 8 年之前
父節點
當前提交
369bfc8a1e
共有 1 個文件被更改,包括 26 次插入34 次删除
  1. 26
    34
      Marlin/Marlin_main.cpp

+ 26
- 34
Marlin/Marlin_main.cpp 查看文件

2436
   /**
2436
   /**
2437
    * Print calibration results for plotting or manual frame adjustment.
2437
    * Print calibration results for plotting or manual frame adjustment.
2438
    */
2438
    */
2439
-  static void print_bilinear_leveling_grid() {
2440
-    SERIAL_ECHOPGM("Bilinear Leveling Grid:\n ");
2441
-    for (uint8_t x = 0; x < ABL_GRID_MAX_POINTS_X; x++) {
2442
-      SERIAL_PROTOCOLPGM("    ");
2443
-      if (x < 10) SERIAL_PROTOCOLCHAR(' ');
2439
+  static void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, float (*fn)(const uint8_t, const uint8_t)) {
2440
+    for (uint8_t x = 0; x < sx; x++) {
2441
+      for (uint8_t i = 0; i < precision + 2 + (x < 10 ? 1 : 0); i++)
2442
+        SERIAL_PROTOCOLCHAR(' ');
2444
       SERIAL_PROTOCOL((int)x);
2443
       SERIAL_PROTOCOL((int)x);
2445
     }
2444
     }
2446
     SERIAL_EOL;
2445
     SERIAL_EOL;
2447
-    for (uint8_t y = 0; y < ABL_GRID_MAX_POINTS_Y; y++) {
2446
+    for (uint8_t y = 0; y < sy; y++) {
2448
       if (y < 10) SERIAL_PROTOCOLCHAR(' ');
2447
       if (y < 10) SERIAL_PROTOCOLCHAR(' ');
2449
       SERIAL_PROTOCOL((int)y);
2448
       SERIAL_PROTOCOL((int)y);
2450
-      for (uint8_t x = 0; x < ABL_GRID_MAX_POINTS_X; x++) {
2449
+      for (uint8_t x = 0; x < sx; x++) {
2451
         SERIAL_PROTOCOLCHAR(' ');
2450
         SERIAL_PROTOCOLCHAR(' ');
2452
-        float offset = bed_level_grid[x][y];
2451
+        float offset = fn(x, y);
2453
         if (offset != UNPROBED) {
2452
         if (offset != UNPROBED) {
2454
-          if (offset > 0) SERIAL_CHAR('+');
2455
-          SERIAL_PROTOCOL_F(offset, 2);
2453
+          if (offset >= 0) SERIAL_CHAR('+');
2454
+          SERIAL_PROTOCOL_F(offset, precision);
2456
         }
2455
         }
2457
         else
2456
         else
2458
-          SERIAL_PROTOCOLPGM(" ====");
2457
+          for (uint8_t i = 0; i < precision + 3; i++)
2458
+            SERIAL_PROTOCOLCHAR(i ? '=' : ' ');
2459
       }
2459
       }
2460
       SERIAL_EOL;
2460
       SERIAL_EOL;
2461
     }
2461
     }
2462
     SERIAL_EOL;
2462
     SERIAL_EOL;
2463
   }
2463
   }
2464
 
2464
 
2465
+  static void print_bilinear_leveling_grid() {
2466
+    SERIAL_ECHOLNPGM("Bilinear Leveling Grid:");
2467
+    print_2d_array(ABL_GRID_MAX_POINTS_X, ABL_GRID_MAX_POINTS_Y, 2,
2468
+      [](const uint8_t x, const uint8_t y) { return bed_level_grid[x][y]; }
2469
+    );
2470
+  }
2471
+
2465
   #if ENABLED(ABL_BILINEAR_SUBDIVISION)
2472
   #if ENABLED(ABL_BILINEAR_SUBDIVISION)
2473
+
2466
     #define ABL_GRID_POINTS_VIRT_X (ABL_GRID_MAX_POINTS_X - 1) * (BILINEAR_SUBDIVISIONS) + 1
2474
     #define ABL_GRID_POINTS_VIRT_X (ABL_GRID_MAX_POINTS_X - 1) * (BILINEAR_SUBDIVISIONS) + 1
2467
     #define ABL_GRID_POINTS_VIRT_Y (ABL_GRID_MAX_POINTS_Y - 1) * (BILINEAR_SUBDIVISIONS) + 1
2475
     #define ABL_GRID_POINTS_VIRT_Y (ABL_GRID_MAX_POINTS_Y - 1) * (BILINEAR_SUBDIVISIONS) + 1
2468
     #define ABL_TEMP_POINTS_X (ABL_GRID_MAX_POINTS_X + 2)
2476
     #define ABL_TEMP_POINTS_X (ABL_GRID_MAX_POINTS_X + 2)
2472
 
2480
 
2473
     static void bed_level_virt_print() {
2481
     static void bed_level_virt_print() {
2474
       SERIAL_ECHOLNPGM("Subdivided with CATMULL ROM Leveling Grid:");
2482
       SERIAL_ECHOLNPGM("Subdivided with CATMULL ROM Leveling Grid:");
2475
-      for (uint8_t x = 0; x < ABL_GRID_POINTS_VIRT_X; x++) {
2476
-        SERIAL_PROTOCOLPGM("       ");
2477
-        if (x < 10) SERIAL_PROTOCOLCHAR(' ');
2478
-        SERIAL_PROTOCOL((int)x);
2479
-      }
2480
-      SERIAL_EOL;
2481
-      for (uint8_t y = 0; y < ABL_GRID_POINTS_VIRT_Y; y++) {
2482
-        if (y < 10) SERIAL_PROTOCOLCHAR(' ');
2483
-        SERIAL_PROTOCOL((int)y);
2484
-        for (uint8_t x = 0; x < ABL_GRID_POINTS_VIRT_X; x++) {
2485
-          SERIAL_PROTOCOLCHAR(' ');
2486
-          float offset = bed_level_grid_virt[x][y];
2487
-          if (offset != UNPROBED) {
2488
-            if (offset >= 0) SERIAL_CHAR('+');
2489
-            SERIAL_PROTOCOL_F(offset, 5);
2490
-          }
2491
-          else
2492
-            SERIAL_PROTOCOLPGM(" ====");
2493
-        }
2494
-        SERIAL_EOL;
2495
-      }
2496
-      SERIAL_EOL;
2483
+      print_2d_array(ABL_GRID_POINTS_VIRT_X, ABL_GRID_POINTS_VIRT_Y, 5,
2484
+        [](const uint8_t x, const uint8_t y) { return bed_level_grid_virt[x][y]; }
2485
+      );
2497
     }
2486
     }
2487
+
2498
     #define LINEAR_EXTRAPOLATION(E, I) ((E) * 2 - (I))
2488
     #define LINEAR_EXTRAPOLATION(E, I) ((E) * 2 - (I))
2499
     float bed_level_virt_coord(const uint8_t x, const uint8_t y) {
2489
     float bed_level_virt_coord(const uint8_t x, const uint8_t y) {
2500
       uint8_t ep = 0, ip = 1;
2490
       uint8_t ep = 0, ip = 1;
2532
       }
2522
       }
2533
       return bed_level_grid[x - 1][y - 1];
2523
       return bed_level_grid[x - 1][y - 1];
2534
     }
2524
     }
2525
+
2535
     static float bed_level_virt_cmr(const float p[4], const uint8_t i, const float t) {
2526
     static float bed_level_virt_cmr(const float p[4], const uint8_t i, const float t) {
2536
       return (
2527
       return (
2537
           p[i-1] * -t * sq(1 - t)
2528
           p[i-1] * -t * sq(1 - t)
2540
         - p[i+2] * sq(t) * (1 - t)
2531
         - p[i+2] * sq(t) * (1 - t)
2541
       ) * 0.5;
2532
       ) * 0.5;
2542
     }
2533
     }
2534
+
2543
     static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
2535
     static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
2544
       float row[4], column[4];
2536
       float row[4], column[4];
2545
       for (uint8_t i = 0; i < 4; i++) {
2537
       for (uint8_t i = 0; i < 4; i++) {
2550
       }
2542
       }
2551
       return bed_level_virt_cmr(row, 1, tx);
2543
       return bed_level_virt_cmr(row, 1, tx);
2552
     }
2544
     }
2545
+
2553
     void bed_level_virt_interpolate() {
2546
     void bed_level_virt_interpolate() {
2554
       for (uint8_t y = 0; y < ABL_GRID_MAX_POINTS_Y; y++)
2547
       for (uint8_t y = 0; y < ABL_GRID_MAX_POINTS_Y; y++)
2555
         for (uint8_t x = 0; x < ABL_GRID_MAX_POINTS_X; x++)
2548
         for (uint8_t x = 0; x < ABL_GRID_MAX_POINTS_X; x++)
2569
   #endif // ABL_BILINEAR_SUBDIVISION
2562
   #endif // ABL_BILINEAR_SUBDIVISION
2570
 #endif // AUTO_BED_LEVELING_BILINEAR
2563
 #endif // AUTO_BED_LEVELING_BILINEAR
2571
 
2564
 
2572
-
2573
 /**
2565
 /**
2574
  * Home an individual linear axis
2566
  * Home an individual linear axis
2575
  */
2567
  */

Loading…
取消
儲存