diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index c341d98f3..b52a348bc 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -323,7 +323,6 @@ extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ]; #if HAS_LEVELING bool leveling_is_valid(); - bool leveling_is_active(); void set_bed_leveling_enabled(const bool enable=true); void reset_bed_level(); #endif diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 3ac04338f..51cdeba87 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2471,18 +2471,6 @@ static void clean_up_after_endstop_or_probe_move() { ; } - bool leveling_is_active() { - return - #if ENABLED(MESH_BED_LEVELING) - mbl.active() - #elif ENABLED(AUTO_BED_LEVELING_UBL) - ubl.state.active - #else - planner.abl_enabled - #endif - ; - } - /** * Turn bed leveling on or off, fixing the current * position as-needed. @@ -2498,7 +2486,7 @@ static void clean_up_after_endstop_or_probe_move() { constexpr bool can_change = true; #endif - if (can_change && enable != leveling_is_active()) { + if (can_change && enable != LEVELING_IS_ACTIVE()) { #if ENABLED(MESH_BED_LEVELING) @@ -2559,7 +2547,7 @@ static void clean_up_after_endstop_or_probe_move() { void set_z_fade_height(const float zfh) { - const bool level_active = leveling_is_active(); + const bool level_active = LEVELING_IS_ACTIVE(); #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -3771,7 +3759,7 @@ inline void gcode_G4() { #elif ENABLED(AUTO_BED_LEVELING_UBL) SERIAL_ECHOPGM("UBL"); #endif - if (leveling_is_active()) { + if (LEVELING_IS_ACTIVE()) { SERIAL_ECHOLNPGM(" (enabled)"); #if ABL_PLANAR const float diff[XYZ] = { @@ -3802,7 +3790,7 @@ inline void gcode_G4() { #elif ENABLED(MESH_BED_LEVELING) SERIAL_ECHOPGM("Mesh Bed Leveling"); - if (leveling_is_active()) { + if (LEVELING_IS_ACTIVE()) { float lz = current_position[Z_AXIS]; planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], lz); SERIAL_ECHOLNPGM(" (enabled)"); @@ -3971,7 +3959,7 @@ inline void gcode_G28(const bool always_home_all) { // Disable the leveling matrix before homing #if HAS_LEVELING #if ENABLED(AUTO_BED_LEVELING_UBL) - const bool ubl_state_at_entry = leveling_is_active(); + const bool ubl_state_at_entry = LEVELING_IS_ACTIVE(); #endif set_bed_leveling_enabled(false); #endif @@ -4261,7 +4249,7 @@ void home_all_axes() { gcode_G28(true); } switch (state) { case MeshReport: if (leveling_is_valid()) { - SERIAL_PROTOCOLLNPAIR("State: ", leveling_is_active() ? MSG_ON : MSG_OFF); + SERIAL_PROTOCOLLNPAIR("State: ", LEVELING_IS_ACTIVE() ? MSG_ON : MSG_OFF); mbl_mesh_report(); } else @@ -4580,7 +4568,7 @@ void home_all_axes() { gcode_G28(true); } abl_probe_index = -1; #endif - abl_should_enable = leveling_is_active(); + abl_should_enable = LEVELING_IS_ACTIVE(); #if ENABLED(AUTO_BED_LEVELING_BILINEAR) @@ -7077,7 +7065,7 @@ inline void gcode_M42() { // Disable bed level correction in M48 because we want the raw data when we probe #if HAS_LEVELING - const bool was_enabled = leveling_is_active(); + const bool was_enabled = LEVELING_IS_ACTIVE(); set_bed_leveling_enabled(false); #endif @@ -9413,7 +9401,7 @@ void quickstop_stepper() { if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units()); #endif - const bool new_status = leveling_is_active(); + const bool new_status = LEVELING_IS_ACTIVE(); if (to_enable && !new_status) { SERIAL_ERROR_START(); @@ -9644,7 +9632,7 @@ inline void gcode_M502() { #endif #if ENABLED(BABYSTEP_ZPROBE_OFFSET) - if (!no_babystep && leveling_is_active()) + if (!no_babystep && LEVELING_IS_ACTIVE()) thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS])); #else UNUSED(no_babystep); @@ -10691,7 +10679,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n #if ENABLED(MESH_BED_LEVELING) - if (leveling_is_active()) { + if (LEVELING_IS_ACTIVE()) { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]); #endif diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 596ca457a..706f679ea 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -1594,7 +1594,7 @@ void MarlinSettings::reset() { SERIAL_ECHOLNPGM(":"); } CONFIG_ECHO_START; - SERIAL_ECHOPAIR(" M420 S", leveling_is_active() ? 1 : 0); + SERIAL_ECHOPAIR(" M420 S", LEVELING_IS_ACTIVE() ? 1 : 0); #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) SERIAL_ECHOPAIR(" Z", planner.z_fade_height); #endif @@ -1615,7 +1615,7 @@ void MarlinSettings::reset() { SERIAL_ECHOLNPGM("Auto Bed Leveling:"); } CONFIG_ECHO_START; - SERIAL_ECHOPAIR(" M420 S", leveling_is_active() ? 1 : 0); + SERIAL_ECHOPAIR(" M420 S", LEVELING_IS_ACTIVE() ? 1 : 0); #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height)); #endif diff --git a/Marlin/planner.h b/Marlin/planner.h index c47eebd8f..8b1de85ad 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -468,6 +468,16 @@ class Planner { #define PLANNER_XY_FEEDRATE() (min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS])) +#if ENABLED(MESH_BED_LEVELING) + #define LEVELING_IS_ACTIVE() (mesh_bed_leveling::active()) +#elif ENABLED(AUTO_BED_LEVELING_UBL) + #define LEVELING_IS_ACTIVE() (unified_bed_leveling::state.active) +#elif HAS_ABL + #define LEVELING_IS_ACTIVE() (Planner::abl_enabled) +#else + #define LEVELING_IS_ACTIVE() (false) +#endif + extern Planner planner; #endif // PLANNER_H diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 83ce9d2fe..a9fa5fa98 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -50,6 +50,11 @@ #if ENABLED(AUTO_BED_LEVELING_UBL) #include "ubl.h" bool ubl_lcd_map_control = false; +#elif HAS_ABL + #include "planner.h" +#elif ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING) + #include "mesh_bed_leveling.h" + extern void mesh_probing_done(); #endif // Initialized by settings.load() @@ -194,11 +199,6 @@ uint16_t max_display_update_time = 0; void lcd_delta_calibrate_menu(); #endif - #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING) - #include "mesh_bed_leveling.h" - extern void mesh_probing_done(); - #endif - //////////////////////////////////////////// //////////// Menu System Actions /////////// //////////////////////////////////////////// @@ -1937,7 +1937,7 @@ void kill_screen(const char* lcd_msg) { if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])) MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28")); else if (leveling_is_valid()) { - _level_state = leveling_is_active(); + _level_state = LEVELING_IS_ACTIVE(); MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling); } diff --git a/Marlin/ultralcd_impl_HD44780.h b/Marlin/ultralcd_impl_HD44780.h index 74429b408..777ef4099 100644 --- a/Marlin/ultralcd_impl_HD44780.h +++ b/Marlin/ultralcd_impl_HD44780.h @@ -792,7 +792,7 @@ static void lcd_implementation_status_screen() { lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS]))); #if HAS_LEVELING - lcd.write(leveling_is_active() || blink ? '_' : ' '); + lcd.write(LEVELING_IS_ACTIVE() || blink ? '_' : ' '); #endif #endif // LCD_HEIGHT > 2