From f3618c3337cf49c53c0d806d44ce43d5b72ef230 Mon Sep 17 00:00:00 2001 From: Bob-the-Kuhn Date: Tue, 21 Mar 2017 01:30:26 -0500 Subject: [PATCH] Reduce UBL RAM usage by making G26/G29 optional --- Marlin/G26_Mesh_Validation_Tool.cpp | 4 +- Marlin/Marlin_main.cpp | 82 +++++++++++++++++++---------- Marlin/UBL.h | 6 --- Marlin/UBL_Bed_Leveling.cpp | 1 + Marlin/UBL_G29.cpp | 9 +++- Marlin/UBL_line_to_destination.cpp | 5 +- Marlin/configuration_store.cpp | 1 + 7 files changed, 67 insertions(+), 41 deletions(-) diff --git a/Marlin/G26_Mesh_Validation_Tool.cpp b/Marlin/G26_Mesh_Validation_Tool.cpp index 80db49b7f..62e65d9a6 100644 --- a/Marlin/G26_Mesh_Validation_Tool.cpp +++ b/Marlin/G26_Mesh_Validation_Tool.cpp @@ -113,6 +113,7 @@ * Y # Y coordinate Specify the starting location of the drawing activity. */ + extern bool g26_debug_flag; extern bool ubl_has_control_of_lcd_panel; extern float feedrate; //extern bool relative_mode; @@ -171,8 +172,7 @@ int8_t prime_flag = 0; - bool keep_heaters_on = false, - g26_debug_flag = false; + bool keep_heaters_on = false; /** * G26: Mesh Validation Pattern generation. diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index d77c1b645..e9f0e27ac 100755 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -299,11 +299,13 @@ #if ENABLED(AUTO_BED_LEVELING_UBL) #include "UBL.h" unified_bed_leveling ubl; -#define UBL_MESH_VALID !( z_values[0][0] == z_values[0][1] && z_values[0][1] == z_values[0][2] \ - && z_values[1][0] == z_values[1][1] && z_values[1][1] == z_values[1][2] \ - && z_values[2][0] == z_values[2][1] && z_values[2][1] == z_values[2][2] \ - && z_values[0][0] == 0 && z_values[1][0] == 0 && z_values[2][0] == 0 \ - || isnan(z_values[0][0])) + #define UBL_MESH_VALID !( ( z_values[0][0] == z_values[0][1] && z_values[0][1] == z_values[0][2] \ + && z_values[1][0] == z_values[1][1] && z_values[1][1] == z_values[1][2] \ + && z_values[2][0] == z_values[2][1] && z_values[2][1] == z_values[2][2] \ + && z_values[0][0] == 0 && z_values[1][0] == 0 && z_values[2][0] == 0 ) \ + || isnan(z_values[0][0])) + extern bool g26_debug_flag; + extern int ubl_eeprom_start; #endif bool Running = true; @@ -7213,10 +7215,54 @@ void quickstop_stepper() { * S[bool] Turns leveling on or off * Z[height] Sets the Z fade height (0 or none to disable) * V[bool] Verbose - Print the leveling grid + * + * L[index] Load UBL mesh from index (0 is default) */ inline void gcode_M420() { - bool to_enable = false; + #if ENABLED(AUTO_BED_LEVELING_UBL) + // L to load a mesh from the EEPROM + if (code_seen('L')) { + const int8_t storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot; + const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(z_values); + if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) { + SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n"); + return; + } + ubl.load_mesh(Storage_Slot); + ubl.state.eeprom_storage_slot = Storage_Slot; + if (Storage_Slot != ubl.state.eeprom_storage_slot) + ubl.store_state(); + ubl.display_map(0); // Right now, we only support one type of map + SERIAL_ECHOLNPAIR("UBL_MESH_VALID = ", UBL_MESH_VALID); + SERIAL_ECHOLNPAIR("eeprom_storage_slot = ", ubl.state.eeprom_storage_slot); + } + #endif // AUTO_BED_LEVELING_UBL + + // V to print the matrix or mesh + if (code_seen('V')) { + #if ABL_PLANAR + planner.bed_level_matrix.debug("Bed Level Correction Matrix:"); + #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) + if (bilinear_grid_spacing[X_AXIS]) { + print_bilinear_leveling_grid(); + #if ENABLED(ABL_BILINEAR_SUBDIVISION) + bed_level_virt_print(); + #endif + } + #elif ENABLED(AUTO_BED_LEVELING_UBL) + ubl.display_map(0); // Currently only supports one map type + SERIAL_ECHOLNPAIR("UBL_MESH_VALID = ", UBL_MESH_VALID); + SERIAL_ECHOLNPAIR("eeprom_storage_slot = ", ubl.state.eeprom_storage_slot); + #elif ENABLED(MESH_BED_LEVELING) + if (mbl.has_mesh()) { + SERIAL_ECHOLNPGM("Mesh Bed Level data:"); + mbl_mesh_report(); + } + #endif + } + + bool to_enable = false; if (code_seen('S')) { to_enable = code_value_bool(); set_bed_leveling_enabled(to_enable); @@ -7243,28 +7289,6 @@ void quickstop_stepper() { SERIAL_ECHO_START; SERIAL_ECHOLNPAIR("Bed Leveling ", new_status ? MSG_ON : MSG_OFF); - - // V to print the matrix or mesh - if (code_seen('V')) { - #if ABL_PLANAR - planner.bed_level_matrix.debug("Bed Level Correction Matrix:"); - #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) - if (bilinear_grid_spacing[X_AXIS]) { - print_bilinear_leveling_grid(); - #if ENABLED(ABL_BILINEAR_SUBDIVISION) - bed_level_virt_print(); - #endif - } - #elif ENABLED(AUTO_BED_LEVELING_UBL) - ubl.display_map(0); // Right now, we only support one type of map - #elif ENABLED(MESH_BED_LEVELING) - if (mbl.has_mesh()) { - SERIAL_ECHOLNPGM("Mesh Bed Level data:"); - mbl_mesh_report(); - } - #endif - } - } #endif @@ -8595,7 +8619,7 @@ void process_next_command() { gcode_G28(); break; - #if PLANNER_LEVELING + #if PLANNER_LEVELING && !ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_MESH_EDIT_ENABLED) case 29: // G29 Detailed Z probe, probes the bed at 3 or more points, // or provides access to the UBL System if enabled. gcode_G29(); diff --git a/Marlin/UBL.h b/Marlin/UBL.h index 51f58e235..fe2c6506e 100644 --- a/Marlin/UBL.h +++ b/Marlin/UBL.h @@ -81,11 +81,6 @@ #define MESH_X_DIST ((float(UBL_MESH_MAX_X) - float(UBL_MESH_MIN_X)) / (float(UBL_MESH_NUM_X_POINTS) - 1.0)) #define MESH_Y_DIST ((float(UBL_MESH_MAX_Y) - float(UBL_MESH_MIN_Y)) / (float(UBL_MESH_NUM_Y_POINTS) - 1.0)) - #if ENABLED(UBL_MESH_EDIT_ENABLED) - extern bool g26_debug_flag; - #else - constexpr bool g26_debug_flag = false; - #endif extern float last_specified_z; extern float fade_scaling_factor_for_current_height; extern float z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS]; @@ -339,7 +334,6 @@ }; // class unified_bed_leveling extern unified_bed_leveling ubl; - extern int ubl_eeprom_start; #define UBL_LAST_EEPROM_INDEX (E2END - sizeof(unified_bed_leveling::state)) diff --git a/Marlin/UBL_Bed_Leveling.cpp b/Marlin/UBL_Bed_Leveling.cpp index 5538c3346..2fa032b91 100644 --- a/Marlin/UBL_Bed_Leveling.cpp +++ b/Marlin/UBL_Bed_Leveling.cpp @@ -27,6 +27,7 @@ #include "UBL.h" #include "hex_print_routines.h" + extern int ubl_eeprom_start; /** * These support functions allow the use of large bit arrays of flags that take very diff --git a/Marlin/UBL_G29.cpp b/Marlin/UBL_G29.cpp index 4feca1b50..1a9bf4bd5 100644 --- a/Marlin/UBL_G29.cpp +++ b/Marlin/UBL_G29.cpp @@ -22,7 +22,7 @@ #include "MarlinConfig.h" -#if ENABLED(AUTO_BED_LEVELING_UBL) +#if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_MESH_EDIT_ENABLED) //#include "vector_3.h" //#include "qr_solve.h" @@ -39,7 +39,10 @@ void lcd_return_to_status(); bool lcd_clicked(); void lcd_implementation_clear(); - + void lcd_mesh_edit_setup(float initial); + float lcd_mesh_edit(); + void lcd_z_offset_edit_setup(float); + float lcd_z_offset_edit(); extern float meshedit_done; extern long babysteps_done; extern float code_value_float(); @@ -62,6 +65,8 @@ #define SIZE_OF_LITTLE_RAISE 0 #define BIG_RAISE_NOT_NEEDED 0 extern void lcd_quick_feedback(); + extern int ubl_eeprom_start; + extern volatile int ubl_encoderDiff; // This is volatile because it is getting changed at interrupt time. /** * G29: Unified Bed Leveling by Roxy diff --git a/Marlin/UBL_line_to_destination.cpp b/Marlin/UBL_line_to_destination.cpp index 91bf3e351..3ed7a2a29 100644 --- a/Marlin/UBL_line_to_destination.cpp +++ b/Marlin/UBL_line_to_destination.cpp @@ -31,7 +31,8 @@ extern float destination[XYZE]; extern void set_current_to_destination(); - + extern float destination[]; + bool g26_debug_flag = false; void debug_current_and_destination(char *title) { // if the title message starts with a '!' it is so important, we are going to @@ -314,7 +315,7 @@ * because part of the Mesh is undefined and we don't have the * information we need to complete the height correction. */ - if (isnan(z0)) z0 = 0.0; + if (isnan(z0)) z0 = 0.0; const float y = LOGICAL_Y_POSITION(mesh_index_to_y_location[current_yi]); diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 34e014d59..276bb068b 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -166,6 +166,7 @@ #if ENABLED(AUTO_BED_LEVELING_UBL) #include "UBL.h" + int ubl_eeprom_start = -1; #endif #if ENABLED(ABL_BILINEAR_SUBDIVISION)