Переглянути джерело

♻️ Common Bed Leveling object name, accessors (#24214)

Scott Lahteine 2 роки тому
джерело
коміт
b523ddf1b2
Аккаунт користувача з таким Email не знайдено
47 змінених файлів з 389 додано та 433 видалено
  1. 3
    3
      Marlin/src/HAL/AVR/inc/SanityCheck.h
  2. 3
    3
      Marlin/src/HAL/DUE/inc/SanityCheck.h
  3. 1
    1
      Marlin/src/MarlinCore.cpp
  4. 4
    4
      Marlin/src/core/utility.cpp
  5. 2
    2
      Marlin/src/feature/bedlevel/abl/bbl.cpp
  6. 9
    12
      Marlin/src/feature/bedlevel/abl/bbl.h
  7. 16
    21
      Marlin/src/feature/bedlevel/bedlevel.cpp
  8. 1
    4
      Marlin/src/feature/bedlevel/bedlevel.h
  9. 1
    1
      Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp
  10. 10
    11
      Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h
  11. 1
    1
      Marlin/src/feature/bedlevel/ubl/ubl.cpp
  12. 17
    18
      Marlin/src/feature/bedlevel/ubl/ubl.h
  13. 17
    27
      Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
  14. 9
    12
      Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp
  15. 8
    8
      Marlin/src/gcode/bedlevel/G26.cpp
  16. 2
    2
      Marlin/src/gcode/bedlevel/G42.cpp
  17. 17
    17
      Marlin/src/gcode/bedlevel/M420.cpp
  18. 14
    14
      Marlin/src/gcode/bedlevel/abl/G29.cpp
  19. 3
    3
      Marlin/src/gcode/bedlevel/abl/M421.cpp
  20. 9
    9
      Marlin/src/gcode/bedlevel/mbl/G29.cpp
  21. 3
    3
      Marlin/src/gcode/bedlevel/mbl/M421.cpp
  22. 1
    1
      Marlin/src/gcode/bedlevel/ubl/G29.cpp
  23. 2
    2
      Marlin/src/gcode/bedlevel/ubl/M421.cpp
  24. 1
    1
      Marlin/src/gcode/control/M17_M18_M84.cpp
  25. 1
    1
      Marlin/src/gcode/motion/M290.cpp
  26. 8
    8
      Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
  27. 4
    4
      Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
  28. 5
    5
      Marlin/src/lcd/dogm/marlinui_DOGM.cpp
  29. 65
    67
      Marlin/src/lcd/e3v2/jyersui/dwin.cpp
  30. 5
    5
      Marlin/src/lcd/e3v2/marlinui/ui_common.cpp
  31. 16
    16
      Marlin/src/lcd/e3v2/proui/dwin.cpp
  32. 1
    1
      Marlin/src/lcd/e3v2/proui/meshviewer.cpp
  33. 31
    34
      Marlin/src/lcd/e3v2/proui/ubl_tools.cpp
  34. 2
    2
      Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp
  35. 3
    3
      Marlin/src/lcd/extui/ui_api.cpp
  36. 1
    1
      Marlin/src/lcd/marlinui.cpp
  37. 2
    2
      Marlin/src/lcd/menu/menu.cpp
  38. 2
    2
      Marlin/src/lcd/menu/menu_bed_leveling.cpp
  39. 1
    1
      Marlin/src/lcd/menu/menu_tune.cpp
  40. 13
    13
      Marlin/src/lcd/menu/menu_ubl.cpp
  41. 2
    2
      Marlin/src/lcd/tft/touch.cpp
  42. 7
    7
      Marlin/src/lcd/tft/ui_1024x600.cpp
  43. 3
    3
      Marlin/src/lcd/tft/ui_320x240.cpp
  44. 3
    3
      Marlin/src/lcd/tft/ui_480x320.cpp
  45. 6
    6
      Marlin/src/module/motion.cpp
  46. 9
    23
      Marlin/src/module/planner.cpp
  47. 45
    44
      Marlin/src/module/settings.cpp

+ 3
- 3
Marlin/src/HAL/AVR/inc/SanityCheck.h Переглянути файл

@@ -37,16 +37,16 @@
37 37
   || X_ENA_PIN  == N || Y_ENA_PIN  == N || Z_ENA_PIN  == N \
38 38
 )
39 39
 #if CONF_SERIAL_IS(0) // D0-D1. No known conflicts.
40
-#endif 
40
+#endif
41 41
 #if CONF_SERIAL_IS(1) && (CHECK_SERIAL_PIN(18) || CHECK_SERIAL_PIN(19))
42 42
   #error "Serial Port 1 pin D18 and/or D19 conflicts with another pin on the board."
43
-#endif 
43
+#endif
44 44
 #if CONF_SERIAL_IS(2) && (CHECK_SERIAL_PIN(16) || CHECK_SERIAL_PIN(17))
45 45
   #error "Serial Port 2 pin D16 and/or D17 conflicts with another pin on the board."
46 46
 #endif
47 47
 #if CONF_SERIAL_IS(3) && (CHECK_SERIAL_PIN(14) || CHECK_SERIAL_PIN(15))
48 48
   #error "Serial Port 3 pin D14 and/or D15 conflicts with another pin on the board."
49
-#endif 
49
+#endif
50 50
 #undef CHECK_SERIAL_PIN
51 51
 
52 52
 /**

+ 3
- 3
Marlin/src/HAL/DUE/inc/SanityCheck.h Переглянути файл

@@ -37,16 +37,16 @@
37 37
   || X_ENA_PIN  == N || Y_ENA_PIN  == N || Z_ENA_PIN  == N \
38 38
 )
39 39
 #if CONF_SERIAL_IS(0) // D0-D1. No known conflicts.
40
-#endif 
40
+#endif
41 41
 #if CONF_SERIAL_IS(1) && (CHECK_SERIAL_PIN(18) || CHECK_SERIAL_PIN(19))
42 42
   #error "Serial Port 1 pin D18 and/or D19 conflicts with another pin on the board."
43
-#endif 
43
+#endif
44 44
 #if CONF_SERIAL_IS(2) && (CHECK_SERIAL_PIN(16) || CHECK_SERIAL_PIN(17))
45 45
   #error "Serial Port 2 pin D16 and/or D17 conflicts with another pin on the board."
46 46
 #endif
47 47
 #if CONF_SERIAL_IS(3) && (CHECK_SERIAL_PIN(14) || CHECK_SERIAL_PIN(15))
48 48
   #error "Serial Port 3 pin D14 and/or D15 conflicts with another pin on the board."
49
-#endif 
49
+#endif
50 50
 #undef CHECK_SERIAL_PIN
51 51
 
52 52
 /**

+ 1
- 1
Marlin/src/MarlinCore.cpp Переглянути файл

@@ -448,7 +448,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
448 448
         TERN_(DISABLE_INACTIVE_W, stepper.disable_axis(W_AXIS));
449 449
         TERN_(DISABLE_INACTIVE_E, stepper.disable_e_steppers());
450 450
 
451
-        TERN_(AUTO_BED_LEVELING_UBL, ubl.steppers_were_disabled());
451
+        TERN_(AUTO_BED_LEVELING_UBL, bedlevel.steppers_were_disabled());
452 452
       }
453 453
     }
454 454
     else

+ 4
- 4
Marlin/src/core/utility.cpp Переглянути файл

@@ -132,10 +132,10 @@ void safe_delay(millis_t ms) {
132 132
         #else
133 133
           #if ENABLED(AUTO_BED_LEVELING_UBL)
134 134
             SERIAL_ECHOPGM("UBL Adjustment Z");
135
-            const float rz = ubl.get_z_correction(current_position);
135
+            const float rz = bedlevel.get_z_correction(current_position);
136 136
           #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
137 137
             SERIAL_ECHOPGM("ABL Adjustment Z");
138
-            const float rz = bbl.get_z_correction(current_position);
138
+            const float rz = bedlevel.get_z_correction(current_position);
139 139
           #endif
140 140
           SERIAL_ECHO(ftostr43sign(rz, '+'));
141 141
           #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
@@ -156,11 +156,11 @@ void safe_delay(millis_t ms) {
156 156
       SERIAL_ECHOPGM("Mesh Bed Leveling");
157 157
       if (planner.leveling_active) {
158 158
         SERIAL_ECHOLNPGM(" (enabled)");
159
-        SERIAL_ECHOPGM("MBL Adjustment Z", ftostr43sign(mbl.get_z(current_position), '+'));
159
+        SERIAL_ECHOPGM("MBL Adjustment Z", ftostr43sign(bedlevel.get_z(current_position), '+'));
160 160
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
161 161
           if (planner.z_fade_height) {
162 162
             SERIAL_ECHOPGM(" (", ftostr43sign(
163
-              mbl.get_z(current_position, planner.fade_scaling_factor_for_z(current_position.z)), '+'
163
+              bedlevel.get_z(current_position, planner.fade_scaling_factor_for_z(current_position.z)), '+'
164 164
             ));
165 165
             SERIAL_CHAR(')');
166 166
           }

+ 2
- 2
Marlin/src/feature/bedlevel/abl/bbl.cpp Переглянути файл

@@ -35,7 +35,7 @@
35 35
   #include "../../../lcd/extui/ui_api.h"
36 36
 #endif
37 37
 
38
-LevelingBilinear bbl;
38
+LevelingBilinear bedlevel;
39 39
 
40 40
 xy_pos_t LevelingBilinear::grid_spacing,
41 41
          LevelingBilinear::grid_start;
@@ -258,8 +258,8 @@ void LevelingBilinear::print_leveling_grid(const bed_mesh_t* _z_values /*= NULL*
258 258
               );
259 259
           }
260 260
   }
261
-#endif // ABL_BILINEAR_SUBDIVISION
262 261
 
262
+#endif // ABL_BILINEAR_SUBDIVISION
263 263
 
264 264
 // Refresh after other values have been updated
265 265
 void LevelingBilinear::refresh_bed_level() {

+ 9
- 12
Marlin/src/feature/bedlevel/abl/bbl.h Переглянути файл

@@ -24,10 +24,12 @@
24 24
 #include "../../../inc/MarlinConfigPre.h"
25 25
 
26 26
 class LevelingBilinear {
27
-private:
27
+public:
28
+  static bed_mesh_t z_values;
28 29
   static xy_pos_t grid_spacing, grid_start;
30
+
31
+private:
29 32
   static xy_float_t grid_factor;
30
-  static bed_mesh_t z_values;
31 33
   static xy_pos_t cached_rel;
32 34
   static xy_int8_t cached_g;
33 35
 
@@ -54,20 +56,15 @@ public:
54 56
   static void print_leveling_grid(const bed_mesh_t* _z_values = NULL);
55 57
   static void refresh_bed_level();
56 58
   static bool has_mesh() { return !!grid_spacing.x; }
57
-  static bed_mesh_t& get_z_values() { return z_values; }
58
-  static const xy_pos_t& get_grid_spacing() { return grid_spacing; }
59
-  static const xy_pos_t& get_grid_start() { return grid_start; }
60
-  static float get_mesh_x(int16_t i) { return grid_start.x + i * grid_spacing.x; }
61
-  static float get_mesh_y(int16_t j) { return grid_start.y + j * grid_spacing.y; }
59
+  static bool mesh_is_valid() { return has_mesh(); }
60
+  static float get_mesh_x(const uint8_t i) { return grid_start.x + i * grid_spacing.x; }
61
+  static float get_mesh_y(const uint8_t j) { return grid_start.y + j * grid_spacing.y; }
62 62
   static float get_z_correction(const xy_pos_t &raw);
63
+  static constexpr float get_z_offset() { return 0.0f; }
63 64
 
64 65
   #if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
65 66
     static void line_to_destination(const_feedRate_t scaled_fr_mm_s, uint16_t x_splits=0xFFFF, uint16_t y_splits=0xFFFF);
66 67
   #endif
67 68
 };
68 69
 
69
-extern LevelingBilinear bbl;
70
-
71
-#define _GET_MESH_X(I) bbl.get_mesh_x(I)
72
-#define _GET_MESH_Y(J) bbl.get_mesh_y(J)
73
-#define Z_VALUES_ARR bbl.get_z_values()
70
+extern LevelingBilinear bedlevel;

+ 16
- 21
Marlin/src/feature/bedlevel/bedlevel.cpp Переглянути файл

@@ -47,14 +47,11 @@
47 47
 #endif
48 48
 
49 49
 bool leveling_is_valid() {
50
-  return TERN1(MESH_BED_LEVELING,          mbl.has_mesh())
51
-      && TERN1(AUTO_BED_LEVELING_BILINEAR, bbl.has_mesh())
52
-      && TERN1(AUTO_BED_LEVELING_UBL,      ubl.mesh_is_valid());
50
+  return TERN1(HAS_MESH, bedlevel.mesh_is_valid());
53 51
 }
54 52
 
55 53
 /**
56
- * Turn bed leveling on or off, fixing the current
57
- * position as-needed.
54
+ * Turn bed leveling on or off, correcting the current position.
58 55
  *
59 56
  * Disable: Current position = physical position
60 57
  *  Enable: Current position = "unleveled" physical position
@@ -65,24 +62,31 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
65 62
 
66 63
   if (can_change && enable != planner.leveling_active) {
67 64
 
65
+    auto _report_leveling = []{
66
+      if (DEBUGGING(LEVELING)) {
67
+        if (planner.leveling_active)
68
+          DEBUG_POS("Leveling ON", current_position);
69
+        else
70
+          DEBUG_POS("Leveling OFF", current_position);
71
+      }
72
+    };
73
+
74
+    _report_leveling();
68 75
     planner.synchronize();
69 76
 
70 77
     if (planner.leveling_active) {      // leveling from on to off
71
-      if (DEBUGGING(LEVELING)) DEBUG_POS("Leveling ON", current_position);
72 78
       // change unleveled current_position to physical current_position without moving steppers.
73 79
       planner.apply_leveling(current_position);
74 80
       planner.leveling_active = false;  // disable only AFTER calling apply_leveling
75
-      if (DEBUGGING(LEVELING)) DEBUG_POS("...Now OFF", current_position);
76 81
     }
77 82
     else {                              // leveling from off to on
78
-      if (DEBUGGING(LEVELING)) DEBUG_POS("Leveling OFF", current_position);
79 83
       planner.leveling_active = true;   // enable BEFORE calling unapply_leveling, otherwise ignored
80 84
       // change physical current_position to unleveled current_position without moving steppers.
81 85
       planner.unapply_leveling(current_position);
82
-      if (DEBUGGING(LEVELING)) DEBUG_POS("...Now ON", current_position);
83 86
     }
84 87
 
85 88
     sync_plan_position();
89
+    _report_leveling();
86 90
   }
87 91
 }
88 92
 
@@ -116,18 +120,9 @@ TemporaryBedLevelingState::TemporaryBedLevelingState(const bool enable) : saved(
116 120
  */
117 121
 void reset_bed_level() {
118 122
   if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("reset_bed_level");
119
-  #if ENABLED(AUTO_BED_LEVELING_UBL)
120
-    ubl.reset();
121
-  #else
122
-    set_bed_leveling_enabled(false);
123
-    #if ENABLED(MESH_BED_LEVELING)
124
-      mbl.reset();
125
-    #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
126
-      bbl.reset();
127
-    #elif ABL_PLANAR
128
-      planner.bed_level_matrix.set_to_identity();
129
-    #endif
130
-  #endif
123
+  IF_DISABLED(AUTO_BED_LEVELING_UBL, set_bed_leveling_enabled(false));
124
+  TERN_(HAS_MESH, bedlevel.reset());
125
+  TERN_(ABL_PLANAR, planner.bed_level_matrix.set_to_identity());
131 126
 }
132 127
 
133 128
 #if EITHER(AUTO_BED_LEVELING_BILINEAR, MESH_BED_LEVELING)

+ 1
- 4
Marlin/src/feature/bedlevel/bedlevel.h Переглянути файл

