Skip to content

Commit 82dd40d

Browse files
Update - new mesh set
1 parent f79c584 commit 82dd40d

30 files changed

Lines changed: 207 additions & 245 deletions

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
LevelingBilinear bedlevel;
3939

4040
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;
41+
xy_pos_t LevelingBilinear::grid_spacing,
42+
LevelingBilinear::grid_start,
43+
LevelingBilinear::cached_rel;
44+
xy_int8_t LevelingBilinear::cached_g;
4545
bed_mesh_t LevelingBilinear::z_values;
4646

4747
/**
@@ -110,17 +110,14 @@ void LevelingBilinear::reset() {
110110
* Set grid spacing and start position
111111
*/
112112
void LevelingBilinear::set_grid(const xy_pos_t& _grid_spacing, const xy_pos_t& _grid_start) {
113-
#if ENABLED(PROUI_MESH_EDIT)
114-
UNUSED(_grid_spacing);
115-
UNUSED(_grid_start);
116-
grid_spacing.x = MESH_X_DIST;
117-
grid_spacing.y = MESH_Y_DIST;
118-
grid_start.x = MESH_MIN_X;
119-
grid_start.y = MESH_MIN_Y;
120-
#else
121-
grid_spacing = _grid_spacing;
122-
grid_start = _grid_start;
123-
#endif
113+
#if ENABLED(PROUI_MESH_EDIT)
114+
UNUSED(_grid_spacing); UNUSED(_grid_start);
115+
grid_start = mesh_min;
116+
grid_spacing.set(MESH_X_DIST, MESH_Y_DIST);
117+
#else
118+
grid_spacing = _grid_spacing;
119+
grid_start = _grid_start;
120+
#endif
124121
grid_factor = grid_spacing.reciprocal();
125122
}
126123

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include "../../../inc/MarlinConfigPre.h"
2525

2626
#if ENABLED(PROUI_MESH_EDIT)
27-
#define MESH_X_DIST (float((MESH_MAX_X) - (MESH_MIN_X)) / (GRID_MAX_CELLS_X))
28-
#define MESH_Y_DIST (float((MESH_MAX_Y) - (MESH_MIN_Y)) / (GRID_MAX_CELLS_Y))
27+
#define MESH_X_DIST ((mesh_max.x - mesh_min.x) / (GRID_MAX_CELLS_X))
28+
#define MESH_Y_DIST ((mesh_max.y - mesh_min.y) / (GRID_MAX_CELLS_Y))
2929
#endif
3030

