Browse Source

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

FB4S_WIFI
Scott Lahteine 3 years ago
committed by Scott Lahteine
parent
commit
b72f9277e9
  1. 2
      Marlin/src/MarlinCore.cpp
  2. 8
      Marlin/src/core/utility.cpp
  3. 4
      Marlin/src/feature/bedlevel/abl/bbl.cpp
  4. 21
      Marlin/src/feature/bedlevel/abl/bbl.h
  5. 37
      Marlin/src/feature/bedlevel/bedlevel.cpp
  6. 5
      Marlin/src/feature/bedlevel/bedlevel.h
  7. 2
      Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp
  8. 21
      Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h
  9. 2
      Marlin/src/feature/bedlevel/ubl/ubl.cpp
  10. 35
      Marlin/src/feature/bedlevel/ubl/ubl.h
  11. 44
      Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
  12. 21
      Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp
  13. 16
      Marlin/src/gcode/bedlevel/G26.cpp
  14. 4
      Marlin/src/gcode/bedlevel/G42.cpp
  15. 34
      Marlin/src/gcode/bedlevel/M420.cpp
  16. 28
      Marlin/src/gcode/bedlevel/abl/G29.cpp
  17. 6
      Marlin/src/gcode/bedlevel/abl/M421.cpp
  18. 18
      Marlin/src/gcode/bedlevel/mbl/G29.cpp
  19. 6
      Marlin/src/gcode/bedlevel/mbl/M421.cpp
  20. 2
      Marlin/src/gcode/bedlevel/ubl/G29.cpp
  21. 4
      Marlin/src/gcode/bedlevel/ubl/M421.cpp
  22. 2
      Marlin/src/gcode/control/M17_M18_M84.cpp
  23. 2
      Marlin/src/gcode/motion/M290.cpp
  24. 16
      Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
  25. 8
      Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
  26. 10
      Marlin/src/lcd/dogm/marlinui_DOGM.cpp
  27. 132
      Marlin/src/lcd/e3v2/jyersui/dwin.cpp
  28. 10
      Marlin/src/lcd/e3v2/marlinui/ui_common.cpp
  29. 32
      Marlin/src/lcd/e3v2/proui/dwin.cpp
  30. 2
      Marlin/src/lcd/e3v2/proui/meshviewer.cpp
  31. 65
      Marlin/src/lcd/e3v2/proui/ubl_tools.cpp
  32. 4
      Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp
  33. 6
      Marlin/src/lcd/extui/ui_api.cpp
  34. 2
      Marlin/src/lcd/marlinui.cpp
  35. 4
      Marlin/src/lcd/menu/menu.cpp
  36. 4
      Marlin/src/lcd/menu/menu_bed_leveling.cpp
  37. 2
      Marlin/src/lcd/menu/menu_tune.cpp
  38. 26
      Marlin/src/lcd/menu/menu_ubl.cpp
  39. 4
      Marlin/src/lcd/tft/touch.cpp
  40. 14
      Marlin/src/lcd/tft/ui_1024x600.cpp
  41. 6
      Marlin/src/lcd/tft/ui_320x240.cpp
  42. 6
      Marlin/src/lcd/tft/ui_480x320.cpp
  43. 12
      Marlin/src/module/motion.cpp
  44. 32
      Marlin/src/module/planner.cpp
  45. 87
      Marlin/src/module/settings.cpp

2
Marlin/src/MarlinCore.cpp

@ -443,7 +443,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
TERN_(DISABLE_INACTIVE_K, stepper.disable_axis(K_AXIS));
TERN_(DISABLE_INACTIVE_E, stepper.disable_e_steppers());
TERN_(AUTO_BED_LEVELING_UBL, ubl.steppers_were_disabled());
TERN_(AUTO_BED_LEVELING_UBL, bedlevel.steppers_were_disabled());
}
}
else

8
Marlin/src/core/utility.cpp

