From 9d7a1ae9f5fa299d7213e7428d71f1a41afcdcec Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 26 Feb 2018 01:00:56 -0600 Subject: [PATCH] Mesh export in Bilinear + UBL M503 (#9818) --- Marlin/configuration_store.cpp | 35 ++++++++++++++++++++++++++-------- Marlin/ubl.cpp | 18 +++++++++++++++++ Marlin/ubl.h | 1 + Marlin/ubl_G29.cpp | 18 ++--------------- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 6272635cd..90f567ab4 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -2061,14 +2061,16 @@ void MarlinSettings::reset() { #if ENABLED(MESH_BED_LEVELING) - for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) { - for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) { - CONFIG_ECHO_START; - SERIAL_ECHOPAIR(" G29 S3 X", (int)px + 1); - SERIAL_ECHOPAIR(" Y", (int)py + 1); - SERIAL_ECHOPGM(" Z"); - SERIAL_PROTOCOL_F(LINEAR_UNIT(mbl.z_values[px][py]), 5); - SERIAL_EOL(); + if (leveling_is_valid()) { + for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) { + for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) { + CONFIG_ECHO_START; + SERIAL_ECHOPAIR(" G29 S3 X", (int)px + 1); + SERIAL_ECHOPAIR(" Y", (int)py + 1); + SERIAL_ECHOPGM(" Z"); + SERIAL_PROTOCOL_F(LINEAR_UNIT(mbl.z_values[px][py]), 5); + SERIAL_EOL(); + } } } @@ -2082,6 +2084,23 @@ void MarlinSettings::reset() { SERIAL_ECHOLNPGM(" meshes.\n"); } + ubl.report_current_mesh(); + + #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) + + if (leveling_is_valid()) { + for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) { + for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) { + CONFIG_ECHO_START; + SERIAL_ECHOPAIR(" G29 W I", (int)px + 1); + SERIAL_ECHOPAIR(" J", (int)py + 1); + SERIAL_ECHOPGM(" Z"); + SERIAL_PROTOCOL_F(LINEAR_UNIT(z_values[px][py]), 5); + SERIAL_EOL(); + } + } + } + #endif #endif // HAS_LEVELING diff --git a/Marlin/ubl.cpp b/Marlin/ubl.cpp index 92eacacdf..c1b76e009 100644 --- a/Marlin/ubl.cpp +++ b/Marlin/ubl.cpp @@ -37,6 +37,24 @@ void unified_bed_leveling::echo_name() { SERIAL_PROTOCOLPGM("Unified Bed Leveling"); } + void unified_bed_leveling::report_current_mesh() { + if (!leveling_is_valid()) return; + SERIAL_ECHO_START(); + SERIAL_ECHOLNPGM(" G29 I 999"); + for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) + for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) + if (!isnan(z_values[x][y])) { + SERIAL_ECHO_START(); + SERIAL_ECHOPAIR(" M421 I ", x); + SERIAL_ECHOPAIR(" J ", y); + SERIAL_ECHOPGM(" Z "); + SERIAL_ECHO_F(z_values[x][y], 6); + SERIAL_ECHOPAIR(" ; X ", LOGICAL_X_POSITION(mesh_index_to_xpos(x))); + SERIAL_ECHOPAIR(", Y ", LOGICAL_Y_POSITION(mesh_index_to_ypos(y))); + SERIAL_EOL(); + } + } + void unified_bed_leveling::report_state() { echo_name(); SERIAL_PROTOCOLPGM(" System v" UBL_VERSION " "); diff --git a/Marlin/ubl.h b/Marlin/ubl.h index 24fbdc55d..0a54c7c7a 100644 --- a/Marlin/ubl.h +++ b/Marlin/ubl.h @@ -109,6 +109,7 @@ class unified_bed_leveling { public: static void echo_name(); + static void report_current_mesh(); static void report_state(); static void save_ubl_active_state_and_disable(); static void restore_ubl_active_state_and_leave(); diff --git a/Marlin/ubl_G29.cpp b/Marlin/ubl_G29.cpp index bd232cb27..8c2f7d47c 100644 --- a/Marlin/ubl_G29.cpp +++ b/Marlin/ubl_G29.cpp @@ -596,21 +596,8 @@ if (parser.seen('S')) { // Store (or Save) Current Mesh Data g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot; - if (g29_storage_slot == -1) { // Special case, we are going to 'Export' the mesh to the - SERIAL_ECHOLNPGM("G29 I 999"); // host in a form it can be reconstructed on a different machine - for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) - for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) - if (!isnan(z_values[x][y])) { - SERIAL_ECHOPAIR("M421 I ", x); - SERIAL_ECHOPAIR(" J ", y); - SERIAL_ECHOPGM(" Z "); - SERIAL_ECHO_F(z_values[x][y], 6); - SERIAL_ECHOPAIR(" ; X ", LOGICAL_X_POSITION(mesh_index_to_xpos(x))); - SERIAL_ECHOPAIR(", Y ", LOGICAL_Y_POSITION(mesh_index_to_ypos(y))); - SERIAL_EOL(); - } - return; - } + if (g29_storage_slot == -1) // Special case, we are going to 'Export' the mesh to the + return report_current_mesh(); int16_t a = settings.calc_num_meshes(); @@ -764,7 +751,6 @@ z_values[location.x_index][location.y_index] = measured_z; } SERIAL_FLUSH(); // Prevent host M105 buffer overrun. - } while (location.x_index >= 0 && --max_iterations); STOW_PROBE();