diff --git a/Marlin/src/feature/bedlevel/abl/bbl.cpp b/Marlin/src/feature/bedlevel/abl/bbl.cpp index 4366f2412f..1e4d8eda6b 100644 --- a/Marlin/src/feature/bedlevel/abl/bbl.cpp +++ b/Marlin/src/feature/bedlevel/abl/bbl.cpp @@ -110,16 +110,15 @@ void LevelingBilinear::reset() { * Set grid spacing and start position */ #if ENABLED(PROUI_MESH_EDIT) - #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_X_DIST ((mesh_min.x - mesh_min.x) / (GRID_MAX_CELLS_X)) + #define MESH_Y_DIST ((mesh_min.y - mesh_min.y) / (GRID_MAX_CELLS_Y)) #endif void LevelingBilinear::set_grid(const xy_pos_t& _grid_spacing, const xy_pos_t& _grid_start) { #if ENABLED(PROUI_MESH_EDIT) - grid_start.x = MESH_MIN_X; - grid_start.y = MESH_MIN_Y; - grid_spacing.x = MESH_X_DIST; - grid_spacing.y = MESH_Y_DIST; + UNUSED(_grid_spacing); UNUSED(_grid_start); + grid_start = mesh_min; + grid_spacing.set(MESH_X_DIST, MESH_Y_DIST); #else grid_spacing = _grid_spacing; grid_start = _grid_start; @@ -135,16 +134,16 @@ void LevelingBilinear::extrapolate_unprobed_bed_level() { #ifdef HALF_IN_X constexpr uint8_t ctrx2 = 0, xend = GRID_MAX_POINTS_X - 1; #else - constexpr uint8_t ctrx1 = (GRID_MAX_CELLS_X) / 2, // left-of-center - ctrx2 = (GRID_MAX_POINTS_X) / 2, // right-of-center + constexpr uint8_t ctrx1 = (GRID_MAX_CELLS_X) / 2, // left-of-center + ctrx2 = (GRID_MAX_POINTS_X) / 2, // right-of-center xend = ctrx1; #endif #ifdef HALF_IN_Y constexpr uint8_t ctry2 = 0, yend = GRID_MAX_POINTS_Y - 1; #else - constexpr uint8_t ctry1 = (GRID_MAX_CELLS_Y) / 2, // top-of-center - ctry2 = (GRID_MAX_POINTS_Y) / 2, // bottom-of-center + constexpr uint8_t ctry1 = (GRID_MAX_CELLS_Y) / 2, // top-of-center + ctry2 = (GRID_MAX_POINTS_Y) / 2, // bottom-of-center yend = ctry1; #endif diff --git a/Marlin/src/feature/bedlevel/bedlevel.cpp b/Marlin/src/feature/bedlevel/bedlevel.cpp index ca1e3c296a..ef84cca8cd 100644 --- a/Marlin/src/feature/bedlevel/bedlevel.cpp +++ b/Marlin/src/feature/bedlevel/bedlevel.cpp @@ -51,11 +51,13 @@ #endif bool leveling_is_valid() { - #if ALL(HAS_MESH, DWIN_LCD_PROUI) - return bedLevelTools.meshValidate(); - #else - return TERN1(HAS_MESH, bedlevel.mesh_is_valid()); - #endif + return ( + #if ALL(HAS_MESH, DWIN_LCD_PROUI) + bedLevelTools.meshValidate() + #else + TERN1(HAS_MESH, bedlevel.mesh_is_valid()) + #endif + ); } /** diff --git a/Marlin/src/feature/bedlevel/hilbert_curve.cpp b/Marlin/src/feature/bedlevel/hilbert_curve.cpp index 57cbdfb34d..b57991297e 100644 --- a/Marlin/src/feature/bedlevel/hilbert_curve.cpp +++ b/Marlin/src/feature/bedlevel/hilbert_curve.cpp @@ -102,8 +102,8 @@ bool hilbert_curve::search_from(uint8_t x, uint8_t y, hilbert_curve::callback_pt */ bool hilbert_curve::search_from_closest(const xy_pos_t &pos, hilbert_curve::callback_ptr func, void *data) { // Find closest grid intersection - const uint8_t grid_x = LROUND(constrain(float(pos.x - (MESH_MIN_X)) / (MESH_X_DIST), 0, (GRID_MAX_POINTS_X) - 1)); - const uint8_t grid_y = LROUND(constrain(float(pos.y - (MESH_MIN_Y)) / (MESH_Y_DIST), 0, (GRID_MAX_POINTS_Y) - 1)); + const uint8_t grid_x = LROUND(constrain((pos.x - mesh_min.x) / (MESH_X_DIST), 0, (GRID_MAX_POINTS_X) - 1)); + const uint8_t grid_y = LROUND(constrain((pos.y - mesh_min.y) / (MESH_Y_DIST), 0, (GRID_MAX_POINTS_Y) - 1)); return search_from(grid_x, grid_y, func, data); } diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp index 755b6bb028..a71920b932 100644 --- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp +++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp @@ -34,13 +34,26 @@ mesh_bed_leveling bedlevel; - float mesh_bed_leveling::z_offset; - float mesh_bed_leveling::index_to_xpos[GRID_MAX_POINTS_X], + float mesh_bed_leveling::z_offset, + mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], + mesh_bed_leveling::index_to_xpos[GRID_MAX_POINTS_X], mesh_bed_leveling::index_to_ypos[GRID_MAX_POINTS_Y]; - float mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; mesh_bed_leveling::mesh_bed_leveling() { initialize(); } + void mesh_bed_leveling::initialize() { + for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i) + index_to_xpos[i] = mesh_min.x + i * (MESH_X_DIST); + for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; ++i) + index_to_ypos[i] = mesh_min.y + i * (MESH_Y_DIST); + reset(); + } + + void mesh_bed_leveling::report_mesh() { + SERIAL_ECHOLN(F(STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh. Z offset: "), p_float_t(z_offset, 5), F("\nMeasured points:")); + print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5, z_values[0]); + } + void mesh_bed_leveling::reset() { z_offset = 0; ZERO(z_values); @@ -49,19 +62,6 @@ #endif } - void mesh_bed_leveling::initialize() { - for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i) - index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST); - for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; ++j) - index_to_ypos[j] = MESH_MIN_Y + j * (MESH_Y_DIST); - reset(); - } - - void mesh_bed_leveling::report_mesh() { - SERIAL_ECHOLN(F(STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh. Z offset: "), p_float_t(z_offset, 5), F("\nMeasured points:")); - print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5, z_values[0]); - } - #if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES) /** diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h index 525f94582b..950d0f757b 100644 --- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h +++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h @@ -32,14 +32,16 @@ enum MeshLevelingState : char { MeshReset // G29 S5 }; -#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)) +#include "../../../module/motion.h" + +#define MESH_X_DIST (mesh_min.x - mesh_max.x / (GRID_MAX_CELLS_X)) +#define MESH_Y_DIST (mesh_min.y - mesh_max.y / (GRID_MAX_CELLS_Y)) class mesh_bed_leveling { public: - static float z_offset; - static float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; - static float index_to_xpos[GRID_MAX_POINTS_X], + static float z_offset, + z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], + index_to_xpos[GRID_MAX_POINTS_X], index_to_ypos[GRID_MAX_POINTS_Y]; mesh_bed_leveling(); @@ -72,14 +74,14 @@ public: } static float get_mesh_x(const uint8_t i) { return index_to_xpos[i]; } - static float get_mesh_y(const uint8_t j) { return index_to_ypos[j]; } + static float get_mesh_y(const uint8_t i) { return index_to_ypos[i]; } static uint8_t cell_index_x(const float 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); } static uint8_t cell_index_y(const float y) { - int8_t cy = (y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST); + int8_t cy = (y - mesh_min.y) * RECIPROCAL(MESH_Y_DIST); return constrain(cy, 0, GRID_MAX_CELLS_Y - 1); } static xy_uint8_t cell_indexes(const float x, const float y) { @@ -88,11 +90,11 @@ public: static xy_uint8_t cell_indexes(const xy_pos_t &xy) { return cell_indexes(xy.x, xy.y); } static int8_t probe_index_x(const float x) { - int8_t px = (x - (MESH_MIN_X) + 0.5f * (MESH_X_DIST)) * RECIPROCAL(MESH_X_DIST); + int8_t px = (x - mesh_min.x + 0.5f * (MESH_X_DIST)) * RECIPROCAL(MESH_X_DIST); return WITHIN(px, 0, (GRID_MAX_POINTS_X) - 1) ? px : -1; } static int8_t probe_index_y(const float y) { - int8_t py = (y - (MESH_MIN_Y) + 0.5f * (MESH_Y_DIST)) * RECIPROCAL(MESH_Y_DIST); + int8_t py = (y - mesh_min.y + 0.5f * (MESH_Y_DIST)) * RECIPROCAL(MESH_Y_DIST); return WITHIN(py, 0, (GRID_MAX_POINTS_Y) - 1) ? py : -1; } static xy_int8_t probe_indexes(const float x, const float y) { diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.cpp b/Marlin/src/feature/bedlevel/ubl/ubl.cpp index 31b35c6a8d..dad447ebba 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl.cpp @@ -167,7 +167,7 @@ static void serial_echo_column_labels(const uint8_t sp) { void unified_bed_leveling::display_map(const uint8_t map_type) { const bool was = gcode.set_autoreport_paused(true); - constexpr uint8_t eachsp = 1 + 6 + 1, // [-3.567] + constexpr uint8_t eachsp = 1 + 6 + 1, // [-3.567] twixt = eachsp * (GRID_MAX_POINTS_X) - 9 * 2; // Leading 4sp, Coordinates 9sp each const bool human = !(map_type & 0x3), csv = map_type == 1, lcd = map_type == 2, comp = map_type & 0x4; @@ -175,8 +175,8 @@ void unified_bed_leveling::display_map(const uint8_t map_type) { SERIAL_ECHOPGM("\nBed Topography Report"); if (human) { SERIAL_ECHOLNPGM(":\n"); - serial_echo_xy(4, MESH_MIN_X, MESH_MAX_Y); - serial_echo_xy(twixt, MESH_MAX_X, MESH_MAX_Y); + serial_echo_xy(4, mesh_min.x, mesh_max.y); + serial_echo_xy(twixt, mesh_max.x, mesh_max.y); SERIAL_EOL(); serial_echo_column_labels(eachsp - 2); } @@ -234,8 +234,8 @@ void unified_bed_leveling::display_map(const uint8_t map_type) { if (human) { serial_echo_column_labels(eachsp - 2); SERIAL_EOL(); - serial_echo_xy(4, MESH_MIN_X, MESH_MIN_Y); - serial_echo_xy(twixt, MESH_MAX_X, MESH_MIN_Y); + serial_echo_xy(4, mesh_min.x, mesh_min.y); + serial_echo_xy(twixt, mesh_max.x, mesh_min.y); SERIAL_EOL(); SERIAL_EOL(); } diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.h b/Marlin/src/feature/bedlevel/ubl/ubl.h index 720db06ea7..ebcbc6a44b 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.h +++ b/Marlin/src/feature/bedlevel/ubl/ubl.h @@ -38,8 +38,8 @@ enum MeshPointType : char { INVALID, REAL, SET_IN_BITMAP, CLOSEST }; struct mesh_index_pair; -#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_X_DIST ((mesh_max.x - mesh_min.x) / (GRID_MAX_CELLS_X)) +#define MESH_Y_DIST ((mesh_max.y - mesh_min.y) / (GRID_MAX_CELLS_Y)) #if ENABLED(OPTIMIZED_MESH_STORAGE) typedef int16_t mesh_store_t[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; @@ -110,8 +110,8 @@ public: static void smart_fill_wlsf(const float ) __O2; // O2 gives smaller code than Os on A2560 static int8_t storage_slot; - static bed_mesh_t z_values; + static bed_mesh_t z_values; #if ENABLED(OPTIMIZED_MESH_STORAGE) static void set_store_from_mesh(const bed_mesh_t &in_values, mesh_store_t &stored_values); static void set_mesh_from_store(const mesh_store_t &stored_values, bed_mesh_t &out_values); @@ -136,11 +136,11 @@ public: FORCE_INLINE static void set_z(const int8_t px, const int8_t py, const float z) { z_values[px][py] = z; } static int8_t cell_index_x_raw(const float x) { - return FLOOR((x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST)); + return FLOOR((x - mesh_min.x) * RECIPROCAL(MESH_X_DIST)); } static int8_t cell_index_y_raw(const float y) { - return FLOOR((y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST)); + return FLOOR((y - mesh_min.y) * RECIPROCAL(MESH_Y_DIST)); } static bool cell_index_x_valid(const float x) { @@ -165,11 +165,11 @@ public: static xy_uint8_t cell_indexes(const xy_pos_t &xy) { return cell_indexes(xy.x, xy.y); } static int8_t closest_x_index(const float x) { - const int8_t px = (x - (MESH_MIN_X) + (MESH_X_DIST) * 0.5) * RECIPROCAL(MESH_X_DIST); + const int8_t px = (x - mesh_min.x + (MESH_X_DIST) * 0.5) * RECIPROCAL(MESH_X_DIST); return WITHIN(px, 0, (GRID_MAX_POINTS_X) - 1) ? px : -1; } static int8_t closest_y_index(const float y) { - const int8_t py = (y - (MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * RECIPROCAL(MESH_Y_DIST); + const int8_t py = (y - mesh_min.y + (MESH_Y_DIST) * 0.5) * RECIPROCAL(MESH_Y_DIST); return WITHIN(py, 0, (GRID_MAX_POINTS_Y) - 1) ? py : -1; } static xy_int8_t closest_indexes(const xy_pos_t &xy) { @@ -262,7 +262,7 @@ public: * UBL_Z_RAISE_WHEN_OFF_MESH is specified, that value is returned. */ #ifdef UBL_Z_RAISE_WHEN_OFF_MESH - if (!WITHIN(rx0, MESH_MIN_X, MESH_MAX_X) || !WITHIN(ry0, MESH_MIN_Y, MESH_MAX_Y)) + if (!WITHIN(rx0, mesh_min.x, mesh_max.x) || !WITHIN(ry0, mesh_min.y, mesh_max.y)) return UBL_Z_RAISE_WHEN_OFF_MESH; #endif @@ -290,19 +290,18 @@ public: static constexpr float get_z_offset() { return 0.0f; } + static float _get_mesh_x(const uint8_t i) { return mesh_min.x + i * (MESH_X_DIST); } + static float _get_mesh_y(const uint8_t i) { return mesh_min.y + i * (MESH_Y_DIST); } + #if ENABLED(PROUI_MESH_EDIT) - static float get_mesh_x(const uint8_t i) { - return MESH_MIN_X + i * (MESH_X_DIST); - } - static float get_mesh_y(const uint8_t j) { - return MESH_MIN_Y + j * (MESH_Y_DIST); - } + static float get_mesh_x(const uint8_t i) { return _get_mesh_x(i); } + static float get_mesh_y(const uint8_t i) { return _get_mesh_y(i); } #else 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]) : _get_mesh_x(i); } - static float get_mesh_y(const uint8_t j) { - return j < (GRID_MAX_POINTS_Y) ? pgm_read_float(&_mesh_index_to_ypos[j]) : MESH_MIN_Y + j * (MESH_Y_DIST); + static float get_mesh_y(const uint8_t i) { + return i < (GRID_MAX_POINTS_Y) ? pgm_read_float(&_mesh_index_to_ypos[i]) : _get_mesh_y(i); } #endif diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index 641a6ce6f4..ffd79f2eef 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -448,7 +448,7 @@ void unified_bed_leveling::G29() { tilt_mesh_based_on_probed_grid(param.J_grid_size == 0); // Zero size does 3-Point restore_ubl_active_state(); #if ENABLED(UBL_G29_J_RECENTER) - do_blocking_move_to_xy(0.5f * ((MESH_MIN_X) + (MESH_MAX_X)), 0.5f * ((MESH_MIN_Y) + (MESH_MAX_Y))); + do_blocking_move_to_xy(0.5f * (mesh_min.x + mesh_max.x), 0.5f * (mesh_min.y + mesh_max.y)); #endif report_current_position(); SET_PROBE_DEPLOYED(true); @@ -786,7 +786,10 @@ void unified_bed_leveling::shift_mesh_height(const float zoffs) { SERIAL_ECHOLNPGM("Probing mesh point ", point_num, "/", GRID_MAX_POINTS, "."); TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_POINT), point_num, int(GRID_MAX_POINTS))); TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout()); - TERN_(DWIN_LCD_PROUI, if (!hmiFlag.cancel_lev) { dwinRedrawScreen(); } else { break; }) + + #if ENABLED(DWIN_LCD_PROUI) + if (!hmiFlag.cancel_lev) dwinRedrawScreen(); else break; + #endif #if HAS_MARLINUI_MENU if (ui.button_pressed()) { @@ -816,13 +819,14 @@ void unified_bed_leveling::shift_mesh_height(const float zoffs) { ExtUI::onMeshUpdate(best.pos, ExtUI::G29_POINT_FINISH); ExtUI::onMeshUpdate(best.pos, measured_z); #endif - TERN_(DWIN_LCD_PROUI, meshViewer.drawMeshPoint(best.pos.x, best.pos.y, measured_z)); + TERN_(DWIN_LCD_PROUI, meshViewer.drawMeshPoint(best.pos, measured_z)); } SERIAL_FLUSH(); // Prevent host M105 buffer overrun. } while (best.pos.x >= 0 && --count); - TERN_(DWIN_LCD_PROUI, if (hmiFlag.cancel_lev) { goto EXIT_PROBE_MESH; }) + if (TERN0(DWIN_LCD_PROUI, hmiFlag.cancel_lev)) + goto EXIT_PROBE_MESH; GRID_LOOP(x, y) if (z_values[x][y] == HUGE_VALF) z_values[x][y] = NAN; // Restore NAN for HUGE_VALF marks @@ -833,18 +837,19 @@ void unified_bed_leveling::shift_mesh_height(const float zoffs) { probe.stow(); TERN_(HAS_MARLINUI_MENU, ui.capture()); - TERN_(Z_AFTER_PROBING, probe.move_z_after_probing()); + probe.move_z_after_probing(); #if ENABLED(DWIN_LCD_PROUI) bedlevel.smart_fill_mesh(); #else do_blocking_move_to_xy( - constrain(nearby.x - probe.offset_xy.x, MESH_MIN_X, MESH_MAX_X), - constrain(nearby.y - probe.offset_xy.y, MESH_MIN_Y, MESH_MAX_Y) + constrain(nearby.x - probe.offset_xy.x, mesh_min.x, mesh_max.x), + constrain(nearby.y - probe.offset_xy.y, mesh_min.y, mesh_max.y) ); #endif - TERN_(DWIN_LCD_PROUI, EXIT_PROBE_MESH:); + EXIT_PROBE_MESH: + restore_ubl_active_state(); } @@ -908,8 +913,8 @@ void set_message_with_feedback(FSTR_P const fstr) { do_blocking_move_to( xyz_pos_t({ - 0.5f * ((MESH_MIN_X) + (MESH_MAX_X)), - 0.5f * ((MESH_MIN_Y) + (MESH_MAX_Y)), + 0.5f * (mesh_min.x + mesh_max.x), + 0.5f * (mesh_min.y + mesh_max.y), MANUAL_PROBE_START_Z #ifdef SAFE_BED_LEVELING_START_I , SAFE_BED_LEVELING_START_I @@ -1204,9 +1209,9 @@ bool unified_bed_leveling::G29_parse_parameters() { } param.XY_seen.x = parser.seenval('X'); - float sx = param.XY_seen.x ? parser.value_float() : current_position.x - TERN0(HAS_BED_PROBE, probe.offset.x); + float sx = param.XY_seen.x ? parser.value_float() : DIFF_TERN(HAS_BED_PROBE, current_position.x, probe.offset.x); param.XY_seen.y = parser.seenval('Y'); - float sy = param.XY_seen.y ? parser.value_float() : current_position.y - TERN0(HAS_BED_PROBE, probe.offset.y); + float sy = param.XY_seen.y ? parser.value_float() : DIFF_TERN(HAS_BED_PROBE, current_position.y, probe.offset.y); if (param.XY_seen.x != param.XY_seen.y) { SERIAL_ECHOLNPGM("Both X & Y locations must be specified.\n"); @@ -1215,8 +1220,8 @@ bool unified_bed_leveling::G29_parse_parameters() { // If X or Y are not valid, use center of the bed values // (for UBL_HILBERT_CURVE default to lower-left corner instead) - if (!COORDINATE_OKAY(sx, X_MIN_BED, X_MAX_BED)) sx = TERN(UBL_HILBERT_CURVE, 0, X_CENTER - TERN0(HAS_BED_PROBE, probe.offset.x)); - if (!COORDINATE_OKAY(sy, Y_MIN_BED, Y_MAX_BED)) sy = TERN(UBL_HILBERT_CURVE, 0, Y_CENTER - TERN0(HAS_BED_PROBE, probe.offset.y)); + if (!COORDINATE_OKAY(sx, X_MIN_BED, X_MAX_BED)) sx = TERN(UBL_HILBERT_CURVE, 0, DIFF_TERN(HAS_BED_PROBE, X_CENTER, probe.offset.x)); + if (!COORDINATE_OKAY(sy, Y_MIN_BED, Y_MAX_BED)) sy = TERN(UBL_HILBERT_CURVE, 0, DIFF_TERN(HAS_BED_PROBE, Y_CENTER, probe.offset.y)); if (err_flag) return UBL_ERR; @@ -1536,7 +1541,7 @@ void unified_bed_leveling::smart_fill_mesh() { } probe.stow(); - TERN_(Z_AFTER_PROBING, probe.move_z_after_probing()); + probe.move_z_after_probing(); if (abort_flag) { SERIAL_ECHOLNPGM("?Error probing point. Aborting operation."); @@ -1548,10 +1553,10 @@ void unified_bed_leveling::smart_fill_mesh() { #ifndef G29J_MESH_TILT_MARGIN #define G29J_MESH_TILT_MARGIN 0 #endif - const float x_min = _MAX((X_MIN_POS) + (G29J_MESH_TILT_MARGIN), MESH_MIN_X, probe.min_x()), - x_max = _MIN((X_MAX_POS) - (G29J_MESH_TILT_MARGIN), MESH_MAX_X, probe.max_x()), - y_min = _MAX((Y_MIN_POS) + (G29J_MESH_TILT_MARGIN), MESH_MIN_Y, probe.min_y()), - y_max = _MIN((Y_MAX_POS) - (G29J_MESH_TILT_MARGIN), MESH_MAX_Y, probe.max_y()), + const float x_min = _MAX((X_MIN_POS) + (G29J_MESH_TILT_MARGIN), mesh_min.x, probe.min_x()), + x_max = _MIN((X_MAX_POS) - (G29J_MESH_TILT_MARGIN), mesh_max.x, probe.max_x()), + y_min = _MAX((Y_MIN_POS) + (G29J_MESH_TILT_MARGIN), mesh_min.y, probe.min_y()), + y_max = _MIN((Y_MAX_POS) - (G29J_MESH_TILT_MARGIN), mesh_max.y, probe.max_y()), dx = (x_max - x_min) / (param.J_grid_size - 1), dy = (y_max - y_min) / (param.J_grid_size - 1); @@ -1622,7 +1627,7 @@ void unified_bed_leveling::smart_fill_mesh() { } } probe.stow(); - TERN_(Z_AFTER_PROBING, probe.move_z_after_probing()); + probe.move_z_after_probing(); if (abort_flag || finish_incremental_LSF(&lsf_results)) { SERIAL_ECHOLNPGM("Could not complete LSF!"); @@ -1773,14 +1778,12 @@ void unified_bed_leveling::smart_fill_mesh() { SERIAL_ECHOLNPGM("Probe Offset M851 Z", p_float_t(probe.offset.z, 7)); #endif - SERIAL_ECHOLNPGM("MESH_MIN_X " STRINGIFY(MESH_MIN_X) "=", MESH_MIN_X); serial_delay(50); - SERIAL_ECHOLNPGM("MESH_MIN_Y " STRINGIFY(MESH_MIN_Y) "=", MESH_MIN_Y); serial_delay(50); - SERIAL_ECHOLNPGM("MESH_MAX_X " STRINGIFY(MESH_MAX_X) "=", MESH_MAX_X); serial_delay(50); - SERIAL_ECHOLNPGM("MESH_MAX_Y " STRINGIFY(MESH_MAX_Y) "=", MESH_MAX_Y); serial_delay(50); - SERIAL_ECHOLNPGM("GRID_MAX_POINTS_X ", GRID_MAX_POINTS_X); serial_delay(50); - SERIAL_ECHOLNPGM("GRID_MAX_POINTS_Y ", GRID_MAX_POINTS_Y); serial_delay(50); + SERIAL_ECHOLNPGM("mesh_min ", mesh_min.x, ", ", mesh_min.y); serial_delay(50); + SERIAL_ECHOLNPGM("mesh_max ", mesh_max.x, ", ", mesh_max.y); serial_delay(50); + SERIAL_ECHOLNPGM("GRID_MAX_POINTS_X ", GRID_MAX_POINTS_X); serial_delay(50); + SERIAL_ECHOLNPGM("GRID_MAX_POINTS_Y ", GRID_MAX_POINTS_Y); serial_delay(50); SERIAL_ECHOLNPGM("MESH_X_DIST ", MESH_X_DIST); - SERIAL_ECHOLNPGM("MESH_Y_DIST ", MESH_Y_DIST); serial_delay(50); + SERIAL_ECHOLNPGM("MESH_Y_DIST ", MESH_Y_DIST); serial_delay(50); SERIAL_ECHOPGM("X-Axis Mesh Points at: "); for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i) { @@ -1790,8 +1793,8 @@ void unified_bed_leveling::smart_fill_mesh() { SERIAL_EOL(); SERIAL_ECHOPGM("Y-Axis Mesh Points at: "); - for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; ++j) { - SERIAL_ECHO(p_float_t(LOGICAL_Y_POSITION(get_mesh_y(j)), 3), F(" ")); + for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; ++i) { + SERIAL_ECHO(p_float_t(LOGICAL_Y_POSITION(get_mesh_y(i)), 3), F(" ")); serial_delay(25); } SERIAL_EOL(); diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp index b6b9ec4368..86059f3cdb 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp @@ -414,8 +414,8 @@ // for mesh inset area. xy_int8_t icell = { - int8_t((raw.x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST)), - int8_t((raw.y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST)) + int8_t((raw.x - mesh_min.x) * RECIPROCAL(MESH_X_DIST)), + int8_t((raw.y - mesh_min.y) * RECIPROCAL(MESH_Y_DIST)) }; LIMIT(icell.x, 0, GRID_MAX_CELLS_X); LIMIT(icell.y, 0, GRID_MAX_CELLS_Y); diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 9240bc0ffd..f324b90d32 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -261,10 +261,8 @@ G29_TYPE GcodeSuite::G29() { // Send 'N' to force homing before G29 (internal only) if (parser.seen_test('N')) process_subcommands_now(TERN(CAN_SET_LEVELING_AFTER_G28, F("G28L0"), FPSTR(G28_STR))); - #if ENABLED(DWIN_LCD_PROUI) - else - process_subcommands_now(F("G28Z")); - #endif + else if (ENABLED(DWIN_LCD_PROUI)) + process_subcommands_now(F("G28Z")); // Don't allow auto-leveling without homing first if (homing_needed_error()) G29_RETURN(false, false); @@ -687,9 +685,9 @@ G29_TYPE GcodeSuite::G29() { // Outer loop is Y with PROBE_Y_FIRST disabled for (PR_OUTER_VAR = 0; PR_OUTER_VAR < PR_OUTER_SIZE && !isnan(abl.measured_z); PR_OUTER_VAR++) { - int8_t inStart, inStop, inInc; + if (TERN0(DWIN_LCD_PROUI, hmiFlag.cancel_lev)) break; - TERN_(DWIN_LCD_PROUI, if (hmiFlag.cancel_lev) break); + int8_t inStart, inStop, inInc; if (zig) { // Zig away from origin inStart = 0; // Left or front @@ -803,7 +801,7 @@ G29_TYPE GcodeSuite::G29() { const float z = abl.measured_z + abl.Z_offset; abl.z_values[abl.meshCount.x][abl.meshCount.y] = z; TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(abl.meshCount, z)); - TERN_(DWIN_LCD_PROUI, meshViewer.drawMeshPoint(abl.meshCount.x, abl.meshCount.y, z)); + TERN_(DWIN_LCD_PROUI, meshViewer.drawMeshPoint(abl.meshCount, z)); #if ENABLED(SOVOL_SV06_RTS) if (pt_index <= GRID_MAX_POINTS) rts.sendData(pt_index, AUTO_BED_LEVEL_ICON_VP); @@ -815,7 +813,8 @@ G29_TYPE GcodeSuite::G29() { abl.reenable = false; // Don't re-enable after modifying the mesh marlin.idle_no_sleep(); - TERN_(DWIN_LCD_PROUI, if (hmiFlag.cancel_lev) break); + + if (TERN0(DWIN_LCD_PROUI, hmiFlag.cancel_lev)) break; } // inner } // outer @@ -1021,7 +1020,7 @@ G29_TYPE GcodeSuite::G29() { // Restore state after probing if (!faux) restore_feedrate_and_scaling(); - TERN_(Z_AFTER_PROBING, probe.move_z_after_probing()); + probe.move_z_after_probing(); #ifdef EVENT_GCODE_AFTER_G29 if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("After G29 G-code: ", EVENT_GCODE_AFTER_G29); diff --git a/Marlin/src/inc/Conditionals-5-post.h b/Marlin/src/inc/Conditionals-5-post.h index c069dcf732..55cd16c8d7 100644 --- a/Marlin/src/inc/Conditionals-5-post.h +++ b/Marlin/src/inc/Conditionals-5-post.h @@ -574,7 +574,7 @@ #endif // Extender cable doesn't support SD_DETECT_PIN - #if ENABLED(NO_SD_DETECT) && DISABLED(DWIN_LCD_PROUI) + #if ENABLED(NO_SD_DETECT) #undef SD_DETECT_PIN #endif @@ -3445,7 +3445,7 @@ #ifndef MESH_MAX_Y #define MESH_MAX_Y _MESH_MAX_Y #endif -#elif DISABLED(DWIN_LCD_PROUI) +#else #undef MESH_MIN_X #undef MESH_MIN_Y #undef MESH_MAX_X diff --git a/Marlin/src/inc/MarlinConfigPre.h b/Marlin/src/inc/MarlinConfigPre.h index 453d1aeb24..e89471f578 100644 --- a/Marlin/src/inc/MarlinConfigPre.h +++ b/Marlin/src/inc/MarlinConfigPre.h @@ -51,8 +51,3 @@ #ifndef __MARLIN_DEPS__ #include HAL_PATH(.., inc/Conditionals_adv.h) #endif - -// ProUI extra features -#if ENABLED(DWIN_LCD_PROUI) - #include "../lcd/dwin/proui/dwin_defines.h" -#endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 373f210157..e6da8bdf2e 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1593,15 +1593,13 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i static_assert(Z_AFTER_PROBING >= 0, "Probes require Z_AFTER_PROBING >= 0."); #endif - #if DISABLED(DWIN_LCD_PROUI) - #if MULTIPLE_PROBING > 0 || EXTRA_PROBING > 0 - #if MULTIPLE_PROBING == 0 - #error "EXTRA_PROBING requires MULTIPLE_PROBING." - #elif MULTIPLE_PROBING < 2 - #error "MULTIPLE_PROBING must be 2 or more." - #elif MULTIPLE_PROBING <= EXTRA_PROBING - #error "EXTRA_PROBING must be less than MULTIPLE_PROBING." - #endif + #if DISABLED(DWIN_LCD_PROUI) && (MULTIPLE_PROBING > 0 || EXTRA_PROBING > 0) + #if MULTIPLE_PROBING == 0 + #error "EXTRA_PROBING requires MULTIPLE_PROBING." + #elif MULTIPLE_PROBING < 2 + #error "MULTIPLE_PROBING must be 2 or more." + #elif MULTIPLE_PROBING <= EXTRA_PROBING + #error "EXTRA_PROBING must be less than MULTIPLE_PROBING." #endif #endif diff --git a/Marlin/src/lcd/dwin/proui/bedlevel_tools.cpp b/Marlin/src/lcd/dwin/proui/bedlevel_tools.cpp index 81c01d21b9..8564d882f6 100644 --- a/Marlin/src/lcd/dwin/proui/bedlevel_tools.cpp +++ b/Marlin/src/lcd/dwin/proui/bedlevel_tools.cpp @@ -69,7 +69,7 @@ BedLevelTools bedLevelTools; bool BedLevelTools::grid_meshview = false; bool BedLevelTools::viewer_print_value = false; #endif -bool BedLevelTools::goto_mesh_value = false; +bool BedLevelTools::goto_mesh_value = false; uint8_t BedLevelTools::mesh_x = 0; uint8_t BedLevelTools::mesh_y = 0; uint8_t BedLevelTools::tilt_grid = 1; @@ -100,21 +100,17 @@ bool drawing_mesh = false; GRID_LOOP(i, j) { float mx = bedlevel.get_mesh_x(i), my = bedlevel.get_mesh_y(j), mz = bedlevel.z_values[i][j]; - #if DEBUG_OUT - if (DEBUGGING(LEVELING)) { - DEBUG_ECHOLN(F("before rotation = ["), p_float_t(mx, 7), C(','), p_float_t(my, 7), C(','), p_float_t(mz, 7), F("] ---> ")); - DEBUG_DELAY(20); - } - #endif + if (DEBUGGING(LEVELING)) { + DEBUG_ECHOLN(F("before rotation = ["), p_float_t(mx, 7), C(','), p_float_t(my, 7), C(','), p_float_t(mz, 7), F("] ---> ")); + DEBUG_DELAY(20); + } rotation.apply_rotation_xyz(mx, my, mz); - #if DEBUG_OUT - if (DEBUGGING(LEVELING)) { - DEBUG_ECHOLN(F("after rotation = ["), p_float_t(mx, 7), C(','), p_float_t(my, 7), C(','), p_float_t(mz, 7), F("] ---> ")); - DEBUG_DELAY(20); - } - #endif + if (DEBUGGING(LEVELING)) { + DEBUG_ECHOLN(F("after rotation = ["), p_float_t(mx, 7), C(','), p_float_t(my, 7), C(','), p_float_t(mz, 7), F("] ---> ")); + DEBUG_DELAY(20); + } bedlevel.z_values[i][j] = mz - lsf_results.D; } @@ -134,7 +130,7 @@ void BedLevelTools::manualMove(const uint8_t mesh_x, const uint8_t mesh_y, bool if (!zmove) { dwinShowPopup(ICON_BLTouch, F("Moving to Point"), F("Please wait until done.")); hmiSaveProcessID(ID_NothingToDo); - gcode.process_subcommands_now(F("G0F600Z" STRINGIFY(Z_CLEARANCE_BETWEEN_PROBES))); + gcode.process_subcommands_now(TS(F("G0 F300 Z"), p_float_t(Z_CLEARANCE_BETWEEN_PROBES, 3))); gcode.process_subcommands_now(TS(F("G42 F4000 I"), mesh_x, F(" J"), mesh_y)); } planner.synchronize(); @@ -176,25 +172,20 @@ void BedLevelTools::meshReset() { // Accessors float BedLevelTools::getMaxValue() { float max = -(__FLT_MAX__); - GRID_LOOP(x, y) { - const float z = bedlevel.z_values[x][y]; - if (!isnan(z)) NOLESS(max, z); - } + GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (!isnan(z)) NOLESS(max, z); } return max; } float BedLevelTools::getMinValue() { float min = __FLT_MAX__; - GRID_LOOP(x, y) { - const float z = bedlevel.z_values[x][y]; - if (!isnan(z)) NOMORE(min, z); - } + GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (!isnan(z)) NOMORE(min, z); } return min; } // Return 'true' if mesh is good and within LCD limits bool BedLevelTools::meshValidate() { - TERN_(PROUI_MESH_EDIT, if ((MESH_MAX_X <= MESH_MIN_X) || (MESH_MAX_Y <= MESH_MIN_Y)) return false); + if (TERN0(mesh_max.x <= mesh_min.x || mesh_max.y <= mesh_min.y)) + return false; GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (isnan(z) || !WITHIN(z, Z_OFFSET_MIN, Z_OFFSET_MAX)) return false; @@ -249,7 +240,7 @@ bool BedLevelTools::meshValidate() { } else { // has value MString<12> msg; - const bool is_wide = (GRID_MAX_POINTS_X) >= TERN(TJC_DISPLAY, 8, 10); + constexpr bool is_wide = (GRID_MAX_POINTS_X) >= TERN(TJC_DISPLAY, 8, 10); if (is_wide) msg.setf(F("%02i"), uint16_t(z * 100) % 100); else diff --git a/Marlin/src/lcd/dwin/proui/bedlevel_tools.h b/Marlin/src/lcd/dwin/proui/bedlevel_tools.h index d2bc433c52..26f2ecc399 100644 --- a/Marlin/src/lcd/dwin/proui/bedlevel_tools.h +++ b/Marlin/src/lcd/dwin/proui/bedlevel_tools.h @@ -53,6 +53,7 @@ public: static bool goto_mesh_value; static uint8_t mesh_x, mesh_y; static uint8_t tilt_grid; + #if ENABLED(AUTO_BED_LEVELING_UBL) static bool createPlaneFromMesh(); #endif diff --git a/Marlin/src/lcd/dwin/proui/dwin.cpp b/Marlin/src/lcd/dwin/proui/dwin.cpp index e5463dd07e..8ec3ed411c 100644 --- a/Marlin/src/lcd/dwin/proui/dwin.cpp +++ b/Marlin/src/lcd/dwin/proui/dwin.cpp @@ -476,7 +476,9 @@ void popupPauseOrStop() { } #endif +// // Draw status line +// void dwinDrawStatusLine(const char *text) { dwinDrawRectangle(1, hmiData.colorStatusBg, 0, STATUS_Y, DWIN_WIDTH, STATUS_Y + 20); if (text) DWINUI::drawCenteredString(hmiData.colorStatusTxt, STATUS_Y + 2, text); @@ -1926,9 +1928,8 @@ void dwinSetDataDefaults() { applyLEDColor(); #endif TERN_(HAS_GCODE_PREVIEW, hmiData.enablePreview = true); - #if HAS_BED_PROBE - IF_DISABLED(BD_SENSOR, hmiData.multiple_probing = MULTIPLE_PROBING); - hmiData.zprobeFeed = DEF_Z_PROBE_FEEDRATE_SLOW; + #if HAS_BED_PROBE && DISABLED(BD_SENSOR) + hmiData.multiple_probing = MULTIPLE_PROBING; #endif } @@ -2590,24 +2591,8 @@ void gotoConfirmToPrint() { )); } else { - #if DISABLED(PROUI_MESH_EDIT) - // AUTO_BED_LEVELING_BILINEAR does not define MESH_INSET - #ifndef MESH_MIN_X - #define MESH_MIN_X (_MAX(X_MIN_BED + (PROBING_MARGIN_LEFT), X_MIN_POS)) - #endif - #ifndef MESH_MIN_Y - #define MESH_MIN_Y (_MAX(Y_MIN_BED + (PROBING_MARGIN_FRONT), Y_MIN_POS)) - #endif - #ifndef MESH_MAX_X - #define MESH_MAX_X (_MIN(X_MAX_BED - (PROBING_MARGIN_RIGHT), X_MAX_POS)) - #endif - #ifndef MESH_MAX_Y - #define MESH_MAX_Y (_MIN(Y_MAX_BED - (PROBING_MARGIN_BACK), Y_MAX_POS)) - #endif - #endif - - LIMIT(xpos, MESH_MIN_X, MESH_MAX_X); - LIMIT(ypos, MESH_MIN_Y, MESH_MAX_Y); + LIMIT(xpos, mesh_min.x, mesh_max.x); + LIMIT(ypos, mesh_min.y, mesh_max.y); probe.stow(); gcode.process_subcommands_now(F("M420S0\nG28O")); inLev = true; @@ -3501,7 +3486,7 @@ void drawMoveMenu() { #endif IF_DISABLED(BD_SENSOR, EDIT_ITEM(ICON_Cancel, MSG_ZPROBE_MULTIPLE, onDrawPInt8Menu, setProbeMultiple, &hmiData.multiple_probing)); #if ENABLED(PROUI_ITEM_ZFR) - EDIT_ITEM(ICON_ProbeZSpeed, MSG_Z_FEED_RATE, onDrawPIntMenu, setProbeZSpeed, &hmiData.zprobeFeed); + EDIT_ITEM(ICON_ProbeZSpeed, MSG_Z_FEED_RATE, onDrawPIntMenu, setProbeZSpeed, &z_probe_slow_mm_s); #endif #if ENABLED(BLTOUCH) MENU_ITEM(ICON_ProbeStow, MSG_MANUAL_STOW, onDrawMenuItem, probeStow); @@ -4465,23 +4450,19 @@ void drawMaxAccelMenu() { void setXMeshInset() { setPFloatOnClick(0, X_BED_SIZE, UNITFDIGITS, applyMeshInset); } void setYMeshInset() { setPFloatOnClick(0, Y_BED_SIZE, UNITFDIGITS, applyMeshInset); } void maxMeshArea() { - hmiData.mesh_min_x = 0; - hmiData.mesh_max_x = X_BED_SIZE; - hmiData.mesh_min_y = 0; - hmiData.mesh_max_y = Y_BED_SIZE; + mesh_min.set(0, 0); + mesh_max.set(X_BED_SIZE, Y_BED_SIZE); resetMeshInset(); redrawMenu(); } void centerMeshArea() { - float max = (MESH_MIN_X + MESH_MIN_Y) * 0.5; - if (max < X_BED_SIZE - MESH_MAX_X) { max = X_BED_SIZE - MESH_MAX_X; } - if (max < MESH_MIN_Y) { max = MESH_MIN_Y; } - if (max < Y_BED_SIZE - MESH_MAX_Y) { max = Y_BED_SIZE - MESH_MAX_Y; } - hmiData.mesh_min_x = max; - hmiData.mesh_max_x = X_BED_SIZE - max; - hmiData.mesh_min_y = max; - hmiData.mesh_max_y = Y_BED_SIZE - max; + float max = (mesh_min.x + mesh_min.y) * 0.5f; + NOLESS(max, (X_BED_SIZE) - mesh_max.x); + NOLESS(max, mesh_min.y); + NOLESS(max, (Y_BED_SIZE) - mesh_min.y); + mesh_min.set(max, max); + mesh_max.set((X_BED_SIZE) - max, (Y_BED_SIZE) - max); resetMeshInset(); redrawMenu(); } @@ -4490,10 +4471,10 @@ void drawMaxAccelMenu() { checkkey = ID_Menu; if (SET_MENU(meshInsetMenu, MSG_MESH_INSET, 7)) { BACK_ITEM(drawMeshSetMenu); - EDIT_ITEM(ICON_Box, MSG_MESH_MIN_X, onDrawPFloatMenu, setXMeshInset, &hmiData.mesh_min_x); - EDIT_ITEM(ICON_ProbeMargin, MSG_MESH_MAX_X, onDrawPFloatMenu, setXMeshInset, &hmiData.mesh_max_x); - EDIT_ITEM(ICON_Box, MSG_MESH_MIN_Y, onDrawPFloatMenu, setYMeshInset, &hmiData.mesh_min_y); - EDIT_ITEM(ICON_ProbeMargin, MSG_MESH_MAX_Y, onDrawPFloatMenu, setYMeshInset, &hmiData.mesh_max_y); + EDIT_ITEM(ICON_Box, MSG_MESH_MIN_X, onDrawPFloatMenu, setXMeshInset, &mesh_min.x); + EDIT_ITEM(ICON_ProbeMargin, MSG_MESH_MAX_X, onDrawPFloatMenu, setXMeshInset, &mesh_max.x); + EDIT_ITEM(ICON_Box, MSG_MESH_MIN_Y, onDrawPFloatMenu, setYMeshInset, &mesh_min.y); + EDIT_ITEM(ICON_ProbeMargin, MSG_MESH_MAX_Y, onDrawPFloatMenu, setYMeshInset, &mesh_max.y); MENU_ITEM(ICON_AxisC, MSG_MESH_AMAX, onDrawMenuItem, maxMeshArea); MENU_ITEM(ICON_SetHome, MSG_MESH_CENTER, onDrawMenuItem, centerMeshArea); } diff --git a/Marlin/src/lcd/dwin/proui/dwin_defines.h b/Marlin/src/lcd/dwin/proui/dwin_defines.h index 154e51a065..27f27333e1 100644 --- a/Marlin/src/lcd/dwin/proui/dwin_defines.h +++ b/Marlin/src/lcd/dwin/proui/dwin_defines.h @@ -33,9 +33,9 @@ #include #include "../../../core/types.h" -//#define TJC_DISPLAY // Enable for TJC display -//#define DACAI_DISPLAY // Enable for DACAI display -//#define TITLE_CENTERED // Center Menu Title Text +//#define TJC_DISPLAY // Enable for TJC display +//#define DACAI_DISPLAY // Enable for DACAI display +//#define TITLE_CENTERED // Center Menu Title Text #if defined(__STM32F1__) || defined(STM32F1) #define DASH_REDRAW 1 @@ -79,27 +79,10 @@ #define defCaseLightBrightness 255 #endif -#ifdef Z_AFTER_HOMING - #define DEF_Z_AFTER_HOMING Z_AFTER_HOMING -#else - #define DEF_Z_AFTER_HOMING 0 +#ifndef Z_AFTER_HOMING + #define Z_AFTER_HOMING 0 #endif -#ifdef PREHEAT_1_TEMP_HOTEND - #define DEF_HOTENDPIDT PREHEAT_1_TEMP_HOTEND -#else - #define DEF_HOTENDPIDT 195 -#endif -#ifdef PREHEAT_1_TEMP_BED - #define DEF_BEDPIDT PREHEAT_1_TEMP_BED -#else - #define DEF_BEDPIDT 60 -#endif -#ifdef PREHEAT_1_TEMP_CHAMBER - #define DEF_CHAMBERPIDT PREHEAT_1_TEMP_CHAMBER -#else - #define DEF_CHAMBERPIDT 0 -#endif #define DEF_PIDCYCLES 5 /** @@ -139,25 +122,9 @@ #define USE_GRID_MESHVIEWER 1 // Enable for two mesh graph types #if ENABLED(PROUI_MESH_EDIT) - #ifndef MESH_INSET + #ifndef MESH_INSET #define MESH_INSET 10 #endif - #ifndef MESH_MIN_X - #define MESH_MIN_X MESH_INSET - #endif - #ifndef MESH_MIN_Y - #define MESH_MIN_Y MESH_INSET - #endif - #ifndef MESH_MAX_X - #define MESH_MAX_X X_BED_SIZE - (MESH_INSET) - #endif - #ifndef MESH_MAX_Y - #define MESH_MAX_Y Y_BED_SIZE - (MESH_INSET) - #endif - constexpr uint16_t DEF_MESH_MIN_X = MESH_MIN_X; - constexpr uint16_t DEF_MESH_MAX_X = MESH_MAX_X; - constexpr uint16_t DEF_MESH_MIN_Y = MESH_MIN_Y; - constexpr uint16_t DEF_MESH_MAX_Y = MESH_MAX_Y; #define MIN_MESH_INSET 0 #define MAX_MESH_INSET X_BED_SIZE #endif @@ -166,14 +133,6 @@ #define MULTIPLE_PROBING 0 #endif -#if HAS_BED_PROBE - constexpr uint16_t DEF_Z_PROBE_FEEDRATE_SLOW = Z_PROBE_FEEDRATE_SLOW; -#endif - -#if HAS_EXTRUDERS - constexpr bool DEF_INVERT_E0_DIR = INVERT_E0_DIR; -#endif - typedef struct { // Color settings uint16_t colorBackground; @@ -200,13 +159,22 @@ typedef struct { int16_t pidCycles = DEF_PIDCYCLES; #endif #if ENABLED(PIDTEMP) - celsius_t hotendPIDT = DEF_HOTENDPIDT; + #ifndef PREHEAT_1_TEMP_HOTEND + #define PREHEAT_1_TEMP_HOTEND 195 + #endif + celsius_t hotendPIDT = PREHEAT_1_TEMP_HOTEND; #endif #if ENABLED(PIDTEMPBED) - celsius_t bedPIDT = DEF_BEDPIDT; + #ifndef PREHEAT_1_TEMP_BED + #define PREHEAT_1_TEMP_BED 60 + #endif + celsius_t bedPIDT = PREHEAT_1_TEMP_BED; #endif #if ENABLED(PIDTEMPCHAMBER) - celsius_t chamberPIDT = DEF_CHAMBERPIDT; + #ifndef PREHEAT_1_TEMP_CHAMBER + #define PREHEAT_1_TEMP_CHAMBER 0 + #endif + celsius_t chamberPIDT = PREHEAT_1_TEMP_CHAMBER; #endif #if ENABLED(PREVENT_COLD_EXTRUSION) celsius_t extMinT = EXTRUDE_MINTEMP; @@ -227,7 +195,7 @@ typedef struct { #endif bool mediaAutoMount = ENABLED(HAS_SD_EXTENDER); #if ALL(INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING) - uint8_t zAfterHoming = DEF_Z_AFTER_HOMING; + uint8_t zAfterHoming = Z_AFTER_HOMING; #define Z_POST_CLEARANCE hmiData.zAfterHoming #endif #if ALL(LED_CONTROL_MENU, HAS_COLOR_LEDS) @@ -236,43 +204,11 @@ typedef struct { #if HAS_GCODE_PREVIEW bool enablePreview = true; #endif - #if ENABLED(PROUI_MESH_EDIT) - float mesh_min_x = DEF_MESH_MIN_X; - float mesh_max_x = DEF_MESH_MAX_X; - float mesh_min_y = DEF_MESH_MIN_Y; - float mesh_max_y = DEF_MESH_MAX_Y; - #endif - #if HAS_BED_PROBE - IF_DISABLED(BD_SENSOR, uint8_t multiple_probing = MULTIPLE_PROBING); - uint16_t zprobeFeed = DEF_Z_PROBE_FEEDRATE_SLOW; - #endif - #if HAS_EXTRUDERS - bool Invert_E0 = DEF_INVERT_E0_DIR; + #if HAS_BED_PROBE && DISABLED(BD_SENSOR) + uint8_t multiple_probing = MULTIPLE_PROBING; #endif } hmi_data_t; extern hmi_data_t hmiData; #define EXTUI_EEPROM_DATA_SIZE sizeof(hmi_data_t) - -// ProUI extra feature redefines -#if ENABLED(PROUI_MESH_EDIT) - #undef MESH_MIN_X - #undef MESH_MAX_X - #undef MESH_MIN_Y - #undef MESH_MAX_Y - #define MESH_MIN_X hmiData.mesh_min_x - #define MESH_MAX_X hmiData.mesh_max_x - #define MESH_MIN_Y hmiData.mesh_min_y - #define MESH_MAX_Y hmiData.mesh_max_y -#endif - -#if HAS_BED_PROBE - #undef Z_PROBE_FEEDRATE_SLOW - #define Z_PROBE_FEEDRATE_SLOW hmiData.zprobeFeed -#endif - -#if HAS_EXTRUDERS - #undef INVERT_E0_DIR - #define INVERT_E0_DIR hmiData.Invert_E0 -#endif diff --git a/Marlin/src/lcd/dwin/proui/dwinui.cpp b/Marlin/src/lcd/dwin/proui/dwinui.cpp index 2d6dc67197..3f1dab2e6b 100644 --- a/Marlin/src/lcd/dwin/proui/dwinui.cpp +++ b/Marlin/src/lcd/dwin/proui/dwinui.cpp @@ -264,11 +264,11 @@ void DWINUI::drawCircle(uint16_t color, uint16_t x, uint16_t y, uint8_t r) { // x: the abscissa of the center of the circle // y: ordinate of the center of the circle // r: circle radius -void DWINUI::drawFillCircle(uint16_t bcolor, uint16_t x, uint16_t y, uint8_t r) { +void DWINUI::drawFillCircle(const uint16_t bcolor, const uint16_t x, const uint16_t y, const uint8_t r) { dwinDrawLine(bcolor, x - r, y, x + r, y); uint16_t b = 1; while (b <= r) { - uint16_t a = SQRT(sq(r) - sq(b)); + const uint16_t a = SQRT(sq(r) - sq(b)); dwinDrawLine(bcolor, x - a, y + b, x + a, y + b); dwinDrawLine(bcolor, x - a, y - b, x + a, y - b); b += TERN(TJC_DISPLAY, 2, 1); diff --git a/Marlin/src/lcd/dwin/proui/dwinui.h b/Marlin/src/lcd/dwin/proui/dwinui.h index 36a0909418..f234639f23 100644 --- a/Marlin/src/lcd/dwin/proui/dwinui.h +++ b/Marlin/src/lcd/dwin/proui/dwinui.h @@ -571,8 +571,8 @@ namespace DWINUI { // x: abscissa of the center of the circle // y: ordinate of the center of the circle // r: circle radius - void drawFillCircle(uint16_t bcolor, uint16_t x,uint16_t y,uint8_t r); - inline void drawFillCircle(uint16_t bcolor, uint8_t r) { + void drawFillCircle(const uint16_t bcolor, const uint16_t x, const uint16_t y, const uint8_t r); + inline void drawFillCircle(const uint16_t bcolor, const uint8_t r) { drawFillCircle(bcolor, cursor.x, cursor.y, r); } diff --git a/Marlin/src/lcd/dwin/proui/gcode_preview.cpp b/Marlin/src/lcd/dwin/proui/gcode_preview.cpp index 0265a89d22..4bb8d88ce4 100644 --- a/Marlin/src/lcd/dwin/proui/gcode_preview.cpp +++ b/Marlin/src/lcd/dwin/proui/gcode_preview.cpp @@ -29,7 +29,11 @@ #include "../../../inc/MarlinConfigPre.h" -#if ALL(DWIN_LCD_PROUI, HAS_GCODE_PREVIEW) +#if ENABLED(DWIN_LCD_PROUI) + +#include "dwin_defines.h" + +#if HAS_GCODE_PREVIEW #include "gcode_preview.h" @@ -222,4 +226,5 @@ void Preview::show() { dwinIconShow(xpos, ypos, 0x00); } -#endif // DWIN_LCD_PROUI && HAS_GCODE_PREVIEW +#endif // HAS_GCODE_PREVIEW +#endif // DWIN_LCD_PROUI diff --git a/Marlin/src/lcd/dwin/proui/meshviewer.cpp b/Marlin/src/lcd/dwin/proui/meshviewer.cpp index f80ee4c986..12997af776 100644 --- a/Marlin/src/lcd/dwin/proui/meshviewer.cpp +++ b/Marlin/src/lcd/dwin/proui/meshviewer.cpp @@ -32,11 +32,10 @@ #if ALL(DWIN_LCD_PROUI, HAS_MESH) -#include "../../../core/types.h" +#include "meshviewer.h" + #include "../../marlinui.h" #include "dwin_popup.h" -#include "../../../feature/bedlevel/bedlevel.h" -#include "meshviewer.h" #if USE_GRID_MESHVIEWER #include "bedlevel_tools.h" @@ -70,32 +69,33 @@ void MeshViewer::drawMeshGrid(const uint8_t csizex, const uint8_t csizey) { for (uint8_t y = 1; y < sizey - 1; ++y) dwinDrawHLine(hmiData.colorSplitLine, px(0), py(y), width); } -void MeshViewer::drawMeshPoint(const uint8_t x, const uint8_t y, const float z) { +void MeshViewer::drawMeshPoint(const xy_uint8_t xy, const float z) { const uint8_t fs = DWINUI::fontWidth(title.meshfont); const int16_t v = isnan(z) ? int16_t(0) : int16_t(LROUND(z * 100)); NOLESS(max, z); NOMORE(min, z); const uint16_t color = DWINUI::rainbowInt(v, zmin, zmax); - DWINUI::drawFillCircle(color, px(x), py(y), r(_MAX(_MIN(v, zmax), zmin))); + const uint8_t x = px(xy.x), y = py(xy.y); + DWINUI::drawFillCircle(color, x, y, r(_MAX(_MIN(v, zmax), zmin))); TERN_(TJC_DISPLAY, delay(100)); - const uint16_t fy = py(y) - fs; + const uint16_t fy = y - fs; if (sizex < TERN(TJC_DISPLAY, 8, 9)) { - if (v == 0) DWINUI::drawFloat(title.meshfont, 1, 2, px(x) - 2 * fs, fy, 0); - else DWINUI::drawSignedFloat(title.meshfont, 1, 2, px(x) - 3 * fs, fy, z); + if (v == 0) DWINUI::drawFloat(title.meshfont, 1, 2, x - 2 * fs, fy, 0); + else DWINUI::drawSignedFloat(title.meshfont, 1, 2, x - 3 * fs, fy, z); } else { char msg[9]; msg[0] = '\0'; switch (v) { case -999 ... -100: - case 100 ... 999: DWINUI::drawSignedFloat(title.meshfont, 1, 1, px(x) - 3 * fs, fy, z); break; + case 100 ... 999: DWINUI::drawSignedFloat(title.meshfont, 1, 1, x - 3 * fs, fy, z); break; case -99 ... -1: sprintf_P(msg, PSTR("-.%2i"), -v); break; case 1 ... 99: sprintf_P(msg, PSTR( ".%2i"), v); break; default: - dwinDrawString(false, title.meshfont, DWINUI::textColor, DWINUI::backColor, px(x) - 4, fy, "0"); + dwinDrawString(false, title.meshfont, DWINUI::textColor, DWINUI::backColor, x - 4, fy, "0"); return; } - dwinDrawString(false, title.meshfont, DWINUI::textColor, DWINUI::backColor, px(x) - 2 * fs, fy, msg); + dwinDrawString(false, title.meshfont, DWINUI::textColor, DWINUI::backColor, x - 2 * fs, fy, msg); } } @@ -103,7 +103,7 @@ void MeshViewer::drawMesh(const bed_mesh_t zval, const uint8_t csizex, const uin drawMeshGrid(csizex, csizey); for (uint8_t y = 0; y < csizey; ++y) { hal.watchdog_refresh(); - for (uint8_t x = 0; x < csizex; ++x) drawMeshPoint(x, y, zval[x][y]); + for (uint8_t x = 0; x < csizex; ++x) drawMeshPoint(xy_uint8_t({x, y}), zval[x][y]); } } diff --git a/Marlin/src/lcd/dwin/proui/meshviewer.h b/Marlin/src/lcd/dwin/proui/meshviewer.h index 93be9ee7c2..c7aec71485 100644 --- a/Marlin/src/lcd/dwin/proui/meshviewer.h +++ b/Marlin/src/lcd/dwin/proui/meshviewer.h @@ -29,11 +29,14 @@ * Date: 2023/05/05 */ +#include "../../../core/types.h" +#include "../../../feature/bedlevel/bedlevel.h" + class MeshViewer { public: static float max, min; static void drawMeshGrid(const uint8_t csizex, const uint8_t csizey); - static void drawMeshPoint(const uint8_t x, const uint8_t y, const float z); + static void drawMeshPoint(const xy_uint8_t xy, const float z); static void draw(const bool withsave=false, const bool redraw=true); static void drawMesh(const bed_mesh_t zval, const uint8_t csizex, const uint8_t csizey); }; diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.cpp index 6030fd02a0..62c8656b7e 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.cpp @@ -53,7 +53,7 @@ constexpr static float gaugeThickness = 0.25; #endif static float meshGetter(uint8_t x, uint8_t y, void*) { - return ExtUI::getMeshPoint(xy_uint8_t({ x, y })); + return ExtUI::getMeshPoint(xy_uint8_t({x, y})); } void BedMeshViewScreen::onEntry() { diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index ded9b80227..82f0c03d5d 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -883,8 +883,8 @@ namespace ExtUI { void moveToMeshPoint(const xy_uint8_t &pos, const float z) { #if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL) REMEMBER(fr, feedrate_mm_s); - const float x_target = MESH_MIN_X + pos.x * (MESH_X_DIST), - y_target = MESH_MIN_Y + pos.y * (MESH_Y_DIST); + const float x_target = mesh_min.x + pos.x * (MESH_X_DIST), + y_target = mesh_min.y + pos.y * (MESH_Y_DIST); if (x_target != current_position.x || y_target != current_position.y) { // If moving across bed, raise nozzle to safe height over bed feedrate_mm_s = z_probe_fast_mm_s; diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index dae4ae6e0e..d2ecdcae40 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -85,6 +85,14 @@ bool relative_mode; // = false bool z_min_trusted; // = false #endif +#if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL) + #if ENABLED(DWIN_LCD_PROUI) + uint16_t z_probe_slow_mm_s = MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW); + xy_pos_t mesh_min{ MESH_MIN_X, MESH_MIN_Y }, + mesh_max{ MESH_MAX_X, MESH_MAX_Y }; + #endif +#endif + // Warn for unexpected TPARA home position #if ENABLED(AXEL_TPARA) static_assert( @@ -1061,7 +1069,7 @@ void do_blocking_move_to(const xyze_pos_t &raw, const feedRate_t fr_mm_s/*=0.0f* * - Execute the move at the probing (or homing) feedrate */ void do_z_clearance(const float zclear, const bool with_probe/*=true*/, const bool lower_allowed/*=false*/) { - IF_DISABLED(HAS_BED_PROBE, UNUSED(with_probe)); + UNUSED(with_probe); float zdest = zclear; TERN_(HAS_BED_PROBE, if (with_probe && probe.offset.z < 0) zdest -= probe.offset.z); NOMORE(zdest, Z_MAX_POS); diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 3079b2fead..51f9e56666 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -67,13 +67,23 @@ extern xyz_pos_t cartes; #define XY_PROBE_FEEDRATE_MM_S PLANNER_XY_FEEDRATE_MM_S #endif -#ifdef Z_PROBE_FEEDRATE_SLOW - TERN(DWIN_LCD_PROUI, const, constexpr) feedRate_t z_probe_slow_mm_s = MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW); +#if ENABLED(DWIN_LCD_PROUI) + extern uint16_t z_probe_slow_mm_s; +#elif defined(Z_PROBE_FEEDRATE_SLOW) + constexpr feedRate_t z_probe_slow_mm_s = MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW); #endif #ifdef Z_PROBE_FEEDRATE_FAST constexpr feedRate_t z_probe_fast_mm_s = MMM_TO_MMS(Z_PROBE_FEEDRATE_FAST); #endif +#if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL) + #if ENABLED(PROUI_MESH_EDIT) + extern xy_pos_t mesh_min, mesh_max; + #else + constexpr xy_pos_t mesh_min{ MESH_MIN_X, MESH_MIN_Y }, mesh_max{ MESH_MAX_X, MESH_MAX_Y }; + #endif +#endif + /** * Feed rates are often configured with mm/m * but the planner and stepper like mm/s units. diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index d0aedbe260..93e0a7bfb7 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -777,42 +777,42 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { * * @return The Z position of the bed at the current XY or NAN on error. */ -#if DISABLED(DWIN_LCD_PROUI) +float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_point/*=Z_PROBE_LOW_POINT*/, const float z_clearance/*=Z_TWEEN_SAFE_CLEARANCE*/) { + DEBUG_SECTION(log_probe, "Probe::run_z_probe", DEBUGGING(LEVELING)); - float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_point/*=Z_PROBE_LOW_POINT*/, const float z_clearance/*=Z_TWEEN_SAFE_CLEARANCE*/) { - DEBUG_SECTION(log_probe, "Probe::run_z_probe", DEBUGGING(LEVELING)); + const float zoffs = SUM_TERN(HAS_HOTEND_OFFSET, -offset.z, hotend_offset[active_extruder].z); - const float zoffs = SUM_TERN(HAS_HOTEND_OFFSET, -offset.z, hotend_offset[active_extruder].z); + auto try_to_probe = [&](PGM_P const plbl, const float z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck) -> bool { + constexpr float error_tolerance = Z_PROBE_ERROR_TOLERANCE; + if (DEBUGGING(LEVELING)) { + DEBUG_ECHOPGM_P(plbl); + DEBUG_ECHOLNPGM("> try_to_probe(..., ", z_probe_low_point, ", ", fr_mm_s, ", ...)"); + } - auto try_to_probe = [&](PGM_P const plbl, const float z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck) -> bool { - constexpr float error_tolerance = Z_PROBE_ERROR_TOLERANCE; - if (DEBUGGING(LEVELING)) { - DEBUG_ECHOPGM_P(plbl); - DEBUG_ECHOLNPGM("> try_to_probe(..., ", z_probe_low_point, ", ", fr_mm_s, ", ...)"); + // Tare the probe, if supported + if (TERN0(PROBE_TARE, tare())) return true; + + // Do a first probe at the fast speed + const bool probe_fail = probe_down_to_z(z_probe_low_point, fr_mm_s), // No probe trigger? + early_fail = (scheck && current_position.z > zoffs + error_tolerance); // Probe triggered too high? + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING) && (probe_fail || early_fail)) { + DEBUG_ECHOPGM(" Probe fail! - "); + if (probe_fail) DEBUG_ECHOLNPGM("No trigger."); + if (early_fail) DEBUG_ECHOLNPGM("Triggered early (above ", zoffs + error_tolerance, "mm)"); } + #else + UNUSED(plbl); + #endif + return probe_fail || early_fail; + }; - // Tare the probe, if supported - if (TERN0(PROBE_TARE, tare())) return true; + // Stop the probe before it goes too low to prevent damage. + // For known Z probe below the expected trigger point, otherwise -10mm lower. + const float z_probe_low_point = zoffs + z_min_point -float((!axis_is_trusted(Z_AXIS)) * 10); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Probe Low Point: ", z_probe_low_point); - // Do a first probe at the fast speed - const bool probe_fail = probe_down_to_z(z_probe_low_point, fr_mm_s), // No probe trigger? - early_fail = (scheck && current_position.z > zoffs + error_tolerance); // Probe triggered too high? - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING) && (probe_fail || early_fail)) { - DEBUG_ECHOPGM(" Probe fail! - "); - if (probe_fail) DEBUG_ECHOLNPGM("No trigger."); - if (early_fail) DEBUG_ECHOLNPGM("Triggered early (above ", zoffs + error_tolerance, "mm)"); - } - #else - UNUSED(plbl); - #endif - return probe_fail || early_fail; - }; - - // Stop the probe before it goes too low to prevent damage. - // For known Z probe below the expected trigger point, otherwise -10mm lower. - const float z_probe_low_point = zoffs + z_min_point -float((!axis_is_trusted(Z_AXIS)) * 10); - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Probe Low Point: ", z_probe_low_point); + #if DISABLED(DWIN_LCD_PROUI) // Double-probing does a fast probe followed by a slow probe #if TOTAL_PROBING == 2 @@ -829,16 +829,19 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { // Raise to give the probe clearance do_z_clearance(z1 + (Z_CLEARANCE_MULTI_PROBE), false); - #elif Z_PROBE_FEEDRATE_FAST != Z_PROBE_FEEDRATE_SLOW + #else - // If the nozzle is well over the travel height then - // move down quickly before doing the slow probe - const float z = (Z_CLEARANCE_DEPLOY_PROBE) + 5.0f + _MAX(zoffs, 0.0f); - if (current_position.z > z) { - // Probe down fast. If the probe never triggered, raise for probe clearance - if (!probe_down_to_z(z, z_probe_fast_mm_s)) - do_z_clearance(z_clearance); + if (z_probe_fast_mm_s != z_probe_slow_mm_s) { + // If the nozzle is well over the travel height then + // move down quickly before doing the slow probe + const float z = (Z_CLEARANCE_DEPLOY_PROBE) + 5.0f + _MAX(zoffs, 0.0f); + if (current_position.z > z) { + // Probe down fast. If the probe never triggered, raise for probe clearance + if (!probe_down_to_z(z, z_probe_fast_mm_s)) + do_z_clearance(z_clearance); + } } + #endif #if EXTRA_PROBING > 0 @@ -861,7 +864,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { // Probe downward slowly to find the bed if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Slow Probe:"); - if (try_to_probe(PSTR("SLOW"), z_probe_low_point, MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW), sanity_check)) return NAN; + if (try_to_probe(PSTR("SLOW"), z_probe_low_point, z_probe_slow_mm_s, sanity_check)) return NAN; TERN_(MEASURE_BACKLASH_WHEN_PROBING, backlash.measure_with_probe()); @@ -930,47 +933,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { #endif - return DIFF_TERN(HAS_HOTEND_OFFSET, measured_z, hotend_offset[active_extruder].z); - } - -#else // if DWIN_LCD_PROUI - - float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_point/*=Z_PROBE_LOW_POINT*/, const float z_clearance/*=Z_TWEEN_SAFE_CLEARANCE*/) { - DEBUG_SECTION(log_probe, "Probe::run_z_probe", DEBUGGING(LEVELING)); - - const float zoffs = SUM_TERN(HAS_HOTEND_OFFSET, -offset.z, hotend_offset[active_extruder].z); - - auto try_to_probe = [&](PGM_P const plbl, const float z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck) -> bool { - constexpr float error_tolerance = Z_PROBE_ERROR_TOLERANCE; - if (DEBUGGING(LEVELING)) { - DEBUG_ECHOPGM_P(plbl); - DEBUG_ECHOLNPGM("> try_to_probe(..., ", z_probe_low_point, ", ", fr_mm_s, ", ...)"); - } - - // Tare the probe, if supported - if (TERN0(PROBE_TARE, tare())) return true; - - // Do a first probe at the fast speed - const bool probe_fail = probe_down_to_z(z_probe_low_point, fr_mm_s), // No probe trigger? - early_fail = (scheck && current_position.z > zoffs + error_tolerance); // Probe triggered too high? - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING) && (probe_fail || early_fail)) { - DEBUG_ECHOPGM(" Probe fail! - "); - if (probe_fail) DEBUG_ECHOLNPGM("No trigger."); - if (early_fail) DEBUG_ECHOLNPGM("Triggered early (above ", zoffs + error_tolerance, "mm)"); - } - #else - UNUSED(plbl); - #endif - return probe_fail || early_fail; - }; - - // Stop the probe before it goes too low to prevent damage. - // For known Z probe below the expected trigger point, otherwise -10mm lower. - const float z_probe_low_point = zoffs + z_min_point - float((!axis_is_trusted(Z_AXIS)) * 10); - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Probe Low Point: ", z_probe_low_point); - - // Double-probing does a fast probe followed by a slow probe + #else // DWIN_LCD_PROUI // Attempt to tare the probe if (TERN0(PROBE_TARE, tare())) return NAN; @@ -1002,13 +965,12 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { } // Return a weighted average of the fast and slow probes - const float measured_z = (hmiData.multiple_probing > 1) ? - (probes_z_sum * 3.0f + z1 * 2.0f) * 0.2f : z1; + const float measured_z = (hmiData.multiple_probing > 1) ? (probes_z_sum * 3.0f + z1 * 2.0f) * 0.2f : z1; - return DIFF_TERN(HAS_HOTEND_OFFSET, measured_z, hotend_offset[active_extruder].z); - } + #endif // DWIN_LCD_PROUI -#endif // !DWIN_LCD_PROUI + return DIFF_TERN(HAS_HOTEND_OFFSET, measured_z, hotend_offset[active_extruder].z); +} #if DO_TOOLCHANGE_FOR_PROBING diff --git a/Marlin/src/module/probe.h b/Marlin/src/module/probe.h index d0f0ada34c..340c8f7902 100644 --- a/Marlin/src/module/probe.h +++ b/Marlin/src/module/probe.h @@ -336,9 +336,9 @@ public: points[1] = xy_float_t({ (X_CENTER) + probe_radius() * COS120, (Y_CENTER) + probe_radius() * SIN120 }); points[2] = xy_float_t({ (X_CENTER) + probe_radius() * COS240, (Y_CENTER) + probe_radius() * SIN240 }); #elif ENABLED(AUTO_BED_LEVELING_UBL) - points[0] = xy_float_t({ _MAX(float(MESH_MIN_X), min_x()), _MAX(float(MESH_MIN_Y), min_y()) }); - points[1] = xy_float_t({ _MIN(float(MESH_MAX_X), max_x()), _MAX(float(MESH_MIN_Y), min_y()) }); - points[2] = xy_float_t({ (_MAX(float(MESH_MIN_X), min_x()) + _MIN(float(MESH_MAX_X), max_x())) / 2, _MIN(float(MESH_MAX_Y), max_y()) }); + points[0] = xy_float_t({ _MAX(mesh_min.x, min_x()), _MAX(mesh_min.y, min_y()) }); + points[1] = xy_float_t({ _MIN(mesh_max.x, max_x()), _MAX(mesh_min.y, min_y()) }); + points[2] = xy_float_t({ (_MAX(mesh_min.x, min_x()) + _MIN(mesh_max.x, max_x())) / 2, _MIN(mesh_max.y, max_y()) }); #else points[0] = xy_float_t({ min_x(), min_y() }); points[1] = xy_float_t({ max_x(), min_y() });