@ -132,10 +132,10 @@ void safe_delay(millis_t ms) {
#else
#if ENABLED(AUTO_BED_LEVELING_UBL)
SERIAL_ECHOPGM("UBL Adjustment Z");
const float rz = ubl.get_z_correction(current_position);
const float rz = bedlevel.get_z_correction(current_position);
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
SERIAL_ECHOPGM("ABL Adjustment Z");
const float rz = bbl.get_z_correction(current_position);
const float rz = bedlevel.get_z_correction(current_position);
#endif
SERIAL_ECHO(ftostr43sign(rz, '+'));
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
@ -156,11 +156,11 @@ void safe_delay(millis_t ms) {
SERIAL_ECHOPGM("Mesh Bed Leveling");
if (planner.leveling_active) {
SERIAL_ECHOLNPGM(" (enabled)");
SERIAL_ECHOPGM("MBL Adjustment Z", ftostr43sign(mbl.get_z(current_position), '+'));
SERIAL_ECHOPGM("MBL Adjustment Z", ftostr43sign(bedlevel.get_z(current_position), '+'));
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
if (planner.z_fade_height) {
SERIAL_ECHOPGM(" (", ftostr43sign(
mbl.get_z(current_position, planner.fade_scaling_factor_for_z(current_position.z)), '+'
bedlevel.get_z(current_position, planner.fade_scaling_factor_for_z(current_position.z)), '+'
));
SERIAL_CHAR(')');
}

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

@ -35,7 +35,7 @@
#include "../../../lcd/extui/ui_api.h"
#endif
LevelingBilinear bbl;
LevelingBilinear bedlevel;
xy_pos_t LevelingBilinear::grid_spacing,
LevelingBilinear::grid_start;
@ -258,8 +258,8 @@ void LevelingBilinear::print_leveling_grid(const bed_mesh_t* _z_values /*= NULL*
);
}
}
#endif // ABL_BILINEAR_SUBDIVISION
#endif // ABL_BILINEAR_SUBDIVISION
// Refresh after other values have been updated
void LevelingBilinear::refresh_bed_level() {

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

@ -24,10 +24,12 @@
#include "../../../inc/MarlinConfigPre.h"
class LevelingBilinear {
private:
public:
static bed_mesh_t z_values;
static xy_pos_t grid_spacing, grid_start;
private:
static xy_float_t grid_factor;
static bed_mesh_t z_values;
static xy_pos_t cached_rel;
static xy_int8_t cached_g;
@ -54,20 +56,15 @@ public:
static void print_leveling_grid(const bed_mesh_t* _z_values = NULL);
static void refresh_bed_level();
static bool has_mesh() { return !!grid_spacing.x; }
static bed_mesh_t& get_z_values() { return z_values; }
static const xy_pos_t& get_grid_spacing() { return grid_spacing; }
static const xy_pos_t& get_grid_start() { return grid_start; }
static float get_mesh_x(int16_t i) { return grid_start.x + i * grid_spacing.x; }
static float get_mesh_y(int16_t j) { return grid_start.y + j * grid_spacing.y; }
static bool mesh_is_valid() { return has_mesh(); }
static float get_mesh_x(const uint8_t i) { return grid_start.x + i * grid_spacing.x; }
static float get_mesh_y(const uint8_t j) { return grid_start.y + j * grid_spacing.y; }
static float get_z_correction(const xy_pos_t &raw);
static constexpr float get_z_offset() { return 0.0f; }
#if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
static void line_to_destination(const_feedRate_t scaled_fr_mm_s, uint16_t x_splits=0xFFFF, uint16_t y_splits=0xFFFF);
#endif
};
extern LevelingBilinear bbl;
#define _GET_MESH_X(I) bbl.get_mesh_x(I)
#define _GET_MESH_Y(J) bbl.get_mesh_y(J)
#define Z_VALUES_ARR bbl.get_z_values()
extern LevelingBilinear bedlevel;

37
Marlin/src/feature/bedlevel/bedlevel.cpp

@ -47,14 +47,11 @@
#endif
bool leveling_is_valid() {
return TERN1(MESH_BED_LEVELING, mbl.has_mesh())
&& TERN1(AUTO_BED_LEVELING_BILINEAR, bbl.has_mesh())
&& TERN1(AUTO_BED_LEVELING_UBL, ubl.mesh_is_valid());
return TERN1(HAS_MESH, bedlevel.mesh_is_valid());
}
/**
* Turn bed leveling on or off, fixing the current
* position as-needed.
* Turn bed leveling on or off, correcting the current position.
*
* Disable: Current position = physical position
* Enable: Current position = "unleveled" physical position
@ -65,24 +62,31 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
if (can_change && enable != planner.leveling_active) {
auto _report_leveling = []{
if (DEBUGGING(LEVELING)) {
if (planner.leveling_active)
DEBUG_POS("Leveling ON", current_position);
else
DEBUG_POS("Leveling OFF", current_position);
}
};
_report_leveling();
planner.synchronize();
if (planner.leveling_active) { // leveling from on to off
if (DEBUGGING(LEVELING)) DEBUG_POS("Leveling ON", current_position);
// change unleveled current_position to physical current_position without moving steppers.
planner.apply_leveling(current_position);
planner.leveling_active = false; // disable only AFTER calling apply_leveling
if (DEBUGGING(LEVELING)) DEBUG_POS("...Now OFF", current_position);
}
else { // leveling from off to on
if (DEBUGGING(LEVELING)) DEBUG_POS("Leveling OFF", current_position);
planner.leveling_active = true; // enable BEFORE calling unapply_leveling, otherwise ignored
// change physical current_position to unleveled current_position without moving steppers.
planner.unapply_leveling(current_position);
if (DEBUGGING(LEVELING)) DEBUG_POS("...Now ON", current_position);
}
sync_plan_position();
_report_leveling();
}
}
@ -116,18 +120,9 @@ TemporaryBedLevelingState::TemporaryBedLevelingState(const bool enable) : saved(
*/
void reset_bed_level() {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("reset_bed_level");
#if ENABLED(AUTO_BED_LEVELING_UBL)
ubl.reset();
#else
set_bed_leveling_enabled(false);
#if ENABLED(MESH_BED_LEVELING)
mbl.reset();
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
bbl.reset();
#elif ABL_PLANAR
planner.bed_level_matrix.set_to_identity();
#endif
#endif
IF_DISABLED(AUTO_BED_LEVELING_UBL, set_bed_leveling_enabled(false));
TERN_(HAS_MESH, bedlevel.reset());
TERN_(ABL_PLANAR, planner.bed_level_matrix.set_to_identity());
}
#if EITHER(AUTO_BED_LEVELING_BILINEAR, MESH_BED_LEVELING)

5
Marlin/src/feature/bedlevel/bedlevel.h

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

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

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

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

@ -34,9 +34,6 @@ enum MeshLevelingState : char {
#define MESH_X_DIST (float(MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_CELLS_X))
#define MESH_Y_DIST (float(MESH_MAX_Y - (MESH_MIN_Y)) / (GRID_MAX_CELLS_Y))
#define _GET_MESH_X(I) mbl.index_to_xpos[I]
#define _GET_MESH_Y(J) mbl.index_to_ypos[J]
#define Z_VALUES_ARR mbl.z_values
class mesh_bed_leveling {
public:
@ -56,6 +53,8 @@ public:
return false;
}
static bool mesh_is_valid() { return has_mesh(); }
static void set_z(const int8_t px, const int8_t py, const_float_t z) { z_values[px][py] = z; }
static void zigzag(const int8_t index, int8_t &px, int8_t &py) {
@ -70,6 +69,9 @@ public:
set_z(px, py, z);
}
static float get_mesh_x(const uint8_t i) { return index_to_xpos[i]; }
static float get_mesh_y(const uint8_t i) { return index_to_ypos[i]; }
static int8_t cell_index_x(const_float_t x) {
int8_t cx = (x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST);
return constrain(cx, 0, GRID_MAX_CELLS_X - 1);
@ -102,12 +104,9 @@ public:
return z1 + delta_a * delta_z;
}
static float get_z(const xy_pos_t &pos
OPTARG(ENABLE_LEVELING_FADE_HEIGHT, const_float_t factor=1.0f)
) {
#if DISABLED(ENABLE_LEVELING_FADE_HEIGHT)
constexpr float factor = 1.0f;
#endif
static float get_z_offset() { return z_offset; }
static float get_z_correction(const xy_pos_t &pos) {
const xy_int8_t ind = cell_indexes(pos);
const float x1 = index_to_xpos[ind.x], x2 = index_to_xpos[ind.x+1],
y1 = index_to_xpos[ind.y], y2 = index_to_xpos[ind.y+1],
@ -115,7 +114,7 @@ public:
z2 = calc_z0(pos.x, x1, z_values[ind.x][ind.y+1], x2, z_values[ind.x+1][ind.y+1]),
zf = calc_z0(pos.y, y1, z1, y2, z2);
return z_offset + zf * factor;
return zf;
}
#if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
@ -123,4 +122,4 @@ public:
#endif
};
extern mesh_bed_leveling mbl;
extern mesh_bed_leveling bedlevel;

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

@ -26,7 +26,7 @@
#include "../bedlevel.h"
unified_bed_leveling ubl;
unified_bed_leveling bedlevel;
#include "../../../MarlinCore.h"
#include "../../../gcode/gcode.h"

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

@ -215,7 +215,7 @@ public:
return _UBL_OUTER_Z_RAISE;
}
const float xratio = (rx0 - mesh_index_to_xpos(x1_i)) * RECIPROCAL(MESH_X_DIST),
const float xratio = (rx0 - get_mesh_x(x1_i)) * RECIPROCAL(MESH_X_DIST),
z1 = z_values[x1_i][yi];
return z1 + xratio * (z_values[_MIN(x1_i, (GRID_MAX_POINTS_X) - 2) + 1][yi] - z1); // Don't allow x1_i+1 to be past the end of the array
@ -238,7 +238,7 @@ public:
return _UBL_OUTER_Z_RAISE;
}
const float yratio = (ry0 - mesh_index_to_ypos(y1_i)) * RECIPROCAL(MESH_Y_DIST),
const float yratio = (ry0 - get_mesh_y(y1_i)) * RECIPROCAL(MESH_Y_DIST),
z1 = z_values[xi][y1_i];
return z1 + yratio * (z_values[xi][_MIN(y1_i, (GRID_MAX_POINTS_Y) - 2) + 1] - z1); // Don't allow y1_i+1 to be past the end of the array
@ -264,16 +264,17 @@ public:
return UBL_Z_RAISE_WHEN_OFF_MESH;
#endif
const uint8_t mx = _MIN(cx, (GRID_MAX_POINTS_X) - 2) + 1, my = _MIN(cy, (GRID_MAX_POINTS_Y) - 2) + 1;
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]);
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]);
float z0 = calc_z0(ry0, mesh_index_to_ypos(cy), z1, mesh_index_to_ypos(cy + 1), z2);
const uint8_t mx = _MIN(cx, (GRID_MAX_POINTS_X) - 2) + 1, my = _MIN(cy, (GRID_MAX_POINTS_Y) - 2) + 1,
x0 = get_mesh_x(cx), x1 = get_mesh_x(cx + 1);
const float z1 = calc_z0(rx0, x0, z_values[cx][cy], x1, z_values[mx][cy]),
z2 = calc_z0(rx0, x0, z_values[cx][my], x1, z_values[mx][my]);
float z0 = calc_z0(ry0, get_mesh_y(cy), z1, get_mesh_y(cy + 1), z2);
if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN
z0 = 0.0; // in ubl.z_values[][] and propagate through the
// calculations. If our correction is NAN, we throw it out
// because part of the Mesh is undefined and we don't have the
// information we need to complete the height correction.
if (isnan(z0)) { // If part of the Mesh is undefined, it will show up as NAN
z0 = 0.0; // in z_values[][] and propagate through the calculations.
// If our correction is NAN, we throw it out because part of
// the Mesh is undefined and we don't have the information
// needed to complete the height correction.
if (DEBUGGING(MESH_ADJUST)) DEBUG_ECHOLNPGM("??? Yikes! NAN in ");
}
@ -287,10 +288,12 @@ public:
}
static float get_z_correction(const xy_pos_t &pos) { return get_z_correction(pos.x, pos.y); }
static float mesh_index_to_xpos(const uint8_t i) {
static constexpr float get_z_offset() { return 0.0f; }
static float get_mesh_x(const uint8_t i) {
return i < (GRID_MAX_POINTS_X) ? pgm_read_float(&_mesh_index_to_xpos[i]) : MESH_MIN_X + i * (MESH_X_DIST);
}
static float mesh_index_to_ypos(const uint8_t i) {
static float get_mesh_y(const uint8_t i) {
return i < (GRID_MAX_POINTS_Y) ? pgm_read_float(&_mesh_index_to_ypos[i]) : MESH_MIN_Y + i * (MESH_Y_DIST);
}
@ -307,11 +310,7 @@ public:
}; // class unified_bed_leveling
extern unified_bed_leveling ubl;
#define _GET_MESH_X(I) ubl.mesh_index_to_xpos(I)
#define _GET_MESH_Y(J) ubl.mesh_index_to_ypos(J)
#define Z_VALUES_ARR ubl.z_values
extern unified_bed_leveling bedlevel;
// Prevent debugging propagating to other files
#include "../../../core/debug_out.h"

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

@ -905,11 +905,7 @@ void set_message_with_feedback(FSTR_P const fstr) {
// It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
if (!location.valid()) continue;
const xyz_pos_t ppos = {
mesh_index_to_xpos(lpos.x),
mesh_index_to_ypos(lpos.y),
z_clearance
};
const xyz_pos_t ppos = { get_mesh_x(lpos.x), get_mesh_y(lpos.y), z_clearance };
if (!position_is_reachable(ppos)) break; // SHOULD NOT OCCUR (find_closest_mesh_point only returns reachable points)
@ -1004,11 +1000,7 @@ void set_message_with_feedback(FSTR_P const fstr) {
done_flags.mark(lpos); // Mark this location as 'adjusted' so a new
// location is used on the next loop
const xyz_pos_t raw = {
mesh_index_to_xpos(lpos.x),
mesh_index_to_ypos(lpos.y),
Z_CLEARANCE_BETWEEN_PROBES
};
const xyz_pos_t raw = { get_mesh_x(lpos.x), get_mesh_y(lpos.y), Z_CLEARANCE_BETWEEN_PROBES };
if (!position_is_reachable(raw)) break; // SHOULD NOT OCCUR (find_closest_mesh_point_of_type only returns reachable)
@ -1241,7 +1233,7 @@ mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
if (!isnan(z_values[i][j])) continue; // Skip valid mesh points
// Skip unreachable points
if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j)))
if (!probe.can_reach(get_mesh_x(i), get_mesh_y(j)))
continue;
found_a_NAN = true;
@ -1293,11 +1285,11 @@ mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
static bool test_func(uint8_t i, uint8_t j, void *data) {
find_closest_t *d = (find_closest_t*)data;
if ( d->type == CLOSEST || d->type == (isnan(ubl.z_values[i][j]) ? INVALID : REAL)
if ( d->type == CLOSEST || d->type == (isnan(bedlevel.z_values[i][j]) ? INVALID : REAL)
|| (d->type == SET_IN_BITMAP && !d->done_flags->marked(i, j))
) {
// Found a Mesh Point of the specified type!
const xy_pos_t mpos = { ubl.mesh_index_to_xpos(i), ubl.mesh_index_to_ypos(j) };
const xy_pos_t mpos = { bedlevel.get_mesh_x(i), bedlevel.get_mesh_y(j) };
// If using the probe as the reference there are some unreachable locations.
// Also for round beds, there are grid points outside the bed the nozzle can't reach.
@ -1341,7 +1333,7 @@ mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const Mesh
|| (type == SET_IN_BITMAP && !done_flags->marked(i, j))
) {
// Found a Mesh Point of the specified type!
const xy_pos_t mpos = { mesh_index_to_xpos(i), mesh_index_to_ypos(j) };
const xy_pos_t mpos = { get_mesh_x(i), get_mesh_y(j) };
// If using the probe as the reference there are some unreachable locations.
// Also for round beds, there are grid points outside the bed the nozzle can't reach.
@ -1397,10 +1389,10 @@ typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info;
void unified_bed_leveling::smart_fill_mesh() {
static const smart_fill_info
info0 PROGMEM = { 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false }, // Bottom of the mesh looking up
info1 PROGMEM = { 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false }, // Top of the mesh looking down
info2 PROGMEM = { 0, GRID_MAX_POINTS_X - 2, 0, GRID_MAX_POINTS_Y, true }, // Left side of the mesh looking right
info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true }; // Right side of the mesh looking left
info0 PROGMEM = { 0, GRID_MAX_POINTS_X, 0, (GRID_MAX_POINTS_Y) - 2, false }, // Bottom of the mesh looking up
info1 PROGMEM = { 0, GRID_MAX_POINTS_X, (GRID_MAX_POINTS_Y) - 1, 0, false }, // Top of the mesh looking down
info2 PROGMEM = { 0, (GRID_MAX_POINTS_X) - 2, 0, GRID_MAX_POINTS_Y, true }, // Left side of the mesh looking right
info3 PROGMEM = { (GRID_MAX_POINTS_X) - 1, 0, 0, GRID_MAX_POINTS_Y, true }; // Right side of the mesh looking left
static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
LOOP_L_N(i, COUNT(info)) {
@ -1589,9 +1581,7 @@ void unified_bed_leveling::smart_fill_mesh() {
matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
GRID_LOOP(i, j) {
float mx = mesh_index_to_xpos(i),
my = mesh_index_to_ypos(j),
mz = z_values[i][j];
float mx = get_mesh_x(i), my = get_mesh_y(j), mz = z_values[i][j];
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
@ -1688,18 +1678,18 @@ void unified_bed_leveling::smart_fill_mesh() {
xy_pos_t ppos;
LOOP_L_N(ix, GRID_MAX_POINTS_X) {
ppos.x = mesh_index_to_xpos(ix);
ppos.x = get_mesh_x(ix);
LOOP_L_N(iy, GRID_MAX_POINTS_Y) {
ppos.y = mesh_index_to_ypos(iy);
ppos.y = get_mesh_y(iy);
if (isnan(z_values[ix][iy])) {
// undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
incremental_LSF_reset(&lsf_results);
xy_pos_t rpos;
LOOP_L_N(jx, GRID_MAX_POINTS_X) {
rpos.x = mesh_index_to_xpos(jx);
rpos.x = get_mesh_x(jx);
LOOP_L_N(jy, GRID_MAX_POINTS_Y) {
if (TEST(bitmap[jx], jy)) {
rpos.y = mesh_index_to_ypos(jy);
rpos.y = get_mesh_y(jy);
const float rz = z_values[jx][jy],
w = 1.0f + weight_scaled / (rpos - ppos).magnitude();
incremental_WLSF(&lsf_results, rpos, rz, w);
@ -1758,7 +1748,7 @@ void unified_bed_leveling::smart_fill_mesh() {
SERIAL_ECHOPGM("X-Axis Mesh Points at: ");
LOOP_L_N(i, GRID_MAX_POINTS_X) {
SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3);
SERIAL_ECHO_F(LOGICAL_X_POSITION(get_mesh_x(i)), 3);
SERIAL_ECHOPGM(" ");
serial_delay(25);
}
@ -1766,7 +1756,7 @@ void unified_bed_leveling::smart_fill_mesh() {
SERIAL_ECHOPGM("Y-Axis Mesh Points at: ");
LOOP_L_N(i, GRID_MAX_POINTS_Y) {
SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3);
SERIAL_ECHO_F(LOGICAL_Y_POSITION(get_mesh_y(i)), 3);
SERIAL_ECHOPGM(" ");
serial_delay(25);
}

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

@ -76,8 +76,8 @@
#endif
// The distance is always MESH_X_DIST so multiply by the constant reciprocal.
const float xratio = (end.x - mesh_index_to_xpos(iend.x)) * RECIPROCAL(MESH_X_DIST),
yratio = (end.y - mesh_index_to_ypos(iend.y)) * RECIPROCAL(MESH_Y_DIST),
const float xratio = (end.x - get_mesh_x(iend.x)) * RECIPROCAL(MESH_X_DIST),
yratio = (end.y - get_mesh_y(iend.y)) * RECIPROCAL(MESH_Y_DIST),
z1 = z_values[iend.x][iend.y ] + xratio * (z_values[iend.x + 1][iend.y ] - z_values[iend.x][iend.y ]),
z2 = z_values[iend.x][iend.y + 1] + xratio * (z_values[iend.x + 1][iend.y + 1] - z_values[iend.x][iend.y + 1]);
@ -139,7 +139,7 @@
icell.y += ineg.y; // Line going down? Just go to the bottom.
while (icell.y != iend.y + ineg.y) {
icell.y += iadd.y;
const float next_mesh_line_y = mesh_index_to_ypos(icell.y);
const float next_mesh_line_y = get_mesh_y(icell.y);
/**
* Skip the calculations for an infinite slope.
@ -155,7 +155,7 @@
// Replace NAN corrections with 0.0 to prevent NAN propagation.
if (isnan(z0)) z0 = 0.0;
dest.y = mesh_index_to_ypos(icell.y);
dest.y = get_mesh_y(icell.y);
/**
* Without this check, it's possible to generate a zero length move, as in the case where
@ -196,7 +196,7 @@
while (icell.x != iend.x + ineg.x) {
icell.x += iadd.x;
dest.x = mesh_index_to_xpos(icell.x);
dest.x = get_mesh_x(icell.x);
dest.y = ratio * dest.x + c; // Calculate Y at the next X mesh line
float z0 = z_correction_for_y_on_vertical_mesh_line(dest.y, icell.x, icell.y)
@ -245,8 +245,8 @@
while (cnt) {
const float next_mesh_line_x = mesh_index_to_xpos(icell.x + iadd.x),
next_mesh_line_y = mesh_index_to_ypos(icell.y + iadd.y);
const float next_mesh_line_x = get_mesh_x(icell.x + iadd.x),
next_mesh_line_y = get_mesh_y(icell.y + iadd.y);
dest.y = ratio * next_mesh_line_x + c; // Calculate Y at the next X mesh line
dest.x = (next_mesh_line_y - c) / ratio; // Calculate X at the next Y mesh line
@ -423,7 +423,7 @@
if (isnan(z_x0y1)) z_x0y1 = 0; // in order to avoid isnan tests per cell,
if (isnan(z_x1y1)) z_x1y1 = 0; // thus guessing zero for undefined points
const xy_pos_t pos = { mesh_index_to_xpos(icell.x), mesh_index_to_ypos(icell.y) };
const xy_pos_t pos = { get_mesh_x(icell.x), get_mesh_y(icell.y) };
xy_pos_t cell = raw - pos;
const float z_xmy0 = (z_x1y0 - z_x0y0) * RECIPROCAL(MESH_X_DIST), // z slope per x along y0 (lower left to lower right)
@ -450,10 +450,7 @@
if (--segments == 0) raw = destination; // if this is last segment, use destination for exact
const float z_cxcy = (z_cxy0 + z_cxym * cell.y) // interpolated mesh z height along cell.x at cell.y
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
* fade_scaling_factor // apply fade factor to interpolated mesh height
#endif
;
TERN_(ENABLE_LEVELING_FADE_HEIGHT, * fade_scaling_factor); // apply fade factor to interpolated height
const float oldz = raw.z; raw.z += z_cxcy;
planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, segment_xyz_mm OPTARG(SCARA_FEEDRATE_SCALING, inv_duration) );

16
Marlin/src/gcode/bedlevel/G26.cpp

@ -293,10 +293,10 @@ typedef struct {
if (circle_flags.marked(p1.x, p1.y) && circle_flags.marked(p2.x, p2.y)) {
xyz_pos_t s, e;
s.x = _GET_MESH_X(p1.x) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
e.x = _GET_MESH_X(p2.x) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
s.y = _GET_MESH_Y(p1.y) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
e.y = _GET_MESH_Y(p2.y) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
s.x = bedlevel.get_mesh_x(p1.x) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
e.x = bedlevel.get_mesh_x(p2.x) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
s.y = bedlevel.get_mesh_y(p1.y) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
e.y = bedlevel.get_mesh_y(p2.y) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
s.z = e.z = layer_height;
#if HAS_ENDSTOPS
@ -448,7 +448,7 @@ typedef struct {
GRID_LOOP(i, j) {
if (!circle_flags.marked(i, j)) {
// We found a circle that needs to be printed
const xy_pos_t m = { _GET_MESH_X(i), _GET_MESH_Y(j) };
const xy_pos_t m = { bedlevel.get_mesh_x(i), bedlevel.get_mesh_y(j) };
// Get the distance to this intersection
float f = (pos - m).magnitude();
@ -729,7 +729,7 @@ void GcodeSuite::G26() {
if (location.valid()) {
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location.pos, ExtUI::G26_POINT_START));
const xy_pos_t circle = _GET_MESH_POS(location.pos);
const xy_pos_t circle = { bedlevel.get_mesh_x(location.pos.a), bedlevel.get_mesh_y(location.pos.b) };
// If this mesh location is outside the printable radius, skip it.
if (!position_is_reachable(circle)) continue;
@ -738,8 +738,8 @@ void GcodeSuite::G26() {
// which is always drawn counter-clockwise.
const xy_int8_t st = location;
const bool f = st.y == 0,
r = st.x >= GRID_MAX_POINTS_X - 1,
b = st.y >= GRID_MAX_POINTS_Y - 1;
r = st.x >= (GRID_MAX_POINTS_X) - 1,
b = st.y >= (GRID_MAX_POINTS_Y) - 1;
#if ENABLED(ARC_SUPPORT)

4
Marlin/src/gcode/bedlevel/G42.cpp

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

34
Marlin/src/gcode/bedlevel/M420.cpp

@ -71,13 +71,13 @@ void GcodeSuite::M420() {
start.set(x_min, y_min);
spacing.set((x_max - x_min) / (GRID_MAX_CELLS_X),
(y_max - y_min) / (GRID_MAX_CELLS_Y));
bbl.set_grid(spacing, start);
bedlevel.set_grid(spacing, start);
#endif
GRID_LOOP(x, y) {
Z_VALUES(x, y) = 0.001 * random(-200, 200);
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y)));
bedlevel.z_values[x][y] = 0.001 * random(-200, 200);
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, bedlevel.z_values[x][y]));
}
TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
SERIAL_ECHOPGM(" (", x_min);
SERIAL_CHAR(','); SERIAL_ECHO(y_min);
@ -101,7 +101,7 @@ void GcodeSuite::M420() {
set_bed_leveling_enabled(false);
#if ENABLED(EEPROM_SETTINGS)
const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.storage_slot;
const int8_t storage_slot = parser.has_value() ? parser.value_int() : bedlevel.storage_slot;
const int16_t a = settings.calc_num_meshes();
if (!a) {
@ -116,7 +116,7 @@ void GcodeSuite::M420() {
}
settings.load_mesh(storage_slot);
ubl.storage_slot = storage_slot;
bedlevel.storage_slot = storage_slot;
#else
@ -128,10 +128,10 @@ void GcodeSuite::M420() {
// L or V display the map info
if (parser.seen("LV")) {
ubl.display_map(parser.byteval('T'));
bedlevel.display_map(parser.byteval('T'));
SERIAL_ECHOPGM("Mesh is ");
if (!ubl.mesh_is_valid()) SERIAL_ECHOPGM("in");
SERIAL_ECHOLNPGM("valid\nStorage slot: ", ubl.storage_slot);
if (!bedlevel.mesh_is_valid()) SERIAL_ECHOPGM("in");
SERIAL_ECHOLNPGM("valid\nStorage slot: ", bedlevel.storage_slot);
}
#endif // AUTO_BED_LEVELING_UBL
@ -148,7 +148,7 @@ void GcodeSuite::M420() {
#if ENABLED(AUTO_BED_LEVELING_UBL)
set_bed_leveling_enabled(false);
ubl.adjust_mesh_to_mean(true, cval);
bedlevel.adjust_mesh_to_mean(true, cval);
#else
@ -156,7 +156,7 @@ void GcodeSuite::M420() {
// Get the sum and average of all mesh values
float mesh_sum = 0;
GRID_LOOP(x, y) mesh_sum += Z_VALUES(x, y);
GRID_LOOP(x, y) mesh_sum += bedlevel.z_values[x][y];
const float zmean = mesh_sum / float(GRID_MAX_POINTS);
#else // midrange
@ -164,7 +164,7 @@ void GcodeSuite::M420() {
// Find the low and high mesh values.
float lo_val = 100, hi_val = -100;
GRID_LOOP(x, y) {
const float z = Z_VALUES(x, y);
const float z = bedlevel.z_values[x][y];
NOMORE(lo_val, z);
NOLESS(hi_val, z);
}
@ -178,10 +178,10 @@ void GcodeSuite::M420() {
set_bed_leveling_enabled(false);
// Subtract the mean from all values
GRID_LOOP(x, y) {
Z_VALUES(x, y) -= zmean;
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y)));
bedlevel.z_values[x][y] -= zmean;
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, bedlevel.z_values[x][y]));
}
TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
}
#endif
@ -202,10 +202,10 @@ void GcodeSuite::M420() {
#else
if (leveling_is_valid()) {
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
bbl.print_leveling_grid();
bedlevel.print_leveling_grid();
#elif ENABLED(MESH_BED_LEVELING)
SERIAL_ECHOLNPGM("Mesh Bed Level data:");
mbl.report_mesh();
bedlevel.report_mesh();
#endif
}
#endif

28
Marlin/src/gcode/bedlevel/abl/G29.cpp

@ -313,8 +313,8 @@ G29_TYPE GcodeSuite::G29() {
if (!isnan(rx) && !isnan(ry)) {
// Get nearest i / j from rx / ry
i = (rx - bbl.get_grid_start().x) / bbl.get_grid_spacing().x + 0.5f;
j = (ry - bbl.get_grid_start().y) / bbl.get_grid_spacing().y + 0.5f;
i = (rx - bedlevel.grid_start.x) / bedlevel.grid_spacing.x + 0.5f;
j = (ry - bedlevel.grid_start.y) / bedlevel.grid_spacing.y + 0.5f;
LIMIT(i, 0, (GRID_MAX_POINTS_X) - 1);
LIMIT(j, 0, (GRID_MAX_POINTS_Y) - 1);
}
@ -323,8 +323,8 @@ G29_TYPE GcodeSuite::G29() {
if (WITHIN(i, 0, (GRID_MAX_POINTS_X) - 1) && WITHIN(j, 0, (GRID_MAX_POINTS_Y) - 1)) {
set_bed_leveling_enabled(false);
Z_VALUES_ARR[i][j] = rz;
bbl.refresh_bed_level();
bedlevel.z_values[i][j] = rz;
bedlevel.refresh_bed_level();
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, rz));
set_bed_leveling_enabled(abl.reenable);
if (abl.reenable) report_current_position();
@ -463,7 +463,7 @@ G29_TYPE GcodeSuite::G29() {
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
if (!abl.dryrun
&& (abl.gridSpacing != bbl.get_grid_spacing() || abl.probe_position_lf != bbl.get_grid_start())
&& (abl.gridSpacing != bedlevel.grid_spacing || abl.probe_position_lf != bedlevel.grid_start)
) {
// Reset grid to 0.0 or "not probed". (Also disables ABL)
reset_bed_level();
@ -473,7 +473,7 @@ G29_TYPE GcodeSuite::G29() {
}
// Pre-populate local Z values from the stored mesh
TERN_(IS_KINEMATIC, COPY(abl.z_values, Z_VALUES_ARR));
TERN_(IS_KINEMATIC, COPY(abl.z_values, bedlevel.z_values));
#endif // AUTO_BED_LEVELING_BILINEAR
@ -760,14 +760,14 @@ G29_TYPE GcodeSuite::G29() {
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
if (abl.dryrun)
bbl.print_leveling_grid(&abl.z_values);
bedlevel.print_leveling_grid(&abl.z_values);
else {
bbl.set_grid(abl.gridSpacing, abl.probe_position_lf);
COPY(Z_VALUES_ARR, abl.z_values);
TERN_(IS_KINEMATIC, bbl.extrapolate_unprobed_bed_level());
bbl.refresh_bed_level();
bedlevel.set_grid(abl.gridSpacing, abl.probe_position_lf);
COPY(bedlevel.z_values, abl.z_values);
TERN_(IS_KINEMATIC, bedlevel.extrapolate_unprobed_bed_level());
bedlevel.refresh_bed_level();
bbl.print_leveling_grid();
bedlevel.print_leveling_grid();
}
#elif ENABLED(AUTO_BED_LEVELING_LINEAR)
@ -887,8 +887,8 @@ G29_TYPE GcodeSuite::G29() {
// Unapply the offset because it is going to be immediately applied
// and cause compensation movement in Z
const float fade_scaling_factor = TERN(ENABLE_LEVELING_FADE_HEIGHT, planner.fade_scaling_factor_for_z(current_position.z), 1);
current_position.z -= fade_scaling_factor * bbl.get_z_correction(current_position);
current_position.z -= bedlevel.get_z_correction(current_position)
TERN_(ENABLE_LEVELING_FADE_HEIGHT, * planner.fade_scaling_factor_for_z(current_position.z));
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(" corrected Z:", current_position.z);
}

6
Marlin/src/gcode/bedlevel/abl/M421.cpp

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

18
Marlin/src/gcode/bedlevel/mbl/G29.cpp

@ -93,14 +93,14 @@ void GcodeSuite::G29() {
SERIAL_ECHOPGM("Mesh Bed Leveling ");
if (leveling_is_valid()) {
serialprintln_onoff(planner.leveling_active);
mbl.report_mesh();
bedlevel.report_mesh();
}
else
SERIAL_ECHOLNPGM("has no data.");
break;
case MeshStart:
mbl.reset();
bedlevel.reset();
mbl_probe_index = 0;
if (!ui.wait_for_move) {
queue.inject(parser.seen_test('N') ? F("G28" TERN(CAN_SET_LEVELING_AFTER_G28, "L0", "") "\nG29S2") : F("G29S2"));
@ -128,7 +128,7 @@ void GcodeSuite::G29() {
}
else {
// Save Z for the previous mesh position
mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z);
bedlevel.set_zigzag_z(mbl_probe_index - 1, current_position.z);
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, current_position.z));
TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(_MIN(mbl_probe_index, GRID_MAX_POINTS), int(GRID_MAX_POINTS), current_position.z));
SET_SOFT_ENDSTOP_LOOSE(false);
@ -138,8 +138,8 @@ void GcodeSuite::G29() {
// Disable software endstops to allow manual adjustment
// If G29 is left hanging without completion they won't be re-enabled!
SET_SOFT_ENDSTOP_LOOSE(true);
mbl.zigzag(mbl_probe_index++, ix, iy);
_manual_goto_xy({ mbl.index_to_xpos[ix], mbl.index_to_ypos[iy] });
bedlevel.zigzag(mbl_probe_index++, ix, iy);
_manual_goto_xy({ bedlevel.index_to_xpos[ix], bedlevel.index_to_ypos[iy] });
}
else {
// Move to the after probing position
@ -195,9 +195,9 @@ void GcodeSuite::G29() {
return echo_not_entered('J');
if (parser.seenval('Z')) {
mbl.z_values[ix][iy] = parser.value_linear_units();
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, mbl.z_values[ix][iy]));
TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ix, iy, mbl.z_values[ix][iy]));
bedlevel.z_values[ix][iy] = parser.value_linear_units();
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, bedlevel.z_values[ix][iy]));
TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ix, iy, bedlevel.z_values[ix][iy]));
}
else
return echo_not_entered('Z');
@ -205,7 +205,7 @@ void GcodeSuite::G29() {
case MeshSetZOffset:
if (parser.seenval('Z'))
mbl.z_offset = parser.value_linear_units();
bedlevel.z_offset = parser.value_linear_units();
else
return echo_not_entered('Z');
break;

6
Marlin/src/gcode/bedlevel/mbl/M421.cpp

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

2
Marlin/src/gcode/bedlevel/ubl/G29.cpp

@ -39,7 +39,7 @@ void GcodeSuite::G29() {
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE));
ubl.G29();
bedlevel.G29();
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
}

4
Marlin/src/gcode/bedlevel/ubl/M421.cpp

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

2
Marlin/src/gcode/control/M17_M18_M84.cpp

@ -242,6 +242,6 @@ void GcodeSuite::M18_M84() {
else
planner.finish_and_disable();
TERN_(AUTO_BED_LEVELING_UBL, ubl.steppers_were_disabled());
TERN_(AUTO_BED_LEVELING_UBL, bedlevel.steppers_were_disabled());
}
}

2
Marlin/src/gcode/motion/M290.cpp

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

16
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp

@ -1281,9 +1281,9 @@ void MarlinUI::draw_status_screen() {
* Show X and Y positions
*/
_XLABEL(_PLOT_X, 0);
lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(ubl.mesh_index_to_xpos(x_plot))));
lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(bedlevel.get_mesh_x(x_plot))));
_YLABEL(_LCD_W_POS, 0);
lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos(y_plot))));
lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(bedlevel.get_mesh_y(y_plot))));
lcd_moveto(_PLOT_X, 0);
@ -1475,8 +1475,8 @@ void MarlinUI::draw_status_screen() {
* Print Z values
*/
_ZLABEL(_LCD_W_POS, 1);
if (!isnan(ubl.z_values[x_plot][y_plot]))
lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot]));
if (!isnan(bedlevel.z_values[x_plot][y_plot]))
lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else
lcd_put_u8str(F(" -----"));
@ -1486,16 +1486,16 @@ void MarlinUI::draw_status_screen() {
* Show all values at right of screen
*/
_XLABEL(_LCD_W_POS, 1);
lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(ubl.mesh_index_to_xpos(x_plot))));
lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(bedlevel.get_mesh_x(x_plot))));
_YLABEL(_LCD_W_POS, 2);
lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos(y_plot))));
lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(bedlevel.get_mesh_y(y_plot))));
/**
* Show the location value
*/
_ZLABEL(_LCD_W_POS, 3);
if (!isnan(ubl.z_values[x_plot][y_plot]))
lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot]));
if (!isnan(bedlevel.z_values[x_plot][y_plot]))
lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else
lcd_put_u8str(F(" -----"));

