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

This commit is contained in:
Scott Lahteine 2022-05-19 06:05:52 -05:00 committed by Scott Lahteine
parent 06c4a9acdb
commit b72f9277e9
47 changed files with 390 additions and 434 deletions

View File

@ -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_K, stepper.disable_axis(K_AXIS));
TERN_(DISABLE_INACTIVE_E, stepper.disable_e_steppers()); 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 else

View File

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

View File

@ -35,7 +35,7 @@
#include "../../../lcd/extui/ui_api.h" #include "../../../lcd/extui/ui_api.h"
#endif #endif
LevelingBilinear bbl; LevelingBilinear bedlevel;
xy_pos_t LevelingBilinear::grid_spacing, xy_pos_t LevelingBilinear::grid_spacing,
LevelingBilinear::grid_start; 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 // Refresh after other values have been updated
void LevelingBilinear::refresh_bed_level() { void LevelingBilinear::refresh_bed_level() {

View File

@ -24,10 +24,12 @@
#include "../../../inc/MarlinConfigPre.h" #include "../../../inc/MarlinConfigPre.h"
class LevelingBilinear { class LevelingBilinear {
private: public:
static xy_pos_t grid_spacing, grid_start;
static xy_float_t grid_factor;
static bed_mesh_t z_values; static bed_mesh_t z_values;
static xy_pos_t grid_spacing, grid_start;
private:
static xy_float_t grid_factor;
static xy_pos_t cached_rel; static xy_pos_t cached_rel;
static xy_int8_t cached_g; 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 print_leveling_grid(const bed_mesh_t* _z_values = NULL);
static void refresh_bed_level(); static void refresh_bed_level();
static bool has_mesh() { return !!grid_spacing.x; } static bool has_mesh() { return !!grid_spacing.x; }
static bed_mesh_t& get_z_values() { return z_values; } static bool mesh_is_valid() { return has_mesh(); }
static const xy_pos_t& get_grid_spacing() { return grid_spacing; } static float get_mesh_x(const uint8_t i) { return grid_start.x + i * grid_spacing.x; }
static const xy_pos_t& get_grid_start() { return grid_start; } static float get_mesh_y(const uint8_t j) { return grid_start.y + j * grid_spacing.y; }
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 float get_z_correction(const xy_pos_t &raw); 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) #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); static void line_to_destination(const_feedRate_t scaled_fr_mm_s, uint16_t x_splits=0xFFFF, uint16_t y_splits=0xFFFF);
#endif #endif
}; };
extern LevelingBilinear bbl; extern LevelingBilinear bedlevel;
#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()

View File

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

View File

@ -69,9 +69,6 @@ class TemporaryBedLevelingState {
#include "mbl/mesh_bed_leveling.h" #include "mbl/mesh_bed_leveling.h"
#endif #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) #if EITHER(AUTO_BED_LEVELING_BILINEAR, MESH_BED_LEVELING)
#include <stdint.h> #include <stdint.h>
@ -92,7 +89,7 @@ class TemporaryBedLevelingState {
bool valid() const { return pos.x >= 0 && pos.y >= 0; } bool valid() const { return pos.x >= 0 && pos.y >= 0; }
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
xy_pos_t meshpos() { 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 #endif
operator xy_int8_t&() { return pos; } operator xy_int8_t&() { return pos; }

View File

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

View File

@ -34,9 +34,6 @@ enum MeshLevelingState : char {
#define MESH_X_DIST (float(MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_CELLS_X)) #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 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 { class mesh_bed_leveling {
public: public:
@ -56,6 +53,8 @@ public:
return false; 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 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) { static void zigzag(const int8_t index, int8_t &px, int8_t &py) {
@ -70,6 +69,9 @@ public:
set_z(px, py, z); 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) { static int8_t cell_index_x(const_float_t x) {
int8_t cx = (x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST); int8_t cx = (x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST);
return constrain(cx, 0, GRID_MAX_CELLS_X - 1); return constrain(cx, 0, GRID_MAX_CELLS_X - 1);
@ -102,12 +104,9 @@ public:
return z1 + delta_a * delta_z; return z1 + delta_a * delta_z;
} }
static float get_z(const xy_pos_t &pos static float get_z_offset() { return z_offset; }
OPTARG(ENABLE_LEVELING_FADE_HEIGHT, const_float_t factor=1.0f)
) { static float get_z_correction(const xy_pos_t &pos) {
#if DISABLED(ENABLE_LEVELING_FADE_HEIGHT)
constexpr float factor = 1.0f;
#endif
const xy_int8_t ind = cell_indexes(pos); const xy_int8_t ind = cell_indexes(pos);
const float x1 = index_to_xpos[ind.x], x2 = index_to_xpos[ind.x+1], 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], 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]), 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); zf = calc_z0(pos.y, y1, z1, y2, z2);
return z_offset + zf * factor; return zf;
} }
#if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES) #if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
@ -123,4 +122,4 @@ public:
#endif #endif
}; };
extern mesh_bed_leveling mbl; extern mesh_bed_leveling bedlevel;

View File

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

View File

