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)
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)");

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
* 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)

View File

@ -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

View File

@ -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();

View File

@ -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();
}

View File

@ -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

View File

@ -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

View File

@ -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

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;
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);
}

View File

@ -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

View File

@ -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

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(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

View File

@ -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

View File

@ -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);

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 (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