8
Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp

@ -1069,15 +1069,15 @@ void MarlinUI::draw_status_screen() {
// Show all values
lcd.setCursor(_LCD_W_POS, 1); lcd_put_u8str(F("X:"));
lcd.print(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
lcd.print(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&bedlevel._mesh_index_to_xpos[x_plot]))));
lcd.setCursor(_LCD_W_POS, 2); lcd_put_u8str(F("Y:"));
lcd.print(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
lcd.print(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&bedlevel._mesh_index_to_ypos[y_plot]))));
// Show the location value
lcd.setCursor(_LCD_W_POS, 3); lcd_put_u8str(F("Z:"));
if (!isnan(ubl.z_values[x_plot][y_plot]))
lcd.print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
if (!isnan(bedlevel.z_values[x_plot][y_plot]))
lcd.print(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else
lcd_put_u8str(F(" -----"));

10
Marlin/src/lcd/dogm/marlinui_DOGM.cpp

@ -574,9 +574,9 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
u8g.setColorIndex(1);
const u8g_uint_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
u8g_uint_t y = y_offset + pixels_per_y_mesh_pnt / 2;
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
for (uint8_t j = 0; j < (GRID_MAX_POINTS_Y); j++, y += pixels_per_y_mesh_pnt)
if (PAGE_CONTAINS(y, y))
for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
for (uint8_t i = 0, x = sx; i < (GRID_MAX_POINTS_X); i++, x += pixels_per_x_mesh_pnt)
u8g.drawBox(x, y, 1, 1);
// Fill in the Specified Mesh Point
@ -596,7 +596,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
// Show X and Y positions at top of screen
u8g.setColorIndex(1);
if (PAGE_UNDER(7)) {
const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
lpos = pos.asLogical();
lcd_put_u8str_P(5, 7, X_LBL);
lcd_put_u8str(ftostr52(lpos.x));
@ -614,8 +614,8 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
// Show the location value
lcd_put_u8str_P(74, LCD_PIXEL_HEIGHT, Z_LBL);
if (!isnan(ubl.z_values[x_plot][y_plot]))
lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot]));
if (!isnan(bedlevel.z_values[x_plot][y_plot]))
lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else
lcd_put_u8str(F(" -----"));
}

