浏览代码

Make MBL a static class, use lookup for index-to-point conversion

Scott Lahteine 8 年前
父节点
当前提交
c9eb1d6ab7
共有 4 个文件被更改,包括 53 次插入48 次删除
  1. 4
    4
      Marlin/Marlin_main.cpp
  2. 14
    1
      Marlin/mesh_bed_leveling.cpp
  3. 34
    42
      Marlin/mesh_bed_leveling.h
  4. 1
    1
      Marlin/ultralcd.cpp

+ 4
- 4
Marlin/Marlin_main.cpp 查看文件

@@ -652,7 +652,7 @@ static bool send_ok[BUFSIZE];
652 652
 #endif
653 653
 
654 654
 #if ENABLED(HOST_KEEPALIVE_FEATURE)
655
-  static MarlinBusyState busy_state = NOT_BUSY;
655
+  MarlinBusyState busy_state = NOT_BUSY;
656 656
   static millis_t next_busy_signal_ms = 0;
657 657
   uint8_t host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
658 658
 #else
@@ -3839,7 +3839,7 @@ inline void gcode_G28() {
3839 3839
         // If there's another point to sample, move there with optional lift.
3840 3840
         if (probe_index < (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
3841 3841
           mbl.zigzag(probe_index, px, py);
3842
-          _mbl_goto_xy(mbl.get_probe_x(px), mbl.get_probe_y(py));
3842
+          _mbl_goto_xy(mbl.index_to_xpos[px], mbl.index_to_ypos[py]);
3843 3843
 
3844 3844
           #if HAS_SOFTWARE_ENDSTOPS
3845 3845
             // Disable software endstops to allow manual adjustment
@@ -9649,14 +9649,14 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9649 9649
     const int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
9650 9650
     if (cx2 != cx1 && TEST(x_splits, gcx)) {
9651 9651
       COPY(end, destination);
9652
-      destination[X_AXIS] = LOGICAL_X_POSITION(mbl.get_probe_x(gcx));
9652
+      destination[X_AXIS] = LOGICAL_X_POSITION(mbl.index_to_xpos[gcx]);
9653 9653
       normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]);
9654 9654
       destination[Y_AXIS] = MBL_SEGMENT_END(Y);
9655 9655
       CBI(x_splits, gcx);
9656 9656
     }
9657 9657
     else if (cy2 != cy1 && TEST(y_splits, gcy)) {
9658 9658
       COPY(end, destination);
9659
-      destination[Y_AXIS] = LOGICAL_Y_POSITION(mbl.get_probe_y(gcy));
9659
+      destination[Y_AXIS] = LOGICAL_Y_POSITION(mbl.index_to_ypos[gcy]);
9660 9660
       normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]);
9661 9661
       destination[X_AXIS] = MBL_SEGMENT_END(X);
9662 9662
       CBI(y_splits, gcy);

+ 14
- 1
Marlin/mesh_bed_leveling.cpp 查看文件

@@ -26,7 +26,20 @@
26 26
 
27 27
   mesh_bed_leveling mbl;
28 28
 
29
-  mesh_bed_leveling::mesh_bed_leveling() { reset(); }
29
+  uint8_t mesh_bed_leveling::status;
30
+
31
+  float mesh_bed_leveling::z_offset,
32
+        mesh_bed_leveling::z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS],
33
+        mesh_bed_leveling::index_to_xpos[MESH_NUM_X_POINTS],
34
+        mesh_bed_leveling::index_to_ypos[MESH_NUM_Y_POINTS];
35
+
36
+  mesh_bed_leveling::mesh_bed_leveling() {
37
+    for (uint8_t i = 0; i < MESH_NUM_X_POINTS; ++i)
38
+      index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST);
39
+    for (uint8_t i = 0; i < MESH_NUM_Y_POINTS; ++i)
40
+      index_to_ypos[i] = MESH_MIN_Y + i * (MESH_Y_DIST);
41
+    reset();
42
+  }
30 43
 
31 44
   void mesh_bed_leveling::reset() {
32 45
     status = MBL_STATUS_NONE;

+ 34
- 42
Marlin/mesh_bed_leveling.h 查看文件

@@ -40,91 +40,83 @@
40 40
     MBL_STATUS_REACTIVATE_BIT = 2
41 41
   };
