|
@ -51,18 +51,11 @@ |
|
|
#include "../../feature/bltouch.h" |
|
|
#include "../../feature/bltouch.h" |
|
|
#endif |
|
|
#endif |
|
|
#ifndef LEVEL_CORNERS_PROBE_TOLERANCE |
|
|
#ifndef LEVEL_CORNERS_PROBE_TOLERANCE |
|
|
#define LEVEL_CORNERS_PROBE_TOLERANCE 0.1 |
|
|
#define LEVEL_CORNERS_PROBE_TOLERANCE 0.2 |
|
|
#endif |
|
|
#endif |
|
|
#if ENABLED(LEVEL_CORNERS_AUDIO_FEEDBACK) |
|
|
float last_z; |
|
|
#include "../../libs/buzzer.h" |
|
|
int good_points; |
|
|
#define PROBE_BUZZ() BUZZ(200, 600) |
|
|
bool corner_probing_done, wait_for_probe; |
|
|
#else |
|
|
|
|
|
#define PROBE_BUZZ() NOOP |
|
|
|
|
|
#endif |
|
|
|
|
|
static float last_z; |
|
|
|
|
|
static bool corner_probing_done; |
|
|
|
|
|
static bool verify_corner; |
|
|
|
|
|
static int good_points; |
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
static_assert(LEVEL_CORNERS_Z_HOP >= 0, "LEVEL_CORNERS_Z_HOP must be >= 0. Please update your configuration."); |
|
|
static_assert(LEVEL_CORNERS_Z_HOP >= 0, "LEVEL_CORNERS_Z_HOP must be >= 0. Please update your configuration."); |
|
@ -75,115 +68,130 @@ extern const char G28_STR[]; |
|
|
|
|
|
|
|
|
static int8_t bed_corner; |
|
|
static int8_t bed_corner; |
|
|
|
|
|
|
|
|
|
|
|
constexpr float inset_lfrb[4] = LEVEL_CORNERS_INSET_LFRB; |
|
|
|
|
|
constexpr xy_pos_t lf { (X_MIN_BED) + inset_lfrb[0], (Y_MIN_BED) + inset_lfrb[1] }, |
|
|
|
|
|
rb { (X_MAX_BED) - inset_lfrb[2], (Y_MAX_BED) - inset_lfrb[3] }; |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* Level corners, starting in the front-left corner. |
|
|
* Level corners, starting in the front-left corner. |
|
|
*/ |
|
|
*/ |
|
|
#if ENABLED(LEVEL_CORNERS_USE_PROBE) |
|
|
#if ENABLED(LEVEL_CORNERS_USE_PROBE) |
|
|
|
|
|
|
|
|
static inline void _lcd_level_bed_corners_probing() { |
|
|
void _lcd_draw_probing() { |
|
|
ui.goto_screen([]{ MenuItem_static::draw((LCD_HEIGHT - 1) / 2, GET_TEXT(MSG_PROBING_MESH)); }); |
|
|
if (ui.should_draw()) MenuItem_static::draw((LCD_HEIGHT - 1) / 2, GET_TEXT(MSG_PROBING_MESH)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
float lfrb[4] = LEVEL_CORNERS_INSET_LFRB; |
|
|
void _lcd_draw_raise() { |
|
|
xy_pos_t lf { (X_MIN_BED) + lfrb[0] - probe.offset_xy.x , (Y_MIN_BED) + lfrb[1] - probe.offset_xy.y }, |
|
|
if (!ui.should_draw()) return; |
|
|
rb { (X_MAX_BED) - lfrb[2] - probe.offset_xy.x , (Y_MAX_BED) - lfrb[3] - probe.offset_xy.y }; |
|
|
MenuItem_confirm::select_screen( |
|
|
|
|
|
GET_TEXT(MSG_BUTTON_DONE), GET_TEXT(MSG_BUTTON_SKIP) |
|
|
|
|
|
, []{ corner_probing_done = true; wait_for_probe = false; } |
|
|
|
|
|
, []{ wait_for_probe = false; } |
|
|
|
|
|
, GET_TEXT(MSG_LEVEL_CORNERS_RAISE) |
|
|
|
|
|
, (const char*)nullptr, PSTR("") |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
do_blocking_move_to_z(LEVEL_CORNERS_Z_HOP - probe.offset.z); |
|
|
void _lcd_draw_level_prompt() { |
|
|
|
|
|
if (!ui.should_draw()) return; |
|
|
|
|
|
MenuItem_confirm::confirm_screen( |
|
|
|
|
|
[]{ queue.inject_P(TERN(HAS_LEVELING, PSTR("G28\nG29"), G28_STR)); |
|
|
|
|
|
ui.return_to_status(); |
|
|
|
|
|
} |
|
|
|
|
|
, []{ ui.goto_previous_screen_no_defer(); } |
|
|
|
|
|
, GET_TEXT(MSG_LEVEL_CORNERS_IN_RANGE) |
|
|
|
|
|
, (const char*)nullptr, PSTR("?") |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
switch (bed_corner) { |
|
|
bool _lcd_level_bed_corners_probe(bool verify=false) { |
|
|
case 0: current_position = lf; break; // copy xy
|
|
|
if (verify) do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP); // do clearance if needed
|
|
|
case 1: current_position.x = rb.x; break; |
|
|
TERN_(BLTOUCH_SLOW_MODE, bltouch.deploy()); // Deploy in LOW SPEED MODE on every probe action
|
|
|
case 2: current_position.y = rb.y; break; |
|
|
do_blocking_move_to_z(last_z - LEVEL_CORNERS_PROBE_TOLERANCE, manual_feedrate_mm_s.z); // Move down to lower tolerance
|
|
|
case 3: current_position.x = lf.x; break; |
|
|
if (TEST(endstops.trigger_state(), TERN(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, Z_MIN, Z_MIN_PROBE))) { // check if probe triggered
|
|
|
#if ENABLED(LEVEL_CENTER_TOO) |
|
|
endstops.hit_on_purpose(); |
|
|
case 4: current_position.set(X_CENTER - probe.offset_xy.x, Y_CENTER - probe.offset_xy.y); good_points--; break; |
|
|
set_current_from_steppers_for_axis(Z_AXIS); |
|
|
#endif |
|
|
sync_plan_position(); |
|
|
|
|
|
TERN_(BLTOUCH_SLOW_MODE, bltouch.stow()); // Stow in LOW SPEED MODE on every trigger
|
|
|
|
|
|
// Triggered outside tolerance range?
|
|
|
|
|
|
if (ABS(current_position.z - last_z) > LEVEL_CORNERS_PROBE_TOLERANCE) { |
|
|
|
|
|
last_z = current_position.z; // Above tolerance. Set a new Z for subsequent corners.
|
|
|
|
|
|
good_points = 0; // ...and start over
|
|
|
|
|
|
} |
|
|
|
|
|
return true; // probe triggered
|
|
|
} |
|
|
} |
|
|
|
|
|
do_blocking_move_to_z(last_z); // go back to tolerance middle point before raise
|
|
|
|
|
|
return false; // probe not triggered
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
do_blocking_move_to_xy(current_position); |
|
|
bool _lcd_level_bed_corners_raise() { |
|
|
|
|
|
bool probe_triggered = false; |
|
|
#if ENABLED(BLTOUCH) && DISABLED(BLTOUCH_HS_MODE) |
|
|
corner_probing_done = false; |
|
|
bltouch.deploy(); // DEPLOY in LOW SPEED MODE on every probe action
|
|
|
wait_for_probe = true; |
|
|
#endif |
|
|
ui.goto_screen(_lcd_draw_raise); // show raise screen
|
|
|
TERN_(HAS_QUIET_PROBING, probe.set_probing_paused(true)); |
|
|
ui.set_selection(true); |
|
|
|
|
|
while (wait_for_probe && !probe_triggered) { //loop while waiting to bed raise and probe trigger
|
|
|
// Move down until the probe is triggered
|
|
|
probe_triggered = PROBE_TRIGGERED(); |
|
|
do_blocking_move_to_z(last_z - (LEVEL_CORNERS_PROBE_TOLERANCE), manual_feedrate_mm_s.z); |
|
|
if (probe_triggered) { |
|
|
|
|
|
endstops.hit_on_purpose(); |
|
|
// Check to see if the probe was triggered
|
|
|
TERN_(LEVEL_CORNERS_AUDIO_FEEDBACK, ui.buzz(200, 600)); |
|
|
bool probe_triggered = TEST(endstops.trigger_state(), TERN(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, Z_MIN, Z_MIN_PROBE)); |
|
|
|
|
|
if (!probe_triggered) { |
|
|
|
|
|
|
|
|
|
|
|
static bool wait_for_probe; |
|
|
|
|
|
|
|
|
|
|
|
ui.goto_screen([]{ |
|
|
|
|
|
MenuItem_confirm::select_screen( |
|
|
|
|
|
GET_TEXT(MSG_BUTTON_DONE), GET_TEXT(MSG_BUTTON_SKIP) |
|
|
|
|
|
, []{ corner_probing_done = true; |
|
|
|
|
|
wait_for_probe = false; |
|
|
|
|
|
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active)); |
|
|
|
|
|
ui.goto_previous_screen_no_defer(); |
|
|
|
|
|
} |
|
|
|
|
|
, []{ wait_for_probe = false; } |
|
|
|
|
|
, GET_TEXT(MSG_LEVEL_CORNERS_RAISE) |
|
|
|
|
|
, (const char*)nullptr, PSTR("") |
|
|
|
|
|
); |
|
|
|
|
|
}); |
|
|
|
|
|
ui.set_selection(true); |
|
|
|
|
|
|
|
|
|
|
|
wait_for_probe = true; |
|
|
|
|
|
while (wait_for_probe && !probe_triggered) { |
|
|
|
|
|
probe_triggered = PROBE_TRIGGERED(); |
|
|
|
|
|
if (probe_triggered) PROBE_BUZZ(); |
|
|
|
|
|
idle(); |
|
|
|
|
|
} |
|
|
} |
|
|
wait_for_probe = false; |
|
|
idle(); |
|
|
|
|
|
|
|
|
TERN_(LEVEL_CORNERS_VERIFY_RAISED, verify_corner = true); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
TERN_(BLTOUCH_SLOW_MODE, bltouch.stow()); |
|
|
|
|
|
ui.goto_screen(_lcd_draw_probing); |
|
|
|
|
|
return (probe_triggered); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
TERN_(HAS_QUIET_PROBING, probe.set_probing_paused(false)); |
|
|
void _lcd_test_corners() { |
|
|
|
|
|
ui.goto_screen(_lcd_draw_probing); |
|
|
#if ENABLED(BLTOUCH) && DISABLED(BLTOUCH_HS_MODE) |
|
|
bed_corner = TERN(LEVEL_CENTER_TOO, 4, 0); |
|
|
bltouch.stow(); |
|
|
last_z = LEVEL_CORNERS_HEIGHT; |
|
|
#endif |
|
|
endstops.enable_z_probe(true); |
|
|
|
|
|
good_points = 0; |
|
|
|
|
|
|
|
|
if (probe_triggered) { |
|
|
do { |
|
|
endstops.hit_on_purpose(); |
|
|
do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP); // clearance
|
|
|
if (!WITHIN(current_position.z, last_z - (LEVEL_CORNERS_PROBE_TOLERANCE), last_z + (LEVEL_CORNERS_PROBE_TOLERANCE))) { |
|
|
// Select next corner coordinates
|
|
|
last_z = current_position.z; |
|
|
xy_pos_t plf = lf - probe.offset_xy, prb = rb - probe.offset_xy; |
|
|
good_points = 0; |
|
|
switch (bed_corner) { |
|
|
|
|
|
case 0: current_position = plf; break; // copy xy
|
|
|
|
|
|
case 1: current_position.x = prb.x; break; |
|
|
|
|
|
case 2: current_position.y = prb.y; break; |
|
|
|
|
|
case 3: current_position.x = plf.x; break; |
|
|
|
|
|
#if ENABLED(LEVEL_CENTER_TOO) |
|
|
|
|
|
case 4: current_position.set(X_CENTER - probe.offset_xy.x, Y_CENTER - probe.offset_xy.y); break; |
|
|
|
|
|
#endif |
|
|
} |
|
|
} |
|
|
if (!verify_corner) good_points++; |
|
|
do_blocking_move_to_xy(current_position); // Goto corner
|
|
|
} |
|
|
|
|
|
|
|
|
if (!_lcd_level_bed_corners_probe()) { // Probe down to tolerance
|
|
|
if (!corner_probing_done) { |
|
|
if (_lcd_level_bed_corners_raise()) { // Prompt user to raise bed if needed
|
|
|
if (!verify_corner) bed_corner++; |
|
|
#if ENABLED(LEVEL_CORNERS_VERIFY_RAISED) // Verify
|
|
|
if (bed_corner > 3) bed_corner = 0; |
|
|
while (!_lcd_level_bed_corners_probe(true)) { // Loop while corner verified
|
|
|
verify_corner = false; |
|
|
if (!_lcd_level_bed_corners_raise()) { // Prompt user to raise bed if needed
|
|
|
if (good_points < 4) |
|
|
if (corner_probing_done) return; // Done was selected
|
|
|
_lcd_level_bed_corners_probing(); |
|
|
break; // Skip was selected
|
|
|
else { |
|
|
|
|
|
ui.goto_screen([]{ |
|
|
|
|
|
MenuItem_confirm::confirm_screen( |
|
|
|
|
|
[]{ ui.goto_previous_screen_no_defer(); |
|
|
|
|
|
queue.inject_P(TERN(HAS_LEVELING, PSTR("G28\nG29"), G28_STR)); |
|
|
|
|
|
} |
|
|
} |
|
|
, []{ ui.goto_previous_screen_no_defer(); } |
|
|
} |
|
|
, GET_TEXT(MSG_LEVEL_CORNERS_IN_RANGE) |
|
|
#endif |
|
|
, (const char*)nullptr, PSTR("?") |
|
|
} |
|
|
); |
|
|
else if (corner_probing_done) // Done was selected
|
|
|
}); |
|
|
return; |
|
|
ui.set_selection(true); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (bed_corner != 4) good_points++; // ignore center
|
|
|
|
|
|
if (++bed_corner > 3) bed_corner = 0; |
|
|
|
|
|
|
|
|
|
|
|
} while (good_points < 4); // loop until all corners whitin tolerance
|
|
|
|
|
|
|
|
|
|
|
|
ui.goto_screen(_lcd_draw_level_prompt); // prompt for bed leveling
|
|
|
|
|
|
ui.set_selection(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#else |
|
|
#else // !LEVEL_CORNERS_USE_PROBE
|
|
|
|
|
|
|
|
|
static inline void _lcd_goto_next_corner() { |
|
|
static inline void _lcd_goto_next_corner() { |
|
|
constexpr float lfrb[4] = LEVEL_CORNERS_INSET_LFRB; |
|
|
|
|
|
constexpr xy_pos_t lf { (X_MIN_BED) + lfrb[0], (Y_MIN_BED) + lfrb[1] }, |
|
|
|
|
|
rb { (X_MAX_BED) - lfrb[2], (Y_MAX_BED) - lfrb[3] }; |
|
|
|
|
|
line_to_z(LEVEL_CORNERS_Z_HOP); |
|
|
line_to_z(LEVEL_CORNERS_Z_HOP); |
|
|
switch (bed_corner) { |
|
|
switch (bed_corner) { |
|
|
case 0: current_position = lf; break; // copy xy
|
|
|
case 0: current_position = lf; break; // copy xy
|
|
@ -199,33 +207,33 @@ static int8_t bed_corner; |
|
|
if (++bed_corner > 3 + ENABLED(LEVEL_CENTER_TOO)) bed_corner = 0; |
|
|
if (++bed_corner > 3 + ENABLED(LEVEL_CENTER_TOO)) bed_corner = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endif |
|
|
#endif // !LEVEL_CORNERS_USE_PROBE
|
|
|
|
|
|
|
|
|
static inline void _lcd_level_bed_corners_homing() { |
|
|
static inline void _lcd_level_bed_corners_homing() { |
|
|
_lcd_draw_homing(); |
|
|
_lcd_draw_homing(); |
|
|
if (all_axes_homed()) { |
|
|
if (!all_axes_homed()) return; |
|
|
#if ENABLED(LEVEL_CORNERS_USE_PROBE) |
|
|
#if ENABLED(LEVEL_CORNERS_USE_PROBE) |
|
|
TERN_(LEVEL_CENTER_TOO, bed_corner = 4); |
|
|
_lcd_test_corners(); |
|
|
endstops.enable_z_probe(true); |
|
|
if (corner_probing_done) ui.goto_previous_screen_no_defer(); |
|
|
ui.goto_screen(_lcd_level_bed_corners_probing); |
|
|
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active)); |
|
|
#else |
|
|
endstops.enable_z_probe(false); |
|
|
bed_corner = 0; |
|
|
#else |
|
|
ui.goto_screen([]{ |
|
|
bed_corner = 0; |
|
|
MenuItem_confirm::select_screen( |
|
|
ui.goto_screen([]{ |
|
|
GET_TEXT(MSG_BUTTON_NEXT), GET_TEXT(MSG_BUTTON_DONE) |
|
|
MenuItem_confirm::select_screen( |
|
|
, _lcd_goto_next_corner |
|
|
GET_TEXT(MSG_BUTTON_NEXT), GET_TEXT(MSG_BUTTON_DONE) |
|
|
, []{ |
|
|
, _lcd_goto_next_corner |
|
|
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active)); |
|
|
, []{ |
|
|
ui.goto_previous_screen_no_defer(); |
|
|
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active)); |
|
|
} |
|
|
ui.goto_previous_screen_no_defer(); |
|
|
, GET_TEXT(TERN(LEVEL_CENTER_TOO, MSG_LEVEL_BED_NEXT_POINT, MSG_NEXT_CORNER)) |
|
|
} |
|
|
, (const char*)nullptr, PSTR("?") |
|
|
, GET_TEXT(TERN(LEVEL_CENTER_TOO, MSG_LEVEL_BED_NEXT_POINT, MSG_NEXT_CORNER)) |
|
|
); |
|
|
, (const char*)nullptr, PSTR("?") |
|
|
}); |
|
|
); |
|
|
ui.set_selection(true); |
|
|
}); |
|
|
_lcd_goto_next_corner(); |
|
|
ui.set_selection(true); |
|
|
#endif |
|
|
_lcd_goto_next_corner(); |
|
|
} |
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void _lcd_level_bed_corners() { |
|
|
void _lcd_level_bed_corners() { |
|
@ -241,13 +249,6 @@ void _lcd_level_bed_corners() { |
|
|
set_bed_leveling_enabled(false); |
|
|
set_bed_leveling_enabled(false); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#if ENABLED(LEVEL_CORNERS_USE_PROBE) |
|
|
|
|
|
last_z = LEVEL_CORNERS_HEIGHT; |
|
|
|
|
|
corner_probing_done = false; |
|
|
|
|
|
verify_corner = false; |
|
|
|
|
|
good_points = 0; |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
ui.goto_screen(_lcd_level_bed_corners_homing); |
|
|
ui.goto_screen(_lcd_level_bed_corners_homing); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|