From 44caf70917d249b6175ef671d9659d408d1dde08 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 25 May 2019 15:24:26 -0500 Subject: [PATCH] Improve editing, fix some small value editing --- Marlin/src/core/utility.cpp | 12 ++++++++++++ Marlin/src/core/utility.h | 3 +++ Marlin/src/lcd/dogm/ultralcd_DOGM.cpp | 2 +- Marlin/src/lcd/menu/menu.h | 4 ++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp index cc7d0065e9..0bc029cece 100644 --- a/Marlin/src/core/utility.cpp +++ b/Marlin/src/core/utility.cpp @@ -161,6 +161,18 @@ void safe_delay(millis_t ms) { return &conv[3]; } + // Convert signed float to fixed-length string with 12.34 / -2.34 format or 123.45 / -23.45 format + char* ftostr42_52(const float &f) { + if (f <= -10 || f >= 100) return ftostr52(f); // need more digits + long i = (f * 1000 + (f < 0 ? -5: 5)) / 10; + conv[2] = (f >= 0 && f < 10) ? ' ' : MINUSOR(i, DIGIMOD(i, 1000)); + conv[3] = DIGIMOD(i, 100); + conv[4] = '.'; + conv[5] = DIGIMOD(i, 10); + conv[6] = DIGIMOD(i, 1); + return &conv[2]; + } + // Convert signed float to fixed-length string with 023.45 / -23.45 format char* ftostr52(const float &f) { long i = (f * 1000 + (f < 0 ? -5: 5)) / 10; diff --git a/Marlin/src/core/utility.h b/Marlin/src/core/utility.h index c04524f672..8cfb43109f 100644 --- a/Marlin/src/core/utility.h +++ b/Marlin/src/core/utility.h @@ -82,6 +82,9 @@ inline void serial_delay(const millis_t ms) { // Convert unsigned float to string with 1.23 format char* ftostr12ns(const float &x); + // Convert signed float to fixed-length string with 12.34 / -2.34 or 023.45 / -23.45 format + char* ftostr42_52(const float &x); + // Convert signed float to fixed-length string with 023.45 / -23.45 format char* ftostr52(const float &x); diff --git a/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp b/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp index a337668db7..ff8bc33787 100644 --- a/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp +++ b/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp @@ -418,7 +418,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop onpage = PAGE_CONTAINS(baseline - (EDIT_FONT_ASCENT - 1), baseline); } if (onpage) { - lcd_moveto(((lcd_chr_fit - 1) - (vallen + 1)) * one_chr_width, baseline); // Right-justified, leaving padded by spaces + lcd_moveto((lcd_chr_fit - (vallen + 1)) * one_chr_width, baseline); // Right-justified, leaving padded by spaces lcd_put_wchar(' '); // overwrite char if value gets shorter lcd_put_u8str(value); } diff --git a/Marlin/src/lcd/menu/menu.h b/Marlin/src/lcd/menu/menu.h index d050031fae..a300096399 100644 --- a/Marlin/src/lcd/menu/menu.h +++ b/Marlin/src/lcd/menu/menu.h @@ -53,7 +53,7 @@ DECLARE_MENU_EDIT_TYPE(uint8_t, uint8, ui8tostr3, 1 ); // 123 DECLARE_MENU_EDIT_TYPE(uint16_t, uint16_3, ui16tostr3, 1 ); // 123, -12 right-justified DECLARE_MENU_EDIT_TYPE(uint16_t, uint16_4, ui16tostr4, 0.1 ); // 1234, -123 right-justified DECLARE_MENU_EDIT_TYPE(float, float3, ftostr3, 1 ); // 123 right-justified -DECLARE_MENU_EDIT_TYPE(float, float52, ftostr52, 100 ); // 123.45, -23.45 +DECLARE_MENU_EDIT_TYPE(float, float52, ftostr42_52, 100 ); // _2.34, 12.34, -2.34 or 123.45, -23.45 DECLARE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000 ); // 1.234 DECLARE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01f ); // 12345 right-justified DECLARE_MENU_EDIT_TYPE(float, float5_25, ftostr5rj, 0.04f ); // 12345 right-justified (25 increment) @@ -123,7 +123,7 @@ DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(uint8); // 123 right-justif DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(uint16_3); // 123, -12 right-justified DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(uint16_4); // 1234, -123 right-justified DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float3); // 123 right-justified -DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52); // 123.45, -23.45 +DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52); // _2.34, 12.34, -2.34 or 123.45, -23.45 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float43); // 1.234 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float5); // 12345 right-justified DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float5_25); // 12345 right-justified (25 increment)