From be555e3578594e4b33ceb8fcf3247f05e9aad038 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 7 Jan 2018 00:03:16 -0600 Subject: [PATCH] Move MBL functions into the class --- Marlin/Marlin.h | 5 +++++ Marlin/Marlin_main.cpp | 15 +++------------ Marlin/mesh_bed_leveling.cpp | 11 +++++++++++ Marlin/mesh_bed_leveling.h | 4 +++- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 7248e7c4f..438c01f08 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -383,6 +383,11 @@ void report_current_position(); float bilinear_z_offset(const float raw[XYZ]); #endif +#if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(MESH_BED_LEVELING) + typedef float (*element_2d_fn)(const uint8_t, const uint8_t); + void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, const element_2d_fn fn); +#endif + #if ENABLED(AUTO_BED_LEVELING_UBL) typedef struct { double A, B, D; } linear_fit; linear_fit* lsf_linear_fit(double x[], double y[], double z[], const int); diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 9b99d1a26..2277239bb 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2537,7 +2537,7 @@ static void clean_up_after_endstop_or_probe_move() { /** * Print calibration results for plotting or manual frame adjustment. */ - static void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, float (*fn)(const uint8_t, const uint8_t)) { + void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, const element_2d_fn fn) { #ifndef SCAD_MESH_OUTPUT for (uint8_t x = 0; x < sx; x++) { for (uint8_t i = 0; i < precision + 2 + (x < 10 ? 1 : 0); i++) @@ -4089,15 +4089,6 @@ void home_all_axes() { gcode_G28(true); } // Save 130 bytes with non-duplication of PSTR void echo_not_entered() { SERIAL_PROTOCOLLNPGM(" not entered."); } - void mbl_mesh_report() { - 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_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]; } - ); - } - /** * G29: Mesh-based Z probe, probes a grid and produces a * mesh to compensate for variable bed height @@ -4138,7 +4129,7 @@ void home_all_axes() { gcode_G28(true); } 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."); @@ -9630,7 +9621,7 @@ void quickstop_stepper() { #endif #elif ENABLED(MESH_BED_LEVELING) SERIAL_ECHOLNPGM("Mesh Bed Level data:"); - mbl_mesh_report(); + mbl.report_mesh(); #endif } #endif diff --git a/Marlin/mesh_bed_leveling.cpp b/Marlin/mesh_bed_leveling.cpp index ca0d2a78e..9bbff6b66 100644 --- a/Marlin/mesh_bed_leveling.cpp +++ b/Marlin/mesh_bed_leveling.cpp @@ -25,6 +25,8 @@ #if ENABLED(MESH_BED_LEVELING) #include "mesh_bed_leveling.h" + #include "Marlin.h" + #include "serial.h" mesh_bed_leveling mbl; @@ -49,4 +51,13 @@ ZERO(z_values); } + 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(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 z_values[ix][iy]; } + ); + } + #endif // MESH_BED_LEVELING diff --git a/Marlin/mesh_bed_leveling.h b/Marlin/mesh_bed_leveling.h index e466aba13..0b82a6dce 100644 --- a/Marlin/mesh_bed_leveling.h +++ b/Marlin/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], @@ -47,8 +46,11 @@ 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; } static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {