Skip to content

Commit 12f0fa1

Browse files
📺 Closer parity with ProUI (#26761)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
1 parent b869afd commit 12f0fa1

43 files changed

Lines changed: 1035 additions & 815 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Marlin/src/feature/bedlevel/abl/bbl.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737

3838
LevelingBilinear bedlevel;
3939

40-
xy_pos_t LevelingBilinear::grid_spacing,
41-
LevelingBilinear::grid_start;
4240
xy_float_t LevelingBilinear::grid_factor;
41+
xy_pos_t LevelingBilinear::grid_spacing,
42+
LevelingBilinear::grid_start,
43+
LevelingBilinear::cached_rel;
44+
xy_int8_t LevelingBilinear::cached_g;
4345
bed_mesh_t LevelingBilinear::z_values;
44-
xy_pos_t LevelingBilinear::cached_rel;
45-
xy_int8_t LevelingBilinear::cached_g;
4646

4747
/**
4848
* Extrapolate a single point from its neighbors
@@ -106,9 +106,17 @@ void LevelingBilinear::reset() {
106106
}
107107
}
108108

109+
/**
110+
* Set grid spacing and start position
111+
*/
109112
void LevelingBilinear::set_grid(const xy_pos_t& _grid_spacing, const xy_pos_t& _grid_start) {
110-
grid_spacing = _grid_spacing;
111-
grid_start = _grid_start;
113+
#if HAS_PROUI_MESH_EDIT
114+
grid_spacing.set(MESH_X_DIST, MESH_Y_DIST);
115+
grid_start = mesh_min;
116+
#else
117+
grid_spacing = _grid_spacing;
118+
grid_start = _grid_start;
119+
#endif
112120
grid_factor = grid_spacing.reciprocal();
113121
}
114122

Marlin/src/feature/bedlevel/bedlevel.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,18 @@
4646
#include "../../lcd/extui/ui_api.h"
4747
#endif
4848

49+
#if HAS_PROUI_MESH_EDIT
50+
#include "../../lcd/dwin/proui/bedlevel_tools.h"
51+
#endif
52+
4953
bool leveling_is_valid() {
50-
return TERN1(HAS_MESH, bedlevel.mesh_is_valid());
54+
return (
55+
#if HAS_PROUI_MESH_EDIT
56+
bedLevelTools.meshValidate()
57+
#else
58+
TERN1(HAS_MESH, bedlevel.mesh_is_valid())
59+
#endif
60+
);
5161
}
5262

5363
/**

Marlin/src/feature/bedlevel/hilbert_curve.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ bool hilbert_curve::search_from(uint8_t x, uint8_t y, hilbert_curve::callback_pt
102102
*/
103103
bool hilbert_curve::search_from_closest(const xy_pos_t &pos, hilbert_curve::callback_ptr func, void *data) {
104104
// Find closest grid intersection
105-
const uint8_t grid_x = LROUND(constrain(float(pos.x - (MESH_MIN_X)) / (MESH_X_DIST), 0, (GRID_MAX_POINTS_X) - 1));
106-
const uint8_t grid_y = LROUND(constrain(float(pos.y - (MESH_MIN_Y)) / (MESH_Y_DIST), 0, (GRID_MAX_POINTS_Y) - 1));
105+
const uint8_t grid_x = LROUND(constrain((pos.x - mesh_min.x) / (MESH_X_DIST), 0, (GRID_MAX_POINTS_X) - 1));
106+
const uint8_t grid_y = LROUND(constrain((pos.y - mesh_min.y) / (MESH_Y_DIST), 0, (GRID_MAX_POINTS_Y) - 1));
107107
return search_from(grid_x, grid_y, func, data);
108108
}
109109

Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,21 @@
3939
mesh_bed_leveling::index_to_xpos[GRID_MAX_POINTS_X],
4040
mesh_bed_leveling::index_to_ypos[GRID_MAX_POINTS_Y];
4141

42-
mesh_bed_leveling::mesh_bed_leveling() {
42+
mesh_bed_leveling::mesh_bed_leveling() { initialize(); }
43+
44+
void mesh_bed_leveling::initialize() {
4345
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i)
44-
index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST);
46+
index_to_xpos[i] = mesh_min.x + i * (MESH_X_DIST);
4547
for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; ++i)
46-
index_to_ypos[i] = MESH_MIN_Y + i * (MESH_Y_DIST);
48+
index_to_ypos[i] = mesh_min.y + i * (MESH_Y_DIST);
4749
reset();
4850
}
4951