@ -215,7 +215,7 @@ public:
return _UBL_OUTER_Z_RAISE; 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]; 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 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; 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]; 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 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; return UBL_Z_RAISE_WHEN_OFF_MESH;
#endif #endif
const uint8_t mx = _MIN(cx, (GRID_MAX_POINTS_X) - 2) + 1, my = _MIN(cy, (GRID_MAX_POINTS_Y) - 2) + 1; 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]); x0 = get_mesh_x(cx), x1 = get_mesh_x(cx + 1);
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]); const float z1 = calc_z0(rx0, x0, z_values[cx][cy], x1, z_values[mx][cy]),
float z0 = calc_z0(ry0, mesh_index_to_ypos(cy), z1, mesh_index_to_ypos(cy + 1), z2); 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 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 z0 = 0.0; // in z_values[][] and propagate through the calculations.
// calculations. If our correction is NAN, we throw it out // If our correction is NAN, we throw it out because part of
// because part of the Mesh is undefined and we don't have the // the Mesh is undefined and we don't have the information
// information we need to complete the height correction. // needed to complete the height correction.
if (DEBUGGING(MESH_ADJUST)) DEBUG_ECHOLNPGM("??? Yikes! NAN in "); 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 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); 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); 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 }; // class unified_bed_leveling
extern unified_bed_leveling ubl; extern unified_bed_leveling bedlevel;
#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
// Prevent debugging propagating to other files // Prevent debugging propagating to other files
#include "../../../core/debug_out.h" #include "../../../core/debug_out.h"

View File

@ -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. // It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
if (!location.valid()) continue; if (!location.valid()) continue;
const xyz_pos_t ppos = { const xyz_pos_t ppos = { get_mesh_x(lpos.x), get_mesh_y(lpos.y), z_clearance };
mesh_index_to_xpos(lpos.x),
mesh_index_to_ypos(lpos.y),
z_clearance
};
if (!position_is_reachable(ppos)) break; // SHOULD NOT OCCUR (find_closest_mesh_point only returns reachable points) 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 done_flags.mark(lpos); // Mark this location as 'adjusted' so a new
// location is used on the next loop // location is used on the next loop
const xyz_pos_t raw = { const xyz_pos_t raw = { get_mesh_x(lpos.x), get_mesh_y(lpos.y), Z_CLEARANCE_BETWEEN_PROBES };
mesh_index_to_xpos(lpos.x),
mesh_index_to_ypos(lpos.y),
Z_CLEARANCE_BETWEEN_PROBES
};
if (!position_is_reachable(raw)) break; // SHOULD NOT OCCUR (find_closest_mesh_point_of_type only returns reachable) 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 if (!isnan(z_values[i][j])) continue; // Skip valid mesh points
// Skip unreachable 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; continue;
found_a_NAN = true; 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) { static bool test_func(uint8_t i, uint8_t j, void *data) {
find_closest_t *d = (find_closest_t*)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)) || (d->type == SET_IN_BITMAP && !d->done_flags->marked(i, j))
) { ) {
// Found a Mesh Point of the specified type! // 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. // 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. // 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)) || (type == SET_IN_BITMAP && !done_flags->marked(i, j))
) { ) {
// Found a Mesh Point of the specified type! // 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. // 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. // 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() { void unified_bed_leveling::smart_fill_mesh() {
static const smart_fill_info 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 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 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 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 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 }; static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
LOOP_L_N(i, COUNT(info)) { 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)); matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
GRID_LOOP(i, j) { GRID_LOOP(i, j) {
float mx = mesh_index_to_xpos(i), float mx = get_mesh_x(i), my = get_mesh_y(j), mz = z_values[i][j];
my = mesh_index_to_ypos(j),
mz = z_values[i][j];
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7); DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
@ -1688,18 +1678,18 @@ void unified_bed_leveling::smart_fill_mesh() {
xy_pos_t ppos; xy_pos_t ppos;
LOOP_L_N(ix, GRID_MAX_POINTS_X) { 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) { 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])) { if (isnan(z_values[ix][iy])) {
// undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points. // undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
incremental_LSF_reset(&lsf_results); incremental_LSF_reset(&lsf_results);
xy_pos_t rpos; xy_pos_t rpos;
LOOP_L_N(jx, GRID_MAX_POINTS_X) { 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) { LOOP_L_N(jy, GRID_MAX_POINTS_Y) {
if (TEST(bitmap[jx], jy)) { 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], const float rz = z_values[jx][jy],
w = 1.0f + weight_scaled / (rpos - ppos).magnitude(); w = 1.0f + weight_scaled / (rpos - ppos).magnitude();
incremental_WLSF(&lsf_results, rpos, rz, w); 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: "); SERIAL_ECHOPGM("X-Axis Mesh Points at: ");
LOOP_L_N(i, GRID_MAX_POINTS_X) { 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_ECHOPGM(" ");
serial_delay(25); serial_delay(25);
} }
@ -1766,7 +1756,7 @@ void unified_bed_leveling::smart_fill_mesh() {
SERIAL_ECHOPGM("Y-Axis Mesh Points at: "); SERIAL_ECHOPGM("Y-Axis Mesh Points at: ");
LOOP_L_N(i, GRID_MAX_POINTS_Y) { 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_ECHOPGM(" ");
serial_delay(25); serial_delay(25);
} }

View File

@ -76,8 +76,8 @@
#endif #endif
// The distance is always MESH_X_DIST so multiply by the constant reciprocal. // 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), const float xratio = (end.x - get_mesh_x(iend.x)) * RECIPROCAL(MESH_X_DIST),
yratio = (end.y - mesh_index_to_ypos(iend.y)) * RECIPROCAL(MESH_Y_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 ]), 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]); 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. icell.y += ineg.y; // Line going down? Just go to the bottom.
while (icell.y != iend.y + ineg.y) { while (icell.y != iend.y + ineg.y) {
icell.y += iadd.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. * Skip the calculations for an infinite slope.
@ -155,7 +155,7 @@
// Replace NAN corrections with 0.0 to prevent NAN propagation. // Replace NAN corrections with 0.0 to prevent NAN propagation.
if (isnan(z0)) z0 = 0.0; 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 * 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) { while (icell.x != iend.x + ineg.x) {
icell.x += iadd.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 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) float z0 = z_correction_for_y_on_vertical_mesh_line(dest.y, icell.x, icell.y)
@ -245,8 +245,8 @@
while (cnt) { while (cnt) {
const float next_mesh_line_x = mesh_index_to_xpos(icell.x + iadd.x), const float next_mesh_line_x = get_mesh_x(icell.x + iadd.x),
next_mesh_line_y = mesh_index_to_ypos(icell.y + iadd.y); 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.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 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_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 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; 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) 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 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 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) TERN_(ENABLE_LEVELING_FADE_HEIGHT, * fade_scaling_factor); // apply fade factor to interpolated height
* fade_scaling_factor // apply fade factor to interpolated mesh height
#endif
;
const float oldz = raw.z; raw.z += z_cxcy; 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) ); planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, segment_xyz_mm OPTARG(SCARA_FEEDRATE_SCALING, inv_duration) );

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -39,7 +39,7 @@ void GcodeSuite::G29() {
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE)); 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)); TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
} }