@@ -69,9 +69,6 @@ class TemporaryBedLevelingState {
69 69
     #include "mbl/mesh_bed_leveling.h"
70 70
   #endif
71 71
 
72
-  #define Z_VALUES(X,Y) Z_VALUES_ARR[X][Y]
73
-  #define _GET_MESH_POS(M) { _GET_MESH_X(M.a), _GET_MESH_Y(M.b) }
74
-
75 72
   #if EITHER(AUTO_BED_LEVELING_BILINEAR, MESH_BED_LEVELING)
76 73
 
77 74
     #include <stdint.h>
@@ -92,7 +89,7 @@ class TemporaryBedLevelingState {
92 89
     bool valid() const { return pos.x >= 0 && pos.y >= 0; }
93 90
     #if ENABLED(AUTO_BED_LEVELING_UBL)
94 91
       xy_pos_t meshpos() {
95
-        return { ubl.mesh_index_to_xpos(pos.x), ubl.mesh_index_to_ypos(pos.y) };
92
+        return { bedlevel.get_mesh_x(pos.x), bedlevel.get_mesh_y(pos.y) };
96 93
       }
97 94
     #endif
98 95
     operator xy_int8_t&() { return pos; }

+ 1
- 1
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp Переглянути файл

@@ -32,7 +32,7 @@
32 32
     #include "../../../lcd/extui/ui_api.h"
33 33
   #endif
34 34
 
35
-  mesh_bed_leveling mbl;
35
+  mesh_bed_leveling bedlevel;
36 36
 
37 37
   float mesh_bed_leveling::z_offset,
38 38
         mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],

+ 10
- 11
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h Переглянути файл

@@ -34,9 +34,6 @@ enum MeshLevelingState : char {
34 34
 
35 35
 #define MESH_X_DIST (float(MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_CELLS_X))
36 36
 #define MESH_Y_DIST (float(MESH_MAX_Y - (MESH_MIN_Y)) / (GRID_MAX_CELLS_Y))
37
-#define _GET_MESH_X(I) mbl.index_to_xpos[I]
38
-#define _GET_MESH_Y(J) mbl.index_to_ypos[J]
39
-#define Z_VALUES_ARR mbl.z_values
40 37
 
41 38
 class mesh_bed_leveling {
42 39
 public:
@@ -56,6 +53,8 @@ public:
56 53
     return false;
57 54
   }
58 55
 
56
+  static bool mesh_is_valid() { return has_mesh(); }
57
+
59 58
   static void set_z(const int8_t px, const int8_t py, const_float_t z) { z_values[px][py] = z; }
60 59
 
61 60
   static void zigzag(const int8_t index, int8_t &px, int8_t &py) {
@@ -70,6 +69,9 @@ public:
70 69
     set_z(px, py, z);
71 70
   }
72 71
 
72
+  static float get_mesh_x(const uint8_t i) { return index_to_xpos[i]; }
73
+  static float get_mesh_y(const uint8_t i) { return index_to_ypos[i]; }
74
+
73 75
   static int8_t cell_index_x(const_float_t x) {
74 76
     int8_t cx = (x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST);
75 77
     return constrain(cx, 0, GRID_MAX_CELLS_X - 1);
@@ -102,12 +104,9 @@ public:
102 104
     return z1 + delta_a * delta_z;
103 105
   }
104 106
 
105
-  static float get_z(const xy_pos_t &pos
106
-    OPTARG(ENABLE_LEVELING_FADE_HEIGHT, const_float_t factor=1.0f)
107
-  ) {
108
-    #if DISABLED(ENABLE_LEVELING_FADE_HEIGHT)
109
-      constexpr float factor = 1.0f;
110
-    #endif
107
+  static float get_z_offset() { return z_offset; }
108
+
109
+  static float get_z_correction(const xy_pos_t &pos) {
111 110
     const xy_int8_t ind = cell_indexes(pos);
112 111
     const float x1 = index_to_xpos[ind.x], x2 = index_to_xpos[ind.x+1],
113 112
                 y1 = index_to_xpos[ind.y], y2 = index_to_xpos[ind.y+1],
@@ -115,7 +114,7 @@ public:
115 114
                 z2 = calc_z0(pos.x, x1, z_values[ind.x][ind.y+1], x2, z_values[ind.x+1][ind.y+1]),
116 115
                 zf = calc_z0(pos.y, y1, z1, y2, z2);
117 116
 
118
-    return z_offset + zf * factor;
117
+    return zf;
119 118
   }
120 119
 
121 120
   #if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
@@ -123,4 +122,4 @@ public:
123 122
   #endif
124 123
 };
125 124
 
126
-extern mesh_bed_leveling mbl;
125
+extern mesh_bed_leveling bedlevel;

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl.cpp Переглянути файл

@@ -26,7 +26,7 @@
26 26
 
27 27
 #include "../bedlevel.h"
28 28
 
29
-unified_bed_leveling ubl;
29
+unified_bed_leveling bedlevel;
30 30
 
31 31
 #include "../../../MarlinCore.h"
32 32
 #include "../../../gcode/gcode.h"

+ 17
- 18
Marlin/src/feature/bedlevel/ubl/ubl.h Переглянути файл

@@ -215,7 +215,7 @@ public:
215 215
       return _UBL_OUTER_Z_RAISE;
216 216
     }
217 217
 
218
-    const float xratio = (rx0 - mesh_index_to_xpos(x1_i)) * RECIPROCAL(MESH_X_DIST),
218
+    const float xratio = (rx0 - get_mesh_x(x1_i)) * RECIPROCAL(MESH_X_DIST),
219 219
                 z1 = z_values[x1_i][yi];
220 220
 
221 221
     return z1 + xratio * (z_values[_MIN(x1_i, (GRID_MAX_POINTS_X) - 2) + 1][yi] - z1);  // Don't allow x1_i+1 to be past the end of the array
@@ -238,7 +238,7 @@ public:
238 238
       return _UBL_OUTER_Z_RAISE;
239 239
     }
240 240
 
241
-    const float yratio = (ry0 - mesh_index_to_ypos(y1_i)) * RECIPROCAL(MESH_Y_DIST),
241
+    const float yratio = (ry0 - get_mesh_y(y1_i)) * RECIPROCAL(MESH_Y_DIST),
242 242
                 z1 = z_values[xi][y1_i];
243 243
 
244 244
     return z1 + yratio * (z_values[xi][_MIN(y1_i, (GRID_MAX_POINTS_Y) - 2) + 1] - z1);  // Don't allow y1_i+1 to be past the end of the array
@@ -264,16 +264,17 @@ public:
264 264
         return UBL_Z_RAISE_WHEN_OFF_MESH;
265 265
     #endif
266 266
 
267
-    const uint8_t mx = _MIN(cx, (GRID_MAX_POINTS_X) - 2) + 1, my = _MIN(cy, (GRID_MAX_POINTS_Y) - 2) + 1;
268
-    const float z1 = calc_z0(rx0, mesh_index_to_xpos(cx), z_values[cx][cy], mesh_index_to_xpos(cx + 1), z_values[mx][cy]);
269
-    const float z2 = calc_z0(rx0, mesh_index_to_xpos(cx), z_values[cx][my], mesh_index_to_xpos(cx + 1), z_values[mx][my]);
270
-    float z0 = calc_z0(ry0, mesh_index_to_ypos(cy), z1, mesh_index_to_ypos(cy + 1), z2);
267
+    const uint8_t mx = _MIN(cx, (GRID_MAX_POINTS_X) - 2) + 1, my = _MIN(cy, (GRID_MAX_POINTS_Y) - 2) + 1,
268
+                  x0 = get_mesh_x(cx), x1 = get_mesh_x(cx + 1);
269
+    const float z1 = calc_z0(rx0, x0, z_values[cx][cy], x1, z_values[mx][cy]),
270
+                z2 = calc_z0(rx0, x0, z_values[cx][my], x1, z_values[mx][my]);
271
+    float z0 = calc_z0(ry0, get_mesh_y(cy), z1, get_mesh_y(cy + 1), z2);
271 272
 
272
-    if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN
273
-      z0 = 0.0;      // in ubl.z_values[][] and propagate through the
274
-                     // calculations. If our correction is NAN, we throw it out
275
-                     // because part of the Mesh is undefined and we don't have the
276
-                     // information we need to complete the height correction.
273
+    if (isnan(z0)) { // If part of the Mesh is undefined, it will show up as NAN
274
+      z0 = 0.0;      // in z_values[][] and propagate through the calculations.
275
+                     // If our correction is NAN, we throw it out because part of
276
+                     // the Mesh is undefined and we don't have the information
277
+                     // needed to complete the height correction.
277 278
 
278 279
       if (DEBUGGING(MESH_ADJUST)) DEBUG_ECHOLNPGM("??? Yikes! NAN in ");
279 280
     }
@@ -287,10 +288,12 @@ public:
287 288
   }
288 289
   static float get_z_correction(const xy_pos_t &pos) { return get_z_correction(pos.x, pos.y); }
289 290
 
290
-  static float mesh_index_to_xpos(const uint8_t i) {
291
+  static constexpr float get_z_offset() { return 0.0f; }
292
+
293
+  static float get_mesh_x(const uint8_t i) {
291 294
     return i < (GRID_MAX_POINTS_X) ? pgm_read_float(&_mesh_index_to_xpos[i]) : MESH_MIN_X + i * (MESH_X_DIST);
292 295
   }
293
-  static float mesh_index_to_ypos(const uint8_t i) {
296
+  static float get_mesh_y(const uint8_t i) {
294 297
     return i < (GRID_MAX_POINTS_Y) ? pgm_read_float(&_mesh_index_to_ypos[i]) : MESH_MIN_Y + i * (MESH_Y_DIST);
295 298
   }
296 299
 
@@ -307,11 +310,7 @@ public:
307 310
 
308 311
 }; // class unified_bed_leveling
309 312
 
310
-extern unified_bed_leveling ubl;
311
-
312
-#define _GET_MESH_X(I) ubl.mesh_index_to_xpos(I)
313
-#define _GET_MESH_Y(J) ubl.mesh_index_to_ypos(J)
314
-#define Z_VALUES_ARR ubl.z_values
313
+extern unified_bed_leveling bedlevel;
315 314
 
316 315
 // Prevent debugging propagating to other files
317 316
 #include "../../../core/debug_out.h"

+ 17
- 27
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp Переглянути файл

@@ -941,11 +941,7 @@ void set_message_with_feedback(FSTR_P const fstr) {
941 941
       // It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
942 942
       if (!location.valid()) continue;
943 943
 
944
-      const xyz_pos_t ppos = {
945
-        mesh_index_to_xpos(lpos.x),
946
-        mesh_index_to_ypos(lpos.y),
947
-        z_clearance
948
-      };
944
+      const xyz_pos_t ppos = { get_mesh_x(lpos.x), get_mesh_y(lpos.y), z_clearance };
949 945
 
950 946
       if (!position_is_reachable(ppos)) break; // SHOULD NOT OCCUR (find_closest_mesh_point only returns reachable points)
951 947
 
@@ -1040,11 +1036,7 @@ void set_message_with_feedback(FSTR_P const fstr) {
1040 1036
 
1041 1037
       done_flags.mark(lpos);                              // Mark this location as 'adjusted' so a new
1042 1038
                                                           // location is used on the next loop
1043
-      const xyz_pos_t raw = {
1044
-        mesh_index_to_xpos(lpos.x),
1045
-        mesh_index_to_ypos(lpos.y),
1046
-        Z_CLEARANCE_BETWEEN_PROBES
1047
-      };
1039
+      const xyz_pos_t raw = { get_mesh_x(lpos.x), get_mesh_y(lpos.y), Z_CLEARANCE_BETWEEN_PROBES };
1048 1040
 
1049 1041
       if (!position_is_reachable(raw)) break;             // SHOULD NOT OCCUR (find_closest_mesh_point_of_type only returns reachable)
1050 1042
 
@@ -1277,7 +1269,7 @@ mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
1277 1269
     if (!isnan(z_values[i][j])) continue;  // Skip valid mesh points
1278 1270
 
1279 1271
     // Skip unreachable points
1280
-    if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j)))
1272
+    if (!probe.can_reach(get_mesh_x(i), get_mesh_y(j)))
1281 1273
       continue;
1282 1274
 
1283 1275
     found_a_NAN = true;
@@ -1329,11 +1321,11 @@ mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
1329 1321
 
