Skip to content

Commit

Permalink
🎨 Misc. tramming menu cleanup (MarlinFirmware#25519)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 26, 2023
1 parent fdd77c4 commit b83e5e8
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
////////////////////////////////////////////

#if HAS_LEVELING && ANY(LCD_BED_TRAMMING, PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
bool leveling_was_active; // = false
bool menu_leveling_was_active; // = false
#endif
#if ANY(PROBE_MANUALLY, MESH_BED_LEVELING, X_AXIS_TWIST_COMPENSATION)
uint8_t manual_probe_index; // = 0
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ inline void clear_menu_history() { screen_history_depth = 0; }
#define STICKY_SCREEN(S) []{ ui.defer_status_screen(); ui.goto_screen(S); }

#if HAS_LEVELING && ANY(LCD_BED_TRAMMING, PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
extern bool leveling_was_active;
extern bool menu_leveling_was_active;
#endif

#if ANY(PROBE_MANUALLY, MESH_BED_LEVELING, X_AXIS_TWIST_COMPENSATION)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_bed_leveling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void menu_bed_leveling() {
#endif

#if ENABLED(LCD_BED_TRAMMING)
SUBMENU(MSG_BED_TRAMMING, _lcd_level_bed_corners);
SUBMENU(MSG_BED_TRAMMING, _lcd_bed_tramming);
#endif

#if ENABLED(EEPROM_SETTINGS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

//
// Level Bed Corners menu
// Bed Tramming menu
//

#include "../../inc/MarlinConfigPre.h"
Expand Down Expand Up @@ -54,7 +54,7 @@
#endif
float last_z;
int good_points;
bool corner_probing_done, wait_for_probe;
bool tramming_done, wait_for_probe;

#if HAS_MARLINUI_U8GLIB
#include "../dogm/marlinui_DOGM.h"
Expand All @@ -66,6 +66,11 @@

static_assert(BED_TRAMMING_Z_HOP >= 0, "BED_TRAMMING_Z_HOP must be >= 0. Please update your configuration.");

#define LF 1
#define RF 2
#define RB 3
#define LB 4

#ifndef BED_TRAMMING_LEVELING_ORDER
#define BED_TRAMMING_LEVELING_ORDER { LF, RF, LB, RB } // Default
//#define BED_TRAMMING_LEVELING_ORDER { LF, LB, RF } // 3 hard-coded points
Expand All @@ -75,18 +80,14 @@ static_assert(BED_TRAMMING_Z_HOP >= 0, "BED_TRAMMING_Z_HOP must be >= 0. Please
//#define BED_TRAMMING_LEVELING_ORDER { LB, RB } // 3-Point tramming - Front
#endif

#define LF 1
#define RF 2
#define RB 3
#define LB 4
constexpr int lco[] = BED_TRAMMING_LEVELING_ORDER;
constexpr bool level_corners_3_points = COUNT(lco) == 2;
static_assert(level_corners_3_points || COUNT(lco) == 4, "BED_TRAMMING_LEVELING_ORDER must have exactly 2 or 4 corners.");
constexpr bool tramming_3_points = COUNT(lco) == 2;
static_assert(tramming_3_points || COUNT(lco) == 4, "BED_TRAMMING_LEVELING_ORDER must have exactly 2 or 4 corners.");

constexpr int lcodiff = ABS(lco[0] - lco[1]);
static_assert(COUNT(lco) == 4 || lcodiff == 1 || lcodiff == 3, "The first two BED_TRAMMING_LEVELING_ORDER corners must be on the same edge.");

constexpr int nr_edge_points = level_corners_3_points ? 3 : 4;
constexpr int nr_edge_points = tramming_3_points ? 3 : 4;
constexpr int available_points = nr_edge_points + ENABLED(BED_TRAMMING_INCLUDE_CENTER);
constexpr int center_index = TERN(BED_TRAMMING_INCLUDE_CENTER, available_points - 1, -1);
constexpr float inset_lfrb[4] = BED_TRAMMING_INSET_LFRB;
Expand All @@ -98,9 +99,9 @@ static int8_t bed_corner;
/**
* Select next corner coordinates
*/
static void _lcd_level_bed_corners_get_next_position() {
static void _lcd_bed_tramming_get_next_position() {

if (level_corners_3_points) {
if (tramming_3_points) {
if (bed_corner >= available_points) bed_corner = 0; // Above max position -> move back to first corner
switch (bed_corner) {
case 0 ... 1:
Expand Down Expand Up @@ -141,9 +142,9 @@ static void _lcd_level_bed_corners_get_next_position() {
else {
current_position = lf; // Left front
switch (lco[bed_corner]) {
case RF: current_position.x = rb.x; break; // Right front
case RB: current_position = rb; break; // Right rear
case LB: current_position.y = rb.y; break; // Left rear
case RF: current_position.x = rb.x; break; // Right Front
case RB: current_position = rb; break; // Right Back
case LB: current_position.y = rb.y; break; // Left Back
}
}
}
Expand Down Expand Up @@ -198,7 +199,7 @@ static void _lcd_level_bed_corners_get_next_position() {
if (!ui.should_draw()) return;
MenuItem_confirm::select_screen(
GET_TEXT_F(MSG_BUTTON_DONE), GET_TEXT_F(MSG_BUTTON_SKIP)
, []{ corner_probing_done = true; wait_for_probe = false; }
, []{ tramming_done = true; wait_for_probe = false; }
, []{ wait_for_probe = false; }
, GET_TEXT_F(MSG_BED_TRAMMING_RAISE)
);
Expand All @@ -207,37 +208,39 @@ static void _lcd_level_bed_corners_get_next_position() {
void _lcd_draw_level_prompt() {
if (!ui.should_draw()) return;
MenuItem_confirm::select_screen(
GET_TEXT_F(TERN(HAS_LEVELING, MSG_BUTTON_LEVEL, MSG_BUTTON_DONE)),
TERN(HAS_LEVELING, GET_TEXT_F(MSG_BUTTON_BACK), nullptr)
GET_TEXT_F(TERN(HAS_LEVELING, MSG_BUTTON_LEVEL, MSG_BUTTON_DONE))
, TERN(HAS_LEVELING, GET_TEXT_F(MSG_BUTTON_BACK), nullptr)
, []{ queue.inject(TERN(HAS_LEVELING, F("G29N"), FPSTR(G28_STR))); ui.return_to_status(); }
, TERN(HAS_LEVELING, ui.goto_previous_screen_no_defer, []{})
, GET_TEXT_F(MSG_BED_TRAMMING_IN_RANGE)
);
}

bool _lcd_level_bed_corners_probe(bool verify=false) {
if (verify) do_blocking_move_to_z(current_position.z + BED_TRAMMING_Z_HOP); // do clearance if needed
bool _lcd_bed_tramming_probe(bool verify=false) {
if (verify) line_to_z(BED_TRAMMING_Z_HOP); // do clearance if needed
TERN_(BLTOUCH, if (!bltouch.high_speed_mode) bltouch.deploy()); // Deploy in LOW SPEED MODE on every probe action
do_blocking_move_to_z(last_z - BED_TRAMMING_PROBE_TOLERANCE, MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW)); // Move down to lower tolerance
if (TEST(endstops.trigger_state(), Z_MIN_PROBE)) { // check if probe triggered
endstops.hit_on_purpose();
set_current_from_steppers_for_axis(Z_AXIS);
sync_plan_position();

TERN_(BLTOUCH, if (!bltouch.high_speed_mode) bltouch.stow()); // Stow in LOW SPEED MODE on every trigger

// Triggered outside tolerance range?
if (ABS(current_position.z - last_z) > BED_TRAMMING_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
line_to_z(last_z); // go back to tolerance middle point before raise
return false; // probe not triggered
}

bool _lcd_level_bed_corners_raise() {
bool _lcd_bed_tramming_raise() {
bool probe_triggered = false;
corner_probing_done = false;
tramming_done = false;
wait_for_probe = true;
ui.goto_screen(_lcd_draw_raise); // show raise screen
ui.set_selection(true);
Expand All @@ -264,25 +267,25 @@ static void _lcd_level_bed_corners_get_next_position() {
ui.refresh(LCDVIEW_REDRAW_NOW);
_lcd_draw_probing(); // update screen with # of good points

do_blocking_move_to_z(current_position.z + BED_TRAMMING_Z_HOP + TERN0(BLTOUCH, bltouch.z_extra_clearance())); // clearance
line_to_z(current_position.z + BED_TRAMMING_Z_HOP + TERN0(BLTOUCH, bltouch.z_extra_clearance())); // clearance

_lcd_level_bed_corners_get_next_position(); // Select next corner coordinates
_lcd_bed_tramming_get_next_position(); // Select next corner coordinates
current_position -= probe.offset_xy; // Account for probe offsets
do_blocking_move_to_xy(current_position); // Goto corner

TERN_(BLTOUCH, if (bltouch.high_speed_mode) bltouch.deploy()); // Deploy in HIGH SPEED MODE
if (!_lcd_level_bed_corners_probe()) { // Probe down to tolerance
if (_lcd_level_bed_corners_raise()) { // Prompt user to raise bed if needed
#if ENABLED(BED_TRAMMING_VERIFY_RAISED) // Verify
while (!_lcd_level_bed_corners_probe(true)) { // Loop while corner verified
if (!_lcd_level_bed_corners_raise()) { // Prompt user to raise bed if needed
if (corner_probing_done) return; // Done was selected
if (!_lcd_bed_tramming_probe()) { // Probe down to tolerance
if (_lcd_bed_tramming_raise()) { // Prompt user to raise bed if needed
#if ENABLED(BED_TRAMMING_VERIFY_RAISED) // Verify
while (!_lcd_bed_tramming_probe(true)) { // Loop while corner verified
if (!_lcd_bed_tramming_raise()) { // Prompt user to raise bed if needed
if (tramming_done) return; // Done was selected
break; // Skip was selected
}
}
#endif
}
else if (corner_probing_done) // Done was selected
else if (tramming_done) // Done was selected
return;
}

Expand All @@ -293,9 +296,9 @@ static void _lcd_level_bed_corners_get_next_position() {

#if ENABLED(BLTOUCH)
if (bltouch.high_speed_mode) {
// In HIGH SPEED MODE do clearance and stow at the very end
do_blocking_move_to_z(current_position.z + BED_TRAMMING_Z_HOP);
// In HIGH SPEED MODE do stow and clearance at the very end
bltouch.stow();
do_z_clearance(BED_TRAMMING_Z_HOP);
}
#endif

Expand All @@ -309,7 +312,7 @@ static void _lcd_level_bed_corners_get_next_position() {
line_to_z(BED_TRAMMING_Z_HOP);

// Select next corner coordinates
_lcd_level_bed_corners_get_next_position();
_lcd_bed_tramming_get_next_position();

line_to_current_position(manual_feedrate_mm_s.x);
line_to_z(BED_TRAMMING_HEIGHT);
Expand All @@ -318,23 +321,27 @@ static void _lcd_level_bed_corners_get_next_position() {

#endif // !BED_TRAMMING_USE_PROBE

static void _lcd_level_bed_corners_homing() {
void _lcd_bed_tramming_homing() {
_lcd_draw_homing();
if (!all_axes_homed()) return;

#if ENABLED(BED_TRAMMING_USE_PROBE)

_lcd_test_corners();
if (corner_probing_done) ui.goto_previous_screen_no_defer();
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
if (tramming_done) ui.goto_previous_screen_no_defer();
TERN_(HAS_LEVELING, set_bed_leveling_enabled(menu_leveling_was_active));
endstops.enable_z_probe(false);
#else

#else // !BED_TRAMMING_USE_PROBE

bed_corner = 0;
ui.goto_screen([]{
MenuItem_confirm::select_screen(
GET_TEXT_F(MSG_BUTTON_NEXT), GET_TEXT_F(MSG_BUTTON_DONE)
, _lcd_goto_next_corner
, []{
line_to_z(BED_TRAMMING_Z_HOP); // Raise Z off the bed when done
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
TERN_(HAS_LEVELING, set_bed_leveling_enabled(menu_leveling_was_active));
ui.goto_previous_screen_no_defer();
}
, GET_TEXT_F(TERN(BED_TRAMMING_INCLUDE_CENTER, MSG_LEVEL_BED_NEXT_POINT, MSG_NEXT_CORNER))
Expand All @@ -343,10 +350,11 @@ static void _lcd_level_bed_corners_homing() {
});
ui.set_selection(true);
_lcd_goto_next_corner();
#endif

#endif // !BED_TRAMMING_USE_PROBE
}

void _lcd_level_bed_corners() {
void _lcd_bed_tramming() {
ui.defer_status_screen();
if (!all_axes_trusted()) {
set_all_unhomed();
Expand All @@ -355,11 +363,11 @@ void _lcd_level_bed_corners() {

// Disable leveling so the planner won't mess with us
#if HAS_LEVELING
leveling_was_active = planner.leveling_active;
menu_leveling_was_active = planner.leveling_active;
set_bed_leveling_enabled(false);
#endif

ui.goto_screen(_lcd_level_bed_corners_homing);
ui.goto_screen(_lcd_bed_tramming_homing);
}

#endif // HAS_MARLINUI_MENU && LCD_BED_TRAMMING
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ class MenuItem_bool : public MenuEditItemBase {
#define YESNO_ITEM_N(N,LABEL, V...) YESNO_ITEM_N_F(N, GET_TEXT_F(LABEL), ##V)

#if ENABLED(LCD_BED_TRAMMING)
void _lcd_level_bed_corners();
void _lcd_bed_tramming();
#endif

#if HAS_FAN
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void menu_motion() {
#endif

#if ENABLED(LCD_BED_TRAMMING) && DISABLED(LCD_BED_LEVELING)
SUBMENU(MSG_BED_TRAMMING, _lcd_level_bed_corners);
SUBMENU(MSG_BED_TRAMMING, _lcd_bed_tramming);
#endif

#if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu_probe_offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ inline void z_clearance_move() {
void set_offset_and_go_back(const_float_t z) {
probe.offset.z = z;
SET_SOFT_ENDSTOP_LOOSE(false);
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
TERN_(HAS_LEVELING, set_bed_leveling_enabled(menu_leveling_was_active));
ui.goto_previous_screen_no_defer();
}

Expand Down Expand Up @@ -143,7 +143,7 @@ void goto_probe_offset_wizard() {

// Store Bed-Leveling-State and disable
#if HAS_LEVELING
leveling_was_active = planner.leveling_active;
menu_leveling_was_active = planner.leveling_active;
set_bed_leveling_enabled(false);
#endif

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu_x_twist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ float measured_z, z_offset;
void xatc_wizard_done() {
if (!ui.wait_for_move) {
xatc.print_points();
set_bed_leveling_enabled(leveling_was_active);
set_bed_leveling_enabled(menu_leveling_was_active);
SET_SOFT_ENDSTOP_LOOSE(false);
ui.goto_screen(menu_advanced_settings);
}
Expand Down Expand Up @@ -199,7 +199,7 @@ void xatc_wizard_homing() {
void xatc_wizard_continue() {
// Store Bed-Leveling-State and disable
#if HAS_LEVELING
leveling_was_active = planner.leveling_active;
menu_leveling_was_active = planner.leveling_active;
set_bed_leveling_enabled(false);
#endif

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Probe {
}
#endif

#else
#else // !IS_KINEMATIC

/**
* Return whether the given position is within the bed, and whether the nozzle
Expand All @@ -138,7 +138,7 @@ class Probe {
}
}

#endif
#endif // !IS_KINEMATIC

static void move_z_after_probing() {
#ifdef Z_AFTER_PROBING
Expand Down
4 changes: 2 additions & 2 deletions buildroot/share/PlatformIO/scripts/common-dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#define HAS_MENU_BACKLASH
#endif
#if ENABLED(LCD_BED_TRAMMING)
#define HAS_MENU_BED_CORNERS
#define HAS_MENU_BED_TRAMMING
#endif
#if ENABLED(CANCEL_OBJECTS)
#define HAS_MENU_CANCELOBJECT
Expand Down Expand Up @@ -99,7 +99,7 @@
#define HAS_MENU_TOUCH_SCREEN
#endif
#if ENABLED(ASSISTED_TRAMMING_WIZARD)
#define HAS_MENU_TRAMMING
#define HAS_MENU_TRAMMING_WIZARD
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
#define HAS_MENU_UBL
Expand Down
2 changes: 1 addition & 1 deletion ini/features.ini
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ MARLIN_INVADERS = build_src_filter=+<src/lcd/menu/game/in
MARLIN_MAZE = build_src_filter=+<src/lcd/menu/game/maze.cpp>
MARLIN_SNAKE = build_src_filter=+<src/lcd/menu/game/snake.cpp>
HAS_MENU_BACKLASH = build_src_filter=+<src/lcd/menu/menu_backlash.cpp>
HAS_MENU_BED_CORNERS = build_src_filter=+<src/lcd/menu/menu_bed_corners.cpp>
HAS_MENU_TRAMMING_WIZARD = build_src_filter=+<src/lcd/menu/menu_tramming_wizard.cpp>
LCD_BED_LEVELING = build_src_filter=+<src/lcd/menu/menu_bed_leveling.cpp>
HAS_MENU_CANCELOBJECT = build_src_filter=+<src/lcd/menu/menu_cancelobject.cpp>
HAS_MENU_DELTA_CALIBRATE = build_src_filter=+<src/lcd/menu/menu_delta_calibrate.cpp>
Expand Down

0 comments on commit b83e5e8

Please sign in to comment.