From 86818c9a89720922c2e6f30c0d4779b3d191f471 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 6 Jan 2018 20:50:21 -0600 Subject: [PATCH] Move MBL functions into the class --- Marlin/src/feature/bedlevel/bedlevel.cpp | 5 +--- .../bedlevel/mbl/mesh_bed_leveling.cpp | 28 +++++++++---------- .../feature/bedlevel/mbl/mesh_bed_leveling.h | 14 +++++----- Marlin/src/gcode/bedlevel/M420.cpp | 2 +- Marlin/src/gcode/bedlevel/mbl/G29.cpp | 2 +- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/Marlin/src/feature/bedlevel/bedlevel.cpp b/Marlin/src/feature/bedlevel/bedlevel.cpp index 84c16f5484..996f3e4b22 100644 --- a/Marlin/src/feature/bedlevel/bedlevel.cpp +++ b/Marlin/src/feature/bedlevel/bedlevel.cpp @@ -178,10 +178,7 @@ void reset_bed_level() { #endif set_bed_leveling_enabled(false); #if ENABLED(MESH_BED_LEVELING) - if (leveling_is_valid()) { - mbl.reset(); - mbl.has_mesh = false; - } + mbl.reset(); #elif ENABLED(AUTO_BED_LEVELING_UBL) ubl.reset(); #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp index 08235b5248..3775300ff6 100644 --- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp +++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp @@ -58,12 +58,12 @@ * Prepare a mesh-leveled linear move in a Cartesian setup, * splitting the move where it crosses mesh borders. */ - void mesh_line_to_destination(const float fr_mm_s, uint8_t x_splits, uint8_t y_splits) { + void mesh_bed_leveling::line_to_destination(const float fr_mm_s, uint8_t x_splits, uint8_t y_splits) { // Get current and destination cells for this line - int cx1 = mbl.cell_index_x(current_position[X_AXIS]), - cy1 = mbl.cell_index_y(current_position[Y_AXIS]), - cx2 = mbl.cell_index_x(destination[X_AXIS]), - cy2 = mbl.cell_index_y(destination[Y_AXIS]); + int cx1 = cell_index_x(current_position[X_AXIS]), + cy1 = cell_index_y(current_position[Y_AXIS]), + cx2 = cell_index_x(destination[X_AXIS]), + cy2 = cell_index_y(destination[Y_AXIS]); NOMORE(cx1, GRID_MAX_POINTS_X - 2); NOMORE(cy1, GRID_MAX_POINTS_Y - 2); NOMORE(cx2, GRID_MAX_POINTS_X - 2); @@ -71,7 +71,7 @@ // Start and end in the same cell? No split needed. if (cx1 == cx2 && cy1 == cy2) { - buffer_line_to_destination(fr_mm_s); + line_to_destination(fr_mm_s); set_current_from_destination(); return; } @@ -87,7 +87,7 @@ // Split on the X grid line CBI(x_splits, gcx); COPY(end, destination); - destination[X_AXIS] = mbl.index_to_xpos[gcx]; + destination[X_AXIS] = index_to_xpos[gcx]; normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]); destination[Y_AXIS] = MBL_SEGMENT_END(Y); } @@ -96,14 +96,14 @@ // Split on the Y grid line CBI(y_splits, gcy); COPY(end, destination); - destination[Y_AXIS] = mbl.index_to_ypos[gcy]; + destination[Y_AXIS] = index_to_ypos[gcy]; normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]); destination[X_AXIS] = MBL_SEGMENT_END(X); } else { // Must already have been split on these border(s) // This should be a rare case. - buffer_line_to_destination(fr_mm_s); + line_to_destination(fr_mm_s); set_current_from_destination(); return; } @@ -112,21 +112,21 @@ destination[E_AXIS] = MBL_SEGMENT_END(E); // Do the split and look for more borders - mesh_line_to_destination(fr_mm_s, x_splits, y_splits); + line_to_destination(fr_mm_s, x_splits, y_splits); // Restore destination from stack COPY(destination, end); - mesh_line_to_destination(fr_mm_s, x_splits, y_splits); + line_to_destination(fr_mm_s, x_splits, y_splits); } #endif // IS_CARTESIAN && !SEGMENT_LEVELED_MOVES - void mbl_mesh_report() { + void mesh_bed_leveling::report_mesh() { SERIAL_PROTOCOLLNPGM("Num X,Y: " STRINGIFY(GRID_MAX_POINTS_X) "," STRINGIFY(GRID_MAX_POINTS_Y)); - SERIAL_PROTOCOLPGM("Z offset: "); SERIAL_PROTOCOL_F(mbl.z_offset, 5); + SERIAL_PROTOCOLPGM("Z offset: "); SERIAL_PROTOCOL_F(z_offset, 5); SERIAL_PROTOCOLLNPGM("\nMeasured points:"); print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5, - [](const uint8_t ix, const uint8_t iy) { return mbl.z_values[ix][iy]; } + [](const uint8_t ix, const uint8_t iy) { return z_values[ix][iy]; } ); } diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h index f183cc7d68..125435df74 100644 --- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h +++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h @@ -47,6 +47,8 @@ public: mesh_bed_leveling(); + static void report_mesh(); + static void reset(); static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; } @@ -105,15 +107,13 @@ public: #endif ; } + + // Support functions, which may be embedded in the class later + #if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES) + void line_to_destination(const float fr_mm_s, uint8_t x_splits=0xFF, uint8_t y_splits=0xFF); + #endif }; extern mesh_bed_leveling mbl; -// Support functions, which may be embedded in the class later -#if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES) - void mesh_line_to_destination(const float fr_mm_s, uint8_t x_splits=0xFF, uint8_t y_splits=0xFF); -#endif - -void mbl_mesh_report(); - #endif // _MESH_BED_LEVELING_H_ diff --git a/Marlin/src/gcode/bedlevel/M420.cpp b/Marlin/src/gcode/bedlevel/M420.cpp index 740b632544..1af94893ed 100644 --- a/Marlin/src/gcode/bedlevel/M420.cpp +++ b/Marlin/src/gcode/bedlevel/M420.cpp @@ -100,7 +100,7 @@ void GcodeSuite::M420() { #endif #elif ENABLED(MESH_BED_LEVELING) SERIAL_ECHOLNPGM("Mesh Bed Level data:"); - mbl_mesh_report(); + mbl.report_mesh(); #endif } #endif diff --git a/Marlin/src/gcode/bedlevel/mbl/G29.cpp b/Marlin/src/gcode/bedlevel/mbl/G29.cpp index 881e567e47..7df32438a5 100644 --- a/Marlin/src/gcode/bedlevel/mbl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/mbl/G29.cpp @@ -81,7 +81,7 @@ void GcodeSuite::G29() { case MeshReport: if (leveling_is_valid()) { SERIAL_PROTOCOLLNPAIR("State: ", planner.leveling_active ? MSG_ON : MSG_OFF); - mbl_mesh_report(); + mbl.report_mesh(); } else SERIAL_PROTOCOLLNPGM("Mesh bed leveling has no data.");