1330 1322
   static bool test_func(uint8_t i, uint8_t j, void *data) {
1331 1323
     find_closest_t *d = (find_closest_t*)data;
1332
-    if (  d->type == CLOSEST || d->type == (isnan(ubl.z_values[i][j]) ? INVALID : REAL)
1324
+    if (  d->type == CLOSEST || d->type == (isnan(bedlevel.z_values[i][j]) ? INVALID : REAL)
1333 1325
       || (d->type == SET_IN_BITMAP && !d->done_flags->marked(i, j))
1334 1326
     ) {
1335 1327
       // Found a Mesh Point of the specified type!
1336
-      const xy_pos_t mpos = { ubl.mesh_index_to_xpos(i), ubl.mesh_index_to_ypos(j) };
1328
+      const xy_pos_t mpos = { bedlevel.get_mesh_x(i), bedlevel.get_mesh_y(j) };
1337 1329
 
1338 1330
       // If using the probe as the reference there are some unreachable locations.
1339 1331
       // Also for round beds, there are grid points outside the bed the nozzle can't reach.
@@ -1377,7 +1369,7 @@ mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const Mesh
1377 1369
         || (type == SET_IN_BITMAP && !done_flags->marked(i, j))
1378 1370
       ) {
1379 1371
         // Found a Mesh Point of the specified type!
1380
-        const xy_pos_t mpos = { mesh_index_to_xpos(i), mesh_index_to_ypos(j) };
1372
+        const xy_pos_t mpos = { get_mesh_x(i), get_mesh_y(j) };
1381 1373
 
1382 1374
         // If using the probe as the reference there are some unreachable locations.
1383 1375
         // Also for round beds, there are grid points outside the bed the nozzle can't reach.
@@ -1433,10 +1425,10 @@ typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info;
1433 1425
 
1434 1426
 void unified_bed_leveling::smart_fill_mesh() {
1435 1427
   static const smart_fill_info
1436
-    info0 PROGMEM = { 0, GRID_MAX_POINTS_X,      0, GRID_MAX_POINTS_Y - 2,  false },  // Bottom of the mesh looking up
1437
-    info1 PROGMEM = { 0, GRID_MAX_POINTS_X,      GRID_MAX_POINTS_Y - 1, 0,  false },  // Top of the mesh looking down
1438
-    info2 PROGMEM = { 0, GRID_MAX_POINTS_X - 2,  0, GRID_MAX_POINTS_Y,      true  },  // Left side of the mesh looking right
1439
-    info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0,  0, GRID_MAX_POINTS_Y,      true  };  // Right side of the mesh looking left
1428
+    info0 PROGMEM = { 0, GRID_MAX_POINTS_X,       0, (GRID_MAX_POINTS_Y) - 2, false },  // Bottom of the mesh looking up
1429
+    info1 PROGMEM = { 0, GRID_MAX_POINTS_X,     (GRID_MAX_POINTS_Y) - 1, 0,   false },  // Top of the mesh looking down
1430
+    info2 PROGMEM = { 0, (GRID_MAX_POINTS_X) - 2, 0, GRID_MAX_POINTS_Y,       true  },  // Left side of the mesh looking right
1431
+    info3 PROGMEM = { (GRID_MAX_POINTS_X) - 1, 0, 0, GRID_MAX_POINTS_Y,       true  };  // Right side of the mesh looking left
1440 1432
   static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
1441 1433
 
1442 1434
   LOOP_L_N(i, COUNT(info)) {
@@ -1625,9 +1617,7 @@ void unified_bed_leveling::smart_fill_mesh() {
1625 1617
     matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
1626 1618
 
1627 1619
     GRID_LOOP(i, j) {
1628
-      float mx = mesh_index_to_xpos(i),
1629
-            my = mesh_index_to_ypos(j),
1630
-            mz = z_values[i][j];
1620
+      float mx = get_mesh_x(i), my = get_mesh_y(j), mz = z_values[i][j];
1631 1621
 
1632 1622
       if (DEBUGGING(LEVELING)) {
1633 1623
         DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
@@ -1724,18 +1714,18 @@ void unified_bed_leveling::smart_fill_mesh() {
1724 1714
 
1725 1715
     xy_pos_t ppos;
1726 1716
     LOOP_L_N(ix, GRID_MAX_POINTS_X) {
1727
-      ppos.x = mesh_index_to_xpos(ix);
1717
+      ppos.x = get_mesh_x(ix);
1728 1718
       LOOP_L_N(iy, GRID_MAX_POINTS_Y) {
1729
-        ppos.y = mesh_index_to_ypos(iy);
1719
+        ppos.y = get_mesh_y(iy);
1730 1720
         if (isnan(z_values[ix][iy])) {
1731 1721
           // undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
1732 1722
           incremental_LSF_reset(&lsf_results);
1733 1723
           xy_pos_t rpos;
1734 1724
           LOOP_L_N(jx, GRID_MAX_POINTS_X) {
1735
-            rpos.x = mesh_index_to_xpos(jx);
1725
+            rpos.x = get_mesh_x(jx);
1736 1726
             LOOP_L_N(jy, GRID_MAX_POINTS_Y) {
1737 1727
               if (TEST(bitmap[jx], jy)) {
1738
-                rpos.y = mesh_index_to_ypos(jy);
1728
+                rpos.y = get_mesh_y(jy);
1739 1729
                 const float rz = z_values[jx][jy],
1740 1730
                              w = 1.0f + weight_scaled / (rpos - ppos).magnitude();
1741 1731
                 incremental_WLSF(&lsf_results, rpos, rz, w);
@@ -1794,7 +1784,7 @@ void unified_bed_leveling::smart_fill_mesh() {
1794 1784
 
1795 1785
     SERIAL_ECHOPGM("X-Axis Mesh Points at: ");
1796 1786
     LOOP_L_N(i, GRID_MAX_POINTS_X) {
1797
-      SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3);
1787
+      SERIAL_ECHO_F(LOGICAL_X_POSITION(get_mesh_x(i)), 3);
1798 1788
       SERIAL_ECHOPGM("  ");
1799 1789
       serial_delay(25);
1800 1790
     }
@@ -1802,7 +1792,7 @@ void unified_bed_leveling::smart_fill_mesh() {
1802 1792
 
1803 1793
     SERIAL_ECHOPGM("Y-Axis Mesh Points at: ");
1804 1794
     LOOP_L_N(i, GRID_MAX_POINTS_Y) {
1805
-      SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3);
1795
+      SERIAL_ECHO_F(LOGICAL_Y_POSITION(get_mesh_y(i)), 3);
1806 1796
       SERIAL_ECHOPGM("  ");
1807 1797
       serial_delay(25);
1808 1798
     }

+ 9
- 12
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp Переглянути файл

@@ -76,8 +76,8 @@
76 76
       #endif
77 77
 
78 78
       // The distance is always MESH_X_DIST so multiply by the constant reciprocal.
79
-      const float xratio = (end.x - mesh_index_to_xpos(iend.x)) * RECIPROCAL(MESH_X_DIST),
80
-                  yratio = (end.y - mesh_index_to_ypos(iend.y)) * RECIPROCAL(MESH_Y_DIST),
79
+      const float xratio = (end.x - get_mesh_x(iend.x)) * RECIPROCAL(MESH_X_DIST),
80
+                  yratio = (end.y - get_mesh_y(iend.y)) * RECIPROCAL(MESH_Y_DIST),
81 81
                   z1 = z_values[iend.x][iend.y    ] + xratio * (z_values[iend.x + 1][iend.y    ] - z_values[iend.x][iend.y    ]),
82 82
                   z2 = z_values[iend.x][iend.y + 1] + xratio * (z_values[iend.x + 1][iend.y + 1] - z_values[iend.x][iend.y + 1]);
83 83
 
@@ -139,7 +139,7 @@
139 139
       icell.y += ineg.y;      // Line going down? Just go to the bottom.
140 140
       while (icell.y != iend.y + ineg.y) {
141 141
         icell.y += iadd.y;
142
-        const float next_mesh_line_y = mesh_index_to_ypos(icell.y);
142
+        const float next_mesh_line_y = get_mesh_y(icell.y);
143 143
 
144 144
         /**
145 145
          * Skip the calculations for an infinite slope.
@@ -155,7 +155,7 @@
155 155
         // Replace NAN corrections with 0.0 to prevent NAN propagation.
156 156
         if (isnan(z0)) z0 = 0.0;
157 157
 
158
-        dest.y = mesh_index_to_ypos(icell.y);
158
+        dest.y = get_mesh_y(icell.y);
159 159
 
160 160
         /**
161 161
          * Without this check, it's possible to generate a zero length move, as in the case where
@@ -196,7 +196,7 @@
196 196
 
197 197
       while (icell.x != iend.x + ineg.x) {
198 198
         icell.x += iadd.x;
199
-        dest.x = mesh_index_to_xpos(icell.x);
199
+        dest.x = get_mesh_x(icell.x);
200 200
         dest.y = ratio * dest.x + c;    // Calculate Y at the next X mesh line
201 201
 
202 202
         float z0 = z_correction_for_y_on_vertical_mesh_line(dest.y, icell.x, icell.y)
@@ -245,8 +245,8 @@
245 245
 
246 246
     while (cnt) {
247 247
 
248
-      const float next_mesh_line_x = mesh_index_to_xpos(icell.x + iadd.x),
249
-                  next_mesh_line_y = mesh_index_to_ypos(icell.y + iadd.y);
248
+      const float next_mesh_line_x = get_mesh_x(icell.x + iadd.x),
249
+                  next_mesh_line_y = get_mesh_y(icell.y + iadd.y);
250 250
 
251 251
       dest.y = ratio * next_mesh_line_x + c;    // Calculate Y at the next X mesh line
252 252
       dest.x = (next_mesh_line_y - c) / ratio;  // Calculate X at the next Y mesh line
@@ -423,7 +423,7 @@
423 423
       if (isnan(z_x0y1)) z_x0y1 = 0;              //   in order to avoid isnan tests per cell,
424 424
       if (isnan(z_x1y1)) z_x1y1 = 0;              //   thus guessing zero for undefined points
425 425
 
426
-      const xy_pos_t pos = { mesh_index_to_xpos(icell.x), mesh_index_to_ypos(icell.y) };
426
+      const xy_pos_t pos = { get_mesh_x(icell.x), get_mesh_y(icell.y) };
427 427
       xy_pos_t cell = raw - pos;
428 428
 
429 429
       const float z_xmy0 = (z_x1y0 - z_x0y0) * RECIPROCAL(MESH_X_DIST),   // z slope per x along y0 (lower left to lower right)
@@ -450,10 +450,7 @@
450 450
         if (--segments == 0) raw = destination;     // if this is last segment, use destination for exact
451 451
 
452 452
         const float z_cxcy = (z_cxy0 + z_cxym * cell.y) // interpolated mesh z height along cell.x at cell.y
453
-          #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
454
-            * fade_scaling_factor                   // apply fade factor to interpolated mesh height
455
-          #endif
456
-        ;
453
+          TERN_(ENABLE_LEVELING_FADE_HEIGHT, * fade_scaling_factor); // apply fade factor to interpolated height
457 454
 
458 455
         const float oldz = raw.z; raw.z += z_cxcy;
459 456
         planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, segment_xyz_mm OPTARG(SCARA_FEEDRATE_SCALING, inv_duration) );

+ 8
- 8
Marlin/src/gcode/bedlevel/G26.cpp Переглянути файл

@@ -293,10 +293,10 @@ typedef struct {
293 293
 
294 294
     if (circle_flags.marked(p1.x, p1.y) && circle_flags.marked(p2.x, p2.y)) {
295 295
       xyz_pos_t s, e;
296
-      s.x = _GET_MESH_X(p1.x) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
297
-      e.x = _GET_MESH_X(p2.x) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
298
-      s.y = _GET_MESH_Y(p1.y) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
299
-      e.y = _GET_MESH_Y(p2.y) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
296
+      s.x = bedlevel.get_mesh_x(p1.x) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
297
+      e.x = bedlevel.get_mesh_x(p2.x) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
298
+      s.y = bedlevel.get_mesh_y(p1.y) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
299
+      e.y = bedlevel.get_mesh_y(p2.y) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
300 300
       s.z = e.z = layer_height;
301 301
 
302 302
       #if HAS_ENDSTOPS
@@ -448,7 +448,7 @@ typedef struct {
448 448
       GRID_LOOP(i, j) {
449 449
         if (!circle_flags.marked(i, j)) {
450 450
           // We found a circle that needs to be printed
451
-          const xy_pos_t m = { _GET_MESH_X(i), _GET_MESH_Y(j) };
451
+          const xy_pos_t m = { bedlevel.get_mesh_x(i), bedlevel.get_mesh_y(j) };
452 452
 
453 453
           // Get the distance to this intersection
454 454
           float f = (pos - m).magnitude();
@@ -729,7 +729,7 @@ void GcodeSuite::G26() {
729 729
 
730 730
     if (location.valid()) {
731 731
       TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location.pos, ExtUI::G26_POINT_START));
732
-      const xy_pos_t circle = _GET_MESH_POS(location.pos);
732
+      const xy_pos_t circle = { bedlevel.get_mesh_x(location.pos.a), bedlevel.get_mesh_y(location.pos.b) };
733 733
 
734 734
       // If this mesh location is outside the printable radius, skip it.
735 735
       if (!position_is_reachable(circle)) continue;
@@ -738,8 +738,8 @@ void GcodeSuite::G26() {
738 738
       // which is always drawn counter-clockwise.
739 739
       const xy_int8_t st = location;
740 740
       const bool f = st.y == 0,
741
-                 r = st.x >= GRID_MAX_POINTS_X - 1,
742
-                 b = st.y >= GRID_MAX_POINTS_Y - 1;
741
+                 r = st.x >= (GRID_MAX_POINTS_X) - 1,
742
+                 b = st.y >= (GRID_MAX_POINTS_Y) - 1;
743 743
 
744 744
       #if ENABLED(ARC_SUPPORT)
745 745
 

+ 2
- 2
Marlin/src/gcode/bedlevel/G42.cpp Переглянути файл

@@ -48,8 +48,8 @@ void GcodeSuite::G42() {
48 48
     // Move to current_position, as modified by I, J, P parameters
49 49
     destination = current_position;
50 50
 
51
-    if (hasI) destination.x = _GET_MESH_X(ix);
52
-    if (hasJ) destination.y = _GET_MESH_Y(iy);
51
+    if (hasI) destination.x = bedlevel.get_mesh_x(ix);
52
+    if (hasJ) destination.y = bedlevel.get_mesh_y(iy);
53 53
 
54 54
     #if HAS_PROBE_XY_OFFSET
55 55
       if (parser.boolval('P')) {

+ 17
- 17
Marlin/src/gcode/bedlevel/M420.cpp Переглянути файл

@@ -71,13 +71,13 @@ void GcodeSuite::M420() {
71 71
         start.set(x_min, y_min);
72 72
         spacing.set((x_max - x_min) / (GRID_MAX_CELLS_X),
73 73
                     (y_max - y_min) / (GRID_MAX_CELLS_Y));
74
-        bbl.set_grid(spacing, start);
74
+        bedlevel.set_grid(spacing, start);
75 75
       #endif
76 76
       GRID_LOOP(x, y) {
77
-        Z_VALUES(x, y) = 0.001 * random(-200, 200);
78
-        TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y)));
77
+        bedlevel.z_values[x][y] = 0.001 * random(-200, 200);
78
+        TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, bedlevel.z_values[x][y]));
79 79
       }
80
-      TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
80
+      TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
81 81
       SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
82 82
       SERIAL_ECHOPGM(" (", x_min);
83 83
       SERIAL_CHAR(','); SERIAL_ECHO(y_min);
@@ -101,7 +101,7 @@ void GcodeSuite::M420() {
101 101
       set_bed_leveling_enabled(false);
102 102
 
103 103
       #if ENABLED(EEPROM_SETTINGS)
104
-        const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.storage_slot;
104
+        const int8_t storage_slot = parser.has_value() ? parser.value_int() : bedlevel.storage_slot;
105 105
         const int16_t a = settings.calc_num_meshes();
106 106
 
107 107
         if (!a) {
@@ -116,7 +116,7 @@ void GcodeSuite::M420() {
116 116
         }
117 117
 
118 118
         settings.load_mesh(storage_slot);
119
-        ubl.storage_slot = storage_slot;
119
+        bedlevel.storage_slot = storage_slot;
120 120
 
121 121
       #else
122 122
 
@@ -128,10 +128,10 @@ void GcodeSuite::M420() {
128 128
 
129 129
     // L or V display the map info
130 130
     if (parser.seen("LV")) {
131
-      ubl.display_map(parser.byteval('T'));
131
+      bedlevel.display_map(parser.byteval('T'));
132 132
       SERIAL_ECHOPGM("Mesh is ");
133
-      if (!ubl.mesh_is_valid()) SERIAL_ECHOPGM("in");
134
-      SERIAL_ECHOLNPGM("valid\nStorage slot: ", ubl.storage_slot);
133
+      if (!bedlevel.mesh_is_valid()) SERIAL_ECHOPGM("in");
134
+      SERIAL_ECHOLNPGM("valid\nStorage slot: ", bedlevel.storage_slot);
135 135
     }
136 136
 
137 137
   #endif // AUTO_BED_LEVELING_UBL
@@ -148,7 +148,7 @@ void GcodeSuite::M420() {
148 148
         #if ENABLED(AUTO_BED_LEVELING_UBL)
149 149
 
150 150
           set_bed_leveling_enabled(false);
151
-          ubl.adjust_mesh_to_mean(true, cval);
151
+          bedlevel.adjust_mesh_to_mean(true, cval);
152 152
 
153 153
         #else
154 154
 
@@ -156,7 +156,7 @@ void GcodeSuite::M420() {
156 156
 
157 157
             // Get the sum and average of all mesh values
158 158
             float mesh_sum = 0;
159
-            GRID_LOOP(x, y) mesh_sum += Z_VALUES(x, y);
159
+            GRID_LOOP(x, y) mesh_sum += bedlevel.z_values[x][y];
160 160
             const float zmean = mesh_sum / float(GRID_MAX_POINTS);
161 161
 
162 162
           #else // midrange
@@ -164,7 +164,7 @@ void GcodeSuite::M420() {
164 164
             // Find the low and high mesh values.
165 165
             float lo_val = 100, hi_val = -100;
166 166
             GRID_LOOP(x, y) {
167
-              const float z = Z_VALUES(x, y);
167
+              const float z = bedlevel.z_values[x][y];
168 168
               NOMORE(lo_val, z);
169 169
               NOLESS(hi_val, z);
170 170
             }
@@ -178,10 +178,10 @@ void GcodeSuite::M420() {
178 178
             set_bed_leveling_enabled(false);
179 179
             // Subtract the mean from all values
180 180
             GRID_LOOP(x, y) {
181
-              Z_VALUES(x, y) -= zmean;
182
-              TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y)));
181
+              bedlevel.z_values[x][y] -= zmean;
182
+              TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, bedlevel.z_values[x][y]));
183 183
             }
184
-            TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
184
+            TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
185 185
           }
186 186
 
187 187
         #endif
@@ -202,10 +202,10 @@ void GcodeSuite::M420() {
202 202
     #else
203 203
       if (leveling_is_valid()) {
204 204
         #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
205
-          bbl.print_leveling_grid();
205
+          bedlevel.print_leveling_grid();
206 206
         #elif ENABLED(MESH_BED_LEVELING)
207 207
           SERIAL_ECHOLNPGM("Mesh Bed Level data:");
208
-          mbl.report_mesh();
208
+          bedlevel.report_mesh();
209 209
         #endif
210 210
       }
211 211
     #endif

+ 14
- 14
Marlin/src/gcode/bedlevel/abl/G29.cpp Переглянути файл

@@ -313,8 +313,8 @@ G29_TYPE GcodeSuite::G29() {
313 313
 
314 314
         if (!isnan(rx) && !isnan(ry)) {
315 315
           // Get nearest i / j from rx / ry
316
-          i = (rx - bbl.get_grid_start().x) / bbl.get_grid_spacing().x + 0.5f;
317
-          j = (ry - bbl.get_grid_start().y) / bbl.get_grid_spacing().y + 0.5f;
316
+          i = (rx - bedlevel.grid_start.x) / bedlevel.grid_spacing.x + 0.5f;
317
+          j = (ry - bedlevel.grid_start.y) / bedlevel.grid_spacing.y + 0.5f;
318 318
           LIMIT(i, 0, (GRID_MAX_POINTS_X) - 1);
319 319
           LIMIT(j, 0, (GRID_MAX_POINTS_Y) - 1);
320 320
         }
@@ -323,8 +323,8 @@ G29_TYPE GcodeSuite::G29() {
323 323
 
324 324
         if (WITHIN(i, 0, (GRID_MAX_POINTS_X) - 1) && WITHIN(j, 0, (GRID_MAX_POINTS_Y) - 1)) {
325 325
           set_bed_leveling_enabled(false);
326
-          Z_VALUES_ARR[i][j] = rz;
327
-          bbl.refresh_bed_level();
326
+          bedlevel.z_values[i][j] = rz;
327
+          bedlevel.refresh_bed_level();
328 328
           TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, rz));
329 329
           set_bed_leveling_enabled(abl.reenable);
330 330
           if (abl.reenable) report_current_position();
@@ -499,7 +499,7 @@ G29_TYPE GcodeSuite::G29() {
499 499
 
500 500
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
501 501
       if (!abl.dryrun
502
-        && (abl.gridSpacing != bbl.get_grid_spacing() || abl.probe_position_lf != bbl.get_grid_start())
502
+        && (abl.gridSpacing != bedlevel.grid_spacing || abl.probe_position_lf != bedlevel.grid_start)
503 503
       ) {
504 504
         // Reset grid to 0.0 or "not probed". (Also disables ABL)
505 505
         reset_bed_level();
@@ -509,7 +509,7 @@ G29_TYPE GcodeSuite::G29() {
509 509
       }
510 510
 
511 511
       // Pre-populate local Z values from the stored mesh
512
-      TERN_(IS_KINEMATIC, COPY(abl.z_values, Z_VALUES_ARR));
512
+      TERN_(IS_KINEMATIC, COPY(abl.z_values, bedlevel.z_values));
513 513
 
514 514
     #endif // AUTO_BED_LEVELING_BILINEAR
515 515
 
@@ -796,14 +796,14 @@ G29_TYPE GcodeSuite::G29() {
796 796
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
797 797
 
798 798
       if (abl.dryrun)
799
-        bbl.print_leveling_grid(&abl.z_values);
799
+        bedlevel.print_leveling_grid(&abl.z_values);
800 800
       else {
801
-        bbl.set_grid(abl.gridSpacing, abl.probe_position_lf);
802
-        COPY(Z_VALUES_ARR, abl.z_values);
803
-        TERN_(IS_KINEMATIC, bbl.extrapolate_unprobed_bed_level());
804
-        bbl.refresh_bed_level();
801
+        bedlevel.set_grid(abl.gridSpacing, abl.probe_position_lf);
802
+        COPY(bedlevel.z_values, abl.z_values);
803
+        TERN_(IS_KINEMATIC, bedlevel.extrapolate_unprobed_bed_level());
804
+        bedlevel.refresh_bed_level();
805 805
 
806
-        bbl.print_leveling_grid();
806
+        bedlevel.print_leveling_grid();
807 807
       }
808 808
 
809 809
     #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
@@ -923,8 +923,8 @@ G29_TYPE GcodeSuite::G29() {
923 923
 
924 924
         // Unapply the offset because it is going to be immediately applied
925 925
         // and cause compensation movement in Z
926
-        const float fade_scaling_factor = TERN(ENABLE_LEVELING_FADE_HEIGHT, planner.fade_scaling_factor_for_z(current_position.z), 1);
927
-        current_position.z -= fade_scaling_factor * bbl.get_z_correction(current_position);
926
+        current_position.z -= bedlevel.get_z_correction(current_position)
927
+          TERN_(ENABLE_LEVELING_FADE_HEIGHT, * planner.fade_scaling_factor_for_z(current_position.z));
928 928
 
929 929
         if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(" corrected Z:", current_position.z);
930 930
       }

+ 3
- 3
Marlin/src/gcode/bedlevel/abl/M421.cpp Переглянути файл

@@ -58,11 +58,11 @@ void GcodeSuite::M421() {
58 58
               sy = iy >= 0 ? iy : 0, ey = iy >= 0 ? iy : GRID_MAX_POINTS_Y - 1;
59 59
       LOOP_S_LE_N(x, sx, ex) {
60 60
         LOOP_S_LE_N(y, sy, ey) {
61
-          Z_VALUES_ARR[x][y] = zval + (hasQ ? Z_VALUES_ARR[x][y] : 0);
62
-          TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, Z_VALUES_ARR[x][y]));
61
+          bedlevel.z_values[x][y] = zval + (hasQ ? bedlevel.z_values[x][y] : 0);
62
+          TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, bedlevel.z_values[x][y]));
63 63
         }
64 64
       }
65
-      bbl.refresh_bed_level();
65
+      bedlevel.refresh_bed_level();
66 66
     }
67 67
     else
68 68
       SERIAL_ERROR_MSG(STR_ERR_MESH_XY);

+ 9
- 9
Marlin/src/gcode/bedlevel/mbl/G29.cpp Переглянути файл

@@ -93,14 +93,14 @@ void GcodeSuite::G29() {
93 93
       SERIAL_ECHOPGM("Mesh Bed Leveling ");
94 94
       if (leveling_is_valid()) {
95 95
         serialprintln_onoff(planner.leveling_active);
96
-        mbl.report_mesh();
96
+        bedlevel.report_mesh();
97 97
       }
98 98
       else
99 99
         SERIAL_ECHOLNPGM("has no data.");
100 100
       break;
101 101
 
102 102
     case MeshStart:
103
-      mbl.reset();
103
+      bedlevel.reset();
104 104
       mbl_probe_index = 0;
105 105
       if (!ui.wait_for_move) {
106 106
         queue.inject(parser.seen_test('N') ? F("G28" TERN(CAN_SET_LEVELING_AFTER_G28, "L0", "") "\nG29S2") : F("G29S2"));
@@ -165,7 +165,7 @@ void GcodeSuite::G29() {
165 165
       }
166 166
       else {
167 167
         // Save Z for the previous mesh position
168
-        mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z);
168
+        bedlevel.set_zigzag_z(mbl_probe_index - 1, current_position.z);
169 169
         TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, current_position.z));
170 170
         TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(_MIN(mbl_probe_index, GRID_MAX_POINTS), int(GRID_MAX_POINTS), current_position.z));
171 171
         SET_SOFT_ENDSTOP_LOOSE(false);
@@ -175,8 +175,8 @@ void GcodeSuite::G29() {
175 175
         // Disable software endstops to allow manual adjustment
176 176
         // If G29 is left hanging without completion they won't be re-enabled!
177 177
         SET_SOFT_ENDSTOP_LOOSE(true);
178
-        mbl.zigzag(mbl_probe_index++, ix, iy);
179
-        _manual_goto_xy({ mbl.index_to_xpos[ix], mbl.index_to_ypos[iy] });
178
+        bedlevel.zigzag(mbl_probe_index++, ix, iy);
179
+        _manual_goto_xy({ bedlevel.index_to_xpos[ix], bedlevel.index_to_ypos[iy] });
180 180
       }
181 181
       else {
182 182
         // Move to the after probing position
@@ -232,9 +232,9 @@ void GcodeSuite::G29() {
232 232
         return echo_not_entered('J');
233 233
 
234 234
       if (parser.seenval('Z')) {
235
-        mbl.z_values[ix][iy] = parser.value_linear_units();
236
-        TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, mbl.z_values[ix][iy]));
237
-        TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ix, iy, mbl.z_values[ix][iy]));
235
+        bedlevel.z_values[ix][iy] = parser.value_linear_units();
236
+        TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, bedlevel.z_values[ix][iy]));
237
+        TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ix, iy, bedlevel.z_values[ix][iy]));
238 238
       }
239 239
       else
240 240
         return echo_not_entered('Z');
@@ -242,7 +242,7 @@ void GcodeSuite::G29() {
242 242
 
243 243
     case MeshSetZOffset:
244 244
       if (parser.seenval('Z'))
245
-        mbl.z_offset = parser.value_linear_units();
245
+        bedlevel.z_offset = parser.value_linear_units();
246 246
       else
247 247
         return echo_not_entered('Z');
248 248
       break;

+ 3
- 3
Marlin/src/gcode/bedlevel/mbl/M421.cpp Переглянути файл

@@ -43,9 +43,9 @@
43 43
  */
44 44
 void GcodeSuite::M421() {
45 45
   const bool hasX = parser.seen('X'), hasI = parser.seen('I');
46
-  const int8_t ix = hasI ? parser.value_int() : hasX ? mbl.probe_index_x(RAW_X_POSITION(parser.value_linear_units())) : -1;
46
+  const int8_t ix = hasI ? parser.value_int() : hasX ? bedlevel.probe_index_x(RAW_X_POSITION(parser.value_linear_units())) : -1;
47 47
   const bool hasY = parser.seen('Y'), hasJ = parser.seen('J');
48
-  const int8_t iy = hasJ ? parser.value_int() : hasY ? mbl.probe_index_y(RAW_Y_POSITION(parser.value_linear_units())) : -1;
48
+  const int8_t iy = hasJ ? parser.value_int() : hasY ? bedlevel.probe_index_y(RAW_Y_POSITION(parser.value_linear_units())) : -1;
49 49
   const bool hasZ = parser.seen('Z'), hasQ = !hasZ && parser.seen('Q');
50 50
 
51 51
   if (int(hasI && hasJ) + int(hasX && hasY) != 1 || !(hasZ || hasQ))
@@ -53,7 +53,7 @@ void GcodeSuite::M421() {
53 53
   else if (ix < 0 || iy < 0)
54 54
     SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
55 55
   else
56
-    mbl.set_z(ix, iy, parser.value_linear_units() + (hasQ ? mbl.z_values[ix][iy] : 0));
56
+    bedlevel.set_z(ix, iy, parser.value_linear_units() + (hasQ ? bedlevel.z_values[ix][iy] : 0));
57 57
 }
58 58
 
59 59
 #endif // MESH_BED_LEVELING

+ 1
- 1
Marlin/src/gcode/bedlevel/ubl/G29.cpp Переглянути файл

@@ -39,7 +39,7 @@ void GcodeSuite::G29() {
39 39
 
40 40
   TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE));
41 41
 
42
-  ubl.G29();
42
+  bedlevel.G29();
43 43
 
44 44
   TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
45 45
 }

+ 2
- 2
Marlin/src/gcode/bedlevel/ubl/M421.cpp Переглянути файл

@@ -56,7 +56,7 @@ void GcodeSuite::M421() {
56 56
              hasZ = parser.seen('Z'),
57 57
              hasQ = !hasZ && parser.seen('Q');
58 58
 
59
-  if (hasC) ij = ubl.find_closest_mesh_point_of_type(CLOSEST, current_position);
59
+  if (hasC) ij = bedlevel.find_closest_mesh_point_of_type(CLOSEST, current_position);
60 60
 
61 61
   // Test for bad parameter combinations
62 62
   if (int(hasC) + int(hasI && hasJ) != 1 || !(hasZ || hasQ || hasN))
@@ -66,7 +66,7 @@ void GcodeSuite::M421() {
66 66
   else if (!WITHIN(ij.x, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(ij.y, 0, GRID_MAX_POINTS_Y - 1))
67 67
     SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
68 68
   else {
69
-    float &zval = ubl.z_values[ij.x][ij.y];                               // Altering this Mesh Point
69
+    float &zval = bedlevel.z_values[ij.x][ij.y];                               // Altering this Mesh Point
70 70
     zval = hasN ? NAN : parser.value_linear_units() + (hasQ ? zval : 0);  // N=NAN, Z=NEWVAL, or Q=ADDVAL
71 71
     TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ij.x, ij.y, zval));          // Ping ExtUI in case it's showing the mesh
72 72
     TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ij.x, ij.y, zval));

+ 1
- 1
Marlin/src/gcode/control/M17_M18_M84.cpp Переглянути файл

@@ -233,6 +233,6 @@ void GcodeSuite::M18_M84() {
233 233
     else
234 234
       planner.finish_and_disable();
235 235
 
236
-    TERN_(AUTO_BED_LEVELING_UBL, ubl.steppers_were_disabled());
236
+    TERN_(AUTO_BED_LEVELING_UBL, bedlevel.steppers_were_disabled());
237 237
   }
238 238
 }

+ 1
- 1
Marlin/src/gcode/motion/M290.cpp Переглянути файл

@@ -111,7 +111,7 @@ void GcodeSuite::M290() {
111 111
     #endif
112 112
 
113 113
     #if ENABLED(MESH_BED_LEVELING)
114
-      SERIAL_ECHOLNPGM("MBL Adjust Z", mbl.z_offset);
114
+      SERIAL_ECHOLNPGM("MBL Adjust Z", bedlevel.z_offset);
115 115
     #endif
116 116
 
117 117
     #if ENABLED(BABYSTEP_DISPLAY_TOTAL)

+ 8
- 8
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp Переглянути файл

@@ -1281,9 +1281,9 @@ void MarlinUI::draw_status_screen() {
1281 1281
          * Show X and Y positions
1282 1282
          */
1283 1283
         _XLABEL(_PLOT_X, 0);
1284
-        lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(ubl.mesh_index_to_xpos(x_plot))));
1284
+        lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(bedlevel.get_mesh_x(x_plot))));
1285 1285
         _YLABEL(_LCD_W_POS, 0);
1286
-        lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos(y_plot))));
1286
+        lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(bedlevel.get_mesh_y(y_plot))));
1287 1287
 
1288 1288
         lcd_moveto(_PLOT_X, 0);
1289 1289
 
@@ -1475,8 +1475,8 @@ void MarlinUI::draw_status_screen() {
1475 1475
          * Print Z values
1476 1476
          */
1477 1477
         _ZLABEL(_LCD_W_POS, 1);
1478
-        if (!isnan(ubl.z_values[x_plot][y_plot]))
1479
-          lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot]));
1478
+        if (!isnan(bedlevel.z_values[x_plot][y_plot]))
1479
+          lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
1480 1480
         else
1481 1481
           lcd_put_u8str(F(" -----"));
1482 1482
 
@@ -1486,16 +1486,16 @@ void MarlinUI::draw_status_screen() {
1486 1486
          * Show all values at right of screen
1487 1487
          */
1488 1488
         _XLABEL(_LCD_W_POS, 1);
1489
-        lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(ubl.mesh_index_to_xpos(x_plot))));
1489
+        lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(bedlevel.get_mesh_x(x_plot))));
1490 1490
         _YLABEL(_LCD_W_POS, 2);
1491
-        lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos(y_plot))));
1491
+        lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(bedlevel.get_mesh_y(y_plot))));
1492 1492
 
