diff --git a/Marlin/src/feature/bedlevel/bedlevel.cpp b/Marlin/src/feature/bedlevel/bedlevel.cpp index 996f3e4b22..262595039a 100644 --- a/Marlin/src/feature/bedlevel/bedlevel.cpp +++ b/Marlin/src/feature/bedlevel/bedlevel.cpp @@ -49,7 +49,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) diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp index 3775300ff6..800630c6ba 100644 --- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp +++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp @@ -31,8 +31,6 @@ mesh_bed_leveling mbl; - bool mesh_bed_leveling::has_mesh; - float mesh_bed_leveling::z_offset, mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], mesh_bed_leveling::index_to_xpos[GRID_MAX_POINTS_X], @@ -47,7 +45,6 @@ } void mesh_bed_leveling::reset() { - has_mesh = false; z_offset = 0; ZERO(z_values); } diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h index 125435df74..45969eea37 100644 --- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h +++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h @@ -39,7 +39,6 @@ enum MeshLevelingState { class mesh_bed_leveling { public: - static bool has_mesh; static float z_offset, z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], index_to_xpos[GRID_MAX_POINTS_X], @@ -51,6 +50,13 @@ public: static void reset(); + FORCE_INLINE static bool has_mesh() { + for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) + for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) + if (z_values[x][y]) return true; + return false; + } + static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; } static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) { diff --git a/Marlin/src/gcode/bedlevel/mbl/G29.cpp b/Marlin/src/gcode/bedlevel/mbl/G29.cpp index 7df32438a5..87dcb5659f 100644 --- a/Marlin/src/gcode/bedlevel/mbl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/mbl/G29.cpp @@ -136,7 +136,6 @@ void GcodeSuite::G29() { SERIAL_PROTOCOLLNPGM("Mesh probing done."); BUZZ(100, 659); BUZZ(100, 698); - mbl.has_mesh = true; gcode.home_all_axes(); set_bed_leveling_enabled(true); @@ -185,9 +184,6 @@ void GcodeSuite::G29() { SERIAL_CHAR('Z'); echo_not_entered(); return; } - - mbl.has_mesh = true; // set since user manually entered a mesh point - break; case MeshSetZOffset: diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index 9926b4d972..f2a2c366be 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -37,7 +37,7 @@ */ // Change EEPROM version if the structure changes -#define EEPROM_VERSION "V48" +#define EEPROM_VERSION "V49" #define EEPROM_OFFSET 100 // Check the integrity of data offsets. @@ -114,7 +114,6 @@ typedef struct SettingsDataStruct { // // MESH_BED_LEVELING // - bool mbl_has_mesh; // mbl.has_mesh float mbl_z_offset; // mbl.z_offset uint8_t mesh_num_x, mesh_num_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y #if ENABLED(MESH_BED_LEVELING) @@ -297,7 +296,6 @@ void MarlinSettings::postprocess() { #if ENABLED(AUTO_BED_LEVELING_BILINEAR) refresh_bed_level(); - //set_bed_leveling_enabled(leveling_is_on); #endif #if HAS_MOTOR_CURRENT_PWM @@ -425,16 +423,13 @@ void MarlinSettings::postprocess() { "MBL Z array is the wrong size." ); const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y; - EEPROM_WRITE(mbl.has_mesh); EEPROM_WRITE(mbl.z_offset); EEPROM_WRITE(mesh_num_x); EEPROM_WRITE(mesh_num_y); EEPROM_WRITE(mbl.z_values); #else // For disabled MBL write a default mesh - const bool leveling_is_on = false; dummy = 0.0f; const uint8_t mesh_num_x = 3, mesh_num_y = 3; - EEPROM_WRITE(leveling_is_on); EEPROM_WRITE(dummy); // z_offset EEPROM_WRITE(mesh_num_x); EEPROM_WRITE(mesh_num_y); @@ -925,18 +920,13 @@ void MarlinSettings::postprocess() { // Mesh (Manual) Bed Leveling // - bool leveling_is_on; uint8_t mesh_num_x, mesh_num_y; - EEPROM_READ_ALWAYS(leveling_is_on); EEPROM_READ(dummy); EEPROM_READ_ALWAYS(mesh_num_x); EEPROM_READ_ALWAYS(mesh_num_y); #if ENABLED(MESH_BED_LEVELING) - if (!validating) { - mbl.has_mesh = leveling_is_on; - mbl.z_offset = dummy; - } + if (!validating) mbl.z_offset = dummy; if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) { // EEPROM data fits the current mesh EEPROM_READ(mbl.z_values);