Browse Source

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

Scott Lahteine 2 years ago
parent
commit
b523ddf1b2
No account linked to committer's email address
47 changed files with 389 additions and 433 deletions
  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 View File

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

+ 3
- 3
Marlin/src/HAL/DUE/inc/SanityCheck.h View File

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

+ 1
- 1
Marlin/src/MarlinCore.cpp View File

448
         TERN_(DISABLE_INACTIVE_W, stepper.disable_axis(W_AXIS));
448
         TERN_(DISABLE_INACTIVE_W, stepper.disable_axis(W_AXIS));
449
         TERN_(DISABLE_INACTIVE_E, stepper.disable_e_steppers());
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
     else
454
     else

+ 4
- 4
Marlin/src/core/utility.cpp View File

132
         #else
132
         #else
133
           #if ENABLED(AUTO_BED_LEVELING_UBL)
133
           #if ENABLED(AUTO_BED_LEVELING_UBL)
134
             SERIAL_ECHOPGM("UBL Adjustment Z");
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
           #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
136
           #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
137
             SERIAL_ECHOPGM("ABL Adjustment Z");
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
           #endif
139
           #endif
140
           SERIAL_ECHO(ftostr43sign(rz, '+'));
140
           SERIAL_ECHO(ftostr43sign(rz, '+'));
141
           #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
141
           #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
156
       SERIAL_ECHOPGM("Mesh Bed Leveling");
156
       SERIAL_ECHOPGM("Mesh Bed Leveling");