3131
class LevelingBilinear {

Marlin/src/feature/bedlevel/bedlevel.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@
5151
#endif
5252

5353
bool leveling_is_valid() {
54-
#if ALL(HAS_MESH, DWIN_LCD_PROUI)
55-
return bedLevelTools.meshValidate();
56-
#else
57-
return TERN1(HAS_MESH, bedlevel.mesh_is_valid());
58-
#endif
54+
return (
55+
#if ALL(HAS_MESH, DWIN_LCD_PROUI)
56+
bedLevelTools.meshValidate()
57+
#else
58+
TERN1(HAS_MESH, bedlevel.mesh_is_valid())
59+
#endif
60+
);
5961
}
6062

6163
/**

Marlin/src/feature/bedlevel/hilbert_curve.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ bool hilbert_curve::search_from(uint8_t x, uint8_t y, hilbert_curve::callback_pt
111111
*/
112112
bool hilbert_curve::search_from_closest(const xy_pos_t &pos, hilbert_curve::callback_ptr func, void *data) {
113113
// Find closest grid intersection
114-
const uint8_t grid_x = LROUND(constrain(float(pos.x - (MESH_MIN_X)) / (MESH_X_DIST), 0, (GRID_MAX_POINTS_X) - 1));
115-
const uint8_t grid_y = LROUND(constrain(float(pos.y - (MESH_MIN_Y)) / (MESH_Y_DIST), 0, (GRID_MAX_POINTS_Y) - 1));
114+
const uint8_t grid_x = LROUND(constrain((pos.x - mesh_min.x) / (MESH_X_DIST), 0, (GRID_MAX_POINTS_X) - 1));
115+
const uint8_t grid_y = LROUND(constrain((pos.y - mesh_min.y) / (MESH_Y_DIST), 0, (GRID_MAX_POINTS_Y) - 1));
116116
return search_from(grid_x, grid_y, func, data);
117117
}
118118

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
#include "../bedlevel.h"
2828

29-
#include "../../../module/motion.h"
30-
3129
#if ENABLED(EXTENSIBLE_UI)
3230
#include "../../../lcd/extui/ui_api.h"
3331
#endif
@@ -46,19 +44,11 @@
4644

4745
mesh_bed_leveling::mesh_bed_leveling() { initialize(); }
4846

49-
void mesh_bed_leveling::reset() {
50-
z_offset = 0;
51-
ZERO(z_values);
52-
#if ENABLED(EXTENSIBLE_UI)
53-
GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0);
54-
#endif
55-
}
56-
5747
void mesh_bed_leveling::initialize() {
5848
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i)
59-
index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST);
49+
index_to_xpos[i] = mesh_min.x + i * (MESH_X_DIST);
6050
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; ++j)
61-
index_to_ypos[j] = MESH_MIN_Y + j * (MESH_Y_DIST);
51+
index_to_ypos[j] = mesh_min.y + j * (MESH_Y_DIST);
6252
reset();
6353
}
6454

@@ -67,6 +57,14 @@
6757
print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5, z_values[0]);
6858
}
6959

60+
void mesh_bed_leveling::reset() {
61+
z_offset = 0;
62+
ZERO(z_values);
63+
#if ENABLED(EXTENSIBLE_UI)
64+
GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0);
65+
#endif
66+
}
67+
7068
#if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
7169

