From dbd07c1d1c418b09a814bf542bf3439bdf714296 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Thu, 2 Apr 2020 15:11:46 +0200 Subject: [PATCH 1/2] Limited LCD output of several uint16 values to 999 --- Firmware/ultralcd.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index daf9f0176..363398a93 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1741,14 +1741,18 @@ static void lcd_menu_fails_stats_mmu_total() { mmu_command(MmuCmd::S3); lcd_timeoutToStatus.stop(); //infinite timeout - uint8_t fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL_TOT); - uint16_t load_fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL_TOT); + 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"), _i("Total failures"), ////c=20 r=1 _i("MMU fails"), fails, ////c=14 r=1 _i("MMU load fails"), load_fails, ////c=14 r=1 - _i("MMU power fails"), mmu_power_failures); ////c=14 r=1 + _i("MMU power fails"), mmu_power_fails); ////c=14 r=1 menu_back_if_clicked_fb(); } @@ -1773,7 +1777,11 @@ static void lcd_menu_fails_stats_total() 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); - lcd_home(); + 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, _i("Total failures"), ////c=20 r=1 _i("Power failures"), power, ////c=14 r=1 @@ -1792,6 +1800,17 @@ static void lcd_menu_fails_stats_total() //! | Crash X:000 Y:000| c=7 r=1 //! ---------------------- //! @endcode +//! @brief Show Last Print Failures Statistics with PAT9125 +//! +//! @code{.unparsed} +//! |01234567890123456789| +//! |Last print failures | c=20 r=1 +//! | Power failures 000| c=14 r=1 +//! | Runouts H 000 S 000| c=14 r=1 +//! | Crash X:000 Y:000| c=7 r=1 +//! ---------------------- +//! @endcode + //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations. static void lcd_menu_fails_stats_print() { @@ -1868,6 +1887,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; lcd_home(); lcd_printf_P(failStatsFmt, _i("Last print failures"), ////c=20 r=1 From 9ccda4c57f0b79bdfe2754387f25de5ab4e5c575 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Tue, 9 Feb 2021 09:10:23 +0100 Subject: [PATCH 2/2] 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