1493 1493
         /**
1494 1494
          * Show the location value
1495 1495
          */
1496 1496
         _ZLABEL(_LCD_W_POS, 3);
1497
-        if (!isnan(ubl.z_values[x_plot][y_plot]))
1498
-          lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot]));
1497
+        if (!isnan(bedlevel.z_values[x_plot][y_plot]))
1498
+          lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
1499 1499
         else
1500 1500
           lcd_put_u8str(F(" -----"));
1501 1501
 

+ 4
- 4
Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp Переглянути файл

@@ -1069,15 +1069,15 @@ void MarlinUI::draw_status_screen() {
1069 1069
 
1070 1070
       // Show all values
1071 1071
       lcd.setCursor(_LCD_W_POS, 1); lcd_put_u8str(F("X:"));
1072
-      lcd.print(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
1072
+      lcd.print(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&bedlevel._mesh_index_to_xpos[x_plot]))));
1073 1073
       lcd.setCursor(_LCD_W_POS, 2); lcd_put_u8str(F("Y:"));
1074
-      lcd.print(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
1074
+      lcd.print(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&bedlevel._mesh_index_to_ypos[y_plot]))));
1075 1075
 
1076 1076
       // Show the location value
1077 1077
       lcd.setCursor(_LCD_W_POS, 3); lcd_put_u8str(F("Z:"));
1078 1078
 
1079
-      if (!isnan(ubl.z_values[x_plot][y_plot]))
1080
-        lcd.print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
1079
+      if (!isnan(bedlevel.z_values[x_plot][y_plot]))
1080
+        lcd.print(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
1081 1081
       else
1082 1082
         lcd_put_u8str(F(" -----"));
1083 1083
 

+ 5
- 5
Marlin/src/lcd/dogm/marlinui_DOGM.cpp Переглянути файл

@@ -579,9 +579,9 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
579 579
       u8g.setColorIndex(1);
580 580
       const u8g_uint_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
581 581
             u8g_uint_t  y = y_offset + pixels_per_y_mesh_pnt / 2;
582
-      for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
582
+      for (uint8_t j = 0; j < (GRID_MAX_POINTS_Y); j++, y += pixels_per_y_mesh_pnt)
583 583
         if (PAGE_CONTAINS(y, y))
584
-          for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
584
+          for (uint8_t i = 0, x = sx; i < (GRID_MAX_POINTS_X); i++, x += pixels_per_x_mesh_pnt)
585 585
             u8g.drawBox(x, y, 1, 1);
586 586
 
587 587
       // Fill in the Specified Mesh Point
@@ -601,7 +601,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
601 601
       // Show X and Y positions at top of screen
602 602
       u8g.setColorIndex(1);
603 603
       if (PAGE_UNDER(7)) {
604
-        const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
604
+        const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
605 605
                        lpos = pos.asLogical();
606 606
         lcd_put_u8str_P(5, 7, X_LBL);
607 607
         lcd_put_u8str(ftostr52(lpos.x));
@@ -619,8 +619,8 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
619 619
 
620 620
         // Show the location value
621 621
         lcd_put_u8str_P(74, LCD_PIXEL_HEIGHT, Z_LBL);
622
-        if (!isnan(ubl.z_values[x_plot][y_plot]))
623
-          lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot]));
622
+        if (!isnan(bedlevel.z_values[x_plot][y_plot]))
623
+          lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
624 624
         else
625 625
           lcd_put_u8str(F(" -----"));
626 626
       }

+ 65
- 67
Marlin/src/lcd/e3v2/jyersui/dwin.cpp Переглянути файл

@@ -207,11 +207,9 @@ CrealityDWINClass CrealityDWIN;
207 207
         struct linear_fit_data lsf_results;
208 208
         incremental_LSF_reset(&lsf_results);
209 209
         GRID_LOOP(x, y) {
210
-          if (!isnan(Z_VALUES_ARR[x][y])) {
211
-            xy_pos_t rpos;
212
-            rpos.x = ubl.mesh_index_to_xpos(x);
213
-            rpos.y = ubl.mesh_index_to_ypos(y);
214
-            incremental_LSF(&lsf_results, rpos, Z_VALUES_ARR[x][y]);
210
+          if (!isnan(bedlevel.z_values[x][y])) {
211
+            xy_pos_t rpos = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
212
+            incremental_LSF(&lsf_results, rpos, bedlevel.z_values[x][y]);
215 213
           }
216 214
         }
217 215
 
@@ -220,13 +218,13 @@ CrealityDWINClass CrealityDWIN;
220 218
           return true;
221 219
         }
222 220
 
223
-        ubl.set_all_mesh_points_to_value(0);
221
+        bedlevel.set_all_mesh_points_to_value(0);
224 222
 
225 223
         matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
226 224
         GRID_LOOP(i, j) {
227
-          float mx = ubl.mesh_index_to_xpos(i),
228
-                my = ubl.mesh_index_to_ypos(j),
229
-                mz = Z_VALUES_ARR[i][j];
225
+          float mx = bedlevel.get_mesh_x(i),
226
+                my = bedlevel.get_mesh_y(j),
227
+                mz = bedlevel.z_values[i][j];
230 228
 
231 229
           if (DEBUGGING(LEVELING)) {
232 230
             DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
@@ -250,7 +248,7 @@ CrealityDWINClass CrealityDWIN;
250 248
             DEBUG_DELAY(20);
251 249
           }
252 250
 
253
-          Z_VALUES_ARR[i][j] = mz - lsf_results.D;
251
+          bedlevel.z_values[i][j] = mz - lsf_results.D;
254 252
         }
255 253
         return false;
256 254
       }
@@ -268,7 +266,7 @@ CrealityDWINClass CrealityDWIN;
268 266
     void manual_move(bool zmove=false) {
269 267
       if (zmove) {
270 268
         planner.synchronize();
271
-        current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
269
+        current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
272 270
         planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
273 271
         planner.synchronize();
274 272
       }
@@ -279,7 +277,7 @@ CrealityDWINClass CrealityDWIN;
279 277
         sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
280 278
         gcode.process_subcommands_now(cmd);
281 279
         planner.synchronize();
282
-        current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
280
+        current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
283 281
         planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
284 282
         planner.synchronize();
285 283
         CrealityDWIN.Redraw_Menu();
@@ -289,8 +287,8 @@ CrealityDWINClass CrealityDWIN;
289 287
     float get_max_value() {
290 288
       float max = __FLT_MIN__;
291 289
       GRID_LOOP(x, y) {
292
-        if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] > max)
293
-          max = Z_VALUES_ARR[x][y];
290
+        if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
291
+          max = bedlevel.z_values[x][y];
294 292
       }
295 293
       return max;
296 294
     }
@@ -298,24 +296,24 @@ CrealityDWINClass CrealityDWIN;
298 296
     float get_min_value() {
299 297
       float min = __FLT_MAX__;
300 298
       GRID_LOOP(x, y) {
301
-        if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] < min)
302
-          min = Z_VALUES_ARR[x][y];
299
+        if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
300
+          min = bedlevel.z_values[x][y];
303 301
       }
304 302
       return min;
305 303
     }
306 304
 
