From 9ccda4c57f0b79bdfe2754387f25de5ab4e5c575 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Tue, 9 Feb 2021 09:10:23 +0100 Subject: [PATCH] Optimize code size ... looks like I've been able to reduce the code by 80B by using the clamp999() function. There are other spots this function can be used as well, I didn't touch those yet. --- Firmware/ultralcd.cpp | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 70b394c5f..c2b6600fb 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1633,6 +1633,10 @@ void lcd_menu_extruder_info() // NOT static due to using ins menu_back_if_clicked(); } +static uint16_t __attribute__((noinline)) clamp999(uint16_t v){ + return v > 999 ? 999 : v; +} + //! @brief Show Fails Statistics MMU //! //! @code{.unparsed} @@ -1666,13 +1670,11 @@ static void lcd_menu_fails_stats_mmu() static void lcd_menu_fails_stats_mmu_print() { lcd_timeoutToStatus.stop(); //infinite timeout - uint8_t fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL); - uint16_t load_fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL); lcd_home(); lcd_printf_P(PSTR("%S\n" " %-16.16S%-3d\n" " %-16.16S%-3d"), _T(MSG_LAST_PRINT_FAILURES), ////c=20 - _T(MSG_MMU_FAILS), fails, ////c=14 - _T(MSG_MMU_LOAD_FAILS), load_fails); ////c=14 + _T(MSG_MMU_FAILS), clamp999( eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL) ), ////c=14 + _T(MSG_MMU_LOAD_FAILS), clamp999( eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL) )); ////c=14 menu_back_if_clicked_fb(); } @@ -1691,18 +1693,12 @@ static void lcd_menu_fails_stats_mmu_total() { mmu_command(MmuCmd::S3); lcd_timeoutToStatus.stop(); //infinite timeout - uint16_t fails = eeprom_read_word((uint16_t*)EEPROM_MMU_FAIL_TOT); - uint16_t load_fails = eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT); - if (fails > 999) fails = 999; - if (load_fails > 999) load_fails = 999; - uint16_t mmu_power_fails = mmu_power_failures; - if (mmu_power_fails > 999) mmu_power_fails = 999; lcd_home(); lcd_printf_P(PSTR("%S\n" " %-16.16S%-3d\n" " %-16.16S%-3d\n" " %-16.16S%-3d"), _T(MSG_TOTAL_FAILURES), ////c=20 - _T(MSG_MMU_FAILS), fails, ////c=14 - _T(MSG_MMU_LOAD_FAILS), load_fails, ////c=14 - _i("MMU power fails"), mmu_power_failures); ////c=14 r=1 + _T(MSG_MMU_FAILS), clamp999( eeprom_read_word((uint16_t*)EEPROM_MMU_FAIL_TOT) ), ////c=14 + _T(MSG_MMU_LOAD_FAILS), clamp999( eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT) ), ////c=14 + _i("MMU power fails"), clamp999( mmu_power_failures )); ////c=14 r=1 menu_back_if_clicked_fb(); } @@ -1723,20 +1719,14 @@ static const char failStatsFmt[] PROGMEM = "%S\n" " %-16.16S%-3d\n" " %-16.16S%- static void lcd_menu_fails_stats_total() { lcd_timeoutToStatus.stop(); //infinite timeout - uint16_t power = eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT); - uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); - uint16_t crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT); - uint16_t crashY = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT); - if (power > 999) power = 999; - if (filam > 999) filam = 999; - if (crashX > 999) crashX = 999; - if (crashY > 999) crashY = 999; lcd_home(); lcd_printf_P(failStatsFmt, _T(MSG_TOTAL_FAILURES), ////c=20 - _T(MSG_POWER_FAILURES), power, ////c=14 - _T(MSG_FIL_RUNOUTS), filam, ////c=14 - _T(MSG_CRASH), crashX, crashY); ////c=7 + _T(MSG_POWER_FAILURES), clamp999( eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) ), ////c=14 + _T(MSG_FIL_RUNOUTS), clamp999( eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) ), ////c=14 + _T(MSG_CRASH), ////c=7 + clamp999( eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT) ), + clamp999( eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT) )); menu_back_if_clicked_fb(); } @@ -1836,8 +1826,7 @@ static void lcd_menu_fails_stats() { lcd_timeoutToStatus.stop(); //infinite timeout uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); - uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); - if (filamentTotal > 999) filamentTotal = 999; + uint16_t filamentTotal = clamp999( eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) ); lcd_home(); lcd_printf_P(failStatsFmt, _T(MSG_LAST_PRINT_FAILURES), ////c=20