View File

@ -56,7 +56,7 @@ void GcodeSuite::M421() {
hasZ = parser.seen('Z'), hasZ = parser.seen('Z'),
hasQ = !hasZ && parser.seen('Q'); 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 // Test for bad parameter combinations
if (int(hasC) + int(hasI && hasJ) != 1 || !(hasZ || hasQ || hasN)) 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)) 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); SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
else { 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 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_(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)); TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ij.x, ij.y, zval));

View File

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

View File

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

View File

@ -1281,9 +1281,9 @@ void MarlinUI::draw_status_screen() {
* Show X and Y positions * Show X and Y positions
*/ */
_XLABEL(_PLOT_X, 0); _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); _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); lcd_moveto(_PLOT_X, 0);
@ -1475,8 +1475,8 @@ void MarlinUI::draw_status_screen() {
* Print Z values * Print Z values
*/ */
_ZLABEL(_LCD_W_POS, 1); _ZLABEL(_LCD_W_POS, 1);
if (!isnan(ubl.z_values[x_plot][y_plot])) if (!isnan(bedlevel.z_values[x_plot][y_plot]))
lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot])); lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else else
lcd_put_u8str(F(" -----")); lcd_put_u8str(F(" -----"));
@ -1486,16 +1486,16 @@ void MarlinUI::draw_status_screen() {
* Show all values at right of screen * Show all values at right of screen
*/ */
_XLABEL(_LCD_W_POS, 1); _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); _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 * Show the location value
*/ */
_ZLABEL(_LCD_W_POS, 3); _ZLABEL(_LCD_W_POS, 3);
if (!isnan(ubl.z_values[x_plot][y_plot])) if (!isnan(bedlevel.z_values[x_plot][y_plot]))
lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot])); lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else else
lcd_put_u8str(F(" -----")); lcd_put_u8str(F(" -----"));

View File

@ -1069,15 +1069,15 @@ void MarlinUI::draw_status_screen() {
// Show all values // Show all values
lcd.setCursor(_LCD_W_POS, 1); lcd_put_u8str(F("X:")); 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.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 // Show the location value
lcd.setCursor(_LCD_W_POS, 3); lcd_put_u8str(F("Z:")); lcd.setCursor(_LCD_W_POS, 3); lcd_put_u8str(F("Z:"));
if (!isnan(ubl.z_values[x_plot][y_plot])) if (!isnan(bedlevel.z_values[x_plot][y_plot]))
lcd.print(ftostr43sign(ubl.z_values[x_plot][y_plot])); lcd.print(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else else
lcd_put_u8str(F(" -----")); lcd_put_u8str(F(" -----"));

View File

@ -574,9 +574,9 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
u8g.setColorIndex(1); u8g.setColorIndex(1);
const u8g_uint_t sx = x_offset + pixels_per_x_mesh_pnt / 2; 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; 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)) 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); u8g.drawBox(x, y, 1, 1);
// Fill in the Specified Mesh Point // 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 // Show X and Y positions at top of screen
u8g.setColorIndex(1); u8g.setColorIndex(1);
if (PAGE_UNDER(7)) { 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(); lpos = pos.asLogical();
lcd_put_u8str_P(5, 7, X_LBL); lcd_put_u8str_P(5, 7, X_LBL);
lcd_put_u8str(ftostr52(lpos.x)); lcd_put_u8str(ftostr52(lpos.x));
@ -614,8 +614,8 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
// Show the location value // Show the location value
lcd_put_u8str_P(74, LCD_PIXEL_HEIGHT, Z_LBL); lcd_put_u8str_P(74, LCD_PIXEL_HEIGHT, Z_LBL);
if (!isnan(ubl.z_values[x_plot][y_plot])) if (!isnan(bedlevel.z_values[x_plot][y_plot]))
lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot])); lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else else
lcd_put_u8str(F(" -----")); lcd_put_u8str(F(" -----"));
} }

View File

