From f8847edca69b9dee19b5c222b4066f6987ae5529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 29 Jan 2022 14:40:47 +0000 Subject: [PATCH 1/6] Remove one unused variable Saves 1 byte of SRAM The variable is only assigned a value but is never used. --- Firmware/Marlin.h | 1 - Firmware/Marlin_main.cpp | 2 -- Firmware/ultralcd.cpp | 1 - 3 files changed, 4 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 6797b954b..08a09a04a 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -354,7 +354,6 @@ extern unsigned long start_pause_print; extern unsigned long t_fan_rising_edge; extern bool mesh_bed_leveling_flag; -extern bool mesh_bed_run_from_menu; extern int8_t lcd_change_fil_state; // save/restore printing diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 4b8dd2d1a..711ea2488 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -208,7 +208,6 @@ static ShortTimer crashDetTimer; //unsigned long load_filament_time; bool mesh_bed_leveling_flag = false; -bool mesh_bed_run_from_menu = false; #ifdef PRUSA_M28 bool prusa_sd_card_upload = false; @@ -3448,7 +3447,6 @@ static void gcode_G80() lcd_setstatuspgm(_T(WELCOME_MSG)); custom_message_type = custom_message_type_old; custom_message_state = custom_message_state_old; - mesh_bed_run_from_menu = false; lcd_update(2); st_synchronize(); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f9d36b88a..c0afd946a 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4493,7 +4493,6 @@ static void lcd_language_menu() void lcd_mesh_bedleveling() { - mesh_bed_run_from_menu = true; enquecommand_P(PSTR("G80")); lcd_return_to_status(); } From 581188ce2c43e5a623b39a0aa011a4f512de30bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 29 Jan 2022 14:53:23 +0000 Subject: [PATCH 2/6] Fix an issue found in code review Unfortunately this increases flash usages by 212 bytes (same usage as in current release) It seems it is most memory effcient to use int16_t (int). int8_t requires more memory. --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 711ea2488..01f9797ae 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5623,7 +5623,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\nZ search height: "); SERIAL_PROTOCOL(MESH_HOME_Z_SEARCH); SERIAL_PROTOCOLLNPGM("\nMeasured points:"); - for (uint8_t y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { + for (int16_t y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { for (uint8_t x = 0; x < MESH_NUM_X_POINTS; x++) { SERIAL_PROTOCOLPGM(" "); SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5); From c705d4aa106e1eefd87b36fc45947b0df8fc7618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 29 Jan 2022 14:58:39 +0000 Subject: [PATCH 3/6] Change set_z() parameters to uin8_t Saves 24 bytes of flash --- Firmware/mesh_bed_calibration.cpp | 6 +++--- Firmware/mesh_bed_leveling.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 23d7c8736..892415e56 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -2872,14 +2872,14 @@ bool sample_mesh_and_store_reference() } mbl.set_z(0, 0, current_position[Z_AXIS]); } - for (int8_t mesh_point = 1; mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS; ++ mesh_point) { + for (uint8_t mesh_point = 1; mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS; ++ mesh_point) { // Don't let the manage_inactivity() function remove power from the motors. refresh_cmd_timeout(); // Print the decrasing ID of the measurement point. current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; go_to_current(homing_feedrate[Z_AXIS]/60); - int8_t ix = mesh_point % MESH_MEAS_NUM_X_POINTS; - int8_t iy = mesh_point / MESH_MEAS_NUM_X_POINTS; + uint8_t ix = mesh_point % MESH_MEAS_NUM_X_POINTS; + uint8_t iy = mesh_point / MESH_MEAS_NUM_X_POINTS; if (iy & 1) ix = (MESH_MEAS_NUM_X_POINTS - 1) - ix; // Zig zag current_position[X_AXIS] = BED_X(ix, MESH_MEAS_NUM_X_POINTS); current_position[Y_AXIS] = BED_Y(iy, MESH_MEAS_NUM_Y_POINTS); diff --git a/Firmware/mesh_bed_leveling.h b/Firmware/mesh_bed_leveling.h index bf3729558..37d9ade78 100644 --- a/Firmware/mesh_bed_leveling.h +++ b/Firmware/mesh_bed_leveling.h @@ -29,7 +29,7 @@ public: // Otherwise a correction matrix is pulled from the EEPROM if available. static void get_meas_xy(int ix, int iy, float &x, float &y, bool use_default); - void set_z(int ix, int iy, float z) { z_values[iy][ix] = z; } + void set_z(uint8_t ix, uint8_t iy, float z) { z_values[iy][ix] = z; } int select_x_index(float x) { int i = 1; From 49693a9fb375f65df6cce8cd57598aab1c883ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 29 Jan 2022 15:01:51 +0000 Subject: [PATCH 4/6] Remove undefined function No change in memory footprint. --- Firmware/mesh_bed_leveling.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Firmware/mesh_bed_leveling.h b/Firmware/mesh_bed_leveling.h index 37d9ade78..7df04844a 100644 --- a/Firmware/mesh_bed_leveling.h +++ b/Firmware/mesh_bed_leveling.h @@ -24,11 +24,6 @@ public: static float get_x(int i) { return float(MESH_MIN_X) + float(MESH_X_DIST) * float(i); } static float get_y(int i) { return float(MESH_MIN_Y) + float(MESH_Y_DIST) * float(i); } - // Measurement point for the Z probe. - // If use_default=true, then the default positions for a correctly built printer are used. - // Otherwise a correction matrix is pulled from the EEPROM if available. - static void get_meas_xy(int ix, int iy, float &x, float &y, bool use_default); - void set_z(uint8_t ix, uint8_t iy, float z) { z_values[iy][ix] = z; } int select_x_index(float x) { From c081e1a5ae39d93ccb77213e4ebf5ac7c6659040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 29 Jan 2022 15:08:10 +0000 Subject: [PATCH 5/6] Loop index can be unsigned Saves 4 bytes of flash memory --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 01f9797ae..bc3334c46 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -11130,7 +11130,7 @@ void uvlo_() eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), sd_position); // Store the mesh bed leveling offsets. This is 2*7*7=98 bytes, which takes 98*3.4us=333us in worst case. - for (int8_t mesh_point = 0; mesh_point < MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS; ++ mesh_point) { + for (uint8_t mesh_point = 0; mesh_point < MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS; ++ mesh_point) { uint8_t ix = mesh_point % MESH_NUM_X_POINTS; // from 0 to MESH_NUM_X_POINTS - 1 uint8_t iy = mesh_point / MESH_NUM_X_POINTS; // Scale the z value to 1u resolution. From aae562e480081e2fe813c5b3a63288f0b5c47ead Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 30 Jan 2022 02:56:05 +0100 Subject: [PATCH 6/6] Fix G81 for loop --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index bc3334c46..3ed9f8165 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5623,7 +5623,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\nZ search height: "); SERIAL_PROTOCOL(MESH_HOME_Z_SEARCH); SERIAL_PROTOCOLLNPGM("\nMeasured points:"); - for (int16_t y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { + for (uint8_t y = MESH_NUM_Y_POINTS; y-- > 0;) { for (uint8_t x = 0; x < MESH_NUM_X_POINTS; x++) { SERIAL_PROTOCOLPGM(" "); SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5);