132
Marlin/src/lcd/e3v2/jyersui/dwin.cpp

@ -207,11 +207,9 @@ CrealityDWINClass CrealityDWIN;
struct linear_fit_data lsf_results;
incremental_LSF_reset(&lsf_results);
GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y])) {
xy_pos_t rpos;
rpos.x = ubl.mesh_index_to_xpos(x);
rpos.y = ubl.mesh_index_to_ypos(y);
incremental_LSF(&lsf_results, rpos, Z_VALUES_ARR[x][y]);
if (!isnan(bedlevel.z_values[x][y])) {
xy_pos_t rpos = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
incremental_LSF(&lsf_results, rpos, bedlevel.z_values[x][y]);
}
}
@ -220,13 +218,13 @@ CrealityDWINClass CrealityDWIN;
return true;
}
ubl.set_all_mesh_points_to_value(0);
bedlevel.set_all_mesh_points_to_value(0);
matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
GRID_LOOP(i, j) {
float mx = ubl.mesh_index_to_xpos(i),
my = ubl.mesh_index_to_ypos(j),
mz = Z_VALUES_ARR[i][j];
float mx = bedlevel.get_mesh_x(i),
my = bedlevel.get_mesh_y(j),
mz = bedlevel.z_values[i][j];
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
@ -250,7 +248,7 @@ CrealityDWINClass CrealityDWIN;
DEBUG_DELAY(20);
}
Z_VALUES_ARR[i][j] = mz - lsf_results.D;
bedlevel.z_values[i][j] = mz - lsf_results.D;
}
return false;
}
@ -268,7 +266,7 @@ CrealityDWINClass CrealityDWIN;
void manual_move(bool zmove=false) {
if (zmove) {
planner.synchronize();
current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize();
}
@ -279,7 +277,7 @@ CrealityDWINClass CrealityDWIN;
sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
gcode.process_subcommands_now(cmd);
planner.synchronize();
current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize();
CrealityDWIN.Redraw_Menu();
@ -289,8 +287,8 @@ CrealityDWINClass CrealityDWIN;
float get_max_value() {
float max = __FLT_MIN__;
GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] > max)
max = Z_VALUES_ARR[x][y];
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
max = bedlevel.z_values[x][y];
}
return max;
}
@ -298,24 +296,24 @@ CrealityDWINClass CrealityDWIN;
float get_min_value() {
float min = __FLT_MAX__;
GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] < min)
min = Z_VALUES_ARR[x][y];
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
min = bedlevel.z_values[x][y];
}
return min;
}
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) {
drawing_mesh = true;
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
const uint16_t cell_width_px = total_width_px / GRID_MAX_POINTS_X;
const uint16_t cell_height_px = total_width_px / GRID_MAX_POINTS_Y;
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x,
cell_width_px = total_width_px / (GRID_MAX_POINTS_X),
cell_height_px = total_width_px / (GRID_MAX_POINTS_Y);
const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
// Clear background from previous selection and select new square
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);
if (selected >= 0) {
const auto selected_y = selected / GRID_MAX_POINTS_X;
const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y);
const auto selected_y = selected / (GRID_MAX_POINTS_X);
const auto selected_x = selected - (GRID_MAX_POINTS_X) * selected_y;
const auto start_y_px = padding_y_top + selected_y * cell_height_px;
const auto start_x_px = padding_x + selected_x * cell_width_px;
DWIN_Draw_Rectangle(1, Color_White, _MAX(0, start_x_px - gridline_width), _MAX(0, start_y_px - gridline_width), start_x_px + cell_width_px, start_y_px + cell_height_px);
@ -329,11 +327,11 @@ CrealityDWINClass CrealityDWIN;
const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
const auto end_y_px = start_y_px + cell_height_px - 1 - gridline_width;
DWIN_Draw_Rectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
isnan(Z_VALUES_ARR[x][y]) ? Color_Grey : ( // gray if undefined
(Z_VALUES_ARR[x][y] < 0 ?
(uint16_t)round(0x1F * -Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
_MIN(0x1F, (((uint8_t)abs(Z_VALUES_ARR[x][y]) / 10) * 4))), // + blue stepping for every mm
isnan(bedlevel.z_values[x][y]) ? Color_Grey : ( // gray if undefined
(bedlevel.z_values[x][y] < 0 ?
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
_MIN(0x1F, (((uint8_t)abs(bedlevel.z_values[x][y]) / 10) * 4))), // + blue stepping for every mm
start_x_px, start_y_px, end_x_px, end_y_px
);
@ -343,14 +341,14 @@ CrealityDWINClass CrealityDWIN;
// Draw value text on
if (viewer_print_value) {
int8_t offset_x, offset_y = cell_height_px / 2 - 6;
if (isnan(Z_VALUES_ARR[x][y])) { // undefined
if (isnan(bedlevel.z_values[x][y])) { // undefined
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"));
}
else { // has value
if (GRID_MAX_POINTS_X < 10)
sprintf_P(buf, PSTR("%s"), dtostrf(abs(Z_VALUES_ARR[x][y]), 1, 2, str_1));
sprintf_P(buf, PSTR("%s"), dtostrf(abs(bedlevel.z_values[x][y]), 1, 2, str_1));
else
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(Z_VALUES_ARR[x][y] - (int16_t)Z_VALUES_ARR[x][y]) * 100));
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(bedlevel.z_values[x][y] - (int16_t)bedlevel.z_values[x][y]) * 100));
offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
if (!(GRID_MAX_POINTS_X < 10))
DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px - 2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F("."));
@ -417,14 +415,14 @@ void CrealityDWINClass::Draw_Float(float value, uint8_t row, bool selected/*=fal
}
void CrealityDWINClass::Draw_Option(uint8_t value, const char * const * options, uint8_t row, bool selected/*=false*/, bool color/*=false*/) {
uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black;
uint16_t tColor = (color) ? GetColor(value, Color_White, false) : Color_White;
uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black,
tColor = (color) ? GetColor(value, Color_White, false) : Color_White;
DWIN_Draw_Rectangle(1, bColor, 202, MBASE(row) + 14, 258, MBASE(row) - 2);
DWIN_Draw_String(false, DWIN_FONT_MENU, tColor, bColor, 202, MBASE(row) - 1, options[value]);
}
uint16_t CrealityDWINClass::GetColor(uint8_t color, uint16_t original, bool light/*=false*/) {
switch (color){
switch (color) {
case Default:
return original;
break;
@ -2842,7 +2840,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (draw)
Draw_Menu_Item(row, ICON_Tilt, F("Autotilt Current Mesh"));
else {
if (ubl.storage_slot < 0) {
if (bedlevel.storage_slot < 0) {
Popup_Handler(MeshSlot);
break;
}
@ -2914,7 +2912,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
}
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
if (ubl.storage_slot < 0) {
if (bedlevel.storage_slot < 0) {
Popup_Handler(MeshSlot);
break;
}
@ -2949,7 +2947,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
Draw_Menu_Item(row, ICON_Mesh, GET_TEXT(MSG_MESH_VIEW), nullptr, true);
else {
#if ENABLED(AUTO_BED_LEVELING_UBL)
if (ubl.storage_slot < 0) {
if (bedlevel.storage_slot < 0) {
Popup_Handler(MeshSlot);
break;
}
@ -2967,16 +2965,16 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case LEVELING_SLOT:
if (draw) {
Draw_Menu_Item(row, ICON_PrintSize, F("Mesh Slot"));
Draw_Float(ubl.storage_slot, row, false, 1);
Draw_Float(bedlevel.storage_slot, row, false, 1);
}
else
Modify_Value(ubl.storage_slot, 0, settings.calc_num_meshes() - 1, 1);
Modify_Value(bedlevel.storage_slot, 0, settings.calc_num_meshes() - 1, 1);
break;
case LEVELING_LOAD:
if (draw)
Draw_Menu_Item(row, ICON_ReadEEPROM, F("Load Mesh"));
else {
if (ubl.storage_slot < 0) {
if (bedlevel.storage_slot < 0) {
Popup_Handler(MeshSlot);
break;
}
@ -2989,7 +2987,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (draw)
Draw_Menu_Item(row, ICON_WriteEEPROM, F("Save Mesh"));
else {
if (ubl.storage_slot < 0) {
if (bedlevel.storage_slot < 0) {
Popup_Handler(MeshSlot);
break;
}
@ -3098,13 +3096,13 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (draw)
Draw_Menu_Item(row, ICON_Mesh, F("Zero Current Mesh"));
else
ZERO(Z_VALUES_ARR);
ZERO(bedlevel.z_values);
break;
case LEVELING_SETTINGS_UNDEF:
if (draw)
Draw_Menu_Item(row, ICON_Mesh, F("Clear Current Mesh"));
else
ubl.invalidate();
bedlevel.invalidate();
break;
#endif // AUTO_BED_LEVELING_UBL
}
@ -3146,7 +3144,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
Draw_Menu_Item(row, ICON_Back, F("Back"));
else {
set_bed_leveling_enabled(level_state);
TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
Draw_Menu(Leveling, LEVELING_MANUAL);
}
break;
@ -3184,36 +3182,36 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case LEVELING_M_OFFSET:
if (draw) {
Draw_Menu_Item(row, ICON_SetZOffset, F("Point Z Offset"));
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
}
else {
if (isnan(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y]))
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
Modify_Value(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
if (isnan(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y]))
bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
Modify_Value(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
}
break;
case LEVELING_M_UP:
if (draw)
Draw_Menu_Item(row, ICON_Axis, F("Microstep Up"));
else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
gcode.process_subcommands_now(F("M290 Z0.01"));
planner.synchronize();
current_position.z += 0.01f;
sync_plan_position();
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
}
break;
case LEVELING_M_DOWN:
if (draw)
Draw_Menu_Item(row, ICON_AxisD, F("Microstep Down"));
else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
gcode.process_subcommands_now(F("M290 Z-0.01"));
planner.synchronize();
current_position.z -= 0.01f;
sync_plan_position();
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
}
break;
case LEVELING_M_GOTO_VALUE:
@ -3305,36 +3303,36 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case UBL_M_OFFSET:
if (draw) {
Draw_Menu_Item(row, ICON_SetZOffset, F("Point Z Offset"));
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
}
else {
if (isnan(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y]))
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
Modify_Value(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
if (isnan(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y]))
bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
Modify_Value(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
}
break;
case UBL_M_UP:
if (draw)
Draw_Menu_Item(row, ICON_Axis, F("Microstep Up"));
else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
gcode.process_subcommands_now(F("M290 Z0.01"));
planner.synchronize();
current_position.z += 0.01f;
sync_plan_position();
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
}
break;
case UBL_M_DOWN:
if (draw)
Draw_Menu_Item(row, ICON_Axis, F("Microstep Down"));
else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
gcode.process_subcommands_now(F("M290 Z-0.01"));
planner.synchronize();
current_position.z -= 0.01f;
sync_plan_position();
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
}
break;
}
@ -3418,13 +3416,13 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case MMESH_OLD:
uint8_t mesh_x, mesh_y;
// 0,0 -> 1,0 -> 2,0 -> 2,1 -> 1,1 -> 0,1 -> 0,2 -> 1,2 -> 2,2
mesh_y = (gridpoint - 1) / GRID_MAX_POINTS_Y;
mesh_x = (gridpoint - 1) % GRID_MAX_POINTS_X;
mesh_y = (gridpoint - 1) / (GRID_MAX_POINTS_Y);
mesh_x = (gridpoint - 1) % (GRID_MAX_POINTS_X);
if (mesh_y % 2 == 1)
mesh_x = GRID_MAX_POINTS_X - mesh_x - 1;
mesh_x = (GRID_MAX_POINTS_X) - mesh_x - 1;
const float currval = Z_VALUES_ARR[mesh_x][mesh_y];
const float currval = bedlevel.z_values[mesh_x][mesh_y];
if (draw) {
Draw_Menu_Item(row, ICON_Zoffset, F("Goto Mesh Value"));
@ -4283,7 +4281,7 @@ void CrealityDWINClass::Popup_Control() {
#if ENABLED(AUTO_BED_LEVELING_UBL)
case MeshSlot:
if (selection == 0) ubl.storage_slot = 0;
if (selection == 0) bedlevel.storage_slot = 0;
Redraw_Menu(true, true);
break;
#endif

10
Marlin/src/lcd/e3v2/marlinui/ui_common.cpp

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

32
Marlin/src/lcd/e3v2/proui/dwin.cpp

@ -3611,7 +3611,7 @@ void Draw_Steps_Menu() {
#define Z_OFFSET_MIN -3
#define Z_OFFSET_MAX 3
void LiveEditMesh() { ((MenuItemPtrClass*)EditZValueItem)->value = &Z_VALUES_ARR[HMI_value.Select ? mesh_x : MenuData.Value][HMI_value.Select ? MenuData.Value : mesh_y]; EditZValueItem->redraw(); }
void LiveEditMesh() { ((MenuItemPtrClass*)EditZValueItem)->value = &bedlevel.z_values[HMI_value.Select ? mesh_x : MenuData.Value][HMI_value.Select ? MenuData.Value : mesh_y]; EditZValueItem->redraw(); }
void ApplyEditMeshX() { mesh_x = MenuData.Value; }
void SetEditMeshX() { HMI_value.Select = 0; SetIntOnClick(0, GRID_MAX_POINTS_X - 1, mesh_x, ApplyEditMeshX, LiveEditMesh); }
void ApplyEditMeshY() { mesh_y = MenuData.Value; }
@ -3622,18 +3622,18 @@ void Draw_Steps_Menu() {
#if ENABLED(AUTO_BED_LEVELING_UBL)
void ApplyUBLSlot() { ubl.storage_slot = MenuData.Value; }
void SetUBLSlot() { SetIntOnClick(0, settings.calc_num_meshes() - 1, ubl.storage_slot, ApplyUBLSlot); }
void ApplyUBLSlot() { bedlevel.storage_slot = MenuData.Value; }
void SetUBLSlot() { SetIntOnClick(0, settings.calc_num_meshes() - 1, bedlevel.storage_slot, ApplyUBLSlot); }
void onDrawUBLSlot(MenuItemClass* menuitem, int8_t line) {
if (ubl.storage_slot < 0) ubl.storage_slot = 0;
onDrawIntMenu(menuitem, line, ubl.storage_slot);
if (bedlevel.storage_slot < 0) bedlevel.storage_slot = 0;
onDrawIntMenu(menuitem, line, bedlevel.storage_slot);
}
void ApplyUBLTiltGrid() { ubl_tools.tilt_grid = MenuData.Value; }
void SetUBLTiltGrid() { SetIntOnClick(1, 3, ubl_tools.tilt_grid, ApplyUBLTiltGrid); }
void UBLTiltMesh() {
if (ubl.storage_slot < 0) ubl.storage_slot = 0;
if (bedlevel.storage_slot < 0) bedlevel.storage_slot = 0;
char buf[15];
if (ubl_tools.tilt_grid > 1) {
sprintf_P(buf, PSTR("G28O\nG29 J%i"), ubl_tools.tilt_grid);
@ -3645,28 +3645,28 @@ void Draw_Steps_Menu() {
}
void UBLSmartFillMesh() {
ubl.smart_fill_mesh();
bedlevel.smart_fill_mesh();
LCD_MESSAGE(MSG_UBL_MESH_FILLED);
}
bool UBLValidMesh() {
const bool valid = ubl_tools.validate();
if (!valid) ubl.invalidate();
if (!valid) bedlevel.invalidate();
return valid;
}
void UBLSaveMesh() {
if (ubl.storage_slot < 0) ubl.storage_slot = 0;
settings.store_mesh(ubl.storage_slot);
ui.status_printf(0, GET_TEXT_F(MSG_MESH_SAVED), ubl.storage_slot);
if (bedlevel.storage_slot < 0) bedlevel.storage_slot = 0;
settings.store_mesh(bedlevel.storage_slot);
ui.status_printf(0, GET_TEXT_F(MSG_MESH_SAVED), bedlevel.storage_slot);
DONE_BUZZ(true);
}
void UBLLoadMesh() {
if (ubl.storage_slot < 0) ubl.storage_slot = 0;
settings.load_mesh(ubl.storage_slot);
if (bedlevel.storage_slot < 0) bedlevel.storage_slot = 0;
settings.load_mesh(bedlevel.storage_slot);
if (UBLValidMesh()) {
ui.status_printf(0, GET_TEXT_F(MSG_MESH_LOADED), ubl.storage_slot);
ui.status_printf(0, GET_TEXT_F(MSG_MESH_LOADED), bedlevel.storage_slot);
DONE_BUZZ(true);
}
else {
@ -3691,7 +3691,7 @@ void Draw_Steps_Menu() {
MENU_ITEM_F(ICON_Level, MSG_AUTO_MESH, onDrawMenuItem, AutoLev);
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
EDIT_ITEM_F(ICON_UBLActive, MSG_UBL_STORAGE_SLOT, onDrawUBLSlot, SetUBLSlot, &ubl.storage_slot);
EDIT_ITEM_F(ICON_UBLActive, MSG_UBL_STORAGE_SLOT, onDrawUBLSlot, SetUBLSlot, &bedlevel.storage_slot);
MENU_ITEM_F(ICON_UBLActive, MSG_UBL_SAVE_MESH, onDrawMenuItem, UBLSaveMesh);
MENU_ITEM_F(ICON_UBLActive, MSG_UBL_LOAD_MESH, onDrawMenuItem, UBLLoadMesh);
EDIT_ITEM_F(ICON_UBLActive, MSG_UBL_TILTING_GRID, onDrawPInt8Menu, SetUBLTiltGrid, &ubl_tools.tilt_grid);
@ -3714,7 +3714,7 @@ void Draw_Steps_Menu() {
BACK_ITEM(Draw_MeshSet_Menu);
EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_X, onDrawPInt8Menu, SetEditMeshX, &mesh_x);
EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_Y, onDrawPInt8Menu, SetEditMeshY, &mesh_y);
EditZValueItem = EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_EDIT_Z, onDrawPFloat3Menu, SetEditZValue, &Z_VALUES_ARR[mesh_x][mesh_y]);
EditZValueItem = EDIT_ITEM_F(ICON_UBLActive, MSG_MESH_EDIT_Z, onDrawPFloat3Menu, SetEditZValue, &bedlevel.z_values[mesh_x][mesh_y]);
}
UpdateMenu(EditMeshMenu);
}

2
Marlin/src/lcd/e3v2/proui/meshviewer.cpp

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

65
Marlin/src/lcd/e3v2/proui/ubl_tools.cpp

@ -63,11 +63,9 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
struct linear_fit_data lsf_results;
incremental_LSF_reset(&lsf_results);
GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y])) {
xy_pos_t rpos;
rpos.x = ubl.mesh_index_to_xpos(x);
rpos.y = ubl.mesh_index_to_ypos(y);
incremental_LSF(&lsf_results, rpos, Z_VALUES_ARR[x][y]);
if (!isnan(bedlevel.z_values[x][y])) {
xy_pos_t rpos = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
incremental_LSF(&lsf_results, rpos, bedlevel.z_values[x][y]);
}
}
@ -76,13 +74,13 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
return true;
}
ubl.set_all_mesh_points_to_value(0);
bedlevel.set_all_mesh_points_to_value(0);
matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
GRID_LOOP(i, j) {
float mx = ubl.mesh_index_to_xpos(i),
my = ubl.mesh_index_to_ypos(j),
mz = Z_VALUES_ARR[i][j];
float mx = bedlevel.get_mesh_x(i),
my = bedlevel.get_mesh_y(j),
mz = bedlevel.z_values[i][j];
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
@ -106,7 +104,7 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
DEBUG_DELAY(20);
}
Z_VALUES_ARR[i][j] = mz - lsf_results.D;
bedlevel.z_values[i][j] = mz - lsf_results.D;
}
return false;
}
@ -124,7 +122,7 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/*=false*/) {
if (zmove) {
planner.synchronize();
current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize();
}
@ -136,7 +134,7 @@ void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y,
sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
gcode.process_subcommands_now(cmd);
planner.synchronize();
current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize();
HMI_ReturnScreen();
@ -146,8 +144,8 @@ void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y,
float UBLMeshToolsClass::get_max_value() {
float max = __FLT_MIN__;
GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] > max)
max = Z_VALUES_ARR[x][y];
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
max = bedlevel.z_values[x][y];
}
return max;
}
@ -155,20 +153,19 @@ float UBLMeshToolsClass::get_max_value() {
float UBLMeshToolsClass::get_min_value() {
float min = __FLT_MAX__;
GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] < min)
min = Z_VALUES_ARR[x][y];
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
min = bedlevel.z_values[x][y];
}
return min;
}
bool UBLMeshToolsClass::validate() {
float min = __FLT_MAX__;
float max = __FLT_MIN__;
float min = __FLT_MAX__, max = __FLT_MIN__;
GRID_LOOP(x, y) {
if (isnan(Z_VALUES_ARR[x][y])) return false;
if (Z_VALUES_ARR[x][y] < min) min = Z_VALUES_ARR[x][y];
if (Z_VALUES_ARR[x][y] > max) max = Z_VALUES_ARR[x][y];
if (isnan(bedlevel.z_values[x][y])) return false;
if (bedlevel.z_values[x][y] < min) min = bedlevel.z_values[x][y];
if (bedlevel.z_values[x][y] > max) max = bedlevel.z_values[x][y];
}
return max <= UBL_Z_OFFSET_MAX && min >= UBL_Z_OFFSET_MIN;
}
@ -177,15 +174,15 @@ bool UBLMeshToolsClass::validate() {
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*/) {
drawing_mesh = true;
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
const uint16_t cell_width_px = total_width_px / GRID_MAX_POINTS_X;
const uint16_t cell_height_px = total_width_px / GRID_MAX_POINTS_Y;
const uint16_t cell_width_px = total_width_px / (GRID_MAX_POINTS_X);
const uint16_t cell_height_px = total_width_px / (GRID_MAX_POINTS_Y);
const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
// Clear background from previous selection and select new square
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);
if (selected >= 0) {
const auto selected_y = selected / GRID_MAX_POINTS_X;
const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y);
const auto selected_y = selected / (GRID_MAX_POINTS_X);
const auto selected_x = selected - (GRID_MAX_POINTS_X) * selected_y;
const auto start_y_px = padding_y_top + selected_y * cell_height_px;
const auto start_x_px = padding_x + selected_x * cell_width_px;
DWIN_Draw_Rectangle(1, Color_White, _MAX(0, start_x_px - gridline_width), _MAX(0, start_y_px - gridline_width), start_x_px + cell_width_px, start_y_px + cell_height_px);
@ -196,14 +193,14 @@ bool UBLMeshToolsClass::validate() {
GRID_LOOP(x, y) {
const auto start_x_px = padding_x + x * cell_width_px;
const auto end_x_px = start_x_px + cell_width_px - 1 - gridline_width;
const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
const auto start_y_px = padding_y_top + ((GRID_MAX_POINTS_Y) - y - 1) * cell_height_px;
const auto end_y_px = start_y_px + cell_height_px - 1 - gridline_width;
DWIN_Draw_Rectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
isnan(Z_VALUES_ARR[x][y]) ? Color_Grey : ( // gray if undefined
(Z_VALUES_ARR[x][y] < 0 ?
(uint16_t)round(0x1F * -Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
_MIN(0x1F, (((uint8_t)abs(Z_VALUES_ARR[x][y]) / 10) * 4))), // + blue stepping for every mm
isnan(bedlevel.z_values[x][y]) ? Color_Grey : ( // gray if undefined
(bedlevel.z_values[x][y] < 0 ?
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
_MIN(0x1F, (((uint8_t)abs(bedlevel.z_values[x][y]) / 10) * 4))), // + blue stepping for every mm
start_x_px, start_y_px, end_x_px, end_y_px
);
@ -213,14 +210,14 @@ bool UBLMeshToolsClass::validate() {
// Draw value text on
if (viewer_print_value) {
int8_t offset_x, offset_y = cell_height_px / 2 - 6;
if (isnan(Z_VALUES_ARR[x][y])) { // undefined
if (isnan(bedlevel.z_values[x][y])) { // undefined
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"));
}
else { // has value
if (GRID_MAX_POINTS_X < 10)
sprintf_P(buf, PSTR("%s"), dtostrf(abs(Z_VALUES_ARR[x][y]), 1, 2, str_1));
sprintf_P(buf, PSTR("%s"), dtostrf(abs(bedlevel.z_values[x][y]), 1, 2, str_1));
else
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(Z_VALUES_ARR[x][y] - (int16_t)Z_VALUES_ARR[x][y]) * 100));
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(bedlevel.z_values[x][y] - (int16_t)bedlevel.z_values[x][y]) * 100));
offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
if (!(GRID_MAX_POINTS_X < 10))
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("."));

4
Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp

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

6
Marlin/src/lcd/extui/ui_api.cpp

@ -889,11 +889,11 @@ namespace ExtUI {
#if HAS_MESH
bed_mesh_t& getMeshArray() { return Z_VALUES_ARR; }
float getMeshPoint(const xy_uint8_t &pos) { return Z_VALUES(pos.x, pos.y); }
bed_mesh_t& getMeshArray() { return bedlevel.z_values; }
float getMeshPoint(const xy_uint8_t &pos) { return bedlevel.z_values[pos.x][pos.y]; }
void setMeshPoint(const xy_uint8_t &pos, const_float_t zoff) {
if (WITHIN(pos.x, 0, (GRID_MAX_POINTS_X) - 1) && WITHIN(pos.y, 0, (GRID_MAX_POINTS_Y) - 1)) {
Z_VALUES(pos.x, pos.y) = zoff;
bedlevel.z_values[pos.x][pos.y] = zoff;
TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
}
}

2
Marlin/src/lcd/marlinui.cpp

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

4
Marlin/src/lcd/menu/menu.cpp

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

4
Marlin/src/lcd/menu/menu_bed_leveling.cpp

@ -214,7 +214,7 @@
BACK_ITEM(MSG_BED_LEVELING);
EDIT_ITEM(uint8, MSG_MESH_X, &xind, 0, (GRID_MAX_POINTS_X) - 1);
EDIT_ITEM(uint8, MSG_MESH_Y, &yind, 0, (GRID_MAX_POINTS_Y) - 1);
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);
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);
END_MENU();
}
@ -281,7 +281,7 @@ void menu_bed_leveling() {
#else
#define LCD_Z_OFFSET_TYPE float42_52 // Values from -99.99 to 99.99
#endif
EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_BED_Z, &mbl.z_offset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_BED_Z, &bedlevel.z_offset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
#endif
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)

2
Marlin/src/lcd/menu/menu_tune.cpp

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

26
Marlin/src/lcd/menu/menu_ubl.cpp

@ -58,7 +58,7 @@ inline float rounded_mesh_value() {
/**
* This screen displays the temporary mesh value and updates it based on encoder
* movement. While this screen is active ubl.fine_tune_mesh sits in a loop getting
* movement. While this screen is active bedlevel.fine_tune_mesh sits in a loop getting
* the current value via ubl_mesh_value, moves the Z axis, and updates the mesh
* value until the encoder button is pressed.
*
@ -70,12 +70,12 @@ inline float rounded_mesh_value() {
void _lcd_mesh_fine_tune(PGM_P const msg) {
constexpr float mesh_edit_step = 1.0f / 200.0f;
ui.defer_status_screen();
if (ubl.encoder_diff) {
if (bedlevel.encoder_diff) {
mesh_edit_accumulator += TERN(IS_TFTGLCD_PANEL,
ubl.encoder_diff * mesh_edit_step / ENCODER_PULSES_PER_STEP,
ubl.encoder_diff > 0 ? mesh_edit_step : -mesh_edit_step
bedlevel.encoder_diff * mesh_edit_step / ENCODER_PULSES_PER_STEP,
bedlevel.encoder_diff > 0 ? mesh_edit_step : -mesh_edit_step
);
ubl.encoder_diff = 0;
bedlevel.encoder_diff = 0;
IF_DISABLED(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
}
TERN_(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
@ -89,7 +89,7 @@ void _lcd_mesh_fine_tune(PGM_P const msg) {
}
//
// Init mesh editing and go to the fine tuning screen (ubl.fine_tune_mesh)
// Init mesh editing and go to the fine tuning screen (bedlevel.fine_tune_mesh)
// To capture encoder events UBL will also call ui.capture and ui.release.
//
void MarlinUI::ubl_mesh_edit_start(const_float_t initial) {
@ -99,7 +99,7 @@ void MarlinUI::ubl_mesh_edit_start(const_float_t initial) {
}
//
// Get the mesh value within a Z adjustment loop (ubl.fine_tune_mesh)
// Get the mesh value within a Z adjustment loop (bedlevel.fine_tune_mesh)
//
float MarlinUI::ubl_mesh_value() { return rounded_mesh_value(); }
@ -291,7 +291,7 @@ void _menu_ubl_fillin() {
}
void _lcd_ubl_invalidate() {
ubl.invalidate();
bedlevel.invalidate();
SERIAL_ECHOLNPGM("Mesh invalidated.");
}
@ -390,8 +390,8 @@ void _lcd_ubl_storage_mesh() {
*/
void _lcd_ubl_map_edit_cmd() {
char ubl_lcd_gcode[50], str[10], str2[10];
dtostrf(ubl.mesh_index_to_xpos(x_plot), 0, 2, str);
dtostrf(ubl.mesh_index_to_ypos(y_plot), 0, 2, str2);
dtostrf(bedlevel.get_mesh_x(x_plot), 0, 2, str);
dtostrf(bedlevel.get_mesh_y(y_plot), 0, 2, str2);
snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29P4X%sY%sR%i"), str, str2, int(n_edit_pts));
queue.inject(ubl_lcd_gcode);
}
@ -400,7 +400,7 @@ void _lcd_ubl_map_edit_cmd() {
* UBL LCD Map Movement
*/
void ubl_map_move_to_xy() {
const xy_pos_t xy = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) };
const xy_pos_t xy = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) };
// Some printers have unreachable areas in the mesh. Skip the move if unreachable.
if (!position_is_reachable(xy)) return;
@ -459,7 +459,7 @@ void ubl_map_screen() {
// Validate if needed
#if IS_KINEMATIC
const xy_pos_t xy = { ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) };
const xy_pos_t xy = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
if (position_is_reachable(xy)) break; // Found a valid point
ui.encoderPosition += step_dir; // Test the next point
#endif
@ -500,7 +500,7 @@ void _ubl_map_screen_homing() {
ui.defer_status_screen();
_lcd_draw_homing();
if (all_axes_homed()) {
ubl.lcd_map_control = true; // Return to the map screen after editing Z
bedlevel.lcd_map_control = true; // Return to the map screen after editing Z
ui.goto_screen(ubl_map_screen, grid_index(x_plot, y_plot)); // Pre-set the encoder value
ui.manual_move.menu_scale = 0; // Immediate move
ubl_map_move_to_xy(); // Move to current mesh point

4
Marlin/src/lcd/tft/touch.cpp

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

14
Marlin/src/lcd/tft/ui_1024x600.cpp

@ -501,14 +501,14 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
tft.set_background(COLOR_BACKGROUND);
tft.add_rectangle(0, 0, GRID_WIDTH, GRID_HEIGHT, COLOR_WHITE);
for (uint16_t x = 0; x < GRID_MAX_POINTS_X ; x++)
for (uint16_t y = 0; y < GRID_MAX_POINTS_Y ; y++)
if (position_is_reachable({ ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) }))
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);
for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++)
for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++)
if (position_is_reachable({ bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) }))
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);
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);
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);
const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
lpos = pos.asLogical();
tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
@ -531,7 +531,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
tft.set_background(COLOR_BACKGROUND);
tft_string.set(Z_LBL);
tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
tft_string.set(isnan(ubl.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(ubl.z_values[x_plot][y_plot]));
tft_string.set(isnan(bedlevel.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
tft_string.trim();
tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);

6
Marlin/src/lcd/tft/ui_320x240.cpp

@ -485,12 +485,12 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++)
for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++)
if (position_is_reachable({ ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) }))
if (position_is_reachable({ bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) }))
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);
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);
const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
lpos = pos.asLogical();
tft.canvas(216, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 96, MENU_ITEM_HEIGHT);
@ -513,7 +513,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
tft.set_background(COLOR_BACKGROUND);
tft_string.set(Z_LBL);
tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
tft_string.set(isnan(ubl.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(ubl.z_values[x_plot][y_plot]));
tft_string.set(isnan(bedlevel.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
tft_string.trim();
tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);

6
Marlin/src/lcd/tft/ui_480x320.cpp

@ -490,12 +490,12 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
for (uint16_t x = 0; x < (GRID_MAX_POINTS_X); x++)
for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++)
if (position_is_reachable({ ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) }))
if (position_is_reachable({ bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) }))
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);
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);
const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
lpos = pos.asLogical();
tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
@ -518,7 +518,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
tft.set_background(COLOR_BACKGROUND);
tft_string.set(Z_LBL);
tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
tft_string.set(isnan(ubl.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(ubl.z_values[x_plot][y_plot]));
tft_string.set(isnan(bedlevel.z_values[x_plot][y_plot]) ? "-----" : ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
tft_string.trim();
tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);

12
Marlin/src/module/motion.cpp

@ -417,7 +417,7 @@ void line_to_current_position(const_feedRate_t fr_mm_s/*=feedrate_mm_s*/) {
#if UBL_SEGMENTED
// UBL segmented line will do Z-only moves in single segment
ubl.line_to_destination_segmented(scaled_fr_mm_s);
bedlevel.line_to_destination_segmented(scaled_fr_mm_s);
#else
if (current_position == destination) return;
@ -904,7 +904,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
* small incremental moves for DELTA or SCARA.
*
* For Unified Bed Leveling (Delta or Segmented Cartesian)
* the ubl.line_to_destination_segmented method replaces this.
* the bedlevel.line_to_destination_segmented method replaces this.
*
* For Auto Bed Leveling (Bilinear) with SEGMENT_LEVELED_MOVES
* this is replaced by segmented_line_to_destination below.
@ -1060,7 +1060,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
#if HAS_MESH
if (planner.leveling_active && planner.leveling_active_at_z(destination.z)) {
#if ENABLED(AUTO_BED_LEVELING_UBL)
ubl.line_to_destination_cartesian(scaled_fr_mm_s, active_extruder); // UBL's motion routine needs to know about
bedlevel.line_to_destination_cartesian(scaled_fr_mm_s, active_extruder); // UBL's motion routine needs to know about
return true; // all moves, including Z-only moves.
#elif ENABLED(SEGMENT_LEVELED_MOVES)
segmented_line_to_destination(scaled_fr_mm_s);
@ -1072,9 +1072,9 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
*/
if (xy_pos_t(current_position) != xy_pos_t(destination)) {
#if ENABLED(MESH_BED_LEVELING)
mbl.line_to_destination(scaled_fr_mm_s);
bedlevel.line_to_destination(scaled_fr_mm_s);
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
bbl.line_to_destination(scaled_fr_mm_s);
bedlevel.line_to_destination(scaled_fr_mm_s);
#endif
return true;
}
@ -1272,7 +1272,7 @@ void prepare_line_to_destination() {
if (
#if UBL_SEGMENTED
#if IS_KINEMATIC // UBL using Kinematic / Cartesian cases as a workaround for now.
ubl.line_to_destination_segmented(MMS_SCALED(feedrate_mm_s))
bedlevel.line_to_destination_segmented(MMS_SCALED(feedrate_mm_s))
#else
line_to_destination_cartesian()
#endif

32
Marlin/src/module/planner.cpp

@ -1581,19 +1581,12 @@ void Planner::check_axes_activity() {
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
#elif DISABLED(MESH_BED_LEVELING)
constexpr float fade_scaling_factor = 1.0;
if (fade_scaling_factor) raw.z += fade_scaling_factor * bedlevel.get_z_correction(raw);
#else
raw.z += bedlevel.get_z_correction(raw);
#endif
raw.z += (
#if ENABLED(MESH_BED_LEVELING)
mbl.get_z(raw OPTARG(ENABLE_LEVELING_FADE_HEIGHT, fade_scaling_factor))
#elif ENABLED(AUTO_BED_LEVELING_UBL)
fade_scaling_factor ? fade_scaling_factor * ubl.get_z_correction(raw) : 0.0
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
fade_scaling_factor ? fade_scaling_factor * bbl.get_z_correction(raw) : 0.0
#endif
);
TERN_(MESH_BED_LEVELING, raw.z += bedlevel.get_z_offset());
#endif
}
@ -1612,21 +1605,14 @@ void Planner::check_axes_activity() {
#elif HAS_MESH
TERN_(MESH_BED_LEVELING, raw.z -= bedlevel.get_z_offset());
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
#elif DISABLED(MESH_BED_LEVELING)
constexpr float fade_scaling_factor = 1.0;
#endif
raw.z -= (
#if ENABLED(MESH_BED_LEVELING)
mbl.get_z(raw OPTARG(ENABLE_LEVELING_FADE_HEIGHT, fade_scaling_factor))
#elif ENABLED(AUTO_BED_LEVELING_UBL)
fade_scaling_factor ? fade_scaling_factor * ubl.get_z_correction(raw) : 0.0
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
fade_scaling_factor ? fade_scaling_factor * bbl.get_z_correction(raw) : 0.0
if (fade_scaling_factor) raw.z -= fade_scaling_factor * bedlevel.get_z_correction(raw);
#else
raw.z -= bedlevel.get_z_correction(raw);
#endif
);
#endif
}

87
Marlin/src/module/settings.cpp

@ -247,9 +247,9 @@ typedef struct SettingsDataStruct {
//
// MESH_BED_LEVELING
//
float mbl_z_offset; // mbl.z_offset
float mbl_z_offset; // bedlevel.z_offset
uint8_t mesh_num_x, mesh_num_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3)] // mbl.z_values
float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3)] // bedlevel.z_values
[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3)];
//
@ -287,7 +287,7 @@ typedef struct SettingsDataStruct {
// AUTO_BED_LEVELING_UBL
//
bool planner_leveling_active; // M420 S planner.leveling_active
int8_t ubl_storage_slot; // ubl.storage_slot
int8_t ubl_storage_slot; // bedlevel.storage_slot
//
// SERVO_ANGLES
@ -598,7 +598,7 @@ void MarlinSettings::postprocess() {
TERN_(ENABLE_LEVELING_FADE_HEIGHT, set_z_fade_height(new_z_fade_height, false)); // false = no report
TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
TERN_(HAS_MOTOR_CURRENT_PWM, stepper.refresh_motor_power());
@ -825,7 +825,7 @@ void MarlinSettings::postprocess() {
{
#if ENABLED(MESH_BED_LEVELING)
static_assert(
sizeof(mbl.z_values) == (GRID_MAX_POINTS) * sizeof(mbl.z_values[0][0]),
sizeof(bedlevel.z_values) == (GRID_MAX_POINTS) * sizeof(bedlevel.z_values[0][0]),
"MBL Z array is the wrong size."
);
#else
@ -835,12 +835,12 @@ void MarlinSettings::postprocess() {
const uint8_t mesh_num_x = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3),
mesh_num_y = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3);
EEPROM_WRITE(TERN(MESH_BED_LEVELING, mbl.z_offset, dummyf));
EEPROM_WRITE(TERN(MESH_BED_LEVELING, bedlevel.z_offset, dummyf));
EEPROM_WRITE(mesh_num_x);
EEPROM_WRITE(mesh_num_y);
#if ENABLED(MESH_BED_LEVELING)
EEPROM_WRITE(mbl.z_values);
EEPROM_WRITE(bedlevel.z_values);
#else
for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummyf);
#endif
@ -877,7 +877,7 @@ void MarlinSettings::postprocess() {
{
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
static_assert(
sizeof(Z_VALUES_ARR) == (GRID_MAX_POINTS) * sizeof(Z_VALUES_ARR[0][0]),
sizeof(bedlevel.z_values) == (GRID_MAX_POINTS) * sizeof(bedlevel.z_values[0][0]),
"Bilinear Z array is the wrong size."
);
#endif
@ -887,16 +887,16 @@ void MarlinSettings::postprocess() {
EEPROM_WRITE(grid_max_x);
EEPROM_WRITE(grid_max_y);
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
EEPROM_WRITE(bbl.get_grid_spacing());
EEPROM_WRITE(bbl.get_grid_start());
EEPROM_WRITE(bedlevel.grid_spacing);
EEPROM_WRITE(bedlevel.grid_start);
#else
const xy_pos_t bilinear_start{0}, bilinear_grid_spacing{0};
const xy_pos_t bilinear_grid_spacing{0}, bilinear_start{0};
EEPROM_WRITE(bilinear_grid_spacing);
EEPROM_WRITE(bilinear_start);
#endif
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
EEPROM_WRITE(Z_VALUES_ARR); // 9-256 floats
EEPROM_WRITE(bedlevel.z_values); // 9-256 floats
#else
dummyf = 0;
for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
@ -919,7 +919,7 @@ void MarlinSettings::postprocess() {
{
_FIELD_TEST(planner_leveling_active);
const bool ubl_active = TERN(AUTO_BED_LEVELING_UBL, planner.leveling_active, false);
const int8_t storage_slot = TERN(AUTO_BED_LEVELING_UBL, ubl.storage_slot, -1);
const int8_t storage_slot = TERN(AUTO_BED_LEVELING_UBL, bedlevel.storage_slot, -1);
EEPROM_WRITE(ubl_active);
EEPROM_WRITE(storage_slot);
}
@ -1591,8 +1591,8 @@ void MarlinSettings::postprocess() {
// UBL Mesh
//
#if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
if (ubl.storage_slot >= 0)
store_mesh(ubl.storage_slot);
if (bedlevel.storage_slot >= 0)
store_mesh(bedlevel.storage_slot);
#endif
if (!eeprom_error) {
@ -1749,20 +1749,20 @@ void MarlinSettings::postprocess() {
EEPROM_READ_ALWAYS(mesh_num_y);
#if ENABLED(MESH_BED_LEVELING)
if (!validating) mbl.z_offset = dummyf;
if (!validating) bedlevel.z_offset = dummyf;
if (mesh_num_x == (GRID_MAX_POINTS_X) && mesh_num_y == (GRID_MAX_POINTS_Y)) {
// EEPROM data fits the current mesh
EEPROM_READ(mbl.z_values);
EEPROM_READ(bedlevel.z_values);
}
else {
// EEPROM data is stale
if (!validating) mbl.reset();
if (!validating) bedlevel.reset();
for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
}
#else
// MBL is disabled - skip the stored data
for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
#endif // MESH_BED_LEVELING
#endif
}
//
@ -1802,8 +1802,8 @@ void MarlinSettings::postprocess() {
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
if (grid_max_x == (GRID_MAX_POINTS_X) && grid_max_y == (GRID_MAX_POINTS_Y)) {
if (!validating) set_bed_leveling_enabled(false);
bbl.set_grid(spacing, start);
EEPROM_READ(Z_VALUES_ARR); // 9 to 256 floats
bedlevel.set_grid(spacing, start);
EEPROM_READ(bedlevel.z_values); // 9 to 256 floats
}
else // EEPROM data is stale
#endif // AUTO_BED_LEVELING_BILINEAR
@ -1830,7 +1830,7 @@ void MarlinSettings::postprocess() {
_FIELD_TEST(planner_leveling_active);
#if ENABLED(AUTO_BED_LEVELING_UBL)
const bool &planner_leveling_active = planner.leveling_active;
const int8_t &ubl_storage_slot = ubl.storage_slot;
const int8_t &ubl_storage_slot = bedlevel.storage_slot;
#else
bool planner_leveling_active;
int8_t ubl_storage_slot;
@ -2540,11 +2540,11 @@ void MarlinSettings::postprocess() {
#if ENABLED(AUTO_BED_LEVELING_UBL)
if (!validating) {
ubl.report_state();
bedlevel.report_state();
if (!ubl.sanity_check()) {
if (!bedlevel.sanity_check()) {
#if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
ubl.echo_name();
bedlevel.echo_name();
DEBUG_ECHOLNPGM(" initialized.\n");
#endif
}
@ -2552,18 +2552,18 @@ void MarlinSettings::postprocess() {
eeprom_error = true;
#if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
DEBUG_ECHOPGM("?Can't enable ");
ubl.echo_name();
bedlevel.echo_name();
DEBUG_ECHOLNPGM(".");
#endif
ubl.reset();
bedlevel.reset();
}
if (ubl.storage_slot >= 0) {
load_mesh(ubl.storage_slot);
DEBUG_ECHOLNPGM("Mesh ", ubl.storage_slot, " loaded from storage.");
if (bedlevel.storage_slot >= 0) {
load_mesh(bedlevel.storage_slot);
DEBUG_ECHOLNPGM("Mesh ", bedlevel.storage_slot, " loaded from storage.");
}
else {
ubl.reset();
bedlevel.reset();
DEBUG_ECHOLNPGM("UBL reset");
}
}
@ -2631,7 +2631,7 @@ void MarlinSettings::postprocess() {
return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8;
}
#define MESH_STORE_SIZE sizeof(TERN(OPTIMIZED_MESH_STORAGE, mesh_store_t, ubl.z_values))
#define MESH_STORE_SIZE sizeof(TERN(OPTIMIZED_MESH_STORAGE, mesh_store_t, bedlevel.z_values))
uint16_t MarlinSettings::calc_num_meshes() {
return (meshes_end - meshes_start_index()) / MESH_STORE_SIZE;
@ -2657,10 +2657,10 @@ void MarlinSettings::postprocess() {
#if ENABLED(OPTIMIZED_MESH_STORAGE)
int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
ubl.set_store_from_mesh(ubl.z_values, z_mesh_store);
bedlevel.set_store_from_mesh(bedlevel.z_values, z_mesh_store);
uint8_t * const src = (uint8_t*)&z_mesh_store;
#else
uint8_t * const src = (uint8_t*)&ubl.z_values;
uint8_t * const src = (uint8_t*)&bedlevel.z_values;
#endif
// Write crc to MAT along with other data, or just tack on to the beginning or end
@ -2695,7 +2695,7 @@ void MarlinSettings::postprocess() {
int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
uint8_t * const dest = (uint8_t*)&z_mesh_store;
#else
uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&bedlevel.z_values;
#endif
persistentStore.access_start();
@ -2705,11 +2705,11 @@ void MarlinSettings::postprocess() {
#if ENABLED(OPTIMIZED_MESH_STORAGE)
if (into) {
float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
ubl.set_mesh_from_store(z_mesh_store, z_values);
bedlevel.set_mesh_from_store(z_mesh_store, z_values);
memcpy(into, z_values, sizeof(z_values));
}
else
ubl.set_mesh_from_store(z_mesh_store, ubl.z_values);
bedlevel.set_mesh_from_store(z_mesh_store, bedlevel.z_values);
#endif
if (status) SERIAL_ECHOLNPGM("?Unable to load mesh data.");
@ -3320,24 +3320,25 @@ void MarlinSettings::reset() {
LOOP_L_N(px, GRID_MAX_POINTS_X) {
CONFIG_ECHO_START();
SERIAL_ECHOPGM(" G29 S3 I", px, " J", py);
SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(mbl.z_values[px][py]), 5);
SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(bedlevel.z_values[px][py]), 5);
}
}
CONFIG_ECHO_START();
SERIAL_ECHOLNPAIR_F(" G29 S4 Z", LINEAR_UNIT(mbl.z_offset), 5);
SERIAL_ECHOLNPAIR_F(" G29 S4 Z", LINEAR_UNIT(bedlevel.z_offset), 5);
}
#elif ENABLED(AUTO_BED_LEVELING_UBL)
if (!forReplay) {
SERIAL_EOL();
ubl.report_state();
SERIAL_ECHO_MSG("Active Mesh Slot ", ubl.storage_slot);
bedlevel.report_state();
SERIAL_ECHO_MSG("Active Mesh Slot ", bedlevel.storage_slot);
SERIAL_ECHO_MSG("EEPROM can hold ", calc_num_meshes(), " meshes.\n");
}
//ubl.report_current_mesh(); // This is too verbose for large meshes. A better (more terse)
//bedlevel.report_current_mesh(); // This is too verbose for large meshes. A better (more terse)
// solution needs to be found.
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
if (leveling_is_valid()) {
@ -3345,7 +3346,7 @@ void MarlinSettings::reset() {
LOOP_L_N(px, GRID_MAX_POINTS_X) {
CONFIG_ECHO_START();
SERIAL_ECHOPGM(" G29 W I", px, " J", py);
SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(Z_VALUES_ARR[px][py]), 5);
SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(bedlevel.z_values[px][py]), 5);
}
}
}

Loading…
Cancel
Save