7270
/**

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include "../../../inc/MarlinConfig.h"
2525

26+
#include "../../../module/motion.h"
27+
2628
enum MeshLevelingState : char {
2729
MeshReport, // G29 S0
2830
MeshStart, // G29 S1
@@ -32,8 +34,8 @@ enum MeshLevelingState : char {
3234
MeshReset // G29 S5
3335
};
3436

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))
37+
#define MESH_X_DIST ((mesh_max.x - mesh_min.x) / (GRID_MAX_CELLS_X))
38+
#define MESH_Y_DIST ((mesh_max.y - mesh_min.y) / (GRID_MAX_CELLS_Y))
3739

3840
class mesh_bed_leveling {
3941
public:
@@ -50,12 +52,12 @@ class mesh_bed_leveling {
5052

5153
mesh_bed_leveling();
5254

53-
static void reset();
54-
5555
static void initialize();
5656

5757
static void report_mesh();
5858

59+
static void reset();
60+
5961
FORCE_INLINE static bool has_mesh() {
6062
GRID_LOOP(x, y) if (z_values[x][y]) return true;
6163
return false;
@@ -81,11 +83,11 @@ class mesh_bed_leveling {
8183
static float get_mesh_y(const uint8_t j) { return index_to_ypos[j]; }
8284

8385
static uint8_t cell_index_x(const float x) {
84-
int8_t cx = (x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST);
86+
int8_t cx = (x - mesh_min.x) * RECIPROCAL(MESH_X_DIST);
8587
return constrain(cx, 0, GRID_MAX_CELLS_X - 1);
8688
}
8789
static uint8_t cell_index_y(const float y) {
88-
int8_t cy = (y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST);
90+
int8_t cy = (y - mesh_min.y) * RECIPROCAL(MESH_Y_DIST);
8991
return constrain(cy, 0, GRID_MAX_CELLS_Y - 1);
9092
}
9193
static xy_uint8_t cell_indexes(const float x, const float y) {
@@ -94,11 +96,11 @@ class mesh_bed_leveling {
9496
static xy_uint8_t cell_indexes(const xy_pos_t &xy) { return cell_indexes(xy.x, xy.y); }
9597

9698
static int8_t probe_index_x(const float x) {
97-
int8_t px = (x - (MESH_MIN_X) + 0.5f * (MESH_X_DIST)) * RECIPROCAL(MESH_X_DIST);
99+
int8_t px = (x - mesh_min.x + 0.5f * (MESH_X_DIST)) * RECIPROCAL(MESH_X_DIST);
98100
return WITHIN(px, 0, (GRID_MAX_POINTS_X) - 1) ? px : -1;
99101
}
100102
static int8_t probe_index_y(const float y) {
101-
int8_t py = (y - (MESH_MIN_Y) + 0.5f * (MESH_Y_DIST)) * RECIPROCAL(MESH_Y_DIST);
103+
int8_t py = (y - mesh_min.y + 0.5f * (MESH_Y_DIST)) * RECIPROCAL(MESH_Y_DIST);
102104
return WITHIN(py, 0, (GRID_MAX_POINTS_Y) - 1) ? py : -1;
103105
}
104106
static xy_int8_t probe_indexes(const float x, const float y) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ void unified_bed_leveling::display_map(const uint8_t map_type) {
177177
SERIAL_ECHOPGM("\nBed Topography Report");
178178
if (human) {
179179
SERIAL_ECHOLNPGM(":\n");
180-
serial_echo_xy(4, MESH_MIN_X, MESH_MAX_Y);
181-
serial_echo_xy(twixt, MESH_MAX_X, MESH_MAX_Y);
180+
serial_echo_xy(4, mesh_min.x, mesh_max.y);
181+
serial_echo_xy(twixt, mesh_max.x, mesh_max.y);
182182
SERIAL_EOL();
183183
serial_echo_column_labels(eachsp - 2);
184184
}
@@ -236,8 +236,8 @@ void unified_bed_leveling::display_map(const uint8_t map_type) {
236236
if (human) {
237237
serial_echo_column_labels(eachsp - 2);
238238
SERIAL_EOL();
239-
serial_echo_xy(4, MESH_MIN_X, MESH_MIN_Y);
240-
serial_echo_xy(twixt, MESH_MAX_X, MESH_MIN_Y);
239+
serial_echo_xy(4, mesh_min.x, mesh_min.y);
240+
serial_echo_xy(twixt, mesh_max.x, mesh_min.y);
241241
SERIAL_EOL();
242242
SERIAL_EOL();
243243
}

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ 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))
41+
#define MESH_X_DIST ((mesh_max.x - mesh_min.x) / (GRID_MAX_CELLS_X))
42+
#define MESH_Y_DIST ((mesh_max.y - mesh_min.y) / (GRID_MAX_CELLS_Y))
4343

4444
#if ENABLED(OPTIMIZED_MESH_STORAGE)
4545
#if ANY(PROUI_EX, PROUI_GRID_PNTS)
@@ -140,11 +140,11 @@ class unified_bed_leveling {
140140
FORCE_INLINE static void set_z(const int8_t px, const int8_t py, const float z) { z_values[px][py] = z; }
141141

142142
static int8_t cell_index_x_raw(const float x) {
143-
return FLOOR((x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST));
143+
return FLOOR((x - mesh_min.x) * RECIPROCAL(MESH_X_DIST));
144144
}
145145

146146
static int8_t cell_index_y_raw(const float y) {
147-
return FLOOR((y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST));
147+
return FLOOR((y - mesh_min.y) * RECIPROCAL(MESH_Y_DIST));
148148
}
149149

150150
static bool cell_index_x_valid(const float x) {
@@ -169,11 +169,11 @@ class unified_bed_leveling {
169169
static xy_uint8_t cell_indexes(const xy_pos_t &xy) { return cell_indexes(xy.x, xy.y); }
170170

171171
static int8_t closest_x_index(const float x) {
172-
const int8_t px = (x - (MESH_MIN_X) + (MESH_X_DIST) * 0.5) * RECIPROCAL(MESH_X_DIST);
172+
const int8_t px = (x - mesh_min.x + (MESH_X_DIST) * 0.5) * RECIPROCAL(MESH_X_DIST);
173173
return WITHIN(px, 0, (GRID_MAX_POINTS_X) - 1) ? px : -1;
174174
}
175175
static int8_t closest_y_index(const float y) {
176-
const int8_t py = (y - (MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * RECIPROCAL(MESH_Y_DIST);
176+
const int8_t py = (y - mesh_min.y + (MESH_Y_DIST) * 0.5) * RECIPROCAL(MESH_Y_DIST);
177177
return WITHIN(py, 0, (GRID_MAX_POINTS_Y) - 1) ? py : -1;
178178
}
179179
static xy_int8_t closest_indexes(const xy_pos_t &xy) {
@@ -266,7 +266,7 @@ class unified_bed_leveling {
266266
* UBL_Z_RAISE_WHEN_OFF_MESH is specified, that value is returned.
267267
*/
268268
#ifdef UBL_Z_RAISE_WHEN_OFF_MESH
269-
if (!WITHIN(rx0, MESH_MIN_X, MESH_MAX_X) || !WITHIN(ry0, MESH_MIN_Y, MESH_MAX_Y))
269+
if (!WITHIN(rx0, mesh_min.x, mesh_max.x) || !WITHIN(ry0, mesh_min.y, mesh_max.y))
270270
return UBL_Z_RAISE_WHEN_OFF_MESH;
271271
#endif
272272