@ -207,11 +207,9 @@ CrealityDWINClass CrealityDWIN;
struct linear_fit_data lsf_results; struct linear_fit_data lsf_results;
incremental_LSF_reset(&lsf_results); incremental_LSF_reset(&lsf_results);
GRID_LOOP(x, y) { GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y])) { if (!isnan(bedlevel.z_values[x][y])) {
xy_pos_t rpos; xy_pos_t rpos = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
rpos.x = ubl.mesh_index_to_xpos(x); incremental_LSF(&lsf_results, rpos, bedlevel.z_values[x][y]);
rpos.y = ubl.mesh_index_to_ypos(y);
incremental_LSF(&lsf_results, rpos, Z_VALUES_ARR[x][y]);
} }
} }
@ -220,13 +218,13 @@ CrealityDWINClass CrealityDWIN;
return true; 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)); matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
GRID_LOOP(i, j) { GRID_LOOP(i, j) {
float mx = ubl.mesh_index_to_xpos(i), float mx = bedlevel.get_mesh_x(i),
my = ubl.mesh_index_to_ypos(j), my = bedlevel.get_mesh_y(j),
mz = Z_VALUES_ARR[i][j]; mz = bedlevel.z_values[i][j];
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7); DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
@ -250,7 +248,7 @@ CrealityDWINClass CrealityDWIN;
DEBUG_DELAY(20); DEBUG_DELAY(20);
} }
Z_VALUES_ARR[i][j] = mz - lsf_results.D; bedlevel.z_values[i][j] = mz - lsf_results.D;
} }
return false; return false;
} }
@ -268,7 +266,7 @@ CrealityDWINClass CrealityDWIN;
void manual_move(bool zmove=false) { void manual_move(bool zmove=false) {
if (zmove) { if (zmove) {
planner.synchronize(); 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.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize(); planner.synchronize();
} }
@ -279,7 +277,7 @@ CrealityDWINClass CrealityDWIN;
sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y); sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
gcode.process_subcommands_now(cmd); gcode.process_subcommands_now(cmd);
planner.synchronize(); 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.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize(); planner.synchronize();
CrealityDWIN.Redraw_Menu(); CrealityDWIN.Redraw_Menu();
@ -289,8 +287,8 @@ CrealityDWINClass CrealityDWIN;
float get_max_value() { float get_max_value() {
float max = __FLT_MIN__; float max = __FLT_MIN__;
GRID_LOOP(x, y) { GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] > max) if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
max = Z_VALUES_ARR[x][y]; max = bedlevel.z_values[x][y];
} }
return max; return max;
} }
@ -298,24 +296,24 @@ CrealityDWINClass CrealityDWIN;
float get_min_value() { float get_min_value() {
float min = __FLT_MAX__; float min = __FLT_MAX__;
GRID_LOOP(x, y) { GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] < min) if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
min = Z_VALUES_ARR[x][y]; min = bedlevel.z_values[x][y];
} }
return min; 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) { 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; drawing_mesh = true;
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x; 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; cell_width_px = total_width_px / (GRID_MAX_POINTS_X),
const uint16_t cell_height_px = total_width_px / GRID_MAX_POINTS_Y; 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); 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 // 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); 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) { if (selected >= 0) {
const auto selected_y = selected / GRID_MAX_POINTS_X; const auto selected_y = selected / (GRID_MAX_POINTS_X);
const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y); 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_y_px = padding_y_top + selected_y * cell_height_px;
const auto start_x_px = padding_x + selected_x * cell_width_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); 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 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; 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/ 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 isnan(bedlevel.z_values[x][y]) ? Color_Grey : ( // gray if undefined
(Z_VALUES_ARR[x][y] < 0 ? (bedlevel.z_values[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(0x1F * -bedlevel.z_values[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 (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(Z_VALUES_ARR[x][y]) / 10) * 4))), // + blue stepping for every mm _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 start_x_px, start_y_px, end_x_px, end_y_px
); );
@ -343,14 +341,14 @@ CrealityDWINClass CrealityDWIN;
// Draw value text on // Draw value text on
if (viewer_print_value) { if (viewer_print_value) {
int8_t offset_x, offset_y = cell_height_px / 2 - 6; 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")); 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 else { // has value
if (GRID_MAX_POINTS_X < 10) 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 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; offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
if (!(GRID_MAX_POINTS_X < 10)) 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(".")); 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,8 +415,8 @@ 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*/) { 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 bColor = (selected) ? Select_Color : Color_Bg_Black,
uint16_t tColor = (color) ? GetColor(value, Color_White, false) : Color_White; tColor = (color) ? GetColor(value, Color_White, false) : Color_White;
DWIN_Draw_Rectangle(1, bColor, 202, MBASE(row) + 14, 258, MBASE(row) - 2); 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]); DWIN_Draw_String(false, DWIN_FONT_MENU, tColor, bColor, 202, MBASE(row) - 1, options[value]);
} }
@ -2842,7 +2840,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (draw) if (draw)
Draw_Menu_Item(row, ICON_Tilt, F("Autotilt Current Mesh")); Draw_Menu_Item(row, ICON_Tilt, F("Autotilt Current Mesh"));
else { else {
if (ubl.storage_slot < 0) { if (bedlevel.storage_slot < 0) {
Popup_Handler(MeshSlot); Popup_Handler(MeshSlot);
break; break;
} }
@ -2914,7 +2912,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
} }
#endif #endif
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
if (ubl.storage_slot < 0) { if (bedlevel.storage_slot < 0) {
Popup_Handler(MeshSlot); Popup_Handler(MeshSlot);
break; 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); Draw_Menu_Item(row, ICON_Mesh, GET_TEXT(MSG_MESH_VIEW), nullptr, true);
else { else {
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
if (ubl.storage_slot < 0) { if (bedlevel.storage_slot < 0) {
Popup_Handler(MeshSlot); Popup_Handler(MeshSlot);
break; break;
} }
@ -2967,16 +2965,16 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case LEVELING_SLOT: case LEVELING_SLOT:
if (draw) { if (draw) {
Draw_Menu_Item(row, ICON_PrintSize, F("Mesh Slot")); 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 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; break;
case LEVELING_LOAD: case LEVELING_LOAD:
if (draw) if (draw)
Draw_Menu_Item(row, ICON_ReadEEPROM, F("Load Mesh")); Draw_Menu_Item(row, ICON_ReadEEPROM, F("Load Mesh"));
else { else {
if (ubl.storage_slot < 0) { if (bedlevel.storage_slot < 0) {
Popup_Handler(MeshSlot); Popup_Handler(MeshSlot);
break; break;
} }
@ -2989,7 +2987,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (draw) if (draw)
Draw_Menu_Item(row, ICON_WriteEEPROM, F("Save Mesh")); Draw_Menu_Item(row, ICON_WriteEEPROM, F("Save Mesh"));
else { else {
if (ubl.storage_slot < 0) { if (bedlevel.storage_slot < 0) {
Popup_Handler(MeshSlot); Popup_Handler(MeshSlot);
break; break;
} }
@ -3098,13 +3096,13 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (draw) if (draw)
Draw_Menu_Item(row, ICON_Mesh, F("Zero Current Mesh")); Draw_Menu_Item(row, ICON_Mesh, F("Zero Current Mesh"));
else else
ZERO(Z_VALUES_ARR); ZERO(bedlevel.z_values);
break; break;
case LEVELING_SETTINGS_UNDEF: case LEVELING_SETTINGS_UNDEF:
if (draw) if (draw)
Draw_Menu_Item(row, ICON_Mesh, F("Clear Current Mesh")); Draw_Menu_Item(row, ICON_Mesh, F("Clear Current Mesh"));
else else
ubl.invalidate(); bedlevel.invalidate();
break; break;
#endif // AUTO_BED_LEVELING_UBL #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")); Draw_Menu_Item(row, ICON_Back, F("Back"));
else { else {
set_bed_leveling_enabled(level_state); 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); Draw_Menu(Leveling, LEVELING_MANUAL);
} }
break; break;
@ -3184,36 +3182,36 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case LEVELING_M_OFFSET: case LEVELING_M_OFFSET:
if (draw) { if (draw) {
Draw_Menu_Item(row, ICON_SetZOffset, F("Point Z Offset")); 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 { else {
if (isnan(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y])) if (isnan(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y]))
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0; bedlevel.z_values[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); Modify_Value(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
} }
break; break;
case LEVELING_M_UP: case LEVELING_M_UP:
if (draw) if (draw)
Draw_Menu_Item(row, ICON_Axis, F("Microstep Up")); 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) { else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01; bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
gcode.process_subcommands_now(F("M290 Z0.01")); gcode.process_subcommands_now(F("M290 Z0.01"));
planner.synchronize(); planner.synchronize();
current_position.z += 0.01f; current_position.z += 0.01f;
sync_plan_position(); 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; break;
case LEVELING_M_DOWN: case LEVELING_M_DOWN:
if (draw) if (draw)
Draw_Menu_Item(row, ICON_AxisD, F("Microstep Down")); 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) { else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01; bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
gcode.process_subcommands_now(F("M290 Z-0.01")); gcode.process_subcommands_now(F("M290 Z-0.01"));
planner.synchronize(); planner.synchronize();
current_position.z -= 0.01f; current_position.z -= 0.01f;
sync_plan_position(); 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; break;
case LEVELING_M_GOTO_VALUE: 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: case UBL_M_OFFSET:
if (draw) { if (draw) {
Draw_Menu_Item(row, ICON_SetZOffset, F("Point Z Offset")); 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 { else {
if (isnan(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y])) if (isnan(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y]))
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0; bedlevel.z_values[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); Modify_Value(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
} }
break; break;
case UBL_M_UP: case UBL_M_UP:
if (draw) if (draw)
Draw_Menu_Item(row, ICON_Axis, F("Microstep Up")); 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) { else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01; bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
gcode.process_subcommands_now(F("M290 Z0.01")); gcode.process_subcommands_now(F("M290 Z0.01"));
planner.synchronize(); planner.synchronize();
current_position.z += 0.01f; current_position.z += 0.01f;
sync_plan_position(); 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; break;
case UBL_M_DOWN: case UBL_M_DOWN:
if (draw) if (draw)
Draw_Menu_Item(row, ICON_Axis, F("Microstep Down")); 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) { else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01; bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
gcode.process_subcommands_now(F("M290 Z-0.01")); gcode.process_subcommands_now(F("M290 Z-0.01"));
planner.synchronize(); planner.synchronize();
current_position.z -= 0.01f; current_position.z -= 0.01f;
sync_plan_position(); 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; break;
} }
@ -3418,13 +3416,13 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case MMESH_OLD: case MMESH_OLD:
uint8_t mesh_x, mesh_y; uint8_t mesh_x, mesh_y;
// 0,0 -> 1,0 -> 2,0 -> 2,1 -> 1,1 -> 0,1 -> 0,2 -> 1,2 -> 2,2 // 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_y = (gridpoint - 1) / (GRID_MAX_POINTS_Y);
mesh_x = (gridpoint - 1) % GRID_MAX_POINTS_X; mesh_x = (gridpoint - 1) % (GRID_MAX_POINTS_X);
if (mesh_y % 2 == 1) 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) { if (draw) {
Draw_Menu_Item(row, ICON_Zoffset, F("Goto Mesh Value")); Draw_Menu_Item(row, ICON_Zoffset, F("Goto Mesh Value"));
@ -4283,7 +4281,7 @@ void CrealityDWINClass::Popup_Control() {
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
case MeshSlot: case MeshSlot:
if (selection == 0) ubl.storage_slot = 0; if (selection == 0) bedlevel.storage_slot = 0;
Redraw_Menu(true, true); Redraw_Menu(true, true);
break; break;
#endif #endif

View File

@ -516,8 +516,8 @@ void MarlinUI::draw_status_message(const bool blink) {
// Display Mesh Point Locations // Display Mesh Point Locations
const dwin_coord_t sx = x_offset + pixels_per_x_mesh_pnt / 2; 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; 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 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 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); DWIN_Draw_Point(Color_White, 1, 1, x, y);
// Put Relevant Text on Display // 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 // Show X and Y positions at top of screen
dwin_font.fg = Color_White; dwin_font.fg = Color_White;
dwin_font.solid = true; 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(); lpos = pos.asLogical();
lcd_moveto( lcd_moveto(
@ -555,8 +555,8 @@ void MarlinUI::draw_status_message(const bool blink) {
// Show the location value // Show the location value
dwin_string.set(Z_LBL); dwin_string.set(Z_LBL);
if (!isnan(Z_VALUES_ARR[x_plot][y_plot])) if (!isnan(bedlevel.z_values[x_plot][y_plot]))
dwin_string.add(ftostr43sign(Z_VALUES_ARR[x_plot][y_plot])); dwin_string.add(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else else
dwin_string.add(PSTR(" -----")); dwin_string.add(PSTR(" -----"));
lcd_moveto( lcd_moveto(

View File

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

View File

@ -117,7 +117,7 @@ void MeshViewerClass::Draw(bool withsave /*= false*/) {
ubl_tools.viewer_print_value = true; ubl_tools.viewer_print_value = true;
ubl_tools.Draw_Bed_Mesh(-1, 1, 8, 10 + TITLE_HEIGHT); ubl_tools.Draw_Bed_Mesh(-1, 1, 8, 10 + TITLE_HEIGHT);
#else #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 #endif
if (withsave) { if (withsave) {
DWINUI::Draw_Button(BTN_Save, 26, 305); DWINUI::Draw_Button(BTN_Save, 26, 305);

View File

@ -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; struct linear_fit_data lsf_results;
incremental_LSF_reset(&lsf_results); incremental_LSF_reset(&lsf_results);
GRID_LOOP(x, y) { GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y])) { if (!isnan(bedlevel.z_values[x][y])) {
xy_pos_t rpos; xy_pos_t rpos = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
rpos.x = ubl.mesh_index_to_xpos(x); incremental_LSF(&lsf_results, rpos, bedlevel.z_values[x][y]);
rpos.y = ubl.mesh_index_to_ypos(y);
incremental_LSF(&lsf_results, rpos, Z_VALUES_ARR[x][y]);
} }
} }
@ -76,13 +74,13 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
return true; 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)); matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
GRID_LOOP(i, j) { GRID_LOOP(i, j) {
float mx = ubl.mesh_index_to_xpos(i), float mx = bedlevel.get_mesh_x(i),
my = ubl.mesh_index_to_ypos(j), my = bedlevel.get_mesh_y(j),
mz = Z_VALUES_ARR[i][j]; mz = bedlevel.z_values[i][j];
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7); 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); DEBUG_DELAY(20);
} }
Z_VALUES_ARR[i][j] = mz - lsf_results.D; bedlevel.z_values[i][j] = mz - lsf_results.D;
} }
return false; 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*/) { void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/*=false*/) {
if (zmove) { if (zmove) {
planner.synchronize(); 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.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize(); 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); sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
gcode.process_subcommands_now(cmd); gcode.process_subcommands_now(cmd);
planner.synchronize(); 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.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize(); planner.synchronize();
HMI_ReturnScreen(); 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 UBLMeshToolsClass::get_max_value() {
float max = __FLT_MIN__; float max = __FLT_MIN__;
GRID_LOOP(x, y) { GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] > max) if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
max = Z_VALUES_ARR[x][y]; max = bedlevel.z_values[x][y];
} }
return max; return max;
} }
@ -155,20 +153,19 @@ float UBLMeshToolsClass::get_max_value() {
float UBLMeshToolsClass::get_min_value() { float UBLMeshToolsClass::get_min_value() {
float min = __FLT_MAX__; float min = __FLT_MAX__;
GRID_LOOP(x, y) { GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] < min) if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
min = Z_VALUES_ARR[x][y]; min = bedlevel.z_values[x][y];
} }
return min; return min;
} }
bool UBLMeshToolsClass::validate() { bool UBLMeshToolsClass::validate() {
float min = __FLT_MAX__; float min = __FLT_MAX__, max = __FLT_MIN__;
float max = __FLT_MIN__;
GRID_LOOP(x, y) { GRID_LOOP(x, y) {
if (isnan(Z_VALUES_ARR[x][y])) return false; if (isnan(bedlevel.z_values[x][y])) return false;
if (Z_VALUES_ARR[x][y] < min) min = Z_VALUES_ARR[x][y]; if (bedlevel.z_values[x][y] < min) min = bedlevel.z_values[x][y];
if (Z_VALUES_ARR[x][y] > max) max = Z_VALUES_ARR[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; 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*/) { 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; drawing_mesh = true;
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x; 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_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_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); 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 // 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); 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) { if (selected >= 0) {
const auto selected_y = selected / GRID_MAX_POINTS_X; const auto selected_y = selected / (GRID_MAX_POINTS_X);
const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y); 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_y_px = padding_y_top + selected_y * cell_height_px;
const auto start_x_px = padding_x + selected_x * cell_width_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); 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) { GRID_LOOP(x, y) {
const auto start_x_px = padding_x + x * cell_width_px; 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 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; 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/ 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 isnan(bedlevel.z_values[x][y]) ? Color_Grey : ( // gray if undefined
(Z_VALUES_ARR[x][y] < 0 ? (bedlevel.z_values[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(0x1F * -bedlevel.z_values[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 (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(Z_VALUES_ARR[x][y]) / 10) * 4))), // + blue stepping for every mm _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 start_x_px, start_y_px, end_x_px, end_y_px
); );
@ -213,14 +210,14 @@ bool UBLMeshToolsClass::validate() {
// Draw value text on // Draw value text on
if (viewer_print_value) { if (viewer_print_value) {
int8_t offset_x, offset_y = cell_height_px / 2 - 6; 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")); 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 else { // has value
if (GRID_MAX_POINTS_X < 10) 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 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; offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
if (!(GRID_MAX_POINTS_X < 10)) 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(".")); 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("."));

View File

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

View File

@ -889,11 +889,11 @@ namespace ExtUI {
#if HAS_MESH #if HAS_MESH
bed_mesh_t& getMeshArray() { return Z_VALUES_ARR; } bed_mesh_t& getMeshArray() { return bedlevel.z_values; }
float getMeshPoint(const xy_uint8_t &pos) { return Z_VALUES(pos.x, pos.y); } 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) { 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)) { 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()); TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
} }
} }

View File

@ -855,7 +855,7 @@ void MarlinUI::init() {
void MarlinUI::external_encoder() { void MarlinUI::external_encoder() {
if (external_control && encoderDiff) { 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 encoderDiff = 0; // Hide encoder events from the screen handler
refresh(LCDVIEW_REDRAW_NOW); // ...but keep the refresh. refresh(LCDVIEW_REDRAW_NOW); // ...but keep the refresh.
} }

View File

@ -203,14 +203,14 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
if (on_status_screen()) { if (on_status_screen()) {
defer_status_screen(false); defer_status_screen(false);
clear_menu_history(); 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(); clear_lcd();
// Re-initialize custom characters that may be re-used // Re-initialize custom characters that may be re-used
#if HAS_MARLINUI_HD44780 #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); set_custom_characters(on_status_screen() ? CHARSET_INFO : CHARSET_MENU);
#endif #endif

View File

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

View File

@ -118,7 +118,7 @@ void menu_tune() {
// Manual bed leveling, Bed Z: // Manual bed leveling, Bed Z:
// //
#if BOTH(MESH_BED_LEVELING, LCD_BED_LEVELING) #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 #endif
// //

View File

@ -58,7 +58,7 @@ inline float rounded_mesh_value() {
/** /**
* This screen displays the temporary mesh value and updates it based on encoder * 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 * the current value via ubl_mesh_value, moves the Z axis, and updates the mesh
* value until the encoder button is pressed. * 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) { void _lcd_mesh_fine_tune(PGM_P const msg) {
constexpr float mesh_edit_step = 1.0f / 200.0f; constexpr float mesh_edit_step = 1.0f / 200.0f;
ui.defer_status_screen(); ui.defer_status_screen();
if (ubl.encoder_diff) { if (bedlevel.encoder_diff) {
mesh_edit_accumulator += TERN(IS_TFTGLCD_PANEL, mesh_edit_accumulator += TERN(IS_TFTGLCD_PANEL,
ubl.encoder_diff * mesh_edit_step / ENCODER_PULSES_PER_STEP, bedlevel.encoder_diff * mesh_edit_step / ENCODER_PULSES_PER_STEP,
ubl.encoder_diff > 0 ? mesh_edit_step : -mesh_edit_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)); IF_DISABLED(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
} }
TERN_(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. // To capture encoder events UBL will also call ui.capture and ui.release.
// //
void MarlinUI::ubl_mesh_edit_start(const_float_t initial) { 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(); } float MarlinUI::ubl_mesh_value() { return rounded_mesh_value(); }
@ -291,7 +291,7 @@ void _menu_ubl_fillin() {
} }
void _lcd_ubl_invalidate() { void _lcd_ubl_invalidate() {
ubl.invalidate(); bedlevel.invalidate();
SERIAL_ECHOLNPGM("Mesh invalidated."); SERIAL_ECHOLNPGM("Mesh invalidated.");
} }
@ -390,8 +390,8 @@ void _lcd_ubl_storage_mesh() {
*/ */
void _lcd_ubl_map_edit_cmd() { void _lcd_ubl_map_edit_cmd() {
char ubl_lcd_gcode[50], str[10], str2[10]; char ubl_lcd_gcode[50], str[10], str2[10];
dtostrf(ubl.mesh_index_to_xpos(x_plot), 0, 2, str); dtostrf(bedlevel.get_mesh_x(x_plot), 0, 2, str);
dtostrf(ubl.mesh_index_to_ypos(y_plot), 0, 2, str2); 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)); 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); queue.inject(ubl_lcd_gcode);
} }
@ -400,7 +400,7 @@ void _lcd_ubl_map_edit_cmd() {
* UBL LCD Map Movement * UBL LCD Map Movement
*/ */
void ubl_map_move_to_xy() { 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. // Some printers have unreachable areas in the mesh. Skip the move if unreachable.
if (!position_is_reachable(xy)) return; if (!position_is_reachable(xy)) return;
@ -459,7 +459,7 @@ void ubl_map_screen() {
// Validate if needed // Validate if needed
#if IS_KINEMATIC #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 if (position_is_reachable(xy)) break; // Found a valid point
ui.encoderPosition += step_dir; // Test the next point ui.encoderPosition += step_dir; // Test the next point
#endif #endif
@ -500,7 +500,7 @@ void _ubl_map_screen_homing() {
ui.defer_status_screen(); ui.defer_status_screen();
_lcd_draw_homing(); _lcd_draw_homing();
if (all_axes_homed()) { 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.goto_screen(ubl_map_screen, grid_index(x_plot, y_plot)); // Pre-set the encoder value
ui.manual_move.menu_scale = 0; // Immediate move ui.manual_move.menu_scale = 0; // Immediate move
ubl_map_move_to_xy(); // Move to current mesh point ubl_map_move_to_xy(); // Move to current mesh point

View File

@ -180,8 +180,8 @@ void Touch::touch(touch_control_t *control) {
ui.refresh(); ui.refresh();
break; break;
case SLIDER: hold(control); ui.encoderPosition = (x - control->x) * control->data / control->width; 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 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 ? ubl.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: case HEATER:
int8_t heater; int8_t heater;
heater = control->data; heater = control->data;

View File

@ -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.set_background(COLOR_BACKGROUND);
tft.add_rectangle(0, 0, GRID_WIDTH, GRID_HEIGHT, COLOR_WHITE); 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 x = 0; x < (GRID_MAX_POINTS_X); x++)
for (uint16_t y = 0; y < GRID_MAX_POINTS_Y ; y++) 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_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(); lpos = pos.asLogical();
tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT); 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.set_background(COLOR_BACKGROUND);
tft_string.set(Z_LBL); tft_string.set(Z_LBL);
tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); 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_string.trim();
tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);

View File

@ -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 x = 0; x < (GRID_MAX_POINTS_X); x++)
for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++) 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_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(); lpos = pos.asLogical();
tft.canvas(216, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 96, MENU_ITEM_HEIGHT); 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.set_background(COLOR_BACKGROUND);
tft_string.set(Z_LBL); tft_string.set(Z_LBL);
tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); 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_string.trim();
tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);

View File

@ -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 x = 0; x < (GRID_MAX_POINTS_X); x++)
for (uint16_t y = 0; y < (GRID_MAX_POINTS_Y); y++) 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_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(); lpos = pos.asLogical();
tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT); 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.set_background(COLOR_BACKGROUND);
tft_string.set(Z_LBL); tft_string.set(Z_LBL);
tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); 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_string.trim();
tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);

View File

@ -417,7 +417,7 @@ void line_to_current_position(const_feedRate_t fr_mm_s/*=feedrate_mm_s*/) {
#if UBL_SEGMENTED #if UBL_SEGMENTED
// UBL segmented line will do Z-only moves in single segment // 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 #else
if (current_position == destination) return; 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. * small incremental moves for DELTA or SCARA.
* *
* For Unified Bed Leveling (Delta or Segmented Cartesian) * 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 * For Auto Bed Leveling (Bilinear) with SEGMENT_LEVELED_MOVES
* this is replaced by segmented_line_to_destination below. * 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 HAS_MESH
if (planner.leveling_active && planner.leveling_active_at_z(destination.z)) { if (planner.leveling_active && planner.leveling_active_at_z(destination.z)) {
#if ENABLED(AUTO_BED_LEVELING_UBL) #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. return true; // all moves, including Z-only moves.
#elif ENABLED(SEGMENT_LEVELED_MOVES) #elif ENABLED(SEGMENT_LEVELED_MOVES)
segmented_line_to_destination(scaled_fr_mm_s); 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 (xy_pos_t(current_position) != xy_pos_t(destination)) {
#if ENABLED(MESH_BED_LEVELING) #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) #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
bbl.line_to_destination(scaled_fr_mm_s); bedlevel.line_to_destination(scaled_fr_mm_s);
#endif #endif
return true; return true;
} }
@ -1272,7 +1272,7 @@ void prepare_line_to_destination() {
if ( if (
#if UBL_SEGMENTED #if UBL_SEGMENTED
#if IS_KINEMATIC // UBL using Kinematic / Cartesian cases as a workaround for now. #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 #else
line_to_destination_cartesian() line_to_destination_cartesian()
#endif #endif

View File

@ -1581,19 +1581,12 @@ void Planner::check_axes_activity() {
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z); const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
#elif DISABLED(MESH_BED_LEVELING) if (fade_scaling_factor) raw.z += fade_scaling_factor * bedlevel.get_z_correction(raw);
constexpr float fade_scaling_factor = 1.0; #else
raw.z += bedlevel.get_z_correction(raw);
#endif #endif
raw.z += ( TERN_(MESH_BED_LEVELING, raw.z += bedlevel.get_z_offset());
#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
);
#endif #endif
} }
@ -1612,22 +1605,15 @@ void Planner::check_axes_activity() {
#elif HAS_MESH #elif HAS_MESH
TERN_(MESH_BED_LEVELING, raw.z -= bedlevel.get_z_offset());
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z); const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
#elif DISABLED(MESH_BED_LEVELING) if (fade_scaling_factor) raw.z -= fade_scaling_factor * bedlevel.get_z_correction(raw);
constexpr float fade_scaling_factor = 1.0; #else
raw.z -= bedlevel.get_z_correction(raw);
#endif #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
);
#endif #endif
} }
} }

View File

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