157
       if (planner.leveling_active) {
157
       if (planner.leveling_active) {
158
         SERIAL_ECHOLNPGM(" (enabled)");
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
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
160
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
161
           if (planner.z_fade_height) {
161
           if (planner.z_fade_height) {
162
             SERIAL_ECHOPGM(" (", ftostr43sign(
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
             SERIAL_CHAR(')');
165
             SERIAL_CHAR(')');
166
           }
166
           }

+ 2
- 2
Marlin/src/feature/bedlevel/abl/bbl.cpp View File

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

+ 9
- 12
Marlin/src/feature/bedlevel/abl/bbl.h View File

24
 #include "../../../inc/MarlinConfigPre.h"
24
 #include "../../../inc/MarlinConfigPre.h"
25
 
25
 
26
 class LevelingBilinear {
26
 class LevelingBilinear {
27
-private:
27
+public:
28
+  static bed_mesh_t z_values;
28
   static xy_pos_t grid_spacing, grid_start;
29
   static xy_pos_t grid_spacing, grid_start;
30
+
31
+private:
29
   static xy_float_t grid_factor;
32
   static xy_float_t grid_factor;
30
-  static bed_mesh_t z_values;
31
   static xy_pos_t cached_rel;
33
   static xy_pos_t cached_rel;
32
   static xy_int8_t cached_g;
34
   static xy_int8_t cached_g;
33
 
35
 
54
   static void print_leveling_grid(const bed_mesh_t* _z_values = NULL);
56
   static void print_leveling_grid(const bed_mesh_t* _z_values = NULL);
55
   static void refresh_bed_level();
57
   static void refresh_bed_level();
56
   static bool has_mesh() { return !!grid_spacing.x; }
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
   static float get_z_correction(const xy_pos_t &raw);
62
   static float get_z_correction(const xy_pos_t &raw);
63
+  static constexpr float get_z_offset() { return 0.0f; }
63
 
64
 
64
   #if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
65
   #if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
65
     static void line_to_destination(const_feedRate_t scaled_fr_mm_s, uint16_t x_splits=0xFFFF, uint16_t y_splits=0xFFFF);
66
     static void line_to_destination(const_feedRate_t scaled_fr_mm_s, uint16_t x_splits=0xFFFF, uint16_t y_splits=0xFFFF);
66
   #endif
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 View File

47
 #endif
47
 #endif
48
 
48
 
49
 bool leveling_is_valid() {
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
  * Disable: Current position = physical position
56
  * Disable: Current position = physical position
60
  *  Enable: Current position = "unleveled" physical position
57
  *  Enable: Current position = "unleveled" physical position
65
 
62
 
66
   if (can_change && enable != planner.leveling_active) {
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
     planner.synchronize();
75
     planner.synchronize();
69
 
76
 
70
     if (planner.leveling_active) {      // leveling from on to off
77
     if (planner.leveling_active) {      // leveling from on to off
71
-      if (DEBUGGING(LEVELING)) DEBUG_POS("Leveling ON", current_position);
72
       // change unleveled current_position to physical current_position without moving steppers.
78
       // change unleveled current_position to physical current_position without moving steppers.
73
       planner.apply_leveling(current_position);
79
       planner.apply_leveling(current_position);
74
       planner.leveling_active = false;  // disable only AFTER calling apply_leveling
80
       planner.leveling_active = false;  // disable only AFTER calling apply_leveling
75
-      if (DEBUGGING(LEVELING)) DEBUG_POS("...Now OFF", current_position);
76
     }
81
     }
77
     else {                              // leveling from off to on
82
     else {                              // leveling from off to on
78
-      if (DEBUGGING(LEVELING)) DEBUG_POS("Leveling OFF", current_position);
79
       planner.leveling_active = true;   // enable BEFORE calling unapply_leveling, otherwise ignored
83
       planner.leveling_active = true;   // enable BEFORE calling unapply_leveling, otherwise ignored
80
       // change physical current_position to unleveled current_position without moving steppers.
84
       // change physical current_position to unleveled current_position without moving steppers.
81
       planner.unapply_leveling(current_position);
85
       planner.unapply_leveling(current_position);
82
-      if (DEBUGGING(LEVELING)) DEBUG_POS("...Now ON", current_position);
83
     }
86
     }
84
 
87
 
85
     sync_plan_position();
88
     sync_plan_position();
89
+    _report_leveling();
86
   }
90
   }
87
 }
91
 }
88
 
92
 
116
  */
120
  */
117
 void reset_bed_level() {
121
 void reset_bed_level() {
118
   if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("reset_bed_level");
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
 #if EITHER(AUTO_BED_LEVELING_BILINEAR, MESH_BED_LEVELING)
128
 #if EITHER(AUTO_BED_LEVELING_BILINEAR, MESH_BED_LEVELING)

+ 1
- 4
Marlin/src/feature/bedlevel/bedlevel.h View File

69
     #include "mbl/mesh_bed_leveling.h"
69
     #include "mbl/mesh_bed_leveling.h"
70
   #endif
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
   #if EITHER(AUTO_BED_LEVELING_BILINEAR, MESH_BED_LEVELING)
72
   #if EITHER(AUTO_BED_LEVELING_BILINEAR, MESH_BED_LEVELING)
76
 
73
 
77
     #include <stdint.h>
74
     #include <stdint.h>
92
     bool valid() const { return pos.x >= 0 && pos.y >= 0; }
89
     bool valid() const { return pos.x >= 0 && pos.y >= 0; }
93
     #if ENABLED(AUTO_BED_LEVELING_UBL)
90
     #if ENABLED(AUTO_BED_LEVELING_UBL)
94
       xy_pos_t meshpos() {
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
     #endif
94
     #endif
98
     operator xy_int8_t&() { return pos; }
95
     operator xy_int8_t&() { return pos; }

+ 1
- 1
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp View File

32
     #include "../../../lcd/extui/ui_api.h"
32
     #include "../../../lcd/extui/ui_api.h"
33
   #endif
33
   #endif
34
 
34
 
35
-  mesh_bed_leveling mbl;
35
+  mesh_bed_leveling bedlevel;
36
 
36
 
37
   float mesh_bed_leveling::z_offset,
37
   float mesh_bed_leveling::z_offset,
38
         mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
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 View File

34
 
34
 
35
 #define MESH_X_DIST (float(MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_CELLS_X))
35
 #define MESH_X_DIST (float(MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_CELLS_X))
36
 #define MESH_Y_DIST (float(MESH_MAX_Y - (MESH_MIN_Y)) / (GRID_MAX_CELLS_Y))
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
 class mesh_bed_leveling {
38
 class mesh_bed_leveling {
42
 public:
39
 public:
56
     return false;
53
     return false;
57
   }
54
   }
58
 
55
 
56
+  static bool mesh_is_valid() { return has_mesh(); }
57
+
59
   static void set_z(const int8_t px, const int8_t py, const_float_t z) { z_values[px][py] = z; }
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
   static void zigzag(const int8_t index, int8_t &px, int8_t &py) {
60
   static void zigzag(const int8_t index, int8_t &px, int8_t &py) {
70
     set_z(px, py, z);
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
   static int8_t cell_index_x(const_float_t x) {
75
   static int8_t cell_index_x(const_float_t x) {
74
     int8_t cx = (x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST);
76
     int8_t cx = (x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST);
75
     return constrain(cx, 0, GRID_MAX_CELLS_X - 1);
77
     return constrain(cx, 0, GRID_MAX_CELLS_X - 1);
102
     return z1 + delta_a * delta_z;
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
     const xy_int8_t ind = cell_indexes(pos);
110
     const xy_int8_t ind = cell_indexes(pos);
112
     const float x1 = index_to_xpos[ind.x], x2 = index_to_xpos[ind.x+1],
111
     const float x1 = index_to_xpos[ind.x], x2 = index_to_xpos[ind.x+1],
113
                 y1 = index_to_xpos[ind.y], y2 = index_to_xpos[ind.y+1],
112
                 y1 = index_to_xpos[ind.y], y2 = index_to_xpos[ind.y+1],
115
                 z2 = calc_z0(pos.x, x1, z_values[ind.x][ind.y+1], x2, z_values[ind.x+1][ind.y+1]),
114
                 z2 = calc_z0(pos.x, x1, z_values[ind.x][ind.y+1], x2, z_values[ind.x+1][ind.y+1]),
116
                 zf = calc_z0(pos.y, y1, z1, y2, z2);
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
   #if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
120
   #if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
123
   #endif
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 View File

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

+ 17
- 18
Marlin/src/feature/bedlevel/ubl/ubl.h View File

215
       return _UBL_OUTER_Z_RAISE;
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
                 z1 = z_values[x1_i][yi];
219
                 z1 = z_values[x1_i][yi];
220
 
220
 
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
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
       return _UBL_OUTER_Z_RAISE;
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
                 z1 = z_values[xi][y1_i];
242
                 z1 = z_values[xi][y1_i];
243
 
243
 
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
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
         return UBL_Z_RAISE_WHEN_OFF_MESH;
264
         return UBL_Z_RAISE_WHEN_OFF_MESH;
265
     #endif
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
       if (DEBUGGING(MESH_ADJUST)) DEBUG_ECHOLNPGM("??? Yikes! NAN in ");
279
       if (DEBUGGING(MESH_ADJUST)) DEBUG_ECHOLNPGM("??? Yikes! NAN in ");
279
     }
280
     }
287
   }
288
   }
288
   static float get_z_correction(const xy_pos_t &pos) { return get_z_correction(pos.x, pos.y); }
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
     return i < (GRID_MAX_POINTS_X) ? pgm_read_float(&_mesh_index_to_xpos[i]) : MESH_MIN_X + i * (MESH_X_DIST);
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
     return i < (GRID_MAX_POINTS_Y) ? pgm_read_float(&_mesh_index_to_ypos[i]) : MESH_MIN_Y + i * (MESH_Y_DIST);
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
 
310
 
308
 }; // class unified_bed_leveling
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
 // Prevent debugging propagating to other files
315
 // Prevent debugging propagating to other files
317
 #include "../../../core/debug_out.h"
316
 #include "../../../core/debug_out.h"

+ 17
- 27
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp View File

941
       // It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
941
       // It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
942
       if (!location.valid()) continue;
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
       if (!position_is_reachable(ppos)) break; // SHOULD NOT OCCUR (find_closest_mesh_point only returns reachable points)
946
       if (!position_is_reachable(ppos)) break; // SHOULD NOT OCCUR (find_closest_mesh_point only returns reachable points)
951
 
947
 
1040
 
1036
 
1041
       done_flags.mark(lpos);                              // Mark this location as 'adjusted' so a new
1037
       done_flags.mark(lpos);                              // Mark this location as 'adjusted' so a new
1042
                                                           // location is used on the next loop
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
       if (!position_is_reachable(raw)) break;             // SHOULD NOT OCCUR (find_closest_mesh_point_of_type only returns reachable)
1041
       if (!position_is_reachable(raw)) break;             // SHOULD NOT OCCUR (find_closest_mesh_point_of_type only returns reachable)
1050
 
1042
 
1277
     if (!isnan(z_values[i][j])) continue;  // Skip valid mesh points
1269
     if (!isnan(z_values[i][j])) continue;  // Skip valid mesh points
1278
 
1270
 
1279
     // Skip unreachable points
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
       continue;
1273
       continue;
1282
 
1274
 
1283
     found_a_NAN = true;
1275
     found_a_NAN = true;
1329
 
1321
 
1330
   static bool test_func(uint8_t i, uint8_t j, void *data) {
1322
   static bool test_func(uint8_t i, uint8_t j, void *data) {
1331
     find_closest_t *d = (find_closest_t*)data;
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
       || (d->type == SET_IN_BITMAP && !d->done_flags->marked(i, j))
1325
       || (d->type == SET_IN_BITMAP && !d->done_flags->marked(i, j))
1334
     ) {
1326
     ) {
1335
       // Found a Mesh Point of the specified type!
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
       // If using the probe as the reference there are some unreachable locations.
1330
       // If using the probe as the reference there are some unreachable locations.
1339
       // Also for round beds, there are grid points outside the bed the nozzle can't reach.
1331
       // Also for round beds, there are grid points outside the bed the nozzle can't reach.
1377
         || (type == SET_IN_BITMAP && !done_flags->marked(i, j))
1369
         || (type == SET_IN_BITMAP && !done_flags->marked(i, j))
1378
       ) {
1370
       ) {
1379
         // Found a Mesh Point of the specified type!
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
         // If using the probe as the reference there are some unreachable locations.
1374
         // If using the probe as the reference there are some unreachable locations.
1383
         // Also for round beds, there are grid points outside the bed the nozzle can't reach.
1375
         // Also for round beds, there are grid points outside the bed the nozzle can't reach.
1433
 
1425
 
1434
 void unified_bed_leveling::smart_fill_mesh() {
1426
 void unified_bed_leveling::smart_fill_mesh() {
1435
   static const smart_fill_info
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
   static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
1432
   static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
1441
 
1433
 
1442
   LOOP_L_N(i, COUNT(info)) {
1434
   LOOP_L_N(i, COUNT(info)) {
1625
     matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
1617
     matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
1626
 
1618
 
1627
     GRID_LOOP(i, j) {
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
       if (DEBUGGING(LEVELING)) {
1622
       if (DEBUGGING(LEVELING)) {
1633
         DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
1623
         DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
1724
 
1714
 
1725
     xy_pos_t ppos;
1715
     xy_pos_t ppos;
1726
     LOOP_L_N(ix, GRID_MAX_POINTS_X) {
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
       LOOP_L_N(iy, GRID_MAX_POINTS_Y) {
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
         if (isnan(z_values[ix][iy])) {
1720
         if (isnan(z_values[ix][iy])) {
1731
           // undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
1721
           // undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
1732
           incremental_LSF_reset(&lsf_results);
1722
           incremental_LSF_reset(&lsf_results);
1733
           xy_pos_t rpos;
1723
           xy_pos_t rpos;
1734
           LOOP_L_N(jx, GRID_MAX_POINTS_X) {
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
             LOOP_L_N(jy, GRID_MAX_POINTS_Y) {
1726
             LOOP_L_N(jy, GRID_MAX_POINTS_Y) {
1737
               if (TEST(bitmap[jx], jy)) {
1727
               if (TEST(bitmap[jx], jy)) {
1738
-                rpos.y = mesh_index_to_ypos(jy);
1728
+                rpos.y = get_mesh_y(jy);
1739
                 const float rz = z_values[jx][jy],
1729
                 const float rz = z_values[jx][jy],
1740
                              w = 1.0f + weight_scaled / (rpos - ppos).magnitude();
1730
                              w = 1.0f + weight_scaled / (rpos - ppos).magnitude();
1741
                 incremental_WLSF(&lsf_results, rpos, rz, w);
1731
                 incremental_WLSF(&lsf_results, rpos, rz, w);
1794
 
1784
 
1795
     SERIAL_ECHOPGM("X-Axis Mesh Points at: ");
1785
     SERIAL_ECHOPGM("X-Axis Mesh Points at: ");
1796
     LOOP_L_N(i, GRID_MAX_POINTS_X) {
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
       SERIAL_ECHOPGM("  ");
1788
       SERIAL_ECHOPGM("  ");
1799
       serial_delay(25);
1789
       serial_delay(25);
1800
     }
1790
     }
1802
 
1792
 
1803
     SERIAL_ECHOPGM("Y-Axis Mesh Points at: ");
1793
     SERIAL_ECHOPGM("Y-Axis Mesh Points at: ");
1804
     LOOP_L_N(i, GRID_MAX_POINTS_Y) {
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
       SERIAL_ECHOPGM("  ");
1796
       SERIAL_ECHOPGM("  ");
1807
       serial_delay(25);
1797
       serial_delay(25);
1808
     }
1798
     }

+ 9
- 12
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp View File

76
       #endif
76
       #endif
77
 
77
 
78
       // The distance is always MESH_X_DIST so multiply by the constant reciprocal.
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
                   z1 = z_values[iend.x][iend.y    ] + xratio * (z_values[iend.x + 1][iend.y    ] - z_values[iend.x][iend.y    ]),
81
                   z1 = z_values[iend.x][iend.y    ] + xratio * (z_values[iend.x + 1][iend.y    ] - z_values[iend.x][iend.y    ]),
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]);
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
       icell.y += ineg.y;      // Line going down? Just go to the bottom.
139
       icell.y += ineg.y;      // Line going down? Just go to the bottom.
140
       while (icell.y != iend.y + ineg.y) {
140
       while (icell.y != iend.y + ineg.y) {
141
         icell.y += iadd.y;
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
          * Skip the calculations for an infinite slope.
145
          * Skip the calculations for an infinite slope.
155
         // Replace NAN corrections with 0.0 to prevent NAN propagation.
155
         // Replace NAN corrections with 0.0 to prevent NAN propagation.
156
         if (isnan(z0)) z0 = 0.0;
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
          * Without this check, it's possible to generate a zero length move, as in the case where
161
          * Without this check, it's possible to generate a zero length move, as in the case where
196
 
196
 
197
       while (icell.x != iend.x + ineg.x) {
197
       while (icell.x != iend.x + ineg.x) {
198
         icell.x += iadd.x;
198
         icell.x += iadd.x;
199
-        dest.x = mesh_index_to_xpos(icell.x);
199
+        dest.x = get_mesh_x(icell.x);
200
         dest.y = ratio * dest.x + c;    // Calculate Y at the next X mesh line
200
         dest.y = ratio * dest.x + c;    // Calculate Y at the next X mesh line
201
 
201
 
202
         float z0 = z_correction_for_y_on_vertical_mesh_line(dest.y, icell.x, icell.y)
202
         float z0 = z_correction_for_y_on_vertical_mesh_line(dest.y, icell.x, icell.y)
245
 
245
 
246
     while (cnt) {
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
       dest.y = ratio * next_mesh_line_x + c;    // Calculate Y at the next X mesh line
251
       dest.y = ratio * next_mesh_line_x + c;    // Calculate Y at the next X mesh line
252
       dest.x = (next_mesh_line_y - c) / ratio;  // Calculate X at the next Y mesh line
252
       dest.x = (next_mesh_line_y - c) / ratio;  // Calculate X at the next Y mesh line
423
       if (isnan(z_x0y1)) z_x0y1 = 0;              //   in order to avoid isnan tests per cell,
423
       if (isnan(z_x0y1)) z_x0y1 = 0;              //   in order to avoid isnan tests per cell,
424
       if (isnan(z_x1y1)) z_x1y1 = 0;              //   thus guessing zero for undefined points
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
       xy_pos_t cell = raw - pos;
427
       xy_pos_t cell = raw - pos;
428
 
428
 
429
       const float z_xmy0 = (z_x1y0 - z_x0y0) * RECIPROCAL(MESH_X_DIST),   // z slope per x along y0 (lower left to lower right)
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
         if (--segments == 0) raw = destination;     // if this is last segment, use destination for exact
450
         if (--segments == 0) raw = destination;     // if this is last segment, use destination for exact
451
 
451
 
452
         const float z_cxcy = (z_cxy0 + z_cxym * cell.y) // interpolated mesh z height along cell.x at cell.y
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
         const float oldz = raw.z; raw.z += z_cxcy;
455
         const float oldz = raw.z; raw.z += z_cxcy;
459
         planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, segment_xyz_mm OPTARG(SCARA_FEEDRATE_SCALING, inv_duration) );
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 View File

293
 
293
 
294
     if (circle_flags.marked(p1.x, p1.y) && circle_flags.marked(p2.x, p2.y)) {
294
     if (circle_flags.marked(p1.x, p1.y) && circle_flags.marked(p2.x, p2.y)) {
295
       xyz_pos_t s, e;
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
       s.z = e.z = layer_height;
300
       s.z = e.z = layer_height;
301
 
301
 
302
       #if HAS_ENDSTOPS
302
       #if HAS_ENDSTOPS
448
       GRID_LOOP(i, j) {
448
       GRID_LOOP(i, j) {
449
         if (!circle_flags.marked(i, j)) {
449
         if (!circle_flags.marked(i, j)) {
450
           // We found a circle that needs to be printed
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
           // Get the distance to this intersection
453
           // Get the distance to this intersection
454
           float f = (pos - m).magnitude();
454
           float f = (pos - m).magnitude();
729
 
729
 
730
     if (location.valid()) {
730
     if (location.valid()) {
731
       TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location.pos, ExtUI::G26_POINT_START));
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
       // If this mesh location is outside the printable radius, skip it.
734
       // If this mesh location is outside the printable radius, skip it.
735
       if (!position_is_reachable(circle)) continue;
735
       if (!position_is_reachable(circle)) continue;
738
       // which is always drawn counter-clockwise.
738
       // which is always drawn counter-clockwise.
739
       const xy_int8_t st = location;
739
       const xy_int8_t st = location;
740
       const bool f = st.y == 0,
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
       #if ENABLED(ARC_SUPPORT)
744
       #if ENABLED(ARC_SUPPORT)
745
 
745
 

+ 2
- 2
Marlin/src/gcode/bedlevel/G42.cpp View File

48
     // Move to current_position, as modified by I, J, P parameters
48
     // Move to current_position, as modified by I, J, P parameters
49
     destination = current_position;
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
     #if HAS_PROBE_XY_OFFSET
54
     #if HAS_PROBE_XY_OFFSET
55
       if (parser.boolval('P')) {
55
       if (parser.boolval('P')) {

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

71
         start.set(x_min, y_min);
71
         start.set(x_min, y_min);
72
         spacing.set((x_max - x_min) / (GRID_MAX_CELLS_X),
72
         spacing.set((x_max - x_min) / (GRID_MAX_CELLS_X),
73
                     (y_max - y_min) / (GRID_MAX_CELLS_Y));
73
                     (y_max - y_min) / (GRID_MAX_CELLS_Y));
74
-        bbl.set_grid(spacing, start);
74
+        bedlevel.set_grid(spacing, start);
75
       #endif
75
       #endif
76
       GRID_LOOP(x, y) {
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
       SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
81
       SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
82
       SERIAL_ECHOPGM(" (", x_min);
82
       SERIAL_ECHOPGM(" (", x_min);
83
       SERIAL_CHAR(','); SERIAL_ECHO(y_min);
83
       SERIAL_CHAR(','); SERIAL_ECHO(y_min);
101
       set_bed_leveling_enabled(false);
101
       set_bed_leveling_enabled(false);
102
 
102
 
103
       #if ENABLED(EEPROM_SETTINGS)
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
         const int16_t a = settings.calc_num_meshes();
105
         const int16_t a = settings.calc_num_meshes();
106
 
106
 
107
         if (!a) {
107
         if (!a) {
116
         }
116
         }
117
 
117
 
118
         settings.load_mesh(storage_slot);
118
         settings.load_mesh(storage_slot);
119
-        ubl.storage_slot = storage_slot;
119
+        bedlevel.storage_slot = storage_slot;
120
 
120
 
121
       #else
121
       #else
122
 
122
 
128
 
128
 
129
     // L or V display the map info
129
     // L or V display the map info
130
     if (parser.seen("LV")) {
130
     if (parser.seen("LV")) {
131
-      ubl.display_map(parser.byteval('T'));
131
+      bedlevel.display_map(parser.byteval('T'));
132
       SERIAL_ECHOPGM("Mesh is ");
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
   #endif // AUTO_BED_LEVELING_UBL
137
   #endif // AUTO_BED_LEVELING_UBL
148
         #if ENABLED(AUTO_BED_LEVELING_UBL)
148
         #if ENABLED(AUTO_BED_LEVELING_UBL)
149
 
149
 
150
           set_bed_leveling_enabled(false);
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
         #else
153
         #else
154
 
154
 
156
 
156
 
157
             // Get the sum and average of all mesh values
157
             // Get the sum and average of all mesh values
158
             float mesh_sum = 0;
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
             const float zmean = mesh_sum / float(GRID_MAX_POINTS);
160
             const float zmean = mesh_sum / float(GRID_MAX_POINTS);
161
 
161
 
162
           #else // midrange
162
           #else // midrange
164
             // Find the low and high mesh values.
164
             // Find the low and high mesh values.
165
             float lo_val = 100, hi_val = -100;
165
             float lo_val = 100, hi_val = -100;
166
             GRID_LOOP(x, y) {
166
             GRID_LOOP(x, y) {
167
-              const float z = Z_VALUES(x, y);
167
+              const float z = bedlevel.z_values[x][y];
168
               NOMORE(lo_val, z);
168
               NOMORE(lo_val, z);
169
               NOLESS(hi_val, z);
169
               NOLESS(hi_val, z);
170
             }
170
             }
178
             set_bed_leveling_enabled(false);
178
             set_bed_leveling_enabled(false);
179
             // Subtract the mean from all values
179
             // Subtract the mean from all values
180
             GRID_LOOP(x, y) {
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
         #endif
187
         #endif
202
     #else
202
     #else
203
       if (leveling_is_valid()) {
203
       if (leveling_is_valid()) {
204
         #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
204
         #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
205
-          bbl.print_leveling_grid();
205
+          bedlevel.print_leveling_grid();
206
         #elif ENABLED(MESH_BED_LEVELING)
206
         #elif ENABLED(MESH_BED_LEVELING)
207
           SERIAL_ECHOLNPGM("Mesh Bed Level data:");
207
           SERIAL_ECHOLNPGM("Mesh Bed Level data:");
208
-          mbl.report_mesh();
208
+          bedlevel.report_mesh();
209
         #endif
209
         #endif
210
       }
210
       }
211
     #endif
211
     #endif

+ 14
- 14
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

313
 
313
 
314
         if (!isnan(rx) && !isnan(ry)) {
314
         if (!isnan(rx) && !isnan(ry)) {
315
           // Get nearest i / j from rx / ry
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
           LIMIT(i, 0, (GRID_MAX_POINTS_X) - 1);
318
           LIMIT(i, 0, (GRID_MAX_POINTS_X) - 1);
319
           LIMIT(j, 0, (GRID_MAX_POINTS_Y) - 1);
319
           LIMIT(j, 0, (GRID_MAX_POINTS_Y) - 1);
320
         }
320
         }
323
 
323
 
324
         if (WITHIN(i, 0, (GRID_MAX_POINTS_X) - 1) && WITHIN(j, 0, (GRID_MAX_POINTS_Y) - 1)) {
324
         if (WITHIN(i, 0, (GRID_MAX_POINTS_X) - 1) && WITHIN(j, 0, (GRID_MAX_POINTS_Y) - 1)) {
325
           set_bed_leveling_enabled(false);
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
           TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, rz));
328
           TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, rz));
329
           set_bed_leveling_enabled(abl.reenable);
329
           set_bed_leveling_enabled(abl.reenable);
330
           if (abl.reenable) report_current_position();
330
           if (abl.reenable) report_current_position();
499
 
499
 
500
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
500
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
501
       if (!abl.dryrun
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
         // Reset grid to 0.0 or "not probed". (Also disables ABL)
504
         // Reset grid to 0.0 or "not probed". (Also disables ABL)
505
         reset_bed_level();
505
         reset_bed_level();
509
       }
509
       }
510
 
510
 
511
       // Pre-populate local Z values from the stored mesh
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
     #endif // AUTO_BED_LEVELING_BILINEAR
514
     #endif // AUTO_BED_LEVELING_BILINEAR
515
 
515
 
796
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
796
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
797
 
797
 
798
       if (abl.dryrun)
798
       if (abl.dryrun)
799
-        bbl.print_leveling_grid(&abl.z_values);
799
+        bedlevel.print_leveling_grid(&abl.z_values);
800
       else {
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
     #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
809
     #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
923
 
923
 
924
         // Unapply the offset because it is going to be immediately applied
924
         // Unapply the offset because it is going to be immediately applied
925
         // and cause compensation movement in Z
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
         if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(" corrected Z:", current_position.z);
929
         if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(" corrected Z:", current_position.z);
930
       }
930
       }

+ 3
- 3
Marlin/src/gcode/bedlevel/abl/M421.cpp View File

58
               sy = iy >= 0 ? iy : 0, ey = iy >= 0 ? iy : GRID_MAX_POINTS_Y - 1;
58
               sy = iy >= 0 ? iy : 0, ey = iy >= 0 ? iy : GRID_MAX_POINTS_Y - 1;
59
       LOOP_S_LE_N(x, sx, ex) {
59
       LOOP_S_LE_N(x, sx, ex) {
60
         LOOP_S_LE_N(y, sy, ey) {
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
     else
67
     else
68
       SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
68
       SERIAL_ERROR_MSG(STR_ERR_MESH_XY);

+ 9
- 9
Marlin/src/gcode/bedlevel/mbl/G29.cpp View File

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

+ 3
- 3
Marlin/src/gcode/bedlevel/mbl/M421.cpp View File

43
  */
43
  */
44
 void GcodeSuite::M421() {
44
 void GcodeSuite::M421() {
45
   const bool hasX = parser.seen('X'), hasI = parser.seen('I');
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
   const bool hasY = parser.seen('Y'), hasJ = parser.seen('J');
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
   const bool hasZ = parser.seen('Z'), hasQ = !hasZ && parser.seen('Q');
49
   const bool hasZ = parser.seen('Z'), hasQ = !hasZ && parser.seen('Q');
50
 
50
 
51
   if (int(hasI && hasJ) + int(hasX && hasY) != 1 || !(hasZ || hasQ))
51
   if (int(hasI && hasJ) + int(hasX && hasY) != 1 || !(hasZ || hasQ))
53
   else if (ix < 0 || iy < 0)
53
   else if (ix < 0 || iy < 0)
54
     SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
54
     SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
55
   else
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
 #endif // MESH_BED_LEVELING
59
 #endif // MESH_BED_LEVELING

+ 1
- 1
Marlin/src/gcode/bedlevel/ubl/G29.cpp View File

39
 
39
 
40
   TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE));
40
   TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE));
41
 
41
 
42
-  ubl.G29();
42
+  bedlevel.G29();
43
 
43
 
44
   TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
44
   TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
45
 }
45
 }

+ 2
- 2
Marlin/src/gcode/bedlevel/ubl/M421.cpp View File

56
              hasZ = parser.seen('Z'),
56
              hasZ = parser.seen('Z'),
57
              hasQ = !hasZ && parser.seen('Q');
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
   // Test for bad parameter combinations
61
   // Test for bad parameter combinations
62
   if (int(hasC) + int(hasI && hasJ) != 1 || !(hasZ || hasQ || hasN))
62
   if (int(hasC) + int(hasI && hasJ) != 1 || !(hasZ || hasQ || hasN))
66
   else if (!WITHIN(ij.x, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(ij.y, 0, GRID_MAX_POINTS_Y - 1))
66
   else if (!WITHIN(ij.x, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(ij.y, 0, GRID_MAX_POINTS_Y - 1))
67
     SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
67
     SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
68
   else {
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
     zval = hasN ? NAN : parser.value_linear_units() + (hasQ ? zval : 0);  // N=NAN, Z=NEWVAL, or Q=ADDVAL
70
     zval = hasN ? NAN : parser.value_linear_units() + (hasQ ? zval : 0);  // N=NAN, Z=NEWVAL, or Q=ADDVAL
71
     TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ij.x, ij.y, zval));          // Ping ExtUI in case it's showing the mesh
71
     TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ij.x, ij.y, zval));          // Ping ExtUI in case it's showing the mesh
72
     TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ij.x, ij.y, zval));
72
     TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ij.x, ij.y, zval));

+ 1
- 1
Marlin/src/gcode/control/M17_M18_M84.cpp View File

233
     else
233
     else
234
       planner.finish_and_disable();
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 View File

111
     #endif
111
     #endif
112
 
112
 
113
     #if ENABLED(MESH_BED_LEVELING)
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
     #endif
115
     #endif
116
 
116
 
117
     #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
117
     #if ENABLED(BABYSTEP_DISPLAY_TOTAL)

+ 8
- 8
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp View File

1281
          * Show X and Y positions
1281
          * Show X and Y positions
1282
          */
1282
          */
1283
         _XLABEL(_PLOT_X, 0);
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
         _YLABEL(_LCD_W_POS, 0);
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
         lcd_moveto(_PLOT_X, 0);
1288
         lcd_moveto(_PLOT_X, 0);
1289
 
1289
 
1475
          * Print Z values
1475
          * Print Z values
1476
          */
1476
          */
1477
         _ZLABEL(_LCD_W_POS, 1);
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
         else
1480
         else
1481
           lcd_put_u8str(F(" -----"));
1481
           lcd_put_u8str(F(" -----"));
1482
 
1482
 
1486
          * Show all values at right of screen
1486
          * Show all values at right of screen
1487
          */
1487
          */
1488
         _XLABEL(_LCD_W_POS, 1);
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
         _YLABEL(_LCD_W_POS, 2);
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
          * Show the location value
1494
          * Show the location value
1495
          */
1495
          */
1496
         _ZLABEL(_LCD_W_POS, 3);
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
         else
1499
         else
1500
           lcd_put_u8str(F(" -----"));
1500
           lcd_put_u8str(F(" -----"));
1501
 
1501
 

+ 4
- 4
Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp View File

1069
 
1069
 
1070
       // Show all values
1070
       // Show all values
1071
       lcd.setCursor(_LCD_W_POS, 1); lcd_put_u8str(F("X:"));
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
       lcd.setCursor(_LCD_W_POS, 2); lcd_put_u8str(F("Y:"));
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
       // Show the location value
1076
       // Show the location value
1077
       lcd.setCursor(_LCD_W_POS, 3); lcd_put_u8str(F("Z:"));
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
       else
1081
       else
1082
         lcd_put_u8str(F(" -----"));
1082
         lcd_put_u8str(F(" -----"));
1083
 
1083
 

+ 5
- 5
Marlin/src/lcd/dogm/marlinui_DOGM.cpp View File

579
       u8g.setColorIndex(1);
579
       u8g.setColorIndex(1);
580
       const u8g_uint_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
580
       const u8g_uint_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
581
             u8g_uint_t  y = y_offset + pixels_per_y_mesh_pnt / 2;
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
         if (PAGE_CONTAINS(y, y))
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
             u8g.drawBox(x, y, 1, 1);
585
             u8g.drawBox(x, y, 1, 1);
586
 
586
 
587
       // Fill in the Specified Mesh Point
587
       // Fill in the Specified Mesh Point
601
       // Show X and Y positions at top of screen
601
       // Show X and Y positions at top of screen
602
       u8g.setColorIndex(1);
602
       u8g.setColorIndex(1);
603
       if (PAGE_UNDER(7)) {
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
                        lpos = pos.asLogical();
605
                        lpos = pos.asLogical();
606
         lcd_put_u8str_P(5, 7, X_LBL);
606
         lcd_put_u8str_P(5, 7, X_LBL);
607
         lcd_put_u8str(ftostr52(lpos.x));
607
         lcd_put_u8str(ftostr52(lpos.x));
619
 
619
 
620
         // Show the location value
620
         // Show the location value
621
         lcd_put_u8str_P(74, LCD_PIXEL_HEIGHT, Z_LBL);
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
         else
624
         else
625
           lcd_put_u8str(F(" -----"));
625
           lcd_put_u8str(F(" -----"));
626
       }
626
       }

+ 65
- 67
Marlin/src/lcd/e3v2/jyersui/dwin.cpp View File

207
         struct linear_fit_data lsf_results;
207
         struct linear_fit_data lsf_results;
208
         incremental_LSF_reset(&lsf_results);
208
         incremental_LSF_reset(&lsf_results);
209
         GRID_LOOP(x, y) {
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
           return true;
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
         matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
223
         matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
226
         GRID_LOOP(i, j) {
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
           if (DEBUGGING(LEVELING)) {
229
           if (DEBUGGING(LEVELING)) {
232
             DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
230
             DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
250
             DEBUG_DELAY(20);
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
         return false;
253
         return false;
256
       }
254
       }
268
     void manual_move(bool zmove=false) {
266
     void manual_move(bool zmove=false) {
269
       if (zmove) {
267
       if (zmove) {
270
         planner.synchronize();
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
         planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
270
         planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
273
         planner.synchronize();
271
         planner.synchronize();
274
       }
272
       }
279
         sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
277
         sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
280
         gcode.process_subcommands_now(cmd);
278
         gcode.process_subcommands_now(cmd);
281
         planner.synchronize();
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
         planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
281
         planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
284
         planner.synchronize();
282
         planner.synchronize();
285
         CrealityDWIN.Redraw_Menu();
283
         CrealityDWIN.Redraw_Menu();
289
     float get_max_value() {
287
     float get_max_value() {
290
       float max = __FLT_MIN__;
288
       float max = __FLT_MIN__;
291
       GRID_LOOP(x, y) {
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
       return max;
293
       return max;
296
     }
294
     }
298
     float get_min_value() {
296
     float get_min_value() {
299
       float min = __FLT_MAX__;
297
       float min = __FLT_MAX__;
300
       GRID_LOOP(x, y) {
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
       return min;
302
       return min;
305
     }
303
     }
306
 
304
 
307
     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) {
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
       drawing_mesh = true;
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
       const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
310
       const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
313
 
311
 
314
       // Clear background from previous selection and select new square
312
       // Clear background from previous selection and select new square
315
       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);
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
       if (selected >= 0) {
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
         const auto start_y_px = padding_y_top + selected_y * cell_height_px;
317
         const auto start_y_px = padding_y_top + selected_y * cell_height_px;
320
         const auto start_x_px = padding_x + selected_x * cell_width_px;
318
         const auto start_x_px = padding_x + selected_x * cell_width_px;
321
         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);
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
         const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
327
         const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
330
         const auto end_y_px   = start_y_px + cell_height_px - 1 - gridline_width;
328
         const auto end_y_px   = start_y_px + cell_height_px - 1 - gridline_width;
331
         DWIN_Draw_Rectangle(1,                                                                                 // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
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
           start_x_px, start_y_px, end_x_px, end_y_px
335
           start_x_px, start_y_px, end_x_px, end_y_px
338
         );
336
         );
339
 
337
 
343
         // Draw value text on
341
         // Draw value text on
344
         if (viewer_print_value) {
342
         if (viewer_print_value) {
345
           int8_t offset_x, offset_y = cell_height_px / 2 - 6;
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
             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"));
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
           else {                          // has value
347
           else {                          // has value
350
             if (GRID_MAX_POINTS_X < 10)
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
             else
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
             offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
352
             offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
355
             if (!(GRID_MAX_POINTS_X < 10))
353
             if (!(GRID_MAX_POINTS_X < 10))
356
               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("."));
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
 }
415
 }
418
 
416
 
419
 void CrealityDWINClass::Draw_Option(uint8_t value, const char * const * options, uint8_t row, bool selected/*=false*/, bool color/*=false*/) {
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
   DWIN_Draw_Rectangle(1, bColor, 202, MBASE(row) + 14, 258, MBASE(row) - 2);
420
   DWIN_Draw_Rectangle(1, bColor, 202, MBASE(row) + 14, 258, MBASE(row) - 2);
423
   DWIN_Draw_String(false, DWIN_FONT_MENU, tColor, bColor, 202, MBASE(row) - 1, options[value]);
421
   DWIN_Draw_String(false, DWIN_FONT_MENU, tColor, bColor, 202, MBASE(row) - 1, options[value]);
424
 }
422
 }
425
 
423
 
426
 uint16_t CrealityDWINClass::GetColor(uint8_t color, uint16_t original, bool light/*=false*/) {
424
 uint16_t CrealityDWINClass::GetColor(uint8_t color, uint16_t original, bool light/*=false*/) {
427
-  switch (color){
425
+  switch (color) {
428
     case Default:
426
     case Default:
429
       return original;
427
       return original;
430
       break;
428
       break;
2842
               if (draw)
2840
               if (draw)
2843
                 Draw_Menu_Item(row, ICON_Tilt, F("Autotilt Current Mesh"));
2841
                 Draw_Menu_Item(row, ICON_Tilt, F("Autotilt Current Mesh"));
2844
               else {
2842
               else {
2845
-                if (ubl.storage_slot < 0) {
2843
+                if (bedlevel.storage_slot < 0) {
2846
                   Popup_Handler(MeshSlot);
2844
                   Popup_Handler(MeshSlot);
2847
                   break;
2845
                   break;
2848
                 }
2846
                 }
2914
                 }
2912
                 }
2915
               #endif
2913
               #endif
2916
               #if ENABLED(AUTO_BED_LEVELING_UBL)
2914
               #if ENABLED(AUTO_BED_LEVELING_UBL)
2917
-                if (ubl.storage_slot < 0) {
2915
+                if (bedlevel.storage_slot < 0) {
2918
                   Popup_Handler(MeshSlot);
2916
                   Popup_Handler(MeshSlot);
2919
                   break;
2917
                   break;
2920
                 }
2918
                 }
2949
               Draw_Menu_Item(row, ICON_Mesh, GET_TEXT(MSG_MESH_VIEW), nullptr, true);
2947
               Draw_Menu_Item(row, ICON_Mesh, GET_TEXT(MSG_MESH_VIEW), nullptr, true);
2950
             else {
2948
             else {
2951
               #if ENABLED(AUTO_BED_LEVELING_UBL)
2949
               #if ENABLED(AUTO_BED_LEVELING_UBL)
2952
-                if (ubl.storage_slot < 0) {
2950
+                if (bedlevel.storage_slot < 0) {
2953
                   Popup_Handler(MeshSlot);
2951
                   Popup_Handler(MeshSlot);
2954
                   break;
2952
                   break;
2955
                 }
2953
                 }
2967
           case LEVELING_SLOT:
2965
           case LEVELING_SLOT:
2968
             if (draw) {
2966
             if (draw) {
2969
               Draw_Menu_Item(row, ICON_PrintSize, F("Mesh Slot"));
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
             else
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
             break;
2972
             break;
2975
           case LEVELING_LOAD:
2973
           case LEVELING_LOAD:
2976
             if (draw)
2974
             if (draw)
2977
               Draw_Menu_Item(row, ICON_ReadEEPROM, F("Load Mesh"));
2975
               Draw_Menu_Item(row, ICON_ReadEEPROM, F("Load Mesh"));
2978
             else {
2976
             else {
2979
-              if (ubl.storage_slot < 0) {
2977
+              if (bedlevel.storage_slot < 0) {
2980
                 Popup_Handler(MeshSlot);
2978
                 Popup_Handler(MeshSlot);
2981
                 break;
2979
                 break;
2982
               }
2980
               }
2989
             if (draw)
2987
             if (draw)
2990
               Draw_Menu_Item(row, ICON_WriteEEPROM, F("Save Mesh"));
2988
               Draw_Menu_Item(row, ICON_WriteEEPROM, F("Save Mesh"));
2991
             else {
2989
             else {
2992
-              if (ubl.storage_slot < 0) {
2990
+              if (bedlevel.storage_slot < 0) {
2993
                 Popup_Handler(MeshSlot);
2991
                 Popup_Handler(MeshSlot);
2994
                 break;
2992
                 break;
2995
               }
2993
               }
3098
               if (draw)
3096
               if (draw)
3099
                 Draw_Menu_Item(row, ICON_Mesh, F("Zero Current Mesh"));
3097
                 Draw_Menu_Item(row, ICON_Mesh, F("Zero Current Mesh"));
3100
               else
3098
               else
3101
-                ZERO(Z_VALUES_ARR);
3099
+                ZERO(bedlevel.z_values);
3102
               break;
3100
               break;
3103
             case LEVELING_SETTINGS_UNDEF:
3101
             case LEVELING_SETTINGS_UNDEF:
3104
               if (draw)
3102
               if (draw)
3105
                 Draw_Menu_Item(row, ICON_Mesh, F("Clear Current Mesh"));
3103
                 Draw_Menu_Item(row, ICON_Mesh, F("Clear Current Mesh"));
3106
               else
3104
               else
3107
-                ubl.invalidate();
3105
+                bedlevel.invalidate();
3108
               break;
3106
               break;
3109
           #endif // AUTO_BED_LEVELING_UBL
3107
           #endif // AUTO_BED_LEVELING_UBL
3110
         }
3108
         }
3146
               Draw_Menu_Item(row, ICON_Back, F("Back"));
3144
               Draw_Menu_Item(row, ICON_Back, F("Back"));
3147
             else {
3145
             else {
3148
               set_bed_leveling_enabled(level_state);
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
               Draw_Menu(Leveling, LEVELING_MANUAL);
3148
               Draw_Menu(Leveling, LEVELING_MANUAL);
3151
             }
3149
             }
3152
             break;
3150
             break;
3184
           case LEVELING_M_OFFSET:
3182
           case LEVELING_M_OFFSET:
3185
             if (draw) {
3183
             if (draw) {
3186
               Draw_Menu_Item(row, ICON_SetZOffset, F("Point Z Offset"));
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
             else {
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
             break;
3192
             break;
3195
           case LEVELING_M_UP:
3193
           case LEVELING_M_UP:
3196
             if (draw)
3194
             if (draw)
3197
               Draw_Menu_Item(row, ICON_Axis, F("Microstep Up"));
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
               gcode.process_subcommands_now(F("M290 Z0.01"));
3198
               gcode.process_subcommands_now(F("M290 Z0.01"));
3201
               planner.synchronize();
3199
               planner.synchronize();
3202
               current_position.z += 0.01f;
3200
               current_position.z += 0.01f;
3203
               sync_plan_position();
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
             break;
3204
             break;
3207
           case LEVELING_M_DOWN:
3205
           case LEVELING_M_DOWN:
3208
             if (draw)
3206
             if (draw)
3209
               Draw_Menu_Item(row, ICON_AxisD, F("Microstep Down"));
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
               gcode.process_subcommands_now(F("M290 Z-0.01"));
3210
               gcode.process_subcommands_now(F("M290 Z-0.01"));
3213
               planner.synchronize();
3211
               planner.synchronize();
3214
               current_position.z -= 0.01f;
3212
               current_position.z -= 0.01f;
3215
               sync_plan_position();
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
             break;
3216
             break;
3219
           case LEVELING_M_GOTO_VALUE:
3217
           case LEVELING_M_GOTO_VALUE:
3305
           case UBL_M_OFFSET:
3303
           case UBL_M_OFFSET:
3306
             if (draw) {
3304
             if (draw) {
3307
               Draw_Menu_Item(row, ICON_SetZOffset, F("Point Z Offset"));
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
             else {
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
             break;
3313
             break;
3316
           case UBL_M_UP:
3314
           case UBL_M_UP:
3317
             if (draw)
3315
             if (draw)
3318
               Draw_Menu_Item(row, ICON_Axis, F("Microstep Up"));
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
               gcode.process_subcommands_now(F("M290 Z0.01"));
3319
               gcode.process_subcommands_now(F("M290 Z0.01"));
3322
               planner.synchronize();
3320
               planner.synchronize();
3323
               current_position.z += 0.01f;
3321
               current_position.z += 0.01f;
3324
               sync_plan_position();
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
             break;
3325
             break;
3328
           case UBL_M_DOWN:
3326
           case UBL_M_DOWN:
3329
             if (draw)
3327
             if (draw)
3330
               Draw_Menu_Item(row, ICON_Axis, F("Microstep Down"));
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
               gcode.process_subcommands_now(F("M290 Z-0.01"));
3331
               gcode.process_subcommands_now(F("M290 Z-0.01"));
3334
               planner.synchronize();
3332
               planner.synchronize();
3335
               current_position.z -= 0.01f;
3333
               current_position.z -= 0.01f;
3336
               sync_plan_position();
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
             break;
3337
             break;
3340
         }
3338
         }
3418
           case MMESH_OLD:
3416
           case MMESH_OLD:
3419
             uint8_t mesh_x, mesh_y;
3417
             uint8_t mesh_x, mesh_y;
3420
             // 0,0 -> 1,0 -> 2,0 -> 2,1 -> 1,1 -> 0,1 -> 0,2 -> 1,2 -> 2,2
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
             if (mesh_y % 2 == 1)
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
             if (draw) {
3427
             if (draw) {
3430
               Draw_Menu_Item(row, ICON_Zoffset, F("Goto Mesh Value"));
3428
               Draw_Menu_Item(row, ICON_Zoffset, F("Goto Mesh Value"));
4283
 
4281
 
4284
       #if ENABLED(AUTO_BED_LEVELING_UBL)
4282
       #if ENABLED(AUTO_BED_LEVELING_UBL)
4285
         case MeshSlot:
4283
         case MeshSlot:
4286
-          if (selection == 0) ubl.storage_slot = 0;
4284
+          if (selection == 0) bedlevel.storage_slot = 0;
4287
           Redraw_Menu(true, true);
4285
           Redraw_Menu(true, true);
4288
           break;
4286
           break;
4289
       #endif
4287
       #endif

+ 5
- 5
Marlin/src/lcd/e3v2/marlinui/ui_common.cpp View File

516
       // Display Mesh Point Locations
516
       // Display Mesh Point Locations
517
       const dwin_coord_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
517
       const dwin_coord_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
518
             dwin_coord_t  y = y_offset + pixels_per_y_mesh_pnt / 2;
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
           DWIN_Draw_Point(Color_White, 1, 1, x, y);
521
           DWIN_Draw_Point(Color_White, 1, 1, x, y);
522
 
522
 
523
       // Put Relevant Text on Display
523
       // Put Relevant Text on Display
525
       // Show X and Y positions at top of screen
525
       // Show X and Y positions at top of screen
526
       dwin_font.fg = Color_White;
526
       dwin_font.fg = Color_White;
527
       dwin_font.solid = true;
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
                      lpos = pos.asLogical();
529
                      lpos = pos.asLogical();
530
 
530
 
531
       lcd_moveto(
531
       lcd_moveto(
555
 
555
 
556
       // Show the location value
556
       // Show the location value
557
       dwin_string.set(Z_LBL);
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
       else
560
       else
561
         dwin_string.add(PSTR(" -----"));
561
         dwin_string.add(PSTR(" -----"));
562
       lcd_moveto(
562
       lcd_moveto(

+ 16
- 16
Marlin/src/lcd/e3v2/proui/dwin.cpp View File

3611
   #define Z_OFFSET_MIN -3
3611
   #define Z_OFFSET_MIN -3
3612
   #define Z_OFFSET_MAX  3
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
   void ApplyEditMeshX() { mesh_x = MenuData.Value; }
3615
   void ApplyEditMeshX() { mesh_x = MenuData.Value; }
3616
   void SetEditMeshX() { HMI_value.Select = 0; SetIntOnClick(0, GRID_MAX_POINTS_X - 1, mesh_x, ApplyEditMeshX, LiveEditMesh); }
3616
   void SetEditMeshX() { HMI_value.Select = 0; SetIntOnClick(0, GRID_MAX_POINTS_X - 1, mesh_x, ApplyEditMeshX, LiveEditMesh); }
3617
   void ApplyEditMeshY() { mesh_y = MenuData.Value; }
3617
   void ApplyEditMeshY() { mesh_y = MenuData.Value; }
3622
 
3622
 
3623
 #if ENABLED(AUTO_BED_LEVELING_UBL)
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
   void onDrawUBLSlot(MenuItemClass* menuitem, int8_t line) {
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
   void ApplyUBLTiltGrid() { ubl_tools.tilt_grid = MenuData.Value; }
3632
   void ApplyUBLTiltGrid() { ubl_tools.tilt_grid = MenuData.Value; }
3633
   void SetUBLTiltGrid() { SetIntOnClick(1, 3, ubl_tools.tilt_grid, ApplyUBLTiltGrid); }
3633
   void SetUBLTiltGrid() { SetIntOnClick(1, 3, ubl_tools.tilt_grid, ApplyUBLTiltGrid); }
3634
 
3634
 
3635
   void UBLTiltMesh() {
3635
   void UBLTiltMesh() {
3636
-    if (ubl.storage_slot < 0) ubl.storage_slot = 0;
3636
+    if (bedlevel.storage_slot < 0) bedlevel.storage_slot = 0;
3637
     char buf[15];
3637
     char buf[15];
3638
     if (ubl_tools.tilt_grid > 1) {
3638
     if (ubl_tools.tilt_grid > 1) {
3639
       sprintf_P(buf, PSTR("G28O\nG29 J%i"), ubl_tools.tilt_grid);
3639
       sprintf_P(buf, PSTR("G28O\nG29 J%i"), ubl_tools.tilt_grid);
3645
   }
3645
   }
3646
 
3646
 
3647
   void UBLSmartFillMesh() {
3647
   void UBLSmartFillMesh() {
3648
-    ubl.smart_fill_mesh();
3648
+    bedlevel.smart_fill_mesh();
3649
     LCD_MESSAGE(MSG_UBL_MESH_FILLED);
3649
     LCD_MESSAGE(MSG_UBL_MESH_FILLED);
3650
   }
3650
   }
3651
 
3651
 
3652
   bool UBLValidMesh() {
3652
   bool UBLValidMesh() {
3653
     const bool valid = ubl_tools.validate();
3653
     const bool valid = ubl_tools.validate();
3654
-    if (!valid) ubl.invalidate();
3654
+    if (!valid) bedlevel.invalidate();
3655
     return valid;
3655
     return valid;
3656
   }
3656
   }
3657
 
3657
 
3658
   void UBLSaveMesh() {
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
     DONE_BUZZ(true);
3662
     DONE_BUZZ(true);
3663
   }
3663
   }
3664
 
3664
 
3665
   void UBLLoadMesh() {
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
     if (UBLValidMesh()) {
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
       DONE_BUZZ(true);
3670
       DONE_BUZZ(true);
3671
     }
3671
     }
3672
     else {
3672
     else {
3691
         MENU_ITEM_F(ICON_Level, MSG_AUTO_MESH, onDrawMenuItem, AutoLev);
3691
         MENU_ITEM_F(ICON_Level, MSG_AUTO_MESH, onDrawMenuItem, AutoLev);
3692
       #endif
3692
       #endif
3693
       #if ENABLED(AUTO_BED_LEVELING_UBL)
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
         MENU_ITEM_F(ICON_UBLActive, MSG_UBL_SAVE_MESH, onDrawMenuItem, UBLSaveMesh);
3695
         MENU_ITEM_F(ICON_UBLActive, MSG_UBL_SAVE_MESH, onDrawMenuItem, UBLSaveMesh);
3696
         MENU_ITEM_F(ICON_UBLActive, MSG_UBL_LOAD_MESH, onDrawMenuItem, UBLLoadMesh);
3696
         MENU_ITEM_F(ICON_UBLActive, MSG_UBL_LOAD_MESH, onDrawMenuItem, UBLLoadMesh);
3697
         EDIT_ITEM_F(ICON_UBLActive, MSG_UBL_TILTING_GRID, onDrawPInt8Menu, SetUBLTiltGrid, &ubl_tools.tilt_grid);
3697
         EDIT_ITEM_F(ICON_UBLActive, MSG_UBL_TILTING_GRID, onDrawPInt8Menu, SetUBLTiltGrid, &ubl_tools.tilt_grid);
3714
         BACK_ITEM(Draw_MeshSet_Menu);
3714
         BACK_ITEM(Draw_MeshSet_Menu);
3715
         EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_X, onDrawPInt8Menu, SetEditMeshX, &mesh_x);
3715
         EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_X, onDrawPInt8Menu, SetEditMeshX, &mesh_x);
3716
         EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_Y, onDrawPInt8Menu, SetEditMeshY, &mesh_y);
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
       UpdateMenu(EditMeshMenu);
3719
       UpdateMenu(EditMeshMenu);
3720
     }
3720
     }

+ 1
- 1
Marlin/src/lcd/e3v2/proui/meshviewer.cpp View File

117
     ubl_tools.viewer_print_value = true;
117
     ubl_tools.viewer_print_value = true;
118
     ubl_tools.Draw_Bed_Mesh(-1, 1, 8, 10 + TITLE_HEIGHT);
118
     ubl_tools.Draw_Bed_Mesh(-1, 1, 8, 10 + TITLE_HEIGHT);
119
   #else
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
   #endif
121
   #endif
122
   if (withsave) {
122
   if (withsave) {
123
     DWINUI::Draw_Button(BTN_Save, 26, 305);
123
     DWINUI::Draw_Button(BTN_Save, 26, 305);

+ 31
- 34
Marlin/src/lcd/e3v2/proui/ubl_tools.cpp View File

63
     struct linear_fit_data lsf_results;
63
     struct linear_fit_data lsf_results;
64
     incremental_LSF_reset(&lsf_results);
64
     incremental_LSF_reset(&lsf_results);
65
     GRID_LOOP(x, y) {
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
       return true;
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
     matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
79
     matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
82
     GRID_LOOP(i, j) {
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
       if (DEBUGGING(LEVELING)) {
85
       if (DEBUGGING(LEVELING)) {
88
         DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
86
         DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
106
         DEBUG_DELAY(20);
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
     return false;
109
     return false;
112
   }
110
   }
124
 void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/*=false*/) {
122
 void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/*=false*/) {
125
   if (zmove) {
123
   if (zmove) {
126
     planner.synchronize();
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
     planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
126
     planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
129
     planner.synchronize();
127
     planner.synchronize();
130
   }
128
   }
136
     sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
134
     sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
137
     gcode.process_subcommands_now(cmd);
135
     gcode.process_subcommands_now(cmd);
138
     planner.synchronize();
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
     planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
138
     planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
141
     planner.synchronize();
139
     planner.synchronize();
142
     HMI_ReturnScreen();
140
     HMI_ReturnScreen();
146
 float UBLMeshToolsClass::get_max_value() {
144
 float UBLMeshToolsClass::get_max_value() {
147
   float max = __FLT_MIN__;
145
   float max = __FLT_MIN__;
148
   GRID_LOOP(x, y) {
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
   return max;
150
   return max;
153
 }
151
 }
155
 float UBLMeshToolsClass::get_min_value() {
153
 float UBLMeshToolsClass::get_min_value() {
156
   float min = __FLT_MAX__;
154
   float min = __FLT_MAX__;
157
   GRID_LOOP(x, y) {
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
   return min;
159
   return min;
162
 }
160
 }
163
 
161
 
164
 bool UBLMeshToolsClass::validate() {
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
   GRID_LOOP(x, y) {
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
   return max <= UBL_Z_OFFSET_MAX && min >= UBL_Z_OFFSET_MIN;
170
   return max <= UBL_Z_OFFSET_MAX && min >= UBL_Z_OFFSET_MIN;
174
 }
171
 }
177
   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*/) {
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
     drawing_mesh = true;
175
     drawing_mesh = true;
179
     const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
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
     const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
179
     const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
183
 
180
 
184
     // Clear background from previous selection and select new square
181
     // Clear background from previous selection and select new square
185
     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);
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
     if (selected >= 0) {
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
       const auto start_y_px = padding_y_top + selected_y * cell_height_px;
186
       const auto start_y_px = padding_y_top + selected_y * cell_height_px;
190
       const auto start_x_px = padding_x + selected_x * cell_width_px;
187
       const auto start_x_px = padding_x + selected_x * cell_width_px;
191
       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);
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
     GRID_LOOP(x, y) {
193
     GRID_LOOP(x, y) {
197
       const auto start_x_px = padding_x + x * cell_width_px;
194
       const auto start_x_px = padding_x + x * cell_width_px;
198
       const auto end_x_px   = start_x_px + cell_width_px - 1 - gridline_width;
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
       const auto end_y_px   = start_y_px + cell_height_px - 1 - gridline_width;
197
       const auto end_y_px   = start_y_px + cell_height_px - 1 - gridline_width;
201
       DWIN_Draw_Rectangle(1,                                                                                 // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
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
         start_x_px, start_y_px, end_x_px, end_y_px
204
         start_x_px, start_y_px, end_x_px, end_y_px
208
       );
205
       );
209
 
206
 
213
       // Draw value text on
210
       // Draw value text on
214
       if (viewer_print_value) {
211
       if (viewer_print_value) {
215
         int8_t offset_x, offset_y = cell_height_px / 2 - 6;
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
           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"));
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
         else {                          // has value
216
         else {                          // has value
220
           if (GRID_MAX_POINTS_X < 10)
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
           else
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
           offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
221
           offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
225
           if (!(GRID_MAX_POINTS_X < 10))
222
           if (!(GRID_MAX_POINTS_X < 10))
226
             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("."));
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 View File

341
   int16_t fixed;
341
   int16_t fixed;
342
 
342
 
343
   for (int i = 0; i < DGUS_LEVEL_GRID_SIZE; i++) {
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
     fixed = dgus_display.ToFixedPoint<float, int16_t, 3>(ExtUI::getMeshPoint(point));
346
     fixed = dgus_display.ToFixedPoint<float, int16_t, 3>(ExtUI::getMeshPoint(point));
347
     data[i] = Swap16(fixed);
347
     data[i] = Swap16(fixed);
348
   }
348
   }

+ 3
- 3
Marlin/src/lcd/extui/ui_api.cpp View File

919
 
919
 
920
     #if HAS_MESH
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
       void setMeshPoint(const xy_uint8_t &pos, const_float_t zoff) {
924
       void setMeshPoint(const xy_uint8_t &pos, const_float_t zoff) {
925
         if (WITHIN(pos.x, 0, (GRID_MAX_POINTS_X) - 1) && WITHIN(pos.y, 0, (GRID_MAX_POINTS_Y) - 1)) {
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
           TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
927
           TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
928
         }
928
         }
929
       }
929
       }

+ 1
- 1
Marlin/src/lcd/marlinui.cpp View File

863
 
863
 
864
       void MarlinUI::external_encoder() {
864
       void MarlinUI::external_encoder() {
865
         if (external_control && encoderDiff) {
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
           encoderDiff = 0;                  // Hide encoder events from the screen handler
867
           encoderDiff = 0;                  // Hide encoder events from the screen handler
868
           refresh(LCDVIEW_REDRAW_NOW);      // ...but keep the refresh.
868
           refresh(LCDVIEW_REDRAW_NOW);      // ...but keep the refresh.
869
         }
869
         }

+ 2
- 2
Marlin/src/lcd/menu/menu.cpp View File

203
     if (on_status_screen()) {
203
     if (on_status_screen()) {
204
       defer_status_screen(false);
204
       defer_status_screen(false);
205
       clear_menu_history();
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
     clear_lcd();
209
     clear_lcd();
210
 
210
 
211
     // Re-initialize custom characters that may be re-used
211
     // Re-initialize custom characters that may be re-used
212
     #if HAS_MARLINUI_HD44780
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
         set_custom_characters(on_status_screen() ? CHARSET_INFO : CHARSET_MENU);
214
         set_custom_characters(on_status_screen() ? CHARSET_INFO : CHARSET_MENU);
215
     #endif
215
     #endif
216
 
216
 

+ 2
- 2
Marlin/src/lcd/menu/menu_bed_leveling.cpp View File

214
     BACK_ITEM(MSG_BED_LEVELING);
214
     BACK_ITEM(MSG_BED_LEVELING);
215
     EDIT_ITEM(uint8, MSG_MESH_X, &xind, 0, (GRID_MAX_POINTS_X) - 1);
215
     EDIT_ITEM(uint8, MSG_MESH_X, &xind, 0, (GRID_MAX_POINTS_X) - 1);
216
     EDIT_ITEM(uint8, MSG_MESH_Y, &yind, 0, (GRID_MAX_POINTS_Y) - 1);
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
     END_MENU();
218
     END_MENU();
219
   }
219
   }
220
 
220
 
281
     #else
281
     #else
282
       #define LCD_Z_OFFSET_TYPE float42_52 // Values from -99.99 to 99.99
282
       #define LCD_Z_OFFSET_TYPE float42_52 // Values from -99.99 to 99.99
283
     #endif
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
   #endif
285
   #endif
286
 
286
 
287
   #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
287
   #if ENABLED(BABYSTEP_ZPROBE_OFFSET)

+ 1
- 1
Marlin/src/lcd/menu/menu_tune.cpp View File

118
   // Manual bed leveling, Bed Z:
118
   // Manual bed leveling, Bed Z:
119
   //
119
   //
120
   #if BOTH(MESH_BED_LEVELING, LCD_BED_LEVELING)
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
   #endif
122
   #endif
123
 
123
 
124
   //
124
   //

+ 13
- 13
Marlin/src/lcd/menu/menu_ubl.cpp View File

58
 
58
 
59
 /**
59
 /**
60
  * This screen displays the temporary mesh value and updates it based on encoder
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
  * the current value via ubl_mesh_value, moves the Z axis, and updates the mesh
62
  * the current value via ubl_mesh_value, moves the Z axis, and updates the mesh
63
  * value until the encoder button is pressed.
63
  * value until the encoder button is pressed.
64
  *
64
  *
70
 void _lcd_mesh_fine_tune(PGM_P const msg) {
70
 void _lcd_mesh_fine_tune(PGM_P const msg) {
71
   constexpr float mesh_edit_step = 1.0f / 200.0f;
71
   constexpr float mesh_edit_step = 1.0f / 200.0f;
72
   ui.defer_status_screen();
72
   ui.defer_status_screen();
73
-  if (ubl.encoder_diff) {
73
+  if (bedlevel.encoder_diff) {
74
     mesh_edit_accumulator += TERN(IS_TFTGLCD_PANEL,
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
     IF_DISABLED(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
79
     IF_DISABLED(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
80
   }
80
   }
81
   TERN_(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
81
   TERN_(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
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
 // To capture encoder events UBL will also call ui.capture and ui.release.
93
 // To capture encoder events UBL will also call ui.capture and ui.release.
94
 //
94
 //
95
 void MarlinUI::ubl_mesh_edit_start(const_float_t initial) {
95
 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
 float MarlinUI::ubl_mesh_value() { return rounded_mesh_value(); }
104
 float MarlinUI::ubl_mesh_value() { return rounded_mesh_value(); }
105
 
105
 
291
 }
291
 }
292
 
292
 
293
 void _lcd_ubl_invalidate() {
293
 void _lcd_ubl_invalidate() {
294
-  ubl.invalidate();
294
+  bedlevel.invalidate();
295
   SERIAL_ECHOLNPGM("Mesh invalidated.");
295
   SERIAL_ECHOLNPGM("Mesh invalidated.");
296
 }
296
 }
297
 
297
 
390
  */
390
  */
391
 void _lcd_ubl_map_edit_cmd() {
391
 void _lcd_ubl_map_edit_cmd() {
392
   char ubl_lcd_gcode[50], str[10], str2[10];
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
   snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29P4X%sY%sR%i"), str, str2, int(n_edit_pts));
395
   snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29P4X%sY%sR%i"), str, str2, int(n_edit_pts));
396
   queue.inject(ubl_lcd_gcode);
396
   queue.inject(ubl_lcd_gcode);
397
 }
397
 }
400
  * UBL LCD Map Movement
400
  * UBL LCD Map Movement
401
  */
401
  */
402
 void ubl_map_move_to_xy() {
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
   // Some printers have unreachable areas in the mesh. Skip the move if unreachable.
405
   // Some printers have unreachable areas in the mesh. Skip the move if unreachable.
406
   if (!position_is_reachable(xy)) return;
406
   if (!position_is_reachable(xy)) return;
459
 
459
 
460
       // Validate if needed
460
       // Validate if needed
461
       #if IS_KINEMATIC
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
         if (position_is_reachable(xy)) break; // Found a valid point
463
         if (position_is_reachable(xy)) break; // Found a valid point
464
         ui.encoderPosition += step_dir;       // Test the next point
464
         ui.encoderPosition += step_dir;       // Test the next point
465
       #endif
465
       #endif
500
   ui.defer_status_screen();
500
   ui.defer_status_screen();
501
   _lcd_draw_homing();
501
   _lcd_draw_homing();
502
   if (all_axes_homed()) {
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
     ui.goto_screen(ubl_map_screen, grid_index(x_plot, y_plot)); // Pre-set the encoder value
504
     ui.goto_screen(ubl_map_screen, grid_index(x_plot, y_plot)); // Pre-set the encoder value
505
     ui.manual_move.menu_scale = 0;  // Immediate move
505
     ui.manual_move.menu_scale = 0;  // Immediate move
506
     ubl_map_move_to_xy();           // Move to current mesh point
506
     ubl_map_move_to_xy();           // Move to current mesh point

+ 2
- 2
Marlin/src/lcd/tft/touch.cpp View File

180
       ui.refresh();
180
       ui.refresh();
181
       break;
181
       break;
182
     case SLIDER:    hold(control); ui.encoderPosition = (x - control->x) * control->data / control->width; break;
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
     case HEATER:
185
     case HEATER:
186
       int8_t heater;
186
       int8_t heater;
187
       heater = control->data;
187
       heater = control->data;

+ 7
- 7
Marlin/src/lcd/tft/ui_1024x600.cpp View File

501
     tft.set_background(COLOR_BACKGROUND);
501
     tft.set_background(COLOR_BACKGROUND);
502
     tft.add_rectangle(0, 0, GRID_WIDTH, GRID_HEIGHT, COLOR_WHITE);
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
                    lpos = pos.asLogical();
512
                    lpos = pos.asLogical();
513
 
513
 
514
     tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
514
     tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
531
     tft.set_background(COLOR_BACKGROUND);
531
     tft.set_background(COLOR_BACKGROUND);
532
     tft_string.set(Z_LBL);
532
     tft_string.set(Z_LBL);
533
     tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
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
     tft_string.trim();
535
     tft_string.trim();
536
     tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
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 View File

485
 
485
 
486
     for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++)
486
     for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++)
487
       for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++)
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
           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);
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
     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);
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
                    lpos = pos.asLogical();
494
                    lpos = pos.asLogical();
495
 
495
 
496
     tft.canvas(216, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 96, MENU_ITEM_HEIGHT);
496
     tft.canvas(216, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 96, MENU_ITEM_HEIGHT);
513
     tft.set_background(COLOR_BACKGROUND);
513
     tft.set_background(COLOR_BACKGROUND);
514
     tft_string.set(Z_LBL);
514
     tft_string.set(Z_LBL);
515
     tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
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
     tft_string.trim();
517
     tft_string.trim();
518
     tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
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 View File

490
 
490
 
491
     for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++)
491
     for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++)
492
       for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++)
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
           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);
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
     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);
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
                    lpos = pos.asLogical();
499
                    lpos = pos.asLogical();
500
 
500
 
501
     tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
501
     tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
518
     tft.set_background(COLOR_BACKGROUND);
518
     tft.set_background(COLOR_BACKGROUND);
519
     tft_string.set(Z_LBL);
519
     tft_string.set(Z_LBL);
520
     tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
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
     tft_string.trim();
522
     tft_string.trim();
523
     tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
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 View File

427
 
427
 
428
     #if UBL_SEGMENTED
428
     #if UBL_SEGMENTED
429
       // UBL segmented line will do Z-only moves in single segment
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
     #else
431
     #else
432
       if (current_position == destination) return;
432
       if (current_position == destination) return;
433
 
433
 
995
    * small incremental moves for DELTA or SCARA.
995
    * small incremental moves for DELTA or SCARA.
996
    *
996
    *
997
    * For Unified Bed Leveling (Delta or Segmented Cartesian)
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
    * For Auto Bed Leveling (Bilinear) with SEGMENT_LEVELED_MOVES
1000
    * For Auto Bed Leveling (Bilinear) with SEGMENT_LEVELED_MOVES
1001
    * this is replaced by segmented_line_to_destination below.
1001
    * this is replaced by segmented_line_to_destination below.
1151
     #if HAS_MESH
1151
     #if HAS_MESH
1152
       if (planner.leveling_active && planner.leveling_active_at_z(destination.z)) {
1152
       if (planner.leveling_active && planner.leveling_active_at_z(destination.z)) {
1153
         #if ENABLED(AUTO_BED_LEVELING_UBL)
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
           return true;                                                        // all moves, including Z-only moves.
1155
           return true;                                                        // all moves, including Z-only moves.
1156
         #elif ENABLED(SEGMENT_LEVELED_MOVES)
1156
         #elif ENABLED(SEGMENT_LEVELED_MOVES)
1157
           segmented_line_to_destination(scaled_fr_mm_s);
1157
           segmented_line_to_destination(scaled_fr_mm_s);
1163
            */
1163
            */
1164
           if (xy_pos_t(current_position) != xy_pos_t(destination)) {
1164
           if (xy_pos_t(current_position) != xy_pos_t(destination)) {
1165
             #if ENABLED(MESH_BED_LEVELING)
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
             #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
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
             #endif
1169
             #endif
1170
             return true;
1170
             return true;
1171
           }
1171
           }
1363
   if (
1363
   if (
1364
     #if UBL_SEGMENTED
1364
     #if UBL_SEGMENTED
1365
       #if IS_KINEMATIC // UBL using Kinematic / Cartesian cases as a workaround for now.
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
       #else
1367
       #else
1368
         line_to_destination_cartesian()
1368
         line_to_destination_cartesian()
1369
       #endif
1369
       #endif

+ 9
- 23
Marlin/src/module/planner.cpp View File

1587
 
1587
 
1588
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1588
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1589
         const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
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
       #endif
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
     #endif
1597
     #endif
1605
   }
1598
   }
1618
 
1611
 
1619
       #elif HAS_MESH
1612
       #elif HAS_MESH
1620
 
1613
 
1614
+        TERN_(MESH_BED_LEVELING, raw.z -= bedlevel.get_z_offset());
1615
+
1621
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1616
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1622
           const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
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
         #endif
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
       #endif
1623
       #endif
1638
     }
1624
     }
1639
   }
1625
   }

+ 45
- 44
Marlin/src/module/settings.cpp View File

247
   //
247
   //
248
   // MESH_BED_LEVELING
248
   // MESH_BED_LEVELING
249
   //
249
   //
250
-  float mbl_z_offset;                                   // mbl.z_offset
250
+  float mbl_z_offset;                                   // bedlevel.z_offset
251
   uint8_t mesh_num_x, mesh_num_y;                       // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
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
                     [TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3)];
253
                     [TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3)];
254
 
254
 
255
   //
255
   //
287
   // AUTO_BED_LEVELING_UBL
287
   // AUTO_BED_LEVELING_UBL
288
   //
288
   //
289
   bool planner_leveling_active;                         // M420 S  planner.leveling_active
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
   // SERVO_ANGLES
293
   // SERVO_ANGLES
615
 
615
 
616
   TERN_(ENABLE_LEVELING_FADE_HEIGHT, set_z_fade_height(new_z_fade_height, false)); // false = no report
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
   TERN_(HAS_MOTOR_CURRENT_PWM, stepper.refresh_motor_power());
620
   TERN_(HAS_MOTOR_CURRENT_PWM, stepper.refresh_motor_power());
621
 
621
 
844
     {
844
     {
845
       #if ENABLED(MESH_BED_LEVELING)
845
       #if ENABLED(MESH_BED_LEVELING)
846
         static_assert(
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
           "MBL Z array is the wrong size."
848
           "MBL Z array is the wrong size."
849
         );
849
         );
850
       #else
850
       #else
854
       const uint8_t mesh_num_x = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3),
854
       const uint8_t mesh_num_x = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3),
855
                     mesh_num_y = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3);
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
       EEPROM_WRITE(mesh_num_x);
858
       EEPROM_WRITE(mesh_num_x);
859
       EEPROM_WRITE(mesh_num_y);
859
       EEPROM_WRITE(mesh_num_y);
860
 
860
 
861
       #if ENABLED(MESH_BED_LEVELING)
861
       #if ENABLED(MESH_BED_LEVELING)
862
-        EEPROM_WRITE(mbl.z_values);
862
+        EEPROM_WRITE(bedlevel.z_values);
863
       #else
863
       #else
864
         for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummyf);
864
         for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummyf);
865
       #endif
865
       #endif
896
     {
896
     {
897
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
897
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
898
         static_assert(
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
           "Bilinear Z array is the wrong size."
900
           "Bilinear Z array is the wrong size."
901
         );
901
         );
902
       #endif
902
       #endif
906
       EEPROM_WRITE(grid_max_x);
906
       EEPROM_WRITE(grid_max_x);
907
       EEPROM_WRITE(grid_max_y);
907
       EEPROM_WRITE(grid_max_y);
908
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
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
       #else
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
         EEPROM_WRITE(bilinear_grid_spacing);
913
         EEPROM_WRITE(bilinear_grid_spacing);
914
         EEPROM_WRITE(bilinear_start);
914
         EEPROM_WRITE(bilinear_start);
915
       #endif
915
       #endif
916
 
916
 
917
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
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
       #else
919
       #else
920
         dummyf = 0;
920
         dummyf = 0;
921
         for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
921
         for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
938
     {
938
     {
939
       _FIELD_TEST(planner_leveling_active);
939
       _FIELD_TEST(planner_leveling_active);
940
       const bool ubl_active = TERN(AUTO_BED_LEVELING_UBL, planner.leveling_active, false);
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
       EEPROM_WRITE(ubl_active);
942
       EEPROM_WRITE(ubl_active);
943
       EEPROM_WRITE(storage_slot);
943
       EEPROM_WRITE(storage_slot);
944
     }
944
     }
1638
     // UBL Mesh
1638
     // UBL Mesh
1639
     //
1639
     //
1640
     #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
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
     #endif
1643
     #endif
1644
 
1644
 
1645
     if (!eeprom_error) {
1645
     if (!eeprom_error) {
1796
         EEPROM_READ_ALWAYS(mesh_num_y);
1796
         EEPROM_READ_ALWAYS(mesh_num_y);
1797
 
1797
 
1798
         #if ENABLED(MESH_BED_LEVELING)
1798
         #if ENABLED(MESH_BED_LEVELING)
1799
-          if (!validating) mbl.z_offset = dummyf;
1799
+          if (!validating) bedlevel.z_offset = dummyf;
1800
           if (mesh_num_x == (GRID_MAX_POINTS_X) && mesh_num_y == (GRID_MAX_POINTS_Y)) {
1800
           if (mesh_num_x == (GRID_MAX_POINTS_X) && mesh_num_y == (GRID_MAX_POINTS_Y)) {
1801
             // EEPROM data fits the current mesh
1801
             // EEPROM data fits the current mesh
1802
-            EEPROM_READ(mbl.z_values);
1802
+            EEPROM_READ(bedlevel.z_values);
1803
           }
1803
           }
1804
           else {
1804
           else {
1805
             // EEPROM data is stale
1805
             // EEPROM data is stale
1806
-            if (!validating) mbl.reset();
1806
+            if (!validating) bedlevel.reset();
1807
             for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
1807
             for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
1808
           }
1808
           }
1809
         #else
1809
         #else
1810
           // MBL is disabled - skip the stored data
1810
           // MBL is disabled - skip the stored data
1811
           for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
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
         #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
1849
         #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
1850
           if (grid_max_x == (GRID_MAX_POINTS_X) && grid_max_y == (GRID_MAX_POINTS_Y)) {
1850
           if (grid_max_x == (GRID_MAX_POINTS_X) && grid_max_y == (GRID_MAX_POINTS_Y)) {
1851
             if (!validating) set_bed_leveling_enabled(false);
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
           else // EEPROM data is stale
1855
           else // EEPROM data is stale
1856
         #endif // AUTO_BED_LEVELING_BILINEAR
1856
         #endif // AUTO_BED_LEVELING_BILINEAR
1877
         _FIELD_TEST(planner_leveling_active);
1877
         _FIELD_TEST(planner_leveling_active);
1878
         #if ENABLED(AUTO_BED_LEVELING_UBL)
1878
         #if ENABLED(AUTO_BED_LEVELING_UBL)
1879
           const bool &planner_leveling_active = planner.leveling_active;
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
         #else
1881
         #else
1882
           bool planner_leveling_active;
1882
           bool planner_leveling_active;
1883
           int8_t ubl_storage_slot;
1883
           int8_t ubl_storage_slot;
2617
 
2617
 
2618
       #if ENABLED(AUTO_BED_LEVELING_UBL)
2618
       #if ENABLED(AUTO_BED_LEVELING_UBL)
2619
         if (!validating) {
2619
         if (!validating) {
2620
-          ubl.report_state();
2620
+          bedlevel.report_state();
2621
 
2621
 
2622
-          if (!ubl.sanity_check()) {
2622
+          if (!bedlevel.sanity_check()) {
2623
             #if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
2623
             #if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
2624
-              ubl.echo_name();
2624
+              bedlevel.echo_name();
2625
               DEBUG_ECHOLNPGM(" initialized.\n");
2625
               DEBUG_ECHOLNPGM(" initialized.\n");
2626
             #endif
2626
             #endif
2627
           }
2627
           }
2629
             eeprom_error = true;
2629
             eeprom_error = true;
2630
             #if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
2630
             #if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
2631
               DEBUG_ECHOPGM("?Can't enable ");
2631
               DEBUG_ECHOPGM("?Can't enable ");
2632
-              ubl.echo_name();
2632
+              bedlevel.echo_name();
2633
               DEBUG_ECHOLNPGM(".");
2633
               DEBUG_ECHOLNPGM(".");
2634
             #endif
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
           else {
2642
           else {
2643
-            ubl.reset();
2643
+            bedlevel.reset();
2644
             DEBUG_ECHOLNPGM("UBL reset");
2644
             DEBUG_ECHOLNPGM("UBL reset");
2645
           }
2645
           }
2646
         }
2646
         }
2708
       return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8;
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
     uint16_t MarlinSettings::calc_num_meshes() {
2713
     uint16_t MarlinSettings::calc_num_meshes() {
2714
       return (meshes_end - meshes_start_index()) / MESH_STORE_SIZE;
2714
       return (meshes_end - meshes_start_index()) / MESH_STORE_SIZE;
2734
 
2734
 
2735
         #if ENABLED(OPTIMIZED_MESH_STORAGE)
2735
         #if ENABLED(OPTIMIZED_MESH_STORAGE)
2736
           int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
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
           uint8_t * const src = (uint8_t*)&z_mesh_store;
2738
           uint8_t * const src = (uint8_t*)&z_mesh_store;
2739
         #else
2739
         #else
2740
-          uint8_t * const src = (uint8_t*)&ubl.z_values;
2740
+          uint8_t * const src = (uint8_t*)&bedlevel.z_values;
2741
         #endif
2741
         #endif
2742
 
2742
 
2743
         // Write crc to MAT along with other data, or just tack on to the beginning or end
2743
         // Write crc to MAT along with other data, or just tack on to the beginning or end
2772
           int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
2772
           int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
2773
           uint8_t * const dest = (uint8_t*)&z_mesh_store;
2773
           uint8_t * const dest = (uint8_t*)&z_mesh_store;
2774
         #else
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
         #endif
2776
         #endif
2777
 
2777
 
2778
         persistentStore.access_start();
2778
         persistentStore.access_start();
2782
         #if ENABLED(OPTIMIZED_MESH_STORAGE)
2782
         #if ENABLED(OPTIMIZED_MESH_STORAGE)
2783
           if (into) {
2783
           if (into) {
2784
             float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
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
             memcpy(into, z_values, sizeof(z_values));
2786
             memcpy(into, z_values, sizeof(z_values));
2787
           }
2787
           }
2788
           else
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
         #endif
2790
         #endif
2791
 
2791
 
2792
         if (status) SERIAL_ECHOLNPGM("?Unable to load mesh data.");
2792
         if (status) SERIAL_ECHOLNPGM("?Unable to load mesh data.");
3441
             LOOP_L_N(px, GRID_MAX_POINTS_X) {
3441
             LOOP_L_N(px, GRID_MAX_POINTS_X) {
3442
               CONFIG_ECHO_START();
3442
               CONFIG_ECHO_START();
3443
               SERIAL_ECHOPGM("  G29 S3 I", px, " J", py);
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
           CONFIG_ECHO_START();
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
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
3451
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
3452
 
3452
 
3453
         if (!forReplay) {
3453
         if (!forReplay) {
3454
           SERIAL_EOL();
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
           SERIAL_ECHO_MSG("EEPROM can hold ", calc_num_meshes(), " meshes.\n");
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
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
3463
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
3463
 
3464
 
3464
         if (leveling_is_valid()) {
3465
         if (leveling_is_valid()) {
3466
             LOOP_L_N(px, GRID_MAX_POINTS_X) {
3467
             LOOP_L_N(px, GRID_MAX_POINTS_X) {
3467
               CONFIG_ECHO_START();
3468
               CONFIG_ECHO_START();
3468
               SERIAL_ECHOPGM("  G29 W I", px, " J", py);
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
         }

Loading…
Cancel
Save