42 42
 
43
-  #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X))/(MESH_NUM_X_POINTS - 1))
44
-  #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y))/(MESH_NUM_Y_POINTS - 1))
43
+  #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (MESH_NUM_X_POINTS - 1))
44
+  #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y)) / (MESH_NUM_Y_POINTS - 1))
45 45
 
46 46
   class mesh_bed_leveling {
47 47
   public:
48
-    uint8_t status; // Has Mesh and Is Active bits
49
-    float z_offset;
50
-    float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
48
+    static uint8_t status; // Has Mesh and Is Active bits
49
+    static float z_offset,
50
+                 z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS],
51
+                 index_to_xpos[MESH_NUM_X_POINTS],
52
+                 index_to_ypos[MESH_NUM_Y_POINTS];
51 53
 
52 54
     mesh_bed_leveling();
53 55
 
54
-    void reset();
56
+    static void reset();
55 57
 
56
-    static FORCE_INLINE float get_probe_x(const int8_t i) { return MESH_MIN_X + (MESH_X_DIST) * i; }
57
-    static FORCE_INLINE float get_probe_y(const int8_t i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
58
-    void set_z(const int8_t px, const int8_t py, const float &z) { z_values[py][px] = z; }
58
+    static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[py][px] = z; }
59 59
 
60
-    bool active() const                 { return TEST(status, MBL_STATUS_ACTIVE_BIT); }
61
-    void set_active(const bool onOff)   { onOff ? SBI(status, MBL_STATUS_ACTIVE_BIT) : CBI(status, MBL_STATUS_ACTIVE_BIT); }
62
-    bool has_mesh() const               { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
63
-    void set_has_mesh(const bool onOff) { onOff ? SBI(status, MBL_STATUS_HAS_MESH_BIT) : CBI(status, MBL_STATUS_HAS_MESH_BIT); }
64
-    bool reactivate()                   { bool b = TEST(status, MBL_STATUS_REACTIVATE_BIT); CBI(status, MBL_STATUS_REACTIVATE_BIT); return b; }
65
-    void set_reactivate(const bool onOff) { onOff ? SBI(status, MBL_STATUS_REACTIVATE_BIT) : CBI(status, MBL_STATUS_REACTIVATE_BIT); }
60
+    static bool active()                       { return TEST(status, MBL_STATUS_ACTIVE_BIT); }
61
+    static void set_active(const bool onOff)   { onOff ? SBI(status, MBL_STATUS_ACTIVE_BIT) : CBI(status, MBL_STATUS_ACTIVE_BIT); }
62
+    static bool has_mesh()                     { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
63
+    static void set_has_mesh(const bool onOff) { onOff ? SBI(status, MBL_STATUS_HAS_MESH_BIT) : CBI(status, MBL_STATUS_HAS_MESH_BIT); }
64
+    static bool reactivate()                   { bool b = TEST(status, MBL_STATUS_REACTIVATE_BIT); CBI(status, MBL_STATUS_REACTIVATE_BIT); return b; }
65
+    static void set_reactivate(const bool onOff) { onOff ? SBI(status, MBL_STATUS_REACTIVATE_BIT) : CBI(status, MBL_STATUS_REACTIVATE_BIT); }
66 66
 
67
-    inline void zigzag(const int8_t index, int8_t &px, int8_t &py) const {
67
+    static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
68 68
       px = index % (MESH_NUM_X_POINTS);
69 69
       py = index / (MESH_NUM_X_POINTS);
70 70
       if (py & 1) px = (MESH_NUM_X_POINTS - 1) - px; // Zig zag
71 71
     }
72 72
 
73
-    void set_zigzag_z(const int8_t index, const float &z) {
73
+    static void set_zigzag_z(const int8_t index, const float &z) {
74 74
       int8_t px, py;
75 75
       zigzag(index, px, py);
76 76
       set_z(px, py, z);
77 77
     }
78 78
 
79
-    int8_t cell_index_x(const float &x) const {
79
+    static int8_t cell_index_x(const float &x) {
80 80
       int8_t cx = (x - (MESH_MIN_X)) * (1.0 / (MESH_X_DIST));
81 81
       return constrain(cx, 0, (MESH_NUM_X_POINTS) - 2);
82 82
     }
83 83
 
84
-    int8_t cell_index_y(const float &y) const {
84
+    static int8_t cell_index_y(const float &y) {
85 85
       int8_t cy = (y - (MESH_MIN_Y)) * (1.0 / (MESH_Y_DIST));
86 86
       return constrain(cy, 0, (MESH_NUM_Y_POINTS) - 2);
87 87
     }
88 88
 
89
-    int8_t probe_index_x(const float &x) const {
89
+    static int8_t probe_index_x(const float &x) {
90 90
       int8_t px = (x - (MESH_MIN_X) + 0.5 * (MESH_X_DIST)) * (1.0 / (MESH_X_DIST));
91 91
       return (px >= 0 && px < (MESH_NUM_X_POINTS)) ? px : -1;
92 92
     }
93 93
 
94
-    int8_t probe_index_y(const float &y) const {
94
+    static int8_t probe_index_y(const float &y) {
95 95
       int8_t py = (y - (MESH_MIN_Y) + 0.5 * (MESH_Y_DIST)) * (1.0 / (MESH_Y_DIST));
96 96
       return (py >= 0 && py < (MESH_NUM_Y_POINTS)) ? py : -1;
97 97
     }
98 98
 
99
-    float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) const {
99
+    static float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {
100 100
       const float delta_z = (z2 - z1) / (a2 - a1);
101 101
       const float delta_a = a0 - a1;
102 102
       return z1 + delta_a * delta_z;
103 103
     }
104 104
 
105
-    float get_z(const float &x0, const float &y0
105
+    static float get_z(const float &x0, const float &y0
106 106
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
107 107
         , const float &factor
108 108
       #endif
109
-    ) const {
110
-      int8_t cx = cell_index_x(x0),
111
-             cy = cell_index_y(y0);
112
-      if (cx < 0 || cy < 0) return z_offset;
113
-      float z1 = calc_z0(x0,
114
-                         get_probe_x(cx), z_values[cy][cx],
115
-                         get_probe_x(cx + 1), z_values[cy][cx + 1]);
116
-      float z2 = calc_z0(x0,
117
-                         get_probe_x(cx), z_values[cy + 1][cx],
118
-                         get_probe_x(cx + 1), z_values[cy + 1][cx + 1]);
119
-      float z0 = calc_z0(y0,
120
-                         get_probe_y(cy), z1,
121
-                         get_probe_y(cy + 1), z2);
122
-
123
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
124
-        return z0 * factor + z_offset;
125
-      #else
126
-        return z0 + z_offset;
127
-      #endif
109
+    ) {
110
+      const int8_t cx = cell_index_x(x0), cy = cell_index_y(y0);
111
+      const float z1 = calc_z0(x0, index_to_xpos[cx], z_values[cy][cx], index_to_xpos[cx + 1], z_values[cy][cx + 1]),
112
+                  z2 = calc_z0(x0, index_to_xpos[cx], z_values[cy + 1][cx], index_to_xpos[cx + 1], z_values[cy + 1][cx + 1]),
113
+                  z0 = calc_z0(y0, index_to_ypos[cy], z1, index_to_ypos[cy + 1], z2);
114
+
115
+      return z_offset + z0
116
+        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
117
+          * factor
118
+        #endif
119
+      ;
128 120
     }
129 121
   };
130 122
 

+ 1
- 1
Marlin/ultralcd.cpp 查看文件

@@ -1437,7 +1437,7 @@ KeepDrawing:
1437 1437
       // _manual_probe_xy runs the menu loop until the move is done
1438 1438
       int8_t px, py;
1439 1439
       mbl.zigzag(manual_probe_index, px, py);
1440
-      _manual_probe_xy(mbl.get_probe_x(px), mbl.get_probe_y(py));
1440
+      _manual_probe_xy(mbl.index_to_xpos[px], mbl.index_to_ypos[py]);
1441 1441
 
1442 1442
       // After the blocking function returns, change menus
1443 1443
       lcd_goto_screen(_lcd_level_bed_get_z);

正在加载...
取消
保存