307 305
     void Draw_Bed_Mesh(int16_t selected = -1, uint8_t gridline_width = 1, uint16_t padding_x = 8, uint16_t padding_y_top = 40 + 53 - 7) {
308 306
       drawing_mesh = true;
309
-      const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
310
-      const uint16_t cell_width_px  = total_width_px / GRID_MAX_POINTS_X;
311
-      const uint16_t cell_height_px = total_width_px / GRID_MAX_POINTS_Y;
307
+      const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x,
308
+                     cell_width_px  = total_width_px / (GRID_MAX_POINTS_X),
309
+                     cell_height_px = total_width_px / (GRID_MAX_POINTS_Y);
312 310
       const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
313 311
 
314 312
       // Clear background from previous selection and select new square
315 313
       DWIN_Draw_Rectangle(1, Color_Bg_Black, _MAX(0, padding_x - gridline_width), _MAX(0, padding_y_top - gridline_width), padding_x + total_width_px, padding_y_top + total_width_px);
316 314
       if (selected >= 0) {
317
-        const auto selected_y = selected / GRID_MAX_POINTS_X;
318
-        const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y);
315
+        const auto selected_y = selected / (GRID_MAX_POINTS_X);
316
+        const auto selected_x = selected - (GRID_MAX_POINTS_X) * selected_y;
319 317
         const auto start_y_px = padding_y_top + selected_y * cell_height_px;
320 318
         const auto start_x_px = padding_x + selected_x * cell_width_px;
321 319
         DWIN_Draw_Rectangle(1, Color_White, _MAX(0, start_x_px - gridline_width), _MAX(0, start_y_px - gridline_width), start_x_px + cell_width_px, start_y_px + cell_height_px);
@@ -329,11 +327,11 @@ CrealityDWINClass CrealityDWIN;
329 327
         const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
330 328
         const auto end_y_px   = start_y_px + cell_height_px - 1 - gridline_width;
331 329
         DWIN_Draw_Rectangle(1,                                                                                 // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
332
-          isnan(Z_VALUES_ARR[x][y]) ? Color_Grey : (                                                           // gray if undefined
333
-            (Z_VALUES_ARR[x][y] < 0 ?
334
-              (uint16_t)round(0x1F * -Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
335
-              (uint16_t)round(0x3F *  Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
336
-                _MIN(0x1F, (((uint8_t)abs(Z_VALUES_ARR[x][y]) / 10) * 4))),                                    // + blue stepping for every mm
330
+          isnan(bedlevel.z_values[x][y]) ? Color_Grey : (                                                           // gray if undefined
331
+            (bedlevel.z_values[x][y] < 0 ?
332
+              (uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
333
+              (uint16_t)round(0x3F *  bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
334
+                _MIN(0x1F, (((uint8_t)abs(bedlevel.z_values[x][y]) / 10) * 4))),                                    // + blue stepping for every mm
337 335
           start_x_px, start_y_px, end_x_px, end_y_px
338 336
         );
339 337
 
@@ -343,14 +341,14 @@ CrealityDWINClass CrealityDWIN;
343 341
         // Draw value text on
344 342
         if (viewer_print_value) {
345 343
           int8_t offset_x, offset_y = cell_height_px / 2 - 6;
346
-          if (isnan(Z_VALUES_ARR[x][y])) {  // undefined
344
+          if (isnan(bedlevel.z_values[x][y])) {  // undefined
347 345
             DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px + cell_width_px / 2 - 5, start_y_px + offset_y, F("X"));
348 346
           }
349 347
           else {                          // has value
350 348
             if (GRID_MAX_POINTS_X < 10)
351
-              sprintf_P(buf, PSTR("%s"), dtostrf(abs(Z_VALUES_ARR[x][y]), 1, 2, str_1));
349
+              sprintf_P(buf, PSTR("%s"), dtostrf(abs(bedlevel.z_values[x][y]), 1, 2, str_1));
352 350
             else
353
-              sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(Z_VALUES_ARR[x][y] - (int16_t)Z_VALUES_ARR[x][y]) * 100));
351
+              sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(bedlevel.z_values[x][y] - (int16_t)bedlevel.z_values[x][y]) * 100));
354 352
             offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
355 353
             if (!(GRID_MAX_POINTS_X < 10))
356 354
               DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px - 2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F("."));
@@ -417,14 +415,14 @@ void CrealityDWINClass::Draw_Float(float value, uint8_t row, bool selected/*=fal
417 415
 }
418 416
 
419 417
 void CrealityDWINClass::Draw_Option(uint8_t value, const char * const * options, uint8_t row, bool selected/*=false*/, bool color/*=false*/) {
420
-  uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black;
421
-  uint16_t tColor = (color) ? GetColor(value, Color_White, false) : Color_White;
418
+  uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black,
419
+           tColor = (color) ? GetColor(value, Color_White, false) : Color_White;
422 420
   DWIN_Draw_Rectangle(1, bColor, 202, MBASE(row) + 14, 258, MBASE(row) - 2);
423 421
   DWIN_Draw_String(false, DWIN_FONT_MENU, tColor, bColor, 202, MBASE(row) - 1, options[value]);
424 422
 }
425 423
 
426 424
 uint16_t CrealityDWINClass::GetColor(uint8_t color, uint16_t original, bool light/*=false*/) {
427
-  switch (color){
425
+  switch (color) {
428 426
     case Default:
429 427
       return original;
430 428
       break;
@@ -2842,7 +2840,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
2842 2840
               if (draw)
2843 2841
                 Draw_Menu_Item(row, ICON_Tilt, F("Autotilt Current Mesh"));
2844 2842
               else {
2845
-                if (ubl.storage_slot < 0) {
2843
+                if (bedlevel.storage_slot < 0) {
2846 2844
                   Popup_Handler(MeshSlot);
2847 2845
                   break;
2848 2846
                 }
@@ -2914,7 +2912,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
2914 2912
                 }
2915 2913
               #endif
2916 2914
               #if ENABLED(AUTO_BED_LEVELING_UBL)
2917
-                if (ubl.storage_slot < 0) {
2915
+                if (bedlevel.storage_slot < 0) {
2918 2916
                   Popup_Handler(MeshSlot);
2919 2917
                   break;
2920 2918
                 }
@@ -2949,7 +2947,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
2949 2947
               Draw_Menu_Item(row, ICON_Mesh, GET_TEXT(MSG_MESH_VIEW), nullptr, true);
2950 2948
             else {
2951 2949
               #if ENABLED(AUTO_BED_LEVELING_UBL)
2952
-                if (ubl.storage_slot < 0) {
2950
+                if (bedlevel.storage_slot < 0) {
2953 2951
                   Popup_Handler(MeshSlot);
2954 2952
                   break;
2955 2953
                 }
@@ -2967,16 +2965,16 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
2967 2965
           case LEVELING_SLOT:
2968 2966
             if (draw) {
2969 2967
               Draw_Menu_Item(row, ICON_PrintSize, F("Mesh Slot"));
2970
-              Draw_Float(ubl.storage_slot, row, false, 1);
2968
+              Draw_Float(bedlevel.storage_slot, row, false, 1);
2971 2969
             }
2972 2970
             else
2973
-              Modify_Value(ubl.storage_slot, 0, settings.calc_num_meshes() - 1, 1);
2971
+              Modify_Value(bedlevel.storage_slot, 0, settings.calc_num_meshes() - 1, 1);
2974 2972
             break;
2975 2973
           case LEVELING_LOAD:
2976 2974
             if (draw)
2977 2975
               Draw_Menu_Item(row, ICON_ReadEEPROM, F("Load Mesh"));
2978 2976
             else {
2979
-              if (ubl.storage_slot < 0) {
2977
+              if (bedlevel.storage_slot < 0) {
2980 2978
                 Popup_Handler(MeshSlot);
2981 2979
                 break;
2982 2980
               }
@@ -2989,7 +2987,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
2989 2987
             if (draw)
2990 2988
               Draw_Menu_Item(row, ICON_WriteEEPROM, F("Save Mesh"));
2991 2989
             else {
2992
-              if (ubl.storage_slot < 0) {
2990
+              if (bedlevel.storage_slot < 0) {
2993 2991
                 Popup_Handler(MeshSlot);
2994 2992
                 break;
2995 2993
               }
@@ -3098,13 +3096,13 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3098 3096
               if (draw)
3099 3097
                 Draw_Menu_Item(row, ICON_Mesh, F("Zero Current Mesh"));
3100 3098
               else
3101
-                ZERO(Z_VALUES_ARR);
3099
+                ZERO(bedlevel.z_values);
3102 3100
               break;
3103 3101
             case LEVELING_SETTINGS_UNDEF:
3104 3102
               if (draw)
3105 3103
                 Draw_Menu_Item(row, ICON_Mesh, F("Clear Current Mesh"));
3106 3104
               else
3107
-                ubl.invalidate();
3105
+                bedlevel.invalidate();
3108 3106
               break;
3109 3107
           #endif // AUTO_BED_LEVELING_UBL
3110 3108
         }
@@ -3146,7 +3144,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3146 3144
               Draw_Menu_Item(row, ICON_Back, F("Back"));
3147 3145
             else {
3148 3146
               set_bed_leveling_enabled(level_state);
3149
-              TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
3147
+              TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
3150 3148
               Draw_Menu(Leveling, LEVELING_MANUAL);
3151 3149
             }
3152 3150
             break;
@@ -3184,36 +3182,36 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3184 3182
           case LEVELING_M_OFFSET:
3185 3183
             if (draw) {
3186 3184
               Draw_Menu_Item(row, ICON_SetZOffset, F("Point Z Offset"));
3187
-              Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
3185
+              Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
3188 3186
             }
3189 3187
             else {
3190
-              if (isnan(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y]))
3191
-                Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
3192
-              Modify_Value(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
3188
+              if (isnan(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y]))
3189
+                bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
3190
+              Modify_Value(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
3193 3191
             }
3194 3192
             break;
3195 3193
           case LEVELING_M_UP:
3196 3194
             if (draw)
3197 3195
               Draw_Menu_Item(row, ICON_Axis, F("Microstep Up"));
3198
-            else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
3199
-              Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
3196
+            else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
3197
+              bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
3200 3198
               gcode.process_subcommands_now(F("M290 Z0.01"));
3201 3199
               planner.synchronize();
3202 3200
               current_position.z += 0.01f;
3203 3201
               sync_plan_position();
3204
-              Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
3202
+              Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
3205 3203
             }
3206 3204
             break;
3207 3205
           case LEVELING_M_DOWN:
3208 3206
             if (draw)
3209 3207
               Draw_Menu_Item(row, ICON_AxisD, F("Microstep Down"));
3210
-            else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
3211
-              Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
3208
+            else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
3209
+              bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
3212 3210
               gcode.process_subcommands_now(F("M290 Z-0.01"));
3213 3211
               planner.synchronize();
3214 3212
               current_position.z -= 0.01f;
3215 3213
               sync_plan_position();
3216
-              Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
3214
+              Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
3217 3215
             }
3218 3216
             break;
3219 3217
           case LEVELING_M_GOTO_VALUE:
@@ -3305,36 +3303,36 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3305 3303
           case UBL_M_OFFSET:
3306 3304
             if (draw) {
3307 3305
               Draw_Menu_Item(row, ICON_SetZOffset, F("Point Z Offset"));
3308
-              Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
3306
+              Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
3309 3307
             }
3310 3308
             else {
3311
-              if (isnan(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y]))
3312
-                Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
3313
-              Modify_Value(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
3309
+              if (isnan(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y]))
3310
+                bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
3311
+              Modify_Value(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
3314 3312
             }
3315 3313
             break;
3316 3314
           case UBL_M_UP:
3317 3315
             if (draw)
3318 3316
               Draw_Menu_Item(row, ICON_Axis, F("Microstep Up"));
3319
-            else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
3320
-              Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
3317
+            else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
3318
+              bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
3321 3319
               gcode.process_subcommands_now(F("M290 Z0.01"));
3322 3320
               planner.synchronize();
3323 3321
               current_position.z += 0.01f;
3324 3322
               sync_plan_position();
3325
-              Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
3323
+              Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
3326 3324
             }
3327 3325
             break;
3328 3326
           case UBL_M_DOWN:
3329 3327
             if (draw)
3330 3328
               Draw_Menu_Item(row, ICON_Axis, F("Microstep Down"));
3331
-            else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
3332
-              Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
3329
+            else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
3330
+              bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
3333 3331
               gcode.process_subcommands_now(F("M290 Z-0.01"));
3334 3332
               planner.synchronize();
3335 3333
               current_position.z -= 0.01f;
3336 3334
               sync_plan_position();
3337
-              Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
3335
+              Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
3338 3336
             }
3339 3337
             break;
3340 3338
         }
@@ -3418,13 +3416,13 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3418 3416
           case MMESH_OLD:
3419 3417
             uint8_t mesh_x, mesh_y;
3420 3418
             // 0,0 -> 1,0 -> 2,0 -> 2,1 -> 1,1 -> 0,1 -> 0,2 -> 1,2 -> 2,2
3421
-            mesh_y = (gridpoint - 1) / GRID_MAX_POINTS_Y;
3422
-            mesh_x = (gridpoint - 1) % GRID_MAX_POINTS_X;
3419
+            mesh_y = (gridpoint - 1) / (GRID_MAX_POINTS_Y);
3420
+            mesh_x = (gridpoint - 1) % (GRID_MAX_POINTS_X);
3423 3421
 
3424 3422
             if (mesh_y % 2 == 1)
3425
-              mesh_x = GRID_MAX_POINTS_X - mesh_x - 1;
3423
+              mesh_x = (GRID_MAX_POINTS_X) - mesh_x - 1;
3426 3424
 
3427
-            const float currval = Z_VALUES_ARR[mesh_x][mesh_y];
3425
+            const float currval = bedlevel.z_values[mesh_x][mesh_y];
3428 3426
 
3429 3427
             if (draw) {
3430 3428
               Draw_Menu_Item(row, ICON_Zoffset, F("Goto Mesh Value"));
@@ -4283,7 +4281,7 @@ void CrealityDWINClass::Popup_Control() {
4283 4281
 
4284 4282
       #if ENABLED(AUTO_BED_LEVELING_UBL)
4285 4283
         case MeshSlot:
4286
-          if (selection == 0) ubl.storage_slot = 0;
4284
+          if (selection == 0) bedlevel.storage_slot = 0;
4287 4285
           Redraw_Menu(true, true);
4288 4286
           break;
4289 4287
       #endif

+ 5
- 5
Marlin/src/lcd/e3v2/marlinui/ui_common.cpp Переглянути файл

@@ -516,8 +516,8 @@ void MarlinUI::draw_status_message(const bool blink) {
516 516
       // Display Mesh Point Locations
517 517
       const dwin_coord_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
518 518
             dwin_coord_t  y = y_offset + pixels_per_y_mesh_pnt / 2;
519
-      for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
520
-        for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
519
+      for (uint8_t j = 0; j < (GRID_MAX_POINTS_Y); j++, y += pixels_per_y_mesh_pnt)
520
+        for (uint8_t i = 0, x = sx; i < (GRID_MAX_POINTS_X); i++, x += pixels_per_x_mesh_pnt)
521 521
           DWIN_Draw_Point(Color_White, 1, 1, x, y);
522 522
 
523 523
       // Put Relevant Text on Display
@@ -525,7 +525,7 @@ void MarlinUI::draw_status_message(const bool blink) {
525 525
       // Show X and Y positions at top of screen
526 526
       dwin_font.fg = Color_White;
527 527
       dwin_font.solid = true;
528
-      const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
528
+      const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
529 529
                      lpos = pos.asLogical();
530 530
 
531 531
       lcd_moveto(
@@ -555,8 +555,8 @@ void MarlinUI::draw_status_message(const bool blink) {
555 555
 
556 556
       // Show the location value
557 557
       dwin_string.set(Z_LBL);
558
-      if (!isnan(Z_VALUES_ARR[x_plot][y_plot]))
559
-        dwin_string.add(ftostr43sign(Z_VALUES_ARR[x_plot][y_plot]));
558
+      if (!isnan(bedlevel.z_values[x_plot][y_plot]))
559
+        dwin_string.add(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
560 560
       else
561 561
         dwin_string.add(PSTR(" -----"));
562 562
       lcd_moveto(

+ 16
- 16
Marlin/src/lcd/e3v2/proui/dwin.cpp Переглянути файл

@@ -3611,7 +3611,7 @@ void Draw_Steps_Menu() {
3611 3611
   #define Z_OFFSET_MIN -3
3612 3612
   #define Z_OFFSET_MAX  3
3613 3613
 
3614
-  void LiveEditMesh() { ((MenuItemPtrClass*)EditZValueItem)->value = &Z_VALUES_ARR[HMI_value.Select ? mesh_x : MenuData.Value][HMI_value.Select ? MenuData.Value : mesh_y]; EditZValueItem->redraw(); }
3614
+  void LiveEditMesh() { ((MenuItemPtrClass*)EditZValueItem)->value = &bedlevel.z_values[HMI_value.Select ? mesh_x : MenuData.Value][HMI_value.Select ? MenuData.Value : mesh_y]; EditZValueItem->redraw(); }
3615 3615
   void ApplyEditMeshX() { mesh_x = MenuData.Value; }
3616 3616
   void SetEditMeshX() { HMI_value.Select = 0; SetIntOnClick(0, GRID_MAX_POINTS_X - 1, mesh_x, ApplyEditMeshX, LiveEditMesh); }
3617 3617
   void ApplyEditMeshY() { mesh_y = MenuData.Value; }
@@ -3622,18 +3622,18 @@ void Draw_Steps_Menu() {
3622 3622
 
3623 3623
 #if ENABLED(AUTO_BED_LEVELING_UBL)
3624 3624
 
3625
-  void ApplyUBLSlot() { ubl.storage_slot = MenuData.Value; }
3626
-  void SetUBLSlot() { SetIntOnClick(0, settings.calc_num_meshes() - 1, ubl.storage_slot, ApplyUBLSlot); }
3625
+  void ApplyUBLSlot() { bedlevel.storage_slot = MenuData.Value; }
3626
+  void SetUBLSlot() { SetIntOnClick(0, settings.calc_num_meshes() - 1, bedlevel.storage_slot, ApplyUBLSlot); }
3627 3627
   void onDrawUBLSlot(MenuItemClass* menuitem, int8_t line) {
3628
-    if (ubl.storage_slot < 0) ubl.storage_slot = 0;
3629
-    onDrawIntMenu(menuitem, line, ubl.storage_slot);
3628
+    if (bedlevel.storage_slot < 0) bedlevel.storage_slot = 0;
3629
+    onDrawIntMenu(menuitem, line, bedlevel.storage_slot);
3630 3630
   }
3631 3631
 
3632 3632
   void ApplyUBLTiltGrid() { ubl_tools.tilt_grid = MenuData.Value; }
3633 3633
   void SetUBLTiltGrid() { SetIntOnClick(1, 3, ubl_tools.tilt_grid, ApplyUBLTiltGrid); }
3634 3634
 
3635 3635
   void UBLTiltMesh() {
3636
-    if (ubl.storage_slot < 0) ubl.storage_slot = 0;
3636
+    if (bedlevel.storage_slot < 0) bedlevel.storage_slot = 0;
3637 3637
     char buf[15];
3638 3638
     if (ubl_tools.tilt_grid > 1) {
3639 3639
       sprintf_P(buf, PSTR("G28O\nG29 J%i"), ubl_tools.tilt_grid);
@@ -3645,28 +3645,28 @@ void Draw_Steps_Menu() {
3645 3645
   }
3646 3646
 
3647 3647
   void UBLSmartFillMesh() {
3648
-    ubl.smart_fill_mesh();
3648
+    bedlevel.smart_fill_mesh();
3649 3649
     LCD_MESSAGE(MSG_UBL_MESH_FILLED);
3650 3650
   }
3651 3651
 
3652 3652
   bool UBLValidMesh() {
3653 3653
     const bool valid = ubl_tools.validate();
3654
-    if (!valid) ubl.invalidate();
3654
+    if (!valid) bedlevel.invalidate();
3655 3655
     return valid;
3656 3656
   }
3657 3657
 
3658 3658
   void UBLSaveMesh() {
3659
-    if (ubl.storage_slot < 0) ubl.storage_slot = 0;
3660
-    settings.store_mesh(ubl.storage_slot);
3661
-    ui.status_printf(0, GET_TEXT_F(MSG_MESH_SAVED), ubl.storage_slot);
3659
+    if (bedlevel.storage_slot < 0) bedlevel.storage_slot = 0;
3660
+    settings.store_mesh(bedlevel.storage_slot);
3661
+    ui.status_printf(0, GET_TEXT_F(MSG_MESH_SAVED), bedlevel.storage_slot);
3662 3662
     DONE_BUZZ(true);
3663 3663
   }
3664 3664
 
3665 3665
   void UBLLoadMesh() {
3666
-    if (ubl.storage_slot < 0) ubl.storage_slot = 0;
3667
-    settings.load_mesh(ubl.storage_slot);
3666
+    if (bedlevel.storage_slot < 0) bedlevel.storage_slot = 0;
3667
+    settings.load_mesh(bedlevel.storage_slot);
3668 3668
     if (UBLValidMesh()) {
3669
-      ui.status_printf(0, GET_TEXT_F(MSG_MESH_LOADED), ubl.storage_slot);
3669
+      ui.status_printf(0, GET_TEXT_F(MSG_MESH_LOADED), bedlevel.storage_slot);
3670 3670
       DONE_BUZZ(true);
3671 3671
     }
3672 3672
     else {
@@ -3691,7 +3691,7 @@ void Draw_Steps_Menu() {
3691 3691
         MENU_ITEM_F(ICON_Level, MSG_AUTO_MESH, onDrawMenuItem, AutoLev);
3692 3692
       #endif
3693 3693
       #if ENABLED(AUTO_BED_LEVELING_UBL)
3694
-        EDIT_ITEM_F(ICON_UBLActive, MSG_UBL_STORAGE_SLOT, onDrawUBLSlot, SetUBLSlot, &ubl.storage_slot);
3694
+        EDIT_ITEM_F(ICON_UBLActive, MSG_UBL_STORAGE_SLOT, onDrawUBLSlot, SetUBLSlot, &bedlevel.storage_slot);
3695 3695
         MENU_ITEM_F(ICON_UBLActive, MSG_UBL_SAVE_MESH, onDrawMenuItem, UBLSaveMesh);
3696 3696
         MENU_ITEM_F(ICON_UBLActive, MSG_UBL_LOAD_MESH, onDrawMenuItem, UBLLoadMesh);
3697 3697
         EDIT_ITEM_F(ICON_UBLActive, MSG_UBL_TILTING_GRID, onDrawPInt8Menu, SetUBLTiltGrid, &ubl_tools.tilt_grid);
@@ -3714,7 +3714,7 @@ void Draw_Steps_Menu() {
3714 3714
         BACK_ITEM(Draw_MeshSet_Menu);
3715 3715
         EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_X, onDrawPInt8Menu, SetEditMeshX, &mesh_x);
3716 3716
         EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_Y, onDrawPInt8Menu, SetEditMeshY, &mesh_y);
3717
-        EditZValueItem = EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_EDIT_Z, onDrawPFloat3Menu, SetEditZValue, &Z_VALUES_ARR[mesh_x][mesh_y]);
3717
+        EditZValueItem = EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_EDIT_Z, onDrawPFloat3Menu, SetEditZValue, &bedlevel.z_values[mesh_x][mesh_y]);
3718 3718
       }
3719 3719
       UpdateMenu(EditMeshMenu);
3720 3720
     }

+ 1
- 1
Marlin/src/lcd/e3v2/proui/meshviewer.cpp Переглянути файл

@@ -117,7 +117,7 @@ void MeshViewerClass::Draw(bool withsave /*= false*/) {
117 117
     ubl_tools.viewer_print_value = true;
118 118
     ubl_tools.Draw_Bed_Mesh(-1, 1, 8, 10 + TITLE_HEIGHT);
119 119
   #else
120
-    DrawMesh(Z_VALUES_ARR, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y);
120
+    DrawMesh(bedlevel.z_values, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y);
121 121
   #endif
122 122
   if (withsave) {
123 123
     DWINUI::Draw_Button(BTN_Save, 26, 305);

+ 31
- 34
Marlin/src/lcd/e3v2/proui/ubl_tools.cpp Переглянути файл

@@ -63,11 +63,9 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
63 63
     struct linear_fit_data lsf_results;
64 64
     incremental_LSF_reset(&lsf_results);
65 65
     GRID_LOOP(x, y) {
66
-      if (!isnan(Z_VALUES_ARR[x][y])) {
67
-        xy_pos_t rpos;
68
-        rpos.x = ubl.mesh_index_to_xpos(x);
69
-        rpos.y = ubl.mesh_index_to_ypos(y);
70
-        incremental_LSF(&lsf_results, rpos, Z_VALUES_ARR[x][y]);
66
+      if (!isnan(bedlevel.z_values[x][y])) {
67
+        xy_pos_t rpos = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
68
+        incremental_LSF(&lsf_results, rpos, bedlevel.z_values[x][y]);
71 69
       }
72 70
     }
73 71
 
@@ -76,13 +74,13 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
76 74
       return true;
77 75
     }
78 76
 
79
-    ubl.set_all_mesh_points_to_value(0);
77
+    bedlevel.set_all_mesh_points_to_value(0);
80 78
 
81 79
     matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
82 80
     GRID_LOOP(i, j) {
83
-      float mx = ubl.mesh_index_to_xpos(i),
84
-            my = ubl.mesh_index_to_ypos(j),
85
-            mz = Z_VALUES_ARR[i][j];
81
+      float mx = bedlevel.get_mesh_x(i),
82
+            my = bedlevel.get_mesh_y(j),
83
+            mz = bedlevel.z_values[i][j];
86 84
 
87 85
       if (DEBUGGING(LEVELING)) {
88 86
         DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
@@ -106,7 +104,7 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
106 104
         DEBUG_DELAY(20);
107 105
       }
108 106
 
109
-      Z_VALUES_ARR[i][j] = mz - lsf_results.D;
107
+      bedlevel.z_values[i][j] = mz - lsf_results.D;
110 108
     }
111 109
     return false;
112 110
   }
@@ -124,7 +122,7 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
124 122
 void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/*=false*/) {
125 123
   if (zmove) {
126 124
     planner.synchronize();
127
-    current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
125
+    current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
128 126
     planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
129 127
     planner.synchronize();
130 128
   }
@@ -136,7 +134,7 @@ void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y,
136 134
     sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
137 135
     gcode.process_subcommands_now(cmd);
138 136
     planner.synchronize();
139
-    current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
137
+    current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
140 138
     planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
141 139
     planner.synchronize();
142 140
     HMI_ReturnScreen();
@@ -146,8 +144,8 @@ void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y,
146 144
 float UBLMeshToolsClass::get_max_value() {
147 145
   float max = __FLT_MIN__;
148 146
   GRID_LOOP(x, y) {
149
-    if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] > max)
150
-      max = Z_VALUES_ARR[x][y];
147
+    if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
148
+      max = bedlevel.z_values[x][y];
151 149
   }
152 150
   return max;
153 151
 }
@@ -155,20 +153,19 @@ float UBLMeshToolsClass::get_max_value() {
155 153
 float UBLMeshToolsClass::get_min_value() {
156 154
   float min = __FLT_MAX__;
157 155
   GRID_LOOP(x, y) {
158
-    if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] < min)
159
-      min = Z_VALUES_ARR[x][y];
156
+    if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
157
+      min = bedlevel.z_values[x][y];
160 158
   }
161 159
   return min;
162 160
 }
163 161
 
164 162
 bool UBLMeshToolsClass::validate() {
165
-  float min = __FLT_MAX__;
166
-  float max = __FLT_MIN__;
163
+  float min = __FLT_MAX__, max = __FLT_MIN__;
167 164
 
168 165
   GRID_LOOP(x, y) {
169
-    if (isnan(Z_VALUES_ARR[x][y])) return false;
170
-    if (Z_VALUES_ARR[x][y] < min) min = Z_VALUES_ARR[x][y];
171
-    if (Z_VALUES_ARR[x][y] > max) max = Z_VALUES_ARR[x][y];
166
+    if (isnan(bedlevel.z_values[x][y])) return false;
167
+    if (bedlevel.z_values[x][y] < min) min = bedlevel.z_values[x][y];
168
+    if (bedlevel.z_values[x][y] > max) max = bedlevel.z_values[x][y];
172 169
   }
173 170
   return max <= UBL_Z_OFFSET_MAX && min >= UBL_Z_OFFSET_MIN;
174 171
 }
@@ -177,15 +174,15 @@ bool UBLMeshToolsClass::validate() {
177 174
   void UBLMeshToolsClass::Draw_Bed_Mesh(int16_t selected /*= -1*/, uint8_t gridline_width /*= 1*/, uint16_t padding_x /*= 8*/, uint16_t padding_y_top /*= 40 + 53 - 7*/) {
178 175
     drawing_mesh = true;
179 176
     const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
180
-    const uint16_t cell_width_px  = total_width_px / GRID_MAX_POINTS_X;
181
-    const uint16_t cell_height_px = total_width_px / GRID_MAX_POINTS_Y;
177
+    const uint16_t cell_width_px  = total_width_px / (GRID_MAX_POINTS_X);
178
+    const uint16_t cell_height_px = total_width_px / (GRID_MAX_POINTS_Y);
182 179
     const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
183 180
 
184 181
     // Clear background from previous selection and select new square
185 182
     DWIN_Draw_Rectangle(1, Color_Bg_Black, _MAX(0, padding_x - gridline_width), _MAX(0, padding_y_top - gridline_width), padding_x + total_width_px, padding_y_top + total_width_px);
186 183
     if (selected >= 0) {
187
-      const auto selected_y = selected / GRID_MAX_POINTS_X;
188
-      const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y);
184
+      const auto selected_y = selected / (GRID_MAX_POINTS_X);
185
+      const auto selected_x = selected - (GRID_MAX_POINTS_X) * selected_y;
189 186
       const auto start_y_px = padding_y_top + selected_y * cell_height_px;
190 187
       const auto start_x_px = padding_x + selected_x * cell_width_px;
191 188
       DWIN_Draw_Rectangle(1, Color_White, _MAX(0, start_x_px - gridline_width), _MAX(0, start_y_px - gridline_width), start_x_px + cell_width_px, start_y_px + cell_height_px);
@@ -196,14 +193,14 @@ bool UBLMeshToolsClass::validate() {
196 193
     GRID_LOOP(x, y) {
197 194
       const auto start_x_px = padding_x + x * cell_width_px;
198 195
       const auto end_x_px   = start_x_px + cell_width_px - 1 - gridline_width;
199
-      const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
196
+      const auto start_y_px = padding_y_top + ((GRID_MAX_POINTS_Y) - y - 1) * cell_height_px;
200 197
       const auto end_y_px   = start_y_px + cell_height_px - 1 - gridline_width;
201 198
       DWIN_Draw_Rectangle(1,                                                                                 // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
202
-        isnan(Z_VALUES_ARR[x][y]) ? Color_Grey : (                                                           // gray if undefined
203
-          (Z_VALUES_ARR[x][y] < 0 ?
204
-            (uint16_t)round(0x1F * -Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
205
-            (uint16_t)round(0x3F *  Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
206
-              _MIN(0x1F, (((uint8_t)abs(Z_VALUES_ARR[x][y]) / 10) * 4))),                                    // + blue stepping for every mm
199
+        isnan(bedlevel.z_values[x][y]) ? Color_Grey : (                                                           // gray if undefined
200
+          (bedlevel.z_values[x][y] < 0 ?
201
+            (uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
202
+            (uint16_t)round(0x3F *  bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
203
+              _MIN(0x1F, (((uint8_t)abs(bedlevel.z_values[x][y]) / 10) * 4))),                                    // + blue stepping for every mm
207 204
         start_x_px, start_y_px, end_x_px, end_y_px
208 205
       );
209 206
 
@@ -213,14 +210,14 @@ bool UBLMeshToolsClass::validate() {
213 210
       // Draw value text on
214 211
       if (viewer_print_value) {
215 212
         int8_t offset_x, offset_y = cell_height_px / 2 - 6;
216
-        if (isnan(Z_VALUES_ARR[x][y])) {  // undefined
213
+        if (isnan(bedlevel.z_values[x][y])) {  // undefined
217 214
           DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px + cell_width_px / 2 - 5, start_y_px + offset_y, F("X"));
218 215
         }
219 216
         else {                          // has value
220 217
           if (GRID_MAX_POINTS_X < 10)
221
-            sprintf_P(buf, PSTR("%s"), dtostrf(abs(Z_VALUES_ARR[x][y]), 1, 2, str_1));
218
+            sprintf_P(buf, PSTR("%s"), dtostrf(abs(bedlevel.z_values[x][y]), 1, 2, str_1));
222 219
           else
223
-            sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(Z_VALUES_ARR[x][y] - (int16_t)Z_VALUES_ARR[x][y]) * 100));
220
+            sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(bedlevel.z_values[x][y] - (int16_t)bedlevel.z_values[x][y]) * 100));
224 221
           offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
225 222
           if (!(GRID_MAX_POINTS_X < 10))
226 223
             DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px - 2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F("."));

+ 2
- 2
Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp Переглянути файл

@@ -341,8 +341,8 @@ void DGUSTxHandler::ABLGrid(DGUS_VP &vp) {
341 341
   int16_t fixed;
342 342
 
343 343
   for (int i = 0; i < DGUS_LEVEL_GRID_SIZE; i++) {
344
-    point.x = i % GRID_MAX_POINTS_X;
345
-    point.y = i / GRID_MAX_POINTS_X;
344
+    point.x = i % (GRID_MAX_POINTS_X);
345
+    point.y = i / (GRID_MAX_POINTS_X);
346 346
     fixed = dgus_display.ToFixedPoint<float, int16_t, 3>(ExtUI::getMeshPoint(point));
347 347
     data[i] = Swap16(fixed);
348 348
   }

+ 3
- 3
Marlin/src/lcd/extui/ui_api.cpp Переглянути файл

@@ -919,11 +919,11 @@ namespace ExtUI {
919 919
 
920 920
     #if HAS_MESH
921 921
 
922
-      bed_mesh_t& getMeshArray() { return Z_VALUES_ARR; }
923
-      float getMeshPoint(const xy_uint8_t &pos) { return Z_VALUES(pos.x, pos.y); }
922
+      bed_mesh_t& getMeshArray() { return bedlevel.z_values; }
923
+      float getMeshPoint(const xy_uint8_t &pos) { return bedlevel.z_values[pos.x][pos.y]; }
924 924
       void setMeshPoint(const xy_uint8_t &pos, const_float_t zoff) {
925 925
         if (WITHIN(pos.x, 0, (GRID_MAX_POINTS_X) - 1) && WITHIN(pos.y, 0, (GRID_MAX_POINTS_Y) - 1)) {
926
-          Z_VALUES(pos.x, pos.y) = zoff;
926
+          bedlevel.z_values[pos.x][pos.y] = zoff;
927 927
           TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
928 928
         }
929 929
       }

+ 1
- 1
Marlin/src/lcd/marlinui.cpp Переглянути файл

@@ -863,7 +863,7 @@ void MarlinUI::init() {
863 863
 
864 864
       void MarlinUI::external_encoder() {
865 865
         if (external_control && encoderDiff) {
866
-          ubl.encoder_diff += encoderDiff;  // Encoder for UBL G29 mesh editing
866
+          bedlevel.encoder_diff += encoderDiff;  // Encoder for UBL G29 mesh editing
867 867
           encoderDiff = 0;                  // Hide encoder events from the screen handler
868 868
           refresh(LCDVIEW_REDRAW_NOW);      // ...but keep the refresh.
869 869
         }

+ 2
- 2
Marlin/src/lcd/menu/menu.cpp Переглянути файл

@@ -203,14 +203,14 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
203 203
     if (on_status_screen()) {
204 204
       defer_status_screen(false);
205 205
       clear_menu_history();
206
-      TERN_(AUTO_BED_LEVELING_UBL, ubl.lcd_map_control = false);
206
+      TERN_(AUTO_BED_LEVELING_UBL, bedlevel.lcd_map_control = false);
207 207
     }
208 208
 
209 209
     clear_lcd();
210 210
 
211 211
     // Re-initialize custom characters that may be re-used
212 212
     #if HAS_MARLINUI_HD44780
213
-      if (TERN1(AUTO_BED_LEVELING_UBL, !ubl.lcd_map_control))
213
+      if (TERN1(AUTO_BED_LEVELING_UBL, !bedlevel.lcd_map_control))
214 214
         set_custom_characters(on_status_screen() ? CHARSET_INFO : CHARSET_MENU);
215 215
     #endif
216 216
 

+ 2
- 2
Marlin/src/lcd/menu/menu_bed_leveling.cpp Переглянути файл

@@ -214,7 +214,7 @@
214 214
     BACK_ITEM(MSG_BED_LEVELING);
215 215
     EDIT_ITEM(uint8, MSG_MESH_X, &xind, 0, (GRID_MAX_POINTS_X) - 1);
216 216
     EDIT_ITEM(uint8, MSG_MESH_Y, &yind, 0, (GRID_MAX_POINTS_Y) - 1);
217
-    EDIT_ITEM_FAST(float43, MSG_MESH_EDIT_Z, &Z_VALUES(xind, yind), -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5, refresh_planner);
217
+    EDIT_ITEM_FAST(float43, MSG_MESH_EDIT_Z, &bedlevel.z_values[xind][yind], -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5, refresh_planner);
218 218
     END_MENU();
219 219
   }
220 220
 
@@ -281,7 +281,7 @@ void menu_bed_leveling() {
281 281
     #else
282 282
       #define LCD_Z_OFFSET_TYPE float42_52 // Values from -99.99 to 99.99
283 283
     #endif
284
-    EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_BED_Z, &mbl.z_offset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
284
+    EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_BED_Z, &bedlevel.z_offset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
285 285
   #endif
286 286
 
287 287
   #if ENABLED(BABYSTEP_ZPROBE_OFFSET)

+ 1
- 1
Marlin/src/lcd/menu/menu_tune.cpp Переглянути файл

@@ -118,7 +118,7 @@ void menu_tune() {
118 118
   // Manual bed leveling, Bed Z:
119 119
   //
120 120
   #if BOTH(MESH_BED_LEVELING, LCD_BED_LEVELING)
121
-    EDIT_ITEM(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
121
+    EDIT_ITEM(float43, MSG_BED_Z, &bedlevel.z_offset, -1, 1);
122 122
   #endif
123 123
 
124 124
   //

+ 13
- 13
Marlin/src/lcd/menu/menu_ubl.cpp Переглянути файл

@@ -58,7 +58,7 @@ inline float rounded_mesh_value() {
58 58
 
59 59
 /**
60 60
  * This screen displays the temporary mesh value and updates it based on encoder
61
- * movement. While this screen is active ubl.fine_tune_mesh sits in a loop getting
61
+ * movement. While this screen is active bedlevel.fine_tune_mesh sits in a loop getting
62 62
  * the current value via ubl_mesh_value, moves the Z axis, and updates the mesh
63 63
  * value until the encoder button is pressed.
64 64
  *
@@ -70,12 +70,12 @@ inline float rounded_mesh_value() {
70 70
 void _lcd_mesh_fine_tune(PGM_P const msg) {
71 71
   constexpr float mesh_edit_step = 1.0f / 200.0f;
72 72
   ui.defer_status_screen();
73
-  if (ubl.encoder_diff) {
73
+  if (bedlevel.encoder_diff) {
74 74
     mesh_edit_accumulator += TERN(IS_TFTGLCD_PANEL,
75
-      ubl.encoder_diff * mesh_edit_step / ENCODER_PULSES_PER_STEP,
76
-      ubl.encoder_diff > 0 ? mesh_edit_step : -mesh_edit_step
75
+      bedlevel.encoder_diff * mesh_edit_step / ENCODER_PULSES_PER_STEP,
76
+      bedlevel.encoder_diff > 0 ? mesh_edit_step : -mesh_edit_step
77 77
     );
78
-    ubl.encoder_diff = 0;
78
+    bedlevel.encoder_diff = 0;
79 79
     IF_DISABLED(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
80 80
   }
81 81
   TERN_(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
@@ -89,7 +89,7 @@ void _lcd_mesh_fine_tune(PGM_P const msg) {
89 89
 }
90 90
 
91 91
 //
92
-// Init mesh editing and go to the fine tuning screen (ubl.fine_tune_mesh)
92
+// Init mesh editing and go to the fine tuning screen (bedlevel.fine_tune_mesh)
93 93
 // To capture encoder events UBL will also call ui.capture and ui.release.
94 94
 //
95 95
 void MarlinUI::ubl_mesh_edit_start(const_float_t initial) {
@@ -99,7 +99,7 @@ void MarlinUI::ubl_mesh_edit_start(const_float_t initial) {
99 99
 }
100 100
 
101 101
 //
102
-// Get the mesh value within a Z adjustment loop (ubl.fine_tune_mesh)
102
+// Get the mesh value within a Z adjustment loop (bedlevel.fine_tune_mesh)
103 103
 //
104 104
 float MarlinUI::ubl_mesh_value() { return rounded_mesh_value(); }
105 105
 
@@ -291,7 +291,7 @@ void _menu_ubl_fillin() {
291 291
 }
292 292
 
293 293
 void _lcd_ubl_invalidate() {
294
-  ubl.invalidate();
294
+  bedlevel.invalidate();
295 295
   SERIAL_ECHOLNPGM("Mesh invalidated.");
296 296
 }
297 297
 
@@ -390,8 +390,8 @@ void _lcd_ubl_storage_mesh() {
390 390
  */
391 391
 void _lcd_ubl_map_edit_cmd() {
392 392
   char ubl_lcd_gcode[50], str[10], str2[10];
393
-  dtostrf(ubl.mesh_index_to_xpos(x_plot), 0, 2, str);
394
-  dtostrf(ubl.mesh_index_to_ypos(y_plot), 0, 2, str2);
393
+  dtostrf(bedlevel.get_mesh_x(x_plot), 0, 2, str);
394
+  dtostrf(bedlevel.get_mesh_y(y_plot), 0, 2, str2);
395 395
   snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29P4X%sY%sR%i"), str, str2, int(n_edit_pts));
396 396
   queue.inject(ubl_lcd_gcode);
397 397
 }
@@ -400,7 +400,7 @@ void _lcd_ubl_map_edit_cmd() {
400 400
  * UBL LCD Map Movement
401 401
  */
402 402
 void ubl_map_move_to_xy() {
403
-  const xy_pos_t xy = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) };
403
+  const xy_pos_t xy = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) };
404 404
 
405 405
   // Some printers have unreachable areas in the mesh. Skip the move if unreachable.
406 406
   if (!position_is_reachable(xy)) return;
@@ -459,7 +459,7 @@ void ubl_map_screen() {
459 459
 
460 460
       // Validate if needed
461 461
       #if IS_KINEMATIC
462
-        const xy_pos_t xy = { ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) };
462
+        const xy_pos_t xy = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
463 463
         if (position_is_reachable(xy)) break; // Found a valid point
464 464
         ui.encoderPosition += step_dir;       // Test the next point
465 465
       #endif
@@ -500,7 +500,7 @@ void _ubl_map_screen_homing() {
500 500
   ui.defer_status_screen();
501 501
   _lcd_draw_homing();
502 502
   if (all_axes_homed()) {
503
-    ubl.lcd_map_control = true;     // Return to the map screen after editing Z
503
+    bedlevel.lcd_map_control = true;     // Return to the map screen after editing Z
504 504
     ui.goto_screen(ubl_map_screen, grid_index(x_plot, y_plot)); // Pre-set the encoder value
505 505
     ui.manual_move.menu_scale = 0;  // Immediate move
506 506
     ubl_map_move_to_xy();           // Move to current mesh point

+ 2
- 2
Marlin/src/lcd/tft/touch.cpp Переглянути файл

@@ -180,8 +180,8 @@ void Touch::touch(touch_control_t *control) {
180 180
       ui.refresh();
181 181
       break;
182 182
     case SLIDER:    hold(control); ui.encoderPosition = (x - control->x) * control->data / control->width; break;
183
-    case INCREASE:  hold(control, repeat_delay - 5); TERN(AUTO_BED_LEVELING_UBL, ui.external_control ? ubl.encoder_diff++ : ui.encoderPosition++, ui.encoderPosition++); break;
184
-    case DECREASE:  hold(control, repeat_delay - 5); TERN(AUTO_BED_LEVELING_UBL, ui.external_control ? ubl.encoder_diff-- : ui.encoderPosition--, ui.encoderPosition--); break;
183
+    case INCREASE:  hold(control, repeat_delay - 5); TERN(AUTO_BED_LEVELING_UBL, ui.external_control ? bedlevel.encoder_diff++ : ui.encoderPosition++, ui.encoderPosition++); break;
184
+    case DECREASE:  hold(control, repeat_delay - 5); TERN(AUTO_BED_LEVELING_UBL, ui.external_control ? bedlevel.encoder_diff-- : ui.encoderPosition--, ui.encoderPosition--); break;
185 185
     case HEATER:
186 186
       int8_t heater;
187 187
       heater = control->data;

+ 7
- 7
Marlin/src/lcd/tft/ui_1024x600.cpp Переглянути файл

@@ -501,14 +501,14 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
501 501
     tft.set_background(COLOR_BACKGROUND);
502 502
     tft.add_rectangle(0, 0, GRID_WIDTH, GRID_HEIGHT, COLOR_WHITE);
503 503
 
504
-    for (uint16_t x = 0; x < GRID_MAX_POINTS_X ; x++)
505
-      for (uint16_t y = 0; y < GRID_MAX_POINTS_Y ; y++)
506
-        if (position_is_reachable({ ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) }))
507
-          tft.add_bar(1 + (x * 2 + 1) * (GRID_WIDTH - 4) / GRID_MAX_POINTS_X / 2, GRID_HEIGHT - 3 - ((y * 2 + 1) * (GRID_HEIGHT - 4) / GRID_MAX_POINTS_Y / 2), 2, 2, COLOR_UBL);
504
+    for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++)
505
+      for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++)
506
+        if (position_is_reachable({ bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) }))
507
+          tft.add_bar(1 + (x * 2 + 1) * (GRID_WIDTH - 4) / (GRID_MAX_POINTS_X) / 2, GRID_HEIGHT - 3 - ((y * 2 + 1) * (GRID_HEIGHT - 4) / (GRID_MAX_POINTS_Y) / 2), 2, 2, COLOR_UBL);
508 508
 
509
-    tft.add_rectangle((x_plot * 2 + 1) * (GRID_WIDTH - 4) / GRID_MAX_POINTS_X / 2 - 1, GRID_HEIGHT - 5 - ((y_plot * 2 + 1) * (GRID_HEIGHT - 4) / GRID_MAX_POINTS_Y / 2), 6, 6, COLOR_UBL);
509
+    tft.add_rectangle((x_plot * 2 + 1) * (GRID_WIDTH - 4) / (GRID_MAX_POINTS_X) / 2 - 1, GRID_HEIGHT - 5 - ((y_plot * 2 + 1) * (GRID_HEIGHT - 4) / (GRID_MAX_POINTS_Y) / 2), 6, 6, COLOR_UBL);
510 510
 
511
-    const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
511
+    const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
512 512
                    lpos = pos.asLogical();
513 513
 
514 514
     tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
@@ -531,7 +531,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
531 531
     tft.set_background(COLOR_BACKGROUND);
532 532
     tft_string.set(Z_LBL);
533 533
     tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
534
-    tft_string.set(isnan(ubl.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(ubl.z_values[x_plot][y_plot]));
534
+    tft_string.set(isnan(bedlevel.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
535 535
     tft_string.trim();
536 536
     tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
537 537
 

+ 3
- 3
Marlin/src/lcd/tft/ui_320x240.cpp Переглянути файл

@@ -485,12 +485,12 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
485 485
 
486 486
     for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++)
487 487
       for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++)
488
-        if (position_is_reachable({ ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) }))
488
+        if (position_is_reachable({ bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) }))
489 489
           tft.add_bar(1 + (x * 2 + 1) * (GRID_WIDTH - 4) / (GRID_MAX_POINTS_X) / 2, GRID_HEIGHT - 3 - ((y * 2 + 1) * (GRID_HEIGHT - 4) / (GRID_MAX_POINTS_Y) / 2), 2, 2, COLOR_UBL);
490 490
 
491 491
     tft.add_rectangle((x_plot * 2 + 1) * (GRID_WIDTH - 4) / (GRID_MAX_POINTS_X) / 2 - 1, GRID_HEIGHT - 5 - ((y_plot * 2 + 1) * (GRID_HEIGHT - 4) / (GRID_MAX_POINTS_Y) / 2), 6, 6, COLOR_UBL);
492 492
 
493
-    const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
493
+    const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
494 494
                    lpos = pos.asLogical();
495 495
 
496 496
     tft.canvas(216, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 96, MENU_ITEM_HEIGHT);
@@ -513,7 +513,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
513 513
     tft.set_background(COLOR_BACKGROUND);
514 514
     tft_string.set(Z_LBL);
515 515
     tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
516
-    tft_string.set(isnan(ubl.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(ubl.z_values[x_plot][y_plot]));
516
+    tft_string.set(isnan(bedlevel.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
517 517
     tft_string.trim();
518 518
     tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
519 519
 

+ 3
- 3
Marlin/src/lcd/tft/ui_480x320.cpp Переглянути файл

@@ -490,12 +490,12 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
490 490
 
491 491
     for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++)
492 492
       for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++)
493
-        if (position_is_reachable({ ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) }))
493
+        if (position_is_reachable({ bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) }))
494 494
           tft.add_bar(1 + (x * 2 + 1) * (GRID_WIDTH - 4) / (GRID_MAX_POINTS_X) / 2, GRID_HEIGHT - 3 - ((y * 2 + 1) * (GRID_HEIGHT - 4) / (GRID_MAX_POINTS_Y) / 2), 2, 2, COLOR_UBL);
495 495
 
496 496
     tft.add_rectangle((x_plot * 2 + 1) * (GRID_WIDTH - 4) / (GRID_MAX_POINTS_X) / 2 - 1, GRID_HEIGHT - 5 - ((y_plot * 2 + 1) * (GRID_HEIGHT - 4) / (GRID_MAX_POINTS_Y) / 2), 6, 6, COLOR_UBL);
497 497
 
498
-    const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
498
+    const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
499 499
                    lpos = pos.asLogical();
500 500
 
501 501
     tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
@@ -518,7 +518,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
518 518
     tft.set_background(COLOR_BACKGROUND);
519 519
     tft_string.set(Z_LBL);
520 520
     tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
521
-    tft_string.set(isnan(ubl.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(ubl.z_values[x_plot][y_plot]));
521
+    tft_string.set(isnan(bedlevel.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
522 522
     tft_string.trim();
523 523
     tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
524 524
 

+ 6
- 6
Marlin/src/module/motion.cpp Переглянути файл

@@ -427,7 +427,7 @@ void line_to_current_position(const_feedRate_t fr_mm_s/*=feedrate_mm_s*/) {
427 427
 
428 428
     #if UBL_SEGMENTED
429 429
       // UBL segmented line will do Z-only moves in single segment
430
-      ubl.line_to_destination_segmented(scaled_fr_mm_s);
430
+      bedlevel.line_to_destination_segmented(scaled_fr_mm_s);
431 431
     #else
432 432
       if (current_position == destination) return;
433 433
 
@@ -995,7 +995,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
995 995
    * small incremental moves for DELTA or SCARA.
996 996
    *
997 997
    * For Unified Bed Leveling (Delta or Segmented Cartesian)
998
-   * the ubl.line_to_destination_segmented method replaces this.
998
+   * the bedlevel.line_to_destination_segmented method replaces this.
999 999
    *
1000 1000
    * For Auto Bed Leveling (Bilinear) with SEGMENT_LEVELED_MOVES
1001 1001
    * this is replaced by segmented_line_to_destination below.
@@ -1151,7 +1151,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
1151 1151
     #if HAS_MESH
1152 1152
       if (planner.leveling_active && planner.leveling_active_at_z(destination.z)) {
1153 1153
         #if ENABLED(AUTO_BED_LEVELING_UBL)
1154
-          ubl.line_to_destination_cartesian(scaled_fr_mm_s, active_extruder); // UBL's motion routine needs to know about
1154
+          bedlevel.line_to_destination_cartesian(scaled_fr_mm_s, active_extruder); // UBL's motion routine needs to know about
1155 1155
           return true;                                                        // all moves, including Z-only moves.
1156 1156
         #elif ENABLED(SEGMENT_LEVELED_MOVES)
1157 1157
           segmented_line_to_destination(scaled_fr_mm_s);
@@ -1163,9 +1163,9 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
1163 1163
            */
1164 1164
           if (xy_pos_t(current_position) != xy_pos_t(destination)) {
1165 1165
             #if ENABLED(MESH_BED_LEVELING)
1166
-              mbl.line_to_destination(scaled_fr_mm_s);
1166
+              bedlevel.line_to_destination(scaled_fr_mm_s);
1167 1167
             #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
1168
-              bbl.line_to_destination(scaled_fr_mm_s);
1168
+              bedlevel.line_to_destination(scaled_fr_mm_s);
1169 1169
             #endif
1170 1170
             return true;
1171 1171
           }
@@ -1363,7 +1363,7 @@ void prepare_line_to_destination() {
1363 1363
   if (
1364 1364
     #if UBL_SEGMENTED
1365 1365
       #if IS_KINEMATIC // UBL using Kinematic / Cartesian cases as a workaround for now.
1366
-        ubl.line_to_destination_segmented(MMS_SCALED(feedrate_mm_s))
1366
+        bedlevel.line_to_destination_segmented(MMS_SCALED(feedrate_mm_s))
1367 1367
       #else
1368 1368
         line_to_destination_cartesian()
1369 1369
       #endif

+ 9
- 23
Marlin/src/module/planner.cpp Переглянути файл

@@ -1587,19 +1587,12 @@ void Planner::check_axes_activity() {
1587 1587
 
1588 1588
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1589 1589
         const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
1590
-      #elif DISABLED(MESH_BED_LEVELING)
1591
-        constexpr float fade_scaling_factor = 1.0;
1590
+        if (fade_scaling_factor) raw.z += fade_scaling_factor * bedlevel.get_z_correction(raw);
1591
+      #else
1592
+        raw.z += bedlevel.get_z_correction(raw);
1592 1593
       #endif
1593 1594
 
1594
-      raw.z += (
1595
-        #if ENABLED(MESH_BED_LEVELING)
1596
-          mbl.get_z(raw OPTARG(ENABLE_LEVELING_FADE_HEIGHT, fade_scaling_factor))
1597
-        #elif ENABLED(AUTO_BED_LEVELING_UBL)
1598
-          fade_scaling_factor ? fade_scaling_factor * ubl.get_z_correction(raw) : 0.0
1599
-        #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
1600
-          fade_scaling_factor ? fade_scaling_factor * bbl.get_z_correction(raw) : 0.0
1601
-        #endif
1602
-      );
1595
+      TERN_(MESH_BED_LEVELING, raw.z += bedlevel.get_z_offset());
1603 1596
 
1604 1597
     #endif
1605 1598
   }
@@ -1618,22 +1611,15 @@ void Planner::check_axes_activity() {
1618 1611
 
1619 1612
       #elif HAS_MESH
1620 1613
 
1614
+        TERN_(MESH_BED_LEVELING, raw.z -= bedlevel.get_z_offset());
1615
+
1621 1616
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1622 1617
           const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
1623
-        #elif DISABLED(MESH_BED_LEVELING)
1624
-          constexpr float fade_scaling_factor = 1.0;
1618
+          if (fade_scaling_factor) raw.z -= fade_scaling_factor * bedlevel.get_z_correction(raw);
1619
+        #else
1620
+          raw.z -= bedlevel.get_z_correction(raw);
1625 1621
         #endif
1626 1622
 
1627
-        raw.z -= (
1628
-          #if ENABLED(MESH_BED_LEVELING)
1629
-            mbl.get_z(raw OPTARG(ENABLE_LEVELING_FADE_HEIGHT, fade_scaling_factor))
1630
-          #elif ENABLED(AUTO_BED_LEVELING_UBL)
1631
-            fade_scaling_factor ? fade_scaling_factor * ubl.get_z_correction(raw) : 0.0
1632
-          #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
1633
-            fade_scaling_factor ? fade_scaling_factor * bbl.get_z_correction(raw) : 0.0
1634
-          #endif
1635
-        );
1636
-
1637 1623
       #endif
1638 1624
     }
1639 1625
   }

+ 45
- 44
Marlin/src/module/settings.cpp Переглянути файл

@@ -247,9 +247,9 @@ typedef struct SettingsDataStruct {
247 247
   //
248 248
   // MESH_BED_LEVELING
249 249
   //
250
-  float mbl_z_offset;                                   // mbl.z_offset
250
+  float mbl_z_offset;                                   // bedlevel.z_offset
251 251
   uint8_t mesh_num_x, mesh_num_y;                       // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
252
-  float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3)]   // mbl.z_values
252
+  float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3)]   // bedlevel.z_values
253 253
                     [TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3)];
254 254
 
255 255
   //
@@ -287,7 +287,7 @@ typedef struct SettingsDataStruct {
287 287
   // AUTO_BED_LEVELING_UBL
288 288
   //
289 289
   bool planner_leveling_active;                         // M420 S  planner.leveling_active
290
-  int8_t ubl_storage_slot;                              // ubl.storage_slot
290
+  int8_t ubl_storage_slot;                              // bedlevel.storage_slot
291 291
 
292 292
   //
293 293
   // SERVO_ANGLES
@@ -615,7 +615,7 @@ void MarlinSettings::postprocess() {
615 615
 
616 616
   TERN_(ENABLE_LEVELING_FADE_HEIGHT, set_z_fade_height(new_z_fade_height, false)); // false = no report
617 617
 
618
-  TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
618
+  TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
619 619
 
620 620
   TERN_(HAS_MOTOR_CURRENT_PWM, stepper.refresh_motor_power());
621 621
 
@@ -844,7 +844,7 @@ void MarlinSettings::postprocess() {
844 844
     {
845 845
       #if ENABLED(MESH_BED_LEVELING)
846 846
         static_assert(
847
-          sizeof(mbl.z_values) == (GRID_MAX_POINTS) * sizeof(mbl.z_values[0][0]),
847
+          sizeof(bedlevel.z_values) == (GRID_MAX_POINTS) * sizeof(bedlevel.z_values[0][0]),
848 848
           "MBL Z array is the wrong size."
849 849
         );
850 850
       #else
@@ -854,12 +854,12 @@ void MarlinSettings::postprocess() {
854 854
       const uint8_t mesh_num_x = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3),
855 855
                     mesh_num_y = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3);
856 856
 
857
-      EEPROM_WRITE(TERN(MESH_BED_LEVELING, mbl.z_offset, dummyf));
857
+      EEPROM_WRITE(TERN(MESH_BED_LEVELING, bedlevel.z_offset, dummyf));
858 858
       EEPROM_WRITE(mesh_num_x);
859 859
       EEPROM_WRITE(mesh_num_y);
860 860
 
861 861
       #if ENABLED(MESH_BED_LEVELING)
862
-        EEPROM_WRITE(mbl.z_values);
862
+        EEPROM_WRITE(bedlevel.z_values);
863 863
       #else
864 864
         for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummyf);
865 865
       #endif
@@ -896,7 +896,7 @@ void MarlinSettings::postprocess() {
896 896
     {
897 897
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
898 898
         static_assert(
899
-          sizeof(Z_VALUES_ARR) == (GRID_MAX_POINTS) * sizeof(Z_VALUES_ARR[0][0]),
899
+          sizeof(bedlevel.z_values) == (GRID_MAX_POINTS) * sizeof(bedlevel.z_values[0][0]),
900 900
           "Bilinear Z array is the wrong size."
901 901
         );
902 902
       #endif
@@ -906,16 +906,16 @@ void MarlinSettings::postprocess() {
906 906
       EEPROM_WRITE(grid_max_x);
907 907
       EEPROM_WRITE(grid_max_y);
908 908
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
909
-        EEPROM_WRITE(bbl.get_grid_spacing());
910
-        EEPROM_WRITE(bbl.get_grid_start());
909
+        EEPROM_WRITE(bedlevel.grid_spacing);
910
+        EEPROM_WRITE(bedlevel.grid_start);
911 911
       #else
912
-        const xy_pos_t bilinear_start{0}, bilinear_grid_spacing{0};
912
+        const xy_pos_t bilinear_grid_spacing{0}, bilinear_start{0};
913 913
         EEPROM_WRITE(bilinear_grid_spacing);
914 914
         EEPROM_WRITE(bilinear_start);
915 915
       #endif
916 916
 
917 917
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
918
-        EEPROM_WRITE(Z_VALUES_ARR);              // 9-256 floats
918
+        EEPROM_WRITE(bedlevel.z_values);              // 9-256 floats
919 919
       #else
920 920
         dummyf = 0;
921 921
         for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
@@ -938,7 +938,7 @@ void MarlinSettings::postprocess() {
938 938
     {
939 939
       _FIELD_TEST(planner_leveling_active);
940 940
       const bool ubl_active = TERN(AUTO_BED_LEVELING_UBL, planner.leveling_active, false);
941
-      const int8_t storage_slot = TERN(AUTO_BED_LEVELING_UBL, ubl.storage_slot, -1);
941
+      const int8_t storage_slot = TERN(AUTO_BED_LEVELING_UBL, bedlevel.storage_slot, -1);
942 942
       EEPROM_WRITE(ubl_active);
943 943
       EEPROM_WRITE(storage_slot);
944 944
     }
@@ -1638,8 +1638,8 @@ void MarlinSettings::postprocess() {
1638 1638
     // UBL Mesh
1639 1639
     //
1640 1640
     #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
1641
-      if (ubl.storage_slot >= 0)
1642
-        store_mesh(ubl.storage_slot);
1641
+      if (bedlevel.storage_slot >= 0)
1642
+        store_mesh(bedlevel.storage_slot);
1643 1643
     #endif
1644 1644
 
1645 1645
     if (!eeprom_error) {
@@ -1796,20 +1796,20 @@ void MarlinSettings::postprocess() {
1796 1796
         EEPROM_READ_ALWAYS(mesh_num_y);
1797 1797
 
1798 1798
         #if ENABLED(MESH_BED_LEVELING)
1799
-          if (!validating) mbl.z_offset = dummyf;
1799
+          if (!validating) bedlevel.z_offset = dummyf;
1800 1800
           if (mesh_num_x == (GRID_MAX_POINTS_X) && mesh_num_y == (GRID_MAX_POINTS_Y)) {
1801 1801
             // EEPROM data fits the current mesh
1802
-            EEPROM_READ(mbl.z_values);
1802
+            EEPROM_READ(bedlevel.z_values);
1803 1803
           }
1804 1804
           else {
1805 1805
             // EEPROM data is stale
1806
-            if (!validating) mbl.reset();
1806
+            if (!validating) bedlevel.reset();
1807 1807
             for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
1808 1808
           }
1809 1809
         #else
1810 1810
           // MBL is disabled - skip the stored data
1811 1811
           for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
1812
-        #endif // MESH_BED_LEVELING
1812
+        #endif
1813 1813
       }
1814 1814
 
1815 1815
       //
@@ -1849,8 +1849,8 @@ void MarlinSettings::postprocess() {
1849 1849
         #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
1850 1850
           if (grid_max_x == (GRID_MAX_POINTS_X) && grid_max_y == (GRID_MAX_POINTS_Y)) {
1851 1851
             if (!validating) set_bed_leveling_enabled(false);
1852
-            bbl.set_grid(spacing, start);
1853
-            EEPROM_READ(Z_VALUES_ARR);                 // 9 to 256 floats
1852
+            bedlevel.set_grid(spacing, start);
1853
+            EEPROM_READ(bedlevel.z_values);                 // 9 to 256 floats
1854 1854
           }
1855 1855
           else // EEPROM data is stale
1856 1856
         #endif // AUTO_BED_LEVELING_BILINEAR
@@ -1877,7 +1877,7 @@ void MarlinSettings::postprocess() {
1877 1877
         _FIELD_TEST(planner_leveling_active);
1878 1878
         #if ENABLED(AUTO_BED_LEVELING_UBL)
1879 1879
           const bool &planner_leveling_active = planner.leveling_active;
1880
-          const int8_t &ubl_storage_slot = ubl.storage_slot;
1880
+          const int8_t &ubl_storage_slot = bedlevel.storage_slot;
1881 1881
         #else
1882 1882
           bool planner_leveling_active;
1883 1883
           int8_t ubl_storage_slot;
@@ -2617,11 +2617,11 @@ void MarlinSettings::postprocess() {
2617 2617
 
2618 2618
       #if ENABLED(AUTO_BED_LEVELING_UBL)
2619 2619
         if (!validating) {
2620
-          ubl.report_state();
2620
+          bedlevel.report_state();
2621 2621
 
2622
-          if (!ubl.sanity_check()) {
2622
+          if (!bedlevel.sanity_check()) {
2623 2623
             #if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
2624
-              ubl.echo_name();
2624
+              bedlevel.echo_name();
2625 2625
               DEBUG_ECHOLNPGM(" initialized.\n");
2626 2626
             #endif
2627 2627
           }
@@ -2629,18 +2629,18 @@ void MarlinSettings::postprocess() {
2629 2629
             eeprom_error = true;
2630 2630
             #if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
2631 2631
               DEBUG_ECHOPGM("?Can't enable ");
2632
-              ubl.echo_name();
2632
+              bedlevel.echo_name();
2633 2633
               DEBUG_ECHOLNPGM(".");
2634 2634
             #endif
2635
-            ubl.reset();
2635
+            bedlevel.reset();
2636 2636
           }
2637 2637
 
2638
-          if (ubl.storage_slot >= 0) {
2639
-            load_mesh(ubl.storage_slot);
2640
-            DEBUG_ECHOLNPGM("Mesh ", ubl.storage_slot, " loaded from storage.");
2638
+          if (bedlevel.storage_slot >= 0) {
2639
+            load_mesh(bedlevel.storage_slot);
2640
+            DEBUG_ECHOLNPGM("Mesh ", bedlevel.storage_slot, " loaded from storage.");
2641 2641
           }
2642 2642
           else {
2643
-            ubl.reset();
2643
+            bedlevel.reset();
2644 2644
             DEBUG_ECHOLNPGM("UBL reset");
2645 2645
           }
2646 2646
         }
@@ -2708,7 +2708,7 @@ void MarlinSettings::postprocess() {
2708 2708
       return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8;
2709 2709
     }
2710 2710
 
2711
-    #define MESH_STORE_SIZE sizeof(TERN(OPTIMIZED_MESH_STORAGE, mesh_store_t, ubl.z_values))
2711
+    #define MESH_STORE_SIZE sizeof(TERN(OPTIMIZED_MESH_STORAGE, mesh_store_t, bedlevel.z_values))
2712 2712
 
2713 2713
     uint16_t MarlinSettings::calc_num_meshes() {
2714 2714
       return (meshes_end - meshes_start_index()) / MESH_STORE_SIZE;
@@ -2734,10 +2734,10 @@ void MarlinSettings::postprocess() {
2734 2734
 
2735 2735
         #if ENABLED(OPTIMIZED_MESH_STORAGE)
2736 2736
           int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
2737
-          ubl.set_store_from_mesh(ubl.z_values, z_mesh_store);
2737
+          bedlevel.set_store_from_mesh(bedlevel.z_values, z_mesh_store);
2738 2738
           uint8_t * const src = (uint8_t*)&z_mesh_store;
2739 2739
         #else
2740
-          uint8_t * const src = (uint8_t*)&ubl.z_values;
2740
+          uint8_t * const src = (uint8_t*)&bedlevel.z_values;
2741 2741
         #endif
2742 2742
 
2743 2743
         // Write crc to MAT along with other data, or just tack on to the beginning or end
@@ -2772,7 +2772,7 @@ void MarlinSettings::postprocess() {
2772 2772
           int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
2773 2773
           uint8_t * const dest = (uint8_t*)&z_mesh_store;
2774 2774
         #else
2775
-          uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
2775
+          uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&bedlevel.z_values;
2776 2776
         #endif
2777 2777
 
2778 2778
         persistentStore.access_start();
@@ -2782,11 +2782,11 @@ void MarlinSettings::postprocess() {
2782 2782
         #if ENABLED(OPTIMIZED_MESH_STORAGE)
2783 2783
           if (into) {
2784 2784
             float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
2785
-            ubl.set_mesh_from_store(z_mesh_store, z_values);
2785
+            bedlevel.set_mesh_from_store(z_mesh_store, z_values);
2786 2786
             memcpy(into, z_values, sizeof(z_values));
2787 2787
           }
2788 2788
           else
2789
-            ubl.set_mesh_from_store(z_mesh_store, ubl.z_values);
2789
+            bedlevel.set_mesh_from_store(z_mesh_store, bedlevel.z_values);
2790 2790
         #endif
2791 2791
 
2792 2792
         if (status) SERIAL_ECHOLNPGM("?Unable to load mesh data.");
@@ -3441,24 +3441,25 @@ void MarlinSettings::reset() {
3441 3441
             LOOP_L_N(px, GRID_MAX_POINTS_X) {
3442 3442
               CONFIG_ECHO_START();
3443 3443
               SERIAL_ECHOPGM("  G29 S3 I", px, " J", py);
3444
-              SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(mbl.z_values[px][py]), 5);
3444
+              SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(bedlevel.z_values[px][py]), 5);
3445 3445
             }
3446 3446
           }
3447 3447
           CONFIG_ECHO_START();
3448
-          SERIAL_ECHOLNPAIR_F("  G29 S4 Z", LINEAR_UNIT(mbl.z_offset), 5);
3448
+          SERIAL_ECHOLNPAIR_F("  G29 S4 Z", LINEAR_UNIT(bedlevel.z_offset), 5);
3449 3449
         }
3450 3450
 
3451 3451
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
3452 3452
 
3453 3453
         if (!forReplay) {
3454 3454
           SERIAL_EOL();
3455
-          ubl.report_state();
3456
-          SERIAL_ECHO_MSG("Active Mesh Slot ", ubl.storage_slot);
3455
+          bedlevel.report_state();
3456
+          SERIAL_ECHO_MSG("Active Mesh Slot ", bedlevel.storage_slot);
3457 3457
           SERIAL_ECHO_MSG("EEPROM can hold ", calc_num_meshes(), " meshes.\n");
3458 3458
         }
3459 3459
 
3460
-       //ubl.report_current_mesh();   // This is too verbose for large meshes. A better (more terse)
3461
-                                                  // solution needs to be found.
3460
+       //bedlevel.report_current_mesh();   // This is too verbose for large meshes. A better (more terse)
3461
+                                           // solution needs to be found.
3462
+
3462 3463
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
3463 3464
 
3464 3465
         if (leveling_is_valid()) {
@@ -3466,7 +3467,7 @@ void MarlinSettings::reset() {
3466 3467
             LOOP_L_N(px, GRID_MAX_POINTS_X) {
3467 3468
               CONFIG_ECHO_START();
3468 3469
               SERIAL_ECHOPGM("  G29 W I", px, " J", py);
3469
-              SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(Z_VALUES_ARR[px][py]), 5);
3470
+              SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(bedlevel.z_values[px][py]), 5);
3470 3471
             }
3471 3472
           }
3472 3473
         }

Завантаження…
Відмінити
Зберегти