From 9a930ebec27008d2e47161d050e7d1f9dd534b66 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 13 Oct 2017 10:25:05 -0500 Subject: [PATCH] Make leveling_is_active a macro --- Marlin/src/core/utility.cpp | 4 +-- Marlin/src/feature/bedlevel/bedlevel.cpp | 16 ++-------- Marlin/src/feature/bedlevel/bedlevel.h | 11 ++++++- Marlin/src/gcode/bedlevel/M420.cpp | 2 +- Marlin/src/gcode/bedlevel/abl/G29.cpp | 4 +-- Marlin/src/gcode/bedlevel/mbl/G29.cpp | 2 +- Marlin/src/gcode/calibrate/G28.cpp | 2 +- Marlin/src/gcode/calibrate/M48.cpp | 6 +++- Marlin/src/lcd/ultralcd.cpp | 4 +-- Marlin/src/lcd/ultralcd_impl_HD44780.h | 2 +- Marlin/src/module/configuration_store.cpp | 4 +-- Marlin/src/module/motion.cpp | 4 +-- Marlin/src/module/planner.cpp | 36 +++++++++-------------- Marlin/src/module/probe.cpp | 2 +- Marlin/src/module/tool_change.cpp | 2 +- 15 files changed, 47 insertions(+), 54 deletions(-) diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp index f970c46a67..c220368fe2 100644 --- a/Marlin/src/core/utility.cpp +++ b/Marlin/src/core/utility.cpp @@ -333,7 +333,7 @@ void safe_delay(millis_t ms) { #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] = { @@ -364,7 +364,7 @@ void safe_delay(millis_t ms) { #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)"); diff --git a/Marlin/src/feature/bedlevel/bedlevel.cpp b/Marlin/src/feature/bedlevel/bedlevel.cpp index 8d944e0364..e8a123c6b6 100644 --- a/Marlin/src/feature/bedlevel/bedlevel.cpp +++ b/Marlin/src/feature/bedlevel/bedlevel.cpp @@ -55,18 +55,6 @@ bool leveling_is_valid() { ; } -bool leveling_is_active() { - return - #if ENABLED(MESH_BED_LEVELING) - mbl.active() - #elif ENABLED(AUTO_BED_LEVELING_UBL) - ubl.state.active - #else // OLDSCHOOL_ABL - planner.abl_enabled - #endif - ; -} - /** * Turn bed leveling on or off, fixing the current * position as-needed. @@ -82,7 +70,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) { 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) @@ -143,7 +131,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) { 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) diff --git a/Marlin/src/feature/bedlevel/bedlevel.h b/Marlin/src/feature/bedlevel/bedlevel.h index 31c444cf15..cdf1be2584 100644 --- a/Marlin/src/feature/bedlevel/bedlevel.h +++ b/Marlin/src/feature/bedlevel/bedlevel.h @@ -40,10 +40,19 @@ #endif bool leveling_is_valid(); -bool leveling_is_active(); void set_bed_leveling_enabled(const bool enable=true); void reset_bed_level(); +#if ENABLED(MESH_BED_LEVELING) + #define LEVELING_IS_ACTIVE() (mbl.active()) +#elif ENABLED(AUTO_BED_LEVELING_UBL) + #define LEVELING_IS_ACTIVE() (ubl.state.active) +#elif HAS_ABL + #define LEVELING_IS_ACTIVE() (planner.abl_enabled) +#else + #define LEVELING_IS_ACTIVE() (false) +#endif + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) void set_z_fade_height(const float zfh); #endif diff --git a/Marlin/src/gcode/bedlevel/M420.cpp b/Marlin/src/gcode/bedlevel/M420.cpp index 994a37e170..5fe1dfe1ba 100644 --- a/Marlin/src/gcode/bedlevel/M420.cpp +++ b/Marlin/src/gcode/bedlevel/M420.cpp @@ -112,7 +112,7 @@ void GcodeSuite::M420() { 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(); diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index fa1c70c85c..218a1c6d3e 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -247,7 +247,7 @@ void GcodeSuite::G29() { abl_probe_index = -1; #endif - abl_should_enable = leveling_is_active(); + abl_should_enable = LEVELING_IS_ACTIVE(); #if ENABLED(AUTO_BED_LEVELING_BILINEAR) @@ -964,7 +964,7 @@ void GcodeSuite::G29() { KEEPALIVE_STATE(IN_HANDLER); - if (planner.abl_enabled) + if (LEVELING_IS_ACTIVE()) SYNC_PLAN_POSITION_KINEMATIC(); } diff --git a/Marlin/src/gcode/bedlevel/mbl/G29.cpp b/Marlin/src/gcode/bedlevel/mbl/G29.cpp index 64ff57e2b4..cd96bbf35e 100644 --- a/Marlin/src/gcode/bedlevel/mbl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/mbl/G29.cpp @@ -92,7 +92,7 @@ void GcodeSuite::G29() { 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 diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index df4109a03b..d960088bbb 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -157,7 +157,7 @@ void GcodeSuite::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 diff --git a/Marlin/src/gcode/calibrate/M48.cpp b/Marlin/src/gcode/calibrate/M48.cpp index 4c32933b00..d3c551f170 100644 --- a/Marlin/src/gcode/calibrate/M48.cpp +++ b/Marlin/src/gcode/calibrate/M48.cpp @@ -32,6 +32,10 @@ #include "../../feature/bedlevel/bedlevel.h" #endif +#if HAS_LEVELING + #include "../../module/planner.h" +#endif + /** * M48: Z probe repeatability measurement function. * @@ -115,7 +119,7 @@ void GcodeSuite::M48() { // 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 diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 6a3728cc92..5ea064803c 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -1086,7 +1086,7 @@ void kill_screen(const char* lcd_msg) { const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment; if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) { - if (leveling_is_active()) + if (LEVELING_IS_ACTIVE()) thermalManager.babystep_axis(Z_AXIS, babystep_increment); zprobe_zoffset = new_zoffset; @@ -1934,7 +1934,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/src/lcd/ultralcd_impl_HD44780.h b/Marlin/src/lcd/ultralcd_impl_HD44780.h index 488e3f1953..108451d3b7 100644 --- a/Marlin/src/lcd/ultralcd_impl_HD44780.h +++ b/Marlin/src/lcd/ultralcd_impl_HD44780.h @@ -795,7 +795,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 diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index 88bd2ad867..49cc205c5f 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -1556,7 +1556,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 @@ -1578,7 +1578,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/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 87cf0b9bf0..0704e28c8d 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -490,14 +490,14 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS }, #if ENABLED(AUTO_BED_LEVELING_BILINEAR) #if ENABLED(DELTA) #define ADJUST_DELTA(V) \ - if (planner.abl_enabled) { \ + if (LEVELING_IS_ACTIVE()) { \ const float zadj = bilinear_z_offset(V); \ delta[A_AXIS] += zadj; \ delta[B_AXIS] += zadj; \ delta[C_AXIS] += zadj; \ } #else - #define ADJUST_DELTA(V) if (planner.abl_enabled) { delta[Z_AXIS] += bilinear_z_offset(V); } + #define ADJUST_DELTA(V) if (LEVELING_IS_ACTIVE()) { delta[Z_AXIS] += bilinear_z_offset(V); } #endif #else #define ADJUST_DELTA(V) NOOP diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 7d55a0df9e..a7fed29e15 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -555,8 +555,9 @@ void Planner::calculate_volumetric_multipliers() { */ void Planner::apply_leveling(float &lx, float &ly, float &lz) { + if (!LEVELING_IS_ACTIVE()) return; + #if ENABLED(AUTO_BED_LEVELING_UBL) - if (!ubl.state.active) return; #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) // if z_fade_height enabled (nonzero) and raw_z above it, no leveling required if (planner.z_fade_height && planner.z_fade_height <= RAW_Z_POSITION(lz)) return; @@ -566,10 +567,6 @@ void Planner::calculate_volumetric_multipliers() { #endif // FADE #endif // UBL - #if OLDSCHOOL_ABL - if (!abl_enabled) return; - #endif - #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL) static float z_fade_factor = 1.0, last_raw_lz = -999.0; if (z_fade_height) { @@ -586,12 +583,11 @@ void Planner::calculate_volumetric_multipliers() { #if ENABLED(MESH_BED_LEVELING) - if (mbl.active()) - lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly) - #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - , z_fade_factor - #endif - ); + lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly) + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + , z_fade_factor + #endif + ); #elif ABL_PLANAR @@ -654,9 +650,7 @@ void Planner::calculate_volumetric_multipliers() { #endif - #if OLDSCHOOL_ABL - if (!abl_enabled) return; - #endif + if (!LEVELING_IS_ACTIVE()) return; #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return; @@ -664,14 +658,12 @@ void Planner::calculate_volumetric_multipliers() { #if ENABLED(MESH_BED_LEVELING) - if (mbl.active()) { - #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0); - logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c); - #else - logical[Z_AXIS] -= mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS])); - #endif - } + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0); + logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c); + #else + logical[Z_AXIS] -= mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS])); + #endif #elif ABL_PLANAR diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index 98185f6a5b..743cefb0de 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -679,7 +679,7 @@ void refresh_zprobe_zoffset(const bool no_babystep/*=false*/) { #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); diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp index 758044292c..8594fa9c49 100644 --- a/Marlin/src/module/tool_change.cpp +++ b/Marlin/src/module/tool_change.cpp @@ -464,7 +464,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