Use planner.leveling_active for all leveling systems

This commit is contained in:
Scott Lahteine
2017-10-13 17:21:25 -05:00
parent 32c607ffe2
commit 3e3911fb81
21 changed files with 143 additions and 180 deletions

View File

@ -44,7 +44,7 @@
bool leveling_is_valid() {
return
#if ENABLED(MESH_BED_LEVELING)
mbl.has_mesh()
mbl.has_mesh
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
!!bilinear_grid_spacing[X_AXIS]
#elif ENABLED(AUTO_BED_LEVELING_UBL)
@ -70,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 != planner.leveling_active) {
#if ENABLED(MESH_BED_LEVELING)
@ -78,23 +78,23 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
const bool enabling = enable && leveling_is_valid();
mbl.set_active(enabling);
planner.leveling_active = enabling;
if (enabling) planner.unapply_leveling(current_position);
#elif ENABLED(AUTO_BED_LEVELING_UBL)
#if PLANNER_LEVELING
if (ubl.state.active) { // leveling from on to off
if (planner.leveling_active) { // leveling from on to off
// change unleveled current_position to physical current_position without moving steppers.
planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
ubl.state.active = false; // disable only AFTER calling apply_leveling
planner.leveling_active = false; // disable only AFTER calling apply_leveling
}
else { // leveling from off to on
ubl.state.active = true; // enable BEFORE calling unapply_leveling, otherwise ignored
planner.leveling_active = true; // enable BEFORE calling unapply_leveling, otherwise ignored
// change physical current_position to unleveled current_position without moving steppers.
planner.unapply_leveling(current_position);
}
#else
ubl.state.active = enable; // just flip the bit, current_position will be wrong until next move.
planner.leveling_active = enable; // just flip the bit, current_position will be wrong until next move.
#endif
#else // OLDSCHOOL_ABL
@ -106,7 +106,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
#endif
// Enable or disable leveling compensation in the planner
planner.abl_enabled = enable;
planner.leveling_active = enable;
if (!enable)
// When disabling just get the current position from the steppers.
@ -131,15 +131,13 @@ 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 = planner.leveling_active;
#if ENABLED(AUTO_BED_LEVELING_UBL)
if (level_active) set_bed_leveling_enabled(false); // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
#endif
planner.z_fade_height = zfh;
planner.inverse_z_fade_height = RECIPROCAL(zfh);
planner.force_fade_recalc();
planner.set_z_fade_height(zfh);
if (level_active) {
#if ENABLED(AUTO_BED_LEVELING_UBL)
@ -166,7 +164,7 @@ void reset_bed_level() {
#if ENABLED(MESH_BED_LEVELING)
if (leveling_is_valid()) {
mbl.reset();
mbl.set_has_mesh(false);
mbl.has_mesh = false;
}
#else
#if ENABLED(DEBUG_LEVELING_FEATURE)