@@ -294,22 +294,23 @@ class unified_bed_leveling {
294294

295295
static constexpr float get_z_offset() { return 0.0f; }
296296

297+
#if !ALL(PROUI_EX, PROUI_MESH_EDIT) || DISABLED(DWIN_LCD_PROUI)
298+
static float _get_mesh_x(const uint8_t i) { return mesh_min.x + i * (MESH_X_DIST); }
299+
static float _get_mesh_y(const uint8_t j) { return mesh_min.y + j * (MESH_Y_DIST); }
300+
#endif
301+
297302
#if ALL(PROUI_EX, PROUI_MESH_EDIT)
298303
static float get_mesh_x(const uint8_t i);
299304
static float get_mesh_y(const uint8_t j);
300-
#elif ENABLED(PROUI_MESH_EDIT)
301-
static float get_mesh_x(const uint8_t i) {
302-
return MESH_MIN_X + i * (MESH_X_DIST);
303-
}
304-
static float get_mesh_y(const uint8_t j) {
305-
return MESH_MIN_Y + j * (MESH_Y_DIST);
306-
}
305+
#elif ENABLED(DWIN_LCD_PROUI)
306+
static float get_mesh_x(const uint8_t i) { return _get_mesh_x(i); }
307+
static float get_mesh_y(const uint8_t j) { return _get_mesh_y(j); }
307308
#else
308309
static float get_mesh_x(const uint8_t i) {
309-
return i < (GRID_MAX_POINTS_X) ? pgm_read_float(&_mesh_index_to_xpos[i]) : MESH_MIN_X + i * (MESH_X_DIST);
310+
return i < (GRID_MAX_POINTS_X) ? pgm_read_float(&_mesh_index_to_xpos[i]) : _get_mesh_x(i);
310311
}
311312
static float get_mesh_y(const uint8_t j) {
312-
return j < (GRID_MAX_POINTS_Y) ? pgm_read_float(&_mesh_index_to_ypos[j]) : MESH_MIN_Y + j * (MESH_Y_DIST);
313+
return j < (GRID_MAX_POINTS_Y) ? pgm_read_float(&_mesh_index_to_ypos[j]) : _get_mesh_y(j);
313314
}
314315
#endif
315316

0 commit comments

Comments
 (0)