52+
void mesh_bed_leveling::report_mesh() {
53+
SERIAL_ECHOLN(F(STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh. Z offset: "), p_float_t(z_offset, 5), F("\nMeasured points:"));
54+
print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5, z_values[0]);
55+
}
56+
5057
void mesh_bed_leveling::reset() {
5158
z_offset = 0;
5259
ZERO(z_values);
@@ -122,9 +129,4 @@
122129

123130
#endif // IS_CARTESIAN && !SEGMENT_LEVELED_MOVES
124131

125-
void mesh_bed_leveling::report_mesh() {
126-
SERIAL_ECHOLN(F(STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh. Z offset: "), p_float_t(z_offset, 5), F("\nMeasured points:"));
127-
print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5, z_values[0]);
128-
}
129-
130132
#endif // MESH_BED_LEVELING

Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ enum MeshLevelingState : char {
3232
MeshReset // G29 S5
3333
};
3434

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))
35+
#include "../../../module/motion.h"
3736

3837
class mesh_bed_leveling {
3938
public:
@@ -44,10 +43,12 @@ class mesh_bed_leveling {
4443

4544
mesh_bed_leveling();
4645

47-
static void report_mesh();
48-
4946
static void reset();
5047

48+
static void initialize();
49+
50+
static void report_mesh();
51+
5152
FORCE_INLINE static bool has_mesh() {
5253
GRID_LOOP(x, y) if (z_values[x][y]) return true;
5354
return false;
@@ -73,11 +74,11 @@ class mesh_bed_leveling {
7374
static float get_mesh_y(const uint8_t i) { return index_to_ypos[i]; }
7475

7576
static uint8_t cell_index_x(const float x) {
76-
int8_t cx = (x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST);
77+
const int8_t cx = (x - mesh_min.x) * RECIPROCAL(MESH_X_DIST);
7778
return constrain(cx, 0, GRID_MAX_CELLS_X - 1);
7879
}
7980
static uint8_t cell_index_y(const float y) {
80-
int8_t cy = (y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST);
81+
const int8_t cy = (y - mesh_min.y) * RECIPROCAL(MESH_Y_DIST);
8182
return constrain(cy, 0, GRID_MAX_CELLS_Y - 1);
8283
}
8384
static xy_uint8_t cell_indexes(const float x, const float y) {
@@ -86,11 +87,11 @@ class mesh_bed_leveling {
8687
static xy_uint8_t cell_indexes(const xy_pos_t &xy) { return cell_indexes(xy.x, xy.y); }
8788

8889
static int8_t probe_index_x(const float x) {
89-
int8_t px = (x - (MESH_MIN_X) + 0.5f * (MESH_X_DIST)) * RECIPROCAL(MESH_X_DIST);
90+
const int8_t px = (x - mesh_min.x + 0.5f * (MESH_X_DIST)) * RECIPROCAL(MESH_X_DIST);
9091
return WITHIN(px, 0, (GRID_MAX_POINTS_X) - 1) ? px : -1;
9192
}
9293
static int8_t probe_index_y(const float y) {
93-
int8_t py = (y - (MESH_MIN_Y) + 0.5f * (MESH_Y_DIST)) * RECIPROCAL(MESH_Y_DIST);
94+
const int8_t py = (y - mesh_min.y + 0.5f * (MESH_Y_DIST)) * RECIPROCAL(MESH_Y_DIST);
9495
return WITHIN(py, 0, (GRID_MAX_POINTS_Y) - 1) ? py : -1;
9596
}
9697
static xy_int8_t probe_indexes(const float x, const float y) {

Marlin/src/feature/bedlevel/ubl/ubl.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,25 @@ void unified_bed_leveling::report_state() {
6363

6464
int8_t unified_bed_leveling::storage_slot;
6565

66-
float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
67-
68-
#define _GRIDPOS(A,N) (MESH_MIN_##A + N * (MESH_##A##_DIST))
69-
70-
const float
71-
unified_bed_leveling::_mesh_index_to_xpos[GRID_MAX_POINTS_X] PROGMEM = ARRAY_N(GRID_MAX_POINTS_X,
72-
_GRIDPOS(X, 0), _GRIDPOS(X, 1), _GRIDPOS(X, 2), _GRIDPOS(X, 3),
73-
_GRIDPOS(X, 4), _GRIDPOS(X, 5), _GRIDPOS(X, 6), _GRIDPOS(X, 7),
74-
_GRIDPOS(X, 8), _GRIDPOS(X, 9), _GRIDPOS(X, 10), _GRIDPOS(X, 11),
75-
_GRIDPOS(X, 12), _GRIDPOS(X, 13), _GRIDPOS(X, 14), _GRIDPOS(X, 15)
76-
),
77-
unified_bed_leveling::_mesh_index_to_ypos[GRID_MAX_POINTS_Y] PROGMEM = ARRAY_N(GRID_MAX_POINTS_Y,
78-
_GRIDPOS(Y, 0), _GRIDPOS(Y, 1), _GRIDPOS(Y, 2), _GRIDPOS(Y, 3),
79-
_GRIDPOS(Y, 4), _GRIDPOS(Y, 5), _GRIDPOS(Y, 6), _GRIDPOS(Y, 7),
80-
_GRIDPOS(Y, 8), _GRIDPOS(Y, 9), _GRIDPOS(Y, 10), _GRIDPOS(Y, 11),
81-
_GRIDPOS(Y, 12), _GRIDPOS(Y, 13), _GRIDPOS(Y, 14), _GRIDPOS(Y, 15)
82-
);
66+
bed_mesh_t unified_bed_leveling::z_values;
67+
68+
#if !HAS_PROUI_MESH_EDIT
69+
#define _GRIDPOS(A,N) (MESH_MIN_##A + N * (MESH_##A##_DIST))
70+
71+
const float
72+
unified_bed_leveling::_mesh_index_to_xpos[GRID_MAX_POINTS_X] PROGMEM = ARRAY_N(GRID_MAX_POINTS_X,
73+
_GRIDPOS(X, 0), _GRIDPOS(X, 1), _GRIDPOS(X, 2), _GRIDPOS(X, 3),
74+
_GRIDPOS(X, 4), _GRIDPOS(X, 5), _GRIDPOS(X, 6), _GRIDPOS(X, 7),
75+
_GRIDPOS(X, 8), _GRIDPOS(X, 9), _GRIDPOS(X, 10), _GRIDPOS(X, 11),
76+
_GRIDPOS(X, 12), _GRIDPOS(X, 13), _GRIDPOS(X, 14), _GRIDPOS(X, 15)
77+
),
78+
unified_bed_leveling::_mesh_index_to_ypos[GRID_MAX_POINTS_Y] PROGMEM = ARRAY_N(GRID_MAX_POINTS_Y,
79+
_GRIDPOS(Y, 0), _GRIDPOS(Y, 1), _GRIDPOS(Y, 2), _GRIDPOS(Y, 3),
80+
_GRIDPOS(Y, 4), _GRIDPOS(Y, 5), _GRIDPOS(Y, 6), _GRIDPOS(Y, 7),
81+
_GRIDPOS(Y, 8), _GRIDPOS(Y, 9), _GRIDPOS(Y, 10), _GRIDPOS(Y, 11),
82+
_GRIDPOS(Y, 12), _GRIDPOS(Y, 13), _GRIDPOS(Y, 14), _GRIDPOS(Y, 15)
83+
);
84+
#endif
8385

8486
volatile int16_t unified_bed_leveling::encoder_diff;
8587

@@ -173,8 +175,8 @@ void unified_bed_leveling::display_map(const uint8_t map_type) {
173175
SERIAL_ECHOPGM("\nBed Topography Report");
174176
if (human) {
175177
SERIAL_ECHOLNPGM(":\n");
176-
serial_echo_xy(4, MESH_MIN_X, MESH_MAX_Y);
177-
serial_echo_xy(twixt, MESH_MAX_X, MESH_MAX_Y);
178+
serial_echo_xy(4, mesh_min.x, mesh_max.y);
179+
serial_echo_xy(twixt, mesh_max.x, mesh_max.y);
178180
SERIAL_EOL();
179181
serial_echo_column_labels(eachsp - 2);
180182
}
@@ -207,6 +209,7 @@ void unified_bed_leveling::display_map(const uint8_t map_type) {
207209
const float f = z_values[i][j];
208210
if (lcd) {
209211
// TODO: Display on Graphical LCD
212+
TERN_(DWIN_LCD_PROUI, dwinMeshViewer());
210213
}
211214
else if (isnan(f))
212215
SERIAL_ECHO(human ? F(" . ") : F("NAN"));
@@ -231,8 +234,8 @@ void unified_bed_leveling::display_map(const uint8_t map_type) {
231234
if (human) {
232235
serial_echo_column_labels(eachsp - 2);
233236
SERIAL_EOL();
234-
serial_echo_xy(4, MESH_MIN_X, MESH_MIN_Y);
235-
serial_echo_xy(twixt, MESH_MAX_X, MESH_MIN_Y);
237+
serial_echo_xy(4, mesh_min.x, mesh_min.y);
238+
serial_echo_xy(twixt, mesh_max.x, mesh_min.y);
236239
SERIAL_EOL();
237240
SERIAL_EOL();
238241
}

Marlin/src/feature/bedlevel/ubl/ubl.h

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ enum MeshPointType : char { INVALID, REAL, SET_IN_BITMAP, CLOSEST };
3838

3939
struct mesh_index_pair;
4040

41-
#define MESH_X_DIST (float((MESH_MAX_X) - (MESH_MIN_X)) / (GRID_MAX_CELLS_X))
42-
#define MESH_Y_DIST (float((MESH_MAX_Y) - (MESH_MIN_Y)) / (GRID_MAX_CELLS_Y))
43-
4441
#if ENABLED(OPTIMIZED_MESH_STORAGE)
4542
typedef int16_t mesh_store_t[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
4643
#endif
@@ -116,8 +113,11 @@ class unified_bed_leveling {
116113
static void set_store_from_mesh(const bed_mesh_t &in_values, mesh_store_t &stored_values);
117114
static void set_mesh_from_store(const mesh_store_t &stored_values, bed_mesh_t &out_values);
118115
#endif
119-
static const float _mesh_index_to_xpos[GRID_MAX_POINTS_X],
120-
_mesh_index_to_ypos[GRID_MAX_POINTS_Y];
116+
117+
#if !HAS_PROUI_MESH_EDIT
118+
static const float _mesh_index_to_xpos[GRID_MAX_POINTS_X],
119+
_mesh_index_to_ypos[GRID_MAX_POINTS_Y];
120+
#endif
121121

122122
#if HAS_MARLINUI_MENU
123123
static bool lcd_map_control;
@@ -133,11 +133,11 @@ class unified_bed_leveling {
133133
FORCE_INLINE static void set_z(const int8_t px, const int8_t py, const float z) { z_values[px][py] = z; }
134134

135135
static int8_t cell_index_x_raw(const float x) {
136-
return FLOOR((x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST));
136+
return FLOOR((x - mesh_min.x) * RECIPROCAL(MESH_X_DIST));
137137
}
138138

139139
static int8_t cell_index_y_raw(const float y) {
140-
return FLOOR((y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST));
140+
return FLOOR((y - mesh_min.y) * RECIPROCAL(MESH_Y_DIST));
141141
}
142142

143143
static bool cell_index_x_valid(const float x) {
@@ -162,11 +162,11 @@ class unified_bed_leveling {
162162
static xy_uint8_t cell_indexes(const xy_pos_t &xy) { return cell_indexes(xy.x, xy.y); }
163163

164164
static int8_t closest_x_index(const float x) {
165-
const int8_t px = (x - (MESH_MIN_X) + (MESH_X_DIST) * 0.5) * RECIPROCAL(MESH_X_DIST);
165+
const int8_t px = (x - mesh_min.x + (MESH_X_DIST) * 0.5) * RECIPROCAL(MESH_X_DIST);
166166
return WITHIN(px, 0, (GRID_MAX_POINTS_X) - 1) ? px : -1;
167167
}
168168
static int8_t closest_y_index(const float y) {
169-
const int8_t py = (y - (MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * RECIPROCAL(MESH_Y_DIST);
169+
const int8_t py = (y - mesh_min.y + (MESH_Y_DIST) * 0.5) * RECIPROCAL(MESH_Y_DIST);
170170
return WITHIN(py, 0, (GRID_MAX_POINTS_Y) - 1) ? py : -1;
171171
}
172172
static xy_int8_t closest_indexes(const xy_pos_t &xy) {
@@ -259,7 +259,7 @@ class unified_bed_leveling {
259259
* UBL_Z_RAISE_WHEN_OFF_MESH is specified, that value is returned.
260260
*/
261261
#ifdef UBL_Z_RAISE_WHEN_OFF_MESH
262-
if (!WITHIN(rx0, MESH_MIN_X, MESH_MAX_X) || !WITHIN(ry0, MESH_MIN_Y, MESH_MAX_Y))
262+
if (!WITHIN(rx0, mesh_min.x, mesh_max.x) || !WITHIN(ry0, mesh_min.y, mesh_max.y))
263263
return UBL_Z_RAISE_WHEN_OFF_MESH;
264264
#endif
265265

@@ -287,12 +287,20 @@ class unified_bed_leveling {
287287

288288
static constexpr float get_z_offset() { return 0.0f; }
289289

290-
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);
292-
}
293-
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);
295-
}
290+
static float _get_mesh_x(const uint8_t i) { return mesh_min.x + i * (MESH_X_DIST); }
291+
static float _get_mesh_y(const uint8_t i) { return mesh_min.y + i * (MESH_Y_DIST); }
292+
293+
#if HAS_PROUI_MESH_EDIT
294+
static float get_mesh_x(const uint8_t i) { return _get_mesh_x(i); }
295+
static float get_mesh_y(const uint8_t i) { return _get_mesh_y(i); }
296+
#else
297+
static float get_mesh_x(const uint8_t i) {
298+
return i < (GRID_MAX_POINTS_X) ? pgm_read_float(&_mesh_index_to_xpos[i]) : _get_mesh_x(i);
299+
}
300+
static float get_mesh_y(const uint8_t i) {
301+
return i < (GRID_MAX_POINTS_Y) ? pgm_read_float(&_mesh_index_to_ypos[i]) : _get_mesh_y(i);
302+
}
303+
#endif
296304

297305
#if UBL_SEGMENTED
298306
static bool line_to_destination_segmented(const feedRate_t scaled_fr_mm_s);

0 commit comments

Comments
 (0)