Make leveling_is_active a macro

This commit is contained in:
Scott Lahteine 2017-10-13 10:25:05 -05:00
parent 58abc66c1d
commit 9a930ebec2
15 changed files with 47 additions and 54 deletions

View File

@ -333,7 +333,7 @@ void safe_delay(millis_t ms) {
#elif ENABLED(AUTO_BED_LEVELING_UBL) #elif ENABLED(AUTO_BED_LEVELING_UBL)
SERIAL_ECHOPGM("UBL"); SERIAL_ECHOPGM("UBL");
#endif #endif
if (leveling_is_active()) { if (LEVELING_IS_ACTIVE()) {
SERIAL_ECHOLNPGM(" (enabled)"); SERIAL_ECHOLNPGM(" (enabled)");
#if ABL_PLANAR #if ABL_PLANAR
const float diff[XYZ] = { const float diff[XYZ] = {
@ -364,7 +364,7 @@ void safe_delay(millis_t ms) {
#elif ENABLED(MESH_BED_LEVELING) #elif ENABLED(MESH_BED_LEVELING)
SERIAL_ECHOPGM("Mesh Bed Leveling"); SERIAL_ECHOPGM("Mesh Bed Leveling");
if (leveling_is_active()) { if (LEVELING_IS_ACTIVE()) {
float lz = current_position[Z_AXIS]; float lz = current_position[Z_AXIS];
planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], lz); planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], lz);
SERIAL_ECHOLNPGM(" (enabled)"); SERIAL_ECHOLNPGM(" (enabled)");

View File

@ -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 * Turn bed leveling on or off, fixing the current
* position as-needed. * position as-needed.
@ -82,7 +70,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
constexpr bool can_change = true; constexpr bool can_change = true;
#endif #endif
if (can_change && enable != leveling_is_active()) { if (can_change && enable != LEVELING_IS_ACTIVE()) {
#if ENABLED(MESH_BED_LEVELING) #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) { 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) #if ENABLED(AUTO_BED_LEVELING_UBL)

View File

@ -40,10 +40,19 @@
#endif #endif
bool leveling_is_valid(); bool leveling_is_valid();
bool leveling_is_active();
void set_bed_leveling_enabled(const bool enable=true); void set_bed_leveling_enabled(const bool enable=true);
void reset_bed_level(); 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) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
void set_z_fade_height(const float zfh); void set_z_fade_height(const float zfh);
#endif #endif

View File

@ -112,7 +112,7 @@ void GcodeSuite::M420() {
if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units()); if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
#endif #endif
const bool new_status = leveling_is_active(); const bool new_status = LEVELING_IS_ACTIVE();
if (to_enable && !new_status) { if (to_enable && !new_status) {
SERIAL_ERROR_START(); SERIAL_ERROR_START();

View File

@ -247,7 +247,7 @@ void GcodeSuite::G29() {
abl_probe_index = -1; abl_probe_index = -1;
#endif #endif
abl_should_enable = leveling_is_active(); abl_should_enable = LEVELING_IS_ACTIVE();
#if ENABLED(AUTO_BED_LEVELING_BILINEAR) #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
@ -964,7 +964,7 @@ void GcodeSuite::G29() {
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
if (planner.abl_enabled) if (LEVELING_IS_ACTIVE())
SYNC_PLAN_POSITION_KINEMATIC(); SYNC_PLAN_POSITION_KINEMATIC();
} }

View File

@ -92,7 +92,7 @@ void GcodeSuite::G29() {
switch (state) { switch (state) {
case MeshReport: case MeshReport:
if (leveling_is_valid()) { 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(); mbl_mesh_report();
} }
else else

View File

@ -157,7 +157,7 @@ void GcodeSuite::G28(const bool always_home_all) {
// Disable the leveling matrix before homing // Disable the leveling matrix before homing
#if HAS_LEVELING #if HAS_LEVELING
#if ENABLED(AUTO_BED_LEVELING_UBL) #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 #endif
set_bed_leveling_enabled(false); set_bed_leveling_enabled(false);
#endif #endif

View File

@ -32,6 +32,10 @@
#include "../../feature/bedlevel/bedlevel.h" #include "../../feature/bedlevel/bedlevel.h"
#endif #endif
#if HAS_LEVELING
#include "../../module/planner.h"
#endif
/** /**
* M48: Z probe repeatability measurement function. * 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 // Disable bed level correction in M48 because we want the raw data when we probe
#if HAS_LEVELING #if HAS_LEVELING
const bool was_enabled = leveling_is_active(); const bool was_enabled = LEVELING_IS_ACTIVE();
set_bed_leveling_enabled(false); set_bed_leveling_enabled(false);
#endif #endif

View File

@ -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; 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 (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); thermalManager.babystep_axis(Z_AXIS, babystep_increment);
zprobe_zoffset = new_zoffset; 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])) if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28")); MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
else if (leveling_is_valid()) { 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); MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling);
} }

View File

@ -795,7 +795,7 @@ static void lcd_implementation_status_screen() {
lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS]))); lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
#if HAS_LEVELING #if HAS_LEVELING
lcd.write(leveling_is_active() || blink ? '_' : ' '); lcd.write(LEVELING_IS_ACTIVE() || blink ? '_' : ' ');
#endif #endif
#endif // LCD_HEIGHT > 2 #endif // LCD_HEIGHT > 2

View File

@ -1556,7 +1556,7 @@ void MarlinSettings::reset() {
SERIAL_ECHOLNPGM(":"); SERIAL_ECHOLNPGM(":");
} }
CONFIG_ECHO_START; 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) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
SERIAL_ECHOPAIR(" Z", planner.z_fade_height); SERIAL_ECHOPAIR(" Z", planner.z_fade_height);
#endif #endif
@ -1578,7 +1578,7 @@ void MarlinSettings::reset() {
SERIAL_ECHOLNPGM("Auto Bed Leveling:"); SERIAL_ECHOLNPGM("Auto Bed Leveling:");
} }
CONFIG_ECHO_START; 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) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height)); SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
#endif #endif

View File

@ -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(AUTO_BED_LEVELING_BILINEAR)
#if ENABLED(DELTA) #if ENABLED(DELTA)
#define ADJUST_DELTA(V) \ #define ADJUST_DELTA(V) \
if (planner.abl_enabled) { \ if (LEVELING_IS_ACTIVE()) { \
const float zadj = bilinear_z_offset(V); \ const float zadj = bilinear_z_offset(V); \
delta[A_AXIS] += zadj; \ delta[A_AXIS] += zadj; \
delta[B_AXIS] += zadj; \ delta[B_AXIS] += zadj; \
delta[C_AXIS] += zadj; \ delta[C_AXIS] += zadj; \
} }
#else #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 #endif
#else #else
#define ADJUST_DELTA(V) NOOP #define ADJUST_DELTA(V) NOOP

View File

@ -555,8 +555,9 @@ void Planner::calculate_volumetric_multipliers() {
*/ */
void Planner::apply_leveling(float &lx, float &ly, float &lz) { void Planner::apply_leveling(float &lx, float &ly, float &lz) {
if (!LEVELING_IS_ACTIVE()) return;
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
if (!ubl.state.active) return;
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
// if z_fade_height enabled (nonzero) and raw_z above it, no leveling required // 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; 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 // FADE
#endif // UBL #endif // UBL
#if OLDSCHOOL_ABL
if (!abl_enabled) return;
#endif
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL)
static float z_fade_factor = 1.0, last_raw_lz = -999.0; static float z_fade_factor = 1.0, last_raw_lz = -999.0;
if (z_fade_height) { if (z_fade_height) {
@ -586,7 +583,6 @@ void Planner::calculate_volumetric_multipliers() {
#if ENABLED(MESH_BED_LEVELING) #if ENABLED(MESH_BED_LEVELING)
if (mbl.active())
lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly) lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
, z_fade_factor , z_fade_factor
@ -654,9 +650,7 @@ void Planner::calculate_volumetric_multipliers() {
#endif #endif
#if OLDSCHOOL_ABL if (!LEVELING_IS_ACTIVE()) return;
if (!abl_enabled) return;
#endif
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return; 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 ENABLED(MESH_BED_LEVELING)
if (mbl.active()) {
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #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); 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); logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);
#else #else
logical[Z_AXIS] -= mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS])); logical[Z_AXIS] -= mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]));
#endif #endif
}
#elif ABL_PLANAR #elif ABL_PLANAR

View File

@ -679,7 +679,7 @@ void refresh_zprobe_zoffset(const bool no_babystep/*=false*/) {
#endif #endif
#if ENABLED(BABYSTEP_ZPROBE_OFFSET) #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])); thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
#else #else
UNUSED(no_babystep); UNUSED(no_babystep);

View File

@ -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 ENABLED(MESH_BED_LEVELING)
if (leveling_is_active()) { if (LEVELING_IS_ACTIVE()) {
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]); if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
#endif #endif