From 1e30d1da47f24190a4e0ceed3631fff529f171af Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 5 Dec 2016 08:25:09 -0600 Subject: [PATCH 1/3] Simplify itostr4sign - This function becomes obsolete if ftostr4sign is re-written. --- Marlin/utility.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Marlin/utility.cpp b/Marlin/utility.cpp index bc68967e9..8f06817c0 100644 --- a/Marlin/utility.cpp +++ b/Marlin/utility.cpp @@ -74,25 +74,32 @@ void safe_delay(millis_t ms) { return str; } - // Convert signed int to rj string with _123, -123, _-12, or __-1 format + // Convert signed int to rj string with 1234, _123, -123, _-12, or __-1 format char *itostr4sign(const int& x) { - int xx = abs(x), sign = 0; - if (xx >= 100) { + int xx = abs(x); + if (x >= 1000) { + conv[0] = DIGIMOD(xx, 1000); conv[1] = DIGIMOD(xx, 100); conv[2] = DIGIMOD(xx, 10); } else { - conv[0] = ' '; - if (xx >= 10) { - sign = 1; + if (xx >= 100) { + conv[0] = x < 0 ? '-' : ' '; + conv[1] = DIGIMOD(xx, 100); conv[2] = DIGIMOD(xx, 10); } else { - conv[1] = ' '; - sign = 2; + conv[0] = ' '; + if (xx >= 10) { + conv[1] = x < 0 ? '-' : ' '; + conv[2] = DIGIMOD(xx, 10); + } + else { + conv[1] = ' '; + conv[2] = x < 0 ? '-' : ' '; + } } } - conv[sign] = x < 0 ? '-' : ' '; conv[3] = DIGIMOD(xx, 1); conv[4] = '\0'; return conv; From bfb8d3b53e2c20e3eab901cd2fe5cd5ca813a80a Mon Sep 17 00:00:00 2001 From: Guthenberg Date: Thu, 1 Dec 2016 15:40:57 +0100 Subject: [PATCH 2/3] Show more decimals in Display, if possible _123, -123, _-12, __-1 plus 1234, 12.3, -1.2 --- Marlin/utility.cpp | 24 ++++++++++++++++++++++++ Marlin/utility.h | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Marlin/utility.cpp b/Marlin/utility.cpp index 8f06817c0..31be8275c 100644 --- a/Marlin/utility.cpp +++ b/Marlin/utility.cpp @@ -129,6 +129,30 @@ void safe_delay(millis_t ms) { return conv; } + // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format + char *ftostr4sign(const float& fx) { + int x = fx * 10, xx = abs(x); + bool ispos = x >= 0, + isten = xx >= 100, + ishun = xx >= 1000; + if (!isten || (ispos && !ishun)) { + // 12.3, _1.2, -1.2 + conv[0] = ispos ? (isten ? DIGIMOD(xx, 100) : ' ') : '-'; + conv[1] = DIGIMOD(xx, 10); + conv[2] = '.'; + conv[3] = DIGIMOD(xx, 1); + } + else { + // 1234, _123, -123, _-12 + conv[0] = ispos ? (xx >= 10000 ? DIGIMOD(xx, 10000) : ' ') : (ishun ? '-' : ' '); + conv[1] = ishun ? DIGIMOD(xx, 1000) : '-'; + conv[2] = DIGIMOD(xx, 100); + conv[3] = DIGIMOD(xx, 10); + } + conv[4] = '\0'; + return conv; + } + // Convert float to fixed-length string with +123.4 / -123.4 format char* ftostr41sign(const float& x) { int xx = x * 10; diff --git a/Marlin/utility.h b/Marlin/utility.h index 95c985793..4bdf18f34 100644 --- a/Marlin/utility.h +++ b/Marlin/utility.h @@ -69,8 +69,8 @@ void safe_delay(millis_t ms); // Convert float to rj string with 123 or -12 format FORCE_INLINE char *ftostr3(const float& x) { return itostr3((int)x); } - // Convert float to rj string with _123, -123, _-12, or __-1 format - FORCE_INLINE char *ftostr4sign(const float& x) { return itostr4sign((int)x); } + // Convert float to rj string with 1234, _123, 12.3, _1.2, -123, _-12, or -1.2 format + char *ftostr4sign(const float& fx); #endif // ULTRA_LCD From d5bf1684feebc02e714cb1ea25730bbbbc0689d5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 5 Dec 2016 08:58:26 -0600 Subject: [PATCH 3/3] Implement as optional feature LCD_DECIMAL_SMALL_XY And reduce the function size to simplify --- Marlin/Configuration_adv.h | 3 ++ .../Cartesio/Configuration_adv.h | 3 ++ .../Felix/Configuration_adv.h | 3 ++ .../Hephestos/Configuration_adv.h | 3 ++ .../Hephestos_2/Configuration_adv.h | 3 ++ .../K8200/Configuration_adv.h | 3 ++ .../K8400/Configuration_adv.h | 3 ++ .../RigidBot/Configuration_adv.h | 3 ++ .../SCARA/Configuration_adv.h | 3 ++ .../TAZ4/Configuration_adv.h | 3 ++ .../WITBOX/Configuration_adv.h | 3 ++ .../delta/biv2.5/Configuration_adv.h | 3 ++ .../delta/generic/Configuration_adv.h | 3 ++ .../delta/kossel_mini/Configuration_adv.h | 3 ++ .../delta/kossel_pro/Configuration_adv.h | 3 ++ .../delta/kossel_xl/Configuration_adv.h | 3 ++ .../makibox/Configuration_adv.h | 3 ++ .../tvrrug/Round2/Configuration_adv.h | 3 ++ Marlin/utility.cpp | 31 +++++++------------ Marlin/utility.h | 9 ++++-- 20 files changed, 73 insertions(+), 21 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index e66f9c9f7..e291db87f 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/Cartesio/Configuration_adv.h b/Marlin/example_configurations/Cartesio/Configuration_adv.h index 680f49f58..dabe5ead0 100644 --- a/Marlin/example_configurations/Cartesio/Configuration_adv.h +++ b/Marlin/example_configurations/Cartesio/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/Felix/Configuration_adv.h b/Marlin/example_configurations/Felix/Configuration_adv.h index 2f848454f..a954e43ae 100644 --- a/Marlin/example_configurations/Felix/Configuration_adv.h +++ b/Marlin/example_configurations/Felix/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/Hephestos/Configuration_adv.h b/Marlin/example_configurations/Hephestos/Configuration_adv.h index 5294766e6..940acf766 100644 --- a/Marlin/example_configurations/Hephestos/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/Hephestos_2/Configuration_adv.h b/Marlin/example_configurations/Hephestos_2/Configuration_adv.h index d48952e1a..52c3a872f 100644 --- a/Marlin/example_configurations/Hephestos_2/Configuration_adv.h +++ b/Marlin/example_configurations/Hephestos_2/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/K8200/Configuration_adv.h b/Marlin/example_configurations/K8200/Configuration_adv.h index b6acbff10..554a6b02b 100644 --- a/Marlin/example_configurations/K8200/Configuration_adv.h +++ b/Marlin/example_configurations/K8200/Configuration_adv.h @@ -435,6 +435,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/K8400/Configuration_adv.h b/Marlin/example_configurations/K8400/Configuration_adv.h index 0df0c0d7d..69043cd68 100644 --- a/Marlin/example_configurations/K8400/Configuration_adv.h +++ b/Marlin/example_configurations/K8400/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/RigidBot/Configuration_adv.h b/Marlin/example_configurations/RigidBot/Configuration_adv.h index 45671c143..a8fd1940d 100644 --- a/Marlin/example_configurations/RigidBot/Configuration_adv.h +++ b/Marlin/example_configurations/RigidBot/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/SCARA/Configuration_adv.h b/Marlin/example_configurations/SCARA/Configuration_adv.h index 5f4e0e2cf..97684b06c 100644 --- a/Marlin/example_configurations/SCARA/Configuration_adv.h +++ b/Marlin/example_configurations/SCARA/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/TAZ4/Configuration_adv.h b/Marlin/example_configurations/TAZ4/Configuration_adv.h index 7e6061864..e81b9e237 100644 --- a/Marlin/example_configurations/TAZ4/Configuration_adv.h +++ b/Marlin/example_configurations/TAZ4/Configuration_adv.h @@ -430,6 +430,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/WITBOX/Configuration_adv.h b/Marlin/example_configurations/WITBOX/Configuration_adv.h index 5294766e6..940acf766 100644 --- a/Marlin/example_configurations/WITBOX/Configuration_adv.h +++ b/Marlin/example_configurations/WITBOX/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h b/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h index cabcff9cf..9e83512ee 100644 --- a/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h +++ b/Marlin/example_configurations/delta/biv2.5/Configuration_adv.h @@ -424,6 +424,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/delta/generic/Configuration_adv.h b/Marlin/example_configurations/delta/generic/Configuration_adv.h index 591e89832..ae111f409 100644 --- a/Marlin/example_configurations/delta/generic/Configuration_adv.h +++ b/Marlin/example_configurations/delta/generic/Configuration_adv.h @@ -424,6 +424,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h index 591e89832..ae111f409 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h @@ -424,6 +424,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h index 0a3becc21..aa4825980 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h @@ -429,6 +429,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h b/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h index 318fe6ecc..909a5bc04 100644 --- a/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h +++ b/Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h @@ -424,6 +424,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/makibox/Configuration_adv.h b/Marlin/example_configurations/makibox/Configuration_adv.h index 749d842bd..e68116b19 100644 --- a/Marlin/example_configurations/makibox/Configuration_adv.h +++ b/Marlin/example_configurations/makibox/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h index 0097c6db2..27dccc0fe 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h @@ -422,6 +422,9 @@ // Include a page of printer information in the LCD Main Menu //#define LCD_INFO_MENU +// On the Info Screen, display XY with one decimal place when possible +//#define LCD_DECIMAL_SMALL_XY + #if ENABLED(SDSUPPORT) // Some RAMPS and other boards don't detect when an SD card is inserted. You can work diff --git a/Marlin/utility.cpp b/Marlin/utility.cpp index 31be8275c..8d638067b 100644 --- a/Marlin/utility.cpp +++ b/Marlin/utility.cpp @@ -129,29 +129,22 @@ void safe_delay(millis_t ms) { return conv; } - // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format - char *ftostr4sign(const float& fx) { - int x = fx * 10, xx = abs(x); - bool ispos = x >= 0, - isten = xx >= 100, - ishun = xx >= 1000; - if (!isten || (ispos && !ishun)) { - // 12.3, _1.2, -1.2 - conv[0] = ispos ? (isten ? DIGIMOD(xx, 100) : ' ') : '-'; + #if ENABLED(LCD_DECIMAL_SMALL_XY) + + // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format + char *ftostr4sign(const float& fx) { + int x = fx * 10; + if (x <= -100 || x >= 1000) return itostr4sign((int)fx); + int xx = abs(x); + conv[0] = x < 0 ? '-' : (xx >= 100 ? DIGIMOD(xx, 100) : ' '); conv[1] = DIGIMOD(xx, 10); conv[2] = '.'; conv[3] = DIGIMOD(xx, 1); + conv[4] = '\0'; + return conv; } - else { - // 1234, _123, -123, _-12 - conv[0] = ispos ? (xx >= 10000 ? DIGIMOD(xx, 10000) : ' ') : (ishun ? '-' : ' '); - conv[1] = ishun ? DIGIMOD(xx, 1000) : '-'; - conv[2] = DIGIMOD(xx, 100); - conv[3] = DIGIMOD(xx, 10); - } - conv[4] = '\0'; - return conv; - } + + #endif // LCD_DECIMAL_SMALL_XY // Convert float to fixed-length string with +123.4 / -123.4 format char* ftostr41sign(const float& x) { diff --git a/Marlin/utility.h b/Marlin/utility.h index 4bdf18f34..09d569deb 100644 --- a/Marlin/utility.h +++ b/Marlin/utility.h @@ -69,8 +69,13 @@ void safe_delay(millis_t ms); // Convert float to rj string with 123 or -12 format FORCE_INLINE char *ftostr3(const float& x) { return itostr3((int)x); } - // Convert float to rj string with 1234, _123, 12.3, _1.2, -123, _-12, or -1.2 format - char *ftostr4sign(const float& fx); + #if ENABLED(LCD_DECIMAL_SMALL_XY) + // Convert float to rj string with 1234, _123, 12.3, _1.2, -123, _-12, or -1.2 format + char *ftostr4sign(const float& fx); + #else + // Convert float to rj string with 1234, _123, -123, __12, _-12, ___1, or __-1 format + FORCE_INLINE char *ftostr4sign(const float& x) { return itostr4sign((int)x); } + #endif #endif // ULTRA_LCD