Additional numtostr functions
This commit is contained in:
		| @@ -530,7 +530,7 @@ FORCE_INLINE void _draw_heater_status(const heater_ind_t heater, const char pref | ||||
|  | ||||
|   if (prefix >= 0) lcd_put_wchar(prefix); | ||||
|  | ||||
|   lcd_put_u8str(i16tostr3(t1 + 0.5)); | ||||
|   lcd_put_u8str(i16tostr3rj(t1 + 0.5)); | ||||
|   lcd_put_wchar('/'); | ||||
|  | ||||
|   #if !HEATER_IDLE_HANDLER | ||||
| @@ -582,7 +582,7 @@ FORCE_INLINE void _draw_bed_status(const bool blink) { | ||||
|       #endif | ||||
|     )); | ||||
|     if (progress) | ||||
|       lcd_put_u8str(ui8tostr3(progress)); | ||||
|       lcd_put_u8str(ui8tostr3rj(progress)); | ||||
|     else | ||||
|       lcd_put_u8str_P(PSTR("---")); | ||||
|     lcd_put_wchar('%'); | ||||
| @@ -631,7 +631,7 @@ void MarlinUI::draw_status_message(const bool blink) { | ||||
|       lcd_put_u8str_P(PSTR("Dia ")); | ||||
|       lcd_put_u8str(ftostr12ns(filwidth.measured_mm)); | ||||
|       lcd_put_u8str_P(PSTR(" V")); | ||||
|       lcd_put_u8str(i16tostr3(planner.volumetric_percent(parser.volumetric_enabled))); | ||||
|       lcd_put_u8str(i16tostr3rj(planner.volumetric_percent(parser.volumetric_enabled))); | ||||
|       lcd_put_wchar('%'); | ||||
|       return; | ||||
|     } | ||||
| @@ -863,7 +863,7 @@ void MarlinUI::draw_status_screen() { | ||||
|     #if LCD_HEIGHT > 3 | ||||
|  | ||||
|       lcd_put_wchar(0, 2, LCD_STR_FEEDRATE[0]); | ||||
|       lcd_put_u8str(i16tostr3(feedrate_percentage)); | ||||
|       lcd_put_u8str(i16tostr3rj(feedrate_percentage)); | ||||
|       lcd_put_wchar('%'); | ||||
|  | ||||
|       char buffer[14]; | ||||
| @@ -902,7 +902,7 @@ void MarlinUI::draw_status_screen() { | ||||
|               #endif | ||||
|             } | ||||
|           lcd_put_wchar(c); | ||||
|           lcd_put_u8str(i16tostr3(per)); | ||||
|           lcd_put_u8str(i16tostr3rj(per)); | ||||
|           lcd_put_wchar('%'); | ||||
|         #endif | ||||
|       #endif | ||||
| @@ -941,7 +941,7 @@ void MarlinUI::draw_status_screen() { | ||||
|     #endif | ||||
|  | ||||
|     lcd_put_wchar(LCD_WIDTH - 9, 1, LCD_STR_FEEDRATE[0]); | ||||
|     lcd_put_u8str(i16tostr3(feedrate_percentage)); | ||||
|     lcd_put_u8str(i16tostr3rj(feedrate_percentage)); | ||||
|     lcd_put_wchar('%'); | ||||
|  | ||||
|     // ========== Line 3 ========== | ||||
| @@ -1415,9 +1415,9 @@ void MarlinUI::draw_status_screen() { | ||||
|        * Print plot position | ||||
|        */ | ||||
|       lcd_put_wchar(_LCD_W_POS, 0, '('); | ||||
|       lcd_put_u8str(ui8tostr3(x_plot)); | ||||
|       lcd_put_u8str(ui8tostr3rj(x_plot)); | ||||
|       lcd_put_wchar(','); | ||||
|       lcd_put_u8str(ui8tostr3(y_plot)); | ||||
|       lcd_put_u8str(ui8tostr3rj(y_plot)); | ||||
|       lcd_put_wchar(')'); | ||||
|  | ||||
|       #if LCD_HEIGHT <= 3   // 16x2 or 20x2 display | ||||
|   | ||||
| @@ -107,7 +107,7 @@ | ||||
| #define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X) | ||||
|  | ||||
| FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, const uint8_t ty) { | ||||
|   const char *str = i16tostr3(temp); | ||||
|   const char *str = i16tostr3rj(temp); | ||||
|   const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1; | ||||
|   lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]); | ||||
|   lcd_put_wchar(LCD_STR_DEGREE[0]); | ||||
| @@ -406,7 +406,7 @@ void MarlinUI::draw_status_screen() { | ||||
|  | ||||
|     #if ENABLED(FILAMENT_LCD_DISPLAY) | ||||
|       strcpy(wstring, ftostr12ns(filwidth.measured_mm)); | ||||
|       strcpy(mstring, i16tostr3(planner.volumetric_percent(parser.volumetric_enabled))); | ||||
|       strcpy(mstring, i16tostr3rj(planner.volumetric_percent(parser.volumetric_enabled))); | ||||
|     #endif | ||||
|  | ||||
|     // Progress / elapsed / estimation updates and string formatting to avoid float math on each LCD draw | ||||
| @@ -438,7 +438,7 @@ void MarlinUI::draw_status_screen() { | ||||
|               #if ENABLED(PRINT_PROGRESS_SHOW_DECIMALS) | ||||
|                 permyriadtostr4(progress) | ||||
|               #else | ||||
|                 ui8tostr3(progress / (PROGRESS_SCALE)) | ||||
|                 ui8tostr3rj(progress / (PROGRESS_SCALE)) | ||||
|               #endif | ||||
|             )); | ||||
|           } | ||||
| @@ -571,7 +571,7 @@ void MarlinUI::draw_status_screen() { | ||||
|     // Laser / Spindle | ||||
|     #if DO_DRAW_CUTTER | ||||
|       if (cutter.power && PAGE_CONTAINS(STATUS_CUTTER_TEXT_Y - INFO_FONT_ASCENT, STATUS_CUTTER_TEXT_Y - 1)) { | ||||
|         lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, i16tostr3(cutter.powerPercent(cutter.power))); | ||||
|         lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, i16tostr3rj(cutter.powerPercent(cutter.power))); | ||||
|         lcd_put_wchar('%'); | ||||
|       } | ||||
|     #endif | ||||
| @@ -598,7 +598,7 @@ void MarlinUI::draw_status_screen() { | ||||
|               c = '*'; | ||||
|             } | ||||
|           #endif | ||||
|           lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3(thermalManager.fanPercent(spd))); | ||||
|           lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3rj(thermalManager.fanPercent(spd))); | ||||
|           lcd_put_wchar(c); | ||||
|         } | ||||
|       } | ||||
| @@ -768,7 +768,7 @@ void MarlinUI::draw_status_screen() { | ||||
|     lcd_put_wchar(3, EXTRAS_2_BASELINE, LCD_STR_FEEDRATE[0]); | ||||
|  | ||||
|     set_font(FONT_STATUSMENU); | ||||
|     lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3(feedrate_percentage)); | ||||
|     lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3rj(feedrate_percentage)); | ||||
|     lcd_put_wchar('%'); | ||||
|  | ||||
|     // | ||||
|   | ||||
| @@ -324,11 +324,11 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop | ||||
|       lcd_put_wchar(LCD_PIXEL_WIDTH - 11 * (MENU_FONT_WIDTH), row_y2, 'E'); | ||||
|       lcd_put_wchar((char)('1' + extruder)); | ||||
|       lcd_put_wchar(' '); | ||||
|       lcd_put_u8str(i16tostr3(thermalManager.degHotend(extruder))); | ||||
|       lcd_put_u8str(i16tostr3rj(thermalManager.degHotend(extruder))); | ||||
|       lcd_put_wchar('/'); | ||||
|  | ||||
|       if (get_blink() || !thermalManager.hotend_idle[extruder].timed_out) | ||||
|         lcd_put_u8str(i16tostr3(thermalManager.degTargetHotend(extruder))); | ||||
|         lcd_put_u8str(i16tostr3rj(thermalManager.degTargetHotend(extruder))); | ||||
|     } | ||||
|  | ||||
|   #endif // ADVANCED_PAUSE_FEATURE | ||||
|   | ||||
| @@ -127,7 +127,7 @@ void MenuItem_gcode::action(PGM_P const, PGM_P const pgcode) { queue.inject_P(pg | ||||
|  * | ||||
|  * The prerequisite is that in the header the type was already declared: | ||||
|  * | ||||
|  *   DEFINE_MENU_EDIT_ITEM_TYPE(int16_t, int3, i16tostr3, 1) | ||||
|  *   DEFINE_MENU_EDIT_ITEM_TYPE(int3, int16_t, i16tostr3rj, 1) | ||||
|  * | ||||
|  * For example, DEFINE_MENU_EDIT_ITEM(int3) expands into: | ||||
|  * | ||||
| @@ -396,11 +396,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { | ||||
|   void lcd_babystep_zoffset() { | ||||
|     if (ui.use_click()) return ui.goto_previous_screen_no_defer(); | ||||
|     ui.defer_status_screen(); | ||||
|     #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET) | ||||
|       const bool do_probe = (active_extruder == 0); | ||||
|     #else | ||||
|       constexpr bool do_probe = true; | ||||
|     #endif | ||||
|     const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0; | ||||
|     if (ui.encoderPosition) { | ||||
|       const int16_t babystep_increment = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR_Z); | ||||
|       ui.encoderPosition = 0; | ||||
| @@ -429,14 +425,14 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { | ||||
|     if (ui.should_draw()) { | ||||
|       #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET) | ||||
|         if (!do_probe) | ||||
|           MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), LCD_Z_OFFSET_FUNC(hotend_offset[active_extruder].z)); | ||||
|         else | ||||
|       #endif | ||||
|           MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), LCD_Z_OFFSET_FUNC(probe.offset.z)); | ||||
|  | ||||
|       #if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY) | ||||
|         if (do_probe) _lcd_zoffset_overlay_gfx(probe.offset.z); | ||||
|           MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), ftostr54sign(hotend_offset[active_extruder].z)); | ||||
|       #endif | ||||
|       if (do_probe) { | ||||
|         MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), ftostr52sign(probe.offset.z)); | ||||
|         #if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY) | ||||
|           _lcd_zoffset_overlay_gfx(probe.offset.z); | ||||
|         #endif | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -48,9 +48,11 @@ typedef void (*selectFunc_t)(); | ||||
| #endif | ||||
|  | ||||
| #if Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9 | ||||
|   // Only values from -9.999 to 9.999 | ||||
|   #define LCD_Z_OFFSET_FUNC(N) ftostr54sign(N) | ||||
|   #define LCD_Z_OFFSET_TYPE float43 | ||||
| #else | ||||
|   // Values from -99.99 to 99.99 | ||||
|   #define LCD_Z_OFFSET_FUNC(N) ftostr52sign(N) | ||||
|   #define LCD_Z_OFFSET_TYPE float52 | ||||
| #endif | ||||
| @@ -266,35 +268,37 @@ class TMenuEditItem : MenuEditItemBase { | ||||
| // Provide a set of Edit Item Types which encompass a primitive | ||||
| // type, a string function, and a scale factor for edit and display. | ||||
| // These items call the Edit Item draw method passing the prepared string. | ||||
| #define DEFINE_MENU_EDIT_ITEM_TYPE(TYPE, NAME, FIX, STRFUNC, SCALE, V...) \ | ||||
| #define __DOFIXfloat PROBE() | ||||
| #define _DOFIX(TYPE,V) TYPE(TERN(IS_PROBE(__DOFIX##TYPE),FIXFLOAT(V),(V))) | ||||
| #define DEFINE_MENU_EDIT_ITEM_TYPE(NAME, TYPE, STRFUNC, SCALE, V...) \ | ||||
|   struct MenuEditItemInfo_##NAME { \ | ||||
|     typedef TYPE type_t; \ | ||||
|     static inline float scale(const float value)   { return value * (SCALE) + (V+0); } \ | ||||
|     static inline float unscale(const float value) { return value / (SCALE) + (V+0); } \ | ||||
|     static inline const char* strfunc(const float value) { return STRFUNC((TYPE)(FIX ? FIXFLOAT(value) : value)); } \ | ||||
|     static inline const char* strfunc(const float value) { return STRFUNC(_DOFIX(TYPE,value)); } \ | ||||
|   }; \ | ||||
|   typedef TMenuEditItem<MenuEditItemInfo_##NAME> MenuItem_##NAME | ||||
|  | ||||
| //                         TYPE      NAME         STRFUNC       SCALE | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t,  percent,     0, ui8tostr4pct, 100.0/255, 0.5);  // 100%   right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(int16_t,  int3,        0, i16tostr3,       1     );   // 123, -12   right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(int16_t,  int4,        0, i16tostr4sign,   1     );   // 1234, -123 right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(int8_t,   int8,        0, i8tostr3,        1     );   // 123, -12   right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t,  uint8,       0, ui8tostr3,       1     );   // 123        right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_3,    0, ui16tostr3,      1     );   // 123        right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_4,    0, ui16tostr4,      0.1   );   // 1234       right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_5,    0, ui16tostr5,      0.01  );   // 12345      right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float,    float3,      1, ftostr3,         1     );   // 123        right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float,    float52,     1, ftostr42_52,   100     );   // _2.34, 12.34, -2.34 or 123.45, -23.45 | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float,    float43,     1, ftostr43sign, 1000     );   // 1.234 | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float,    float5,      1, ftostr5rj,       1     );   // 12345      right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float,    float5_25,   1, ftostr5rj,       0.04f );   // 12345      right-justified (25 increment) | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float,    float51,     1, ftostr51rj,     10     );   // 1234.5     right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float,    float41sign, 1, ftostr41sign,   10     );   // +123.4 | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float,    float51sign, 1, ftostr51sign,   10     );   // +1234.5 | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float,    float52sign, 1, ftostr52sign,  100     );   // +123.45 | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint32_t, long5,       0, ftostr5rj,       0.01f );   // 12345      right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint32_t, long5_25,    0, ftostr5rj,       0.04f );   // 12345      right-justified (25 increment) | ||||
| //                         NAME         TYPE      STRFUNC          SCALE         +ROUND | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(percent     ,uint8_t  ,ui8tostr4pctrj  , 100.f/255.f, 0.5f);  // 100%   right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(int3        ,int16_t  ,i16tostr3rj     ,   1     );   // 123, -12   right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(int4        ,int16_t  ,i16tostr4signrj ,   1     );   // 1234, -123 right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(int8        ,int8_t   ,i8tostr3rj      ,   1     );   // 123, -12   right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint8       ,uint8_t  ,ui8tostr3rj     ,   1     );   // 123        right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint16_3    ,uint16_t ,ui16tostr3rj    ,   1     );   // 123        right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint16_4    ,uint16_t ,ui16tostr4rj    ,   0.1f  );   // 1234       right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(uint16_5    ,uint16_t ,ui16tostr5rj    ,   0.01f );   // 12345      right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float3      ,float    ,ftostr3         ,   1     );   // 123        right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float52     ,float    ,ftostr42_52     , 100     );   // _2.34, 12.34, -2.34 or 123.45, -23.45 | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float43     ,float    ,ftostr43sign    ,1000     );   // -1.234, _1.234, +1.234 | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float5      ,float    ,ftostr5rj       ,   1     );   // 12345      right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float5_25   ,float    ,ftostr5rj       ,   0.04f );   // 12345      right-justified (25 increment) | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float51     ,float    ,ftostr51rj      ,  10     );   // 1234.5     right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float41sign ,float    ,ftostr41sign    ,  10     );   // +123.4 | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float51sign ,float    ,ftostr51sign    ,  10     );   // +1234.5 | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(float52sign ,float    ,ftostr52sign    , 100     );   // +123.45 | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(long5       ,uint32_t ,ftostr5rj       ,   0.01f );   // 12345      right-justified | ||||
| DEFINE_MENU_EDIT_ITEM_TYPE(long5_25    ,uint32_t ,ftostr5rj       ,   0.04f );   // 12345      right-justified (25 increment) | ||||
|  | ||||
| class MenuItem_bool : public MenuEditItemBase { | ||||
|   public: | ||||
|   | ||||
| @@ -33,7 +33,7 @@ char conv[8] = { 0 }; | ||||
| #define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-')) | ||||
|  | ||||
| // Convert a full-range unsigned 8bit int to a percentage | ||||
| const char* ui8tostr4pct(const uint8_t i) { | ||||
| const char* ui8tostr4pctrj(const uint8_t i) { | ||||
|   const uint8_t n = ui8_to_percent(i); | ||||
|   conv[3] = RJDIGIT(n, 100); | ||||
|   conv[4] = RJDIGIT(n, 10); | ||||
| @@ -43,7 +43,7 @@ const char* ui8tostr4pct(const uint8_t i) { | ||||
| } | ||||
|  | ||||
| // Convert unsigned 8bit int to string 123 format | ||||
| const char* ui8tostr3(const uint8_t i) { | ||||
| const char* ui8tostr3rj(const uint8_t i) { | ||||
|   conv[4] = RJDIGIT(i, 100); | ||||
|   conv[5] = RJDIGIT(i, 10); | ||||
|   conv[6] = DIGIMOD(i, 1); | ||||
| @@ -51,7 +51,7 @@ const char* ui8tostr3(const uint8_t i) { | ||||
| } | ||||
|  | ||||
| // Convert signed 8bit int to rj string with 123 or -12 format | ||||
| const char* i8tostr3(const int8_t x) { | ||||
| const char* i8tostr3rj(const int8_t x) { | ||||
|   int xx = x; | ||||
|   conv[4] = MINUSOR(xx, RJDIGIT(xx, 100)); | ||||
|   conv[5] = RJDIGIT(xx, 10); | ||||
| @@ -88,7 +88,7 @@ const char* i8tostr3(const int8_t x) { | ||||
| #endif | ||||
|  | ||||
| // Convert unsigned 16bit int to string 12345 format | ||||
| const char* ui16tostr5(const uint16_t xx) { | ||||
| const char* ui16tostr5rj(const uint16_t xx) { | ||||
|   conv[2] = RJDIGIT(xx, 10000); | ||||
|   conv[3] = RJDIGIT(xx, 1000); | ||||
|   conv[4] = RJDIGIT(xx, 100); | ||||
| @@ -98,7 +98,7 @@ const char* ui16tostr5(const uint16_t xx) { | ||||
| } | ||||
|  | ||||
| // Convert unsigned 16bit int to string 1234 format | ||||
| const char* ui16tostr4(const uint16_t xx) { | ||||
| const char* ui16tostr4rj(const uint16_t xx) { | ||||
|   conv[3] = RJDIGIT(xx, 1000); | ||||
|   conv[4] = RJDIGIT(xx, 100); | ||||
|   conv[5] = RJDIGIT(xx, 10); | ||||
| @@ -107,7 +107,7 @@ const char* ui16tostr4(const uint16_t xx) { | ||||
| } | ||||
|  | ||||
| // Convert unsigned 16bit int to string 123 format | ||||
| const char* ui16tostr3(const uint16_t xx) { | ||||
| const char* ui16tostr3rj(const uint16_t xx) { | ||||
|   conv[4] = RJDIGIT(xx, 100); | ||||
|   conv[5] = RJDIGIT(xx, 10); | ||||
|   conv[6] = DIGIMOD(xx, 1); | ||||
| @@ -115,7 +115,7 @@ const char* ui16tostr3(const uint16_t xx) { | ||||
| } | ||||
|  | ||||
| // Convert signed 16bit int to rj string with 123 or -12 format | ||||
| const char* i16tostr3(const int16_t x) { | ||||
| const char* i16tostr3rj(const int16_t x) { | ||||
|   int xx = x; | ||||
|   conv[4] = MINUSOR(xx, RJDIGIT(xx, 100)); | ||||
|   conv[5] = RJDIGIT(xx, 10); | ||||
| @@ -136,7 +136,7 @@ const char* i16tostr3left(const int16_t i) { | ||||
| } | ||||
|  | ||||
| // Convert signed 16bit int to rj string with 1234, _123, -123, _-12, or __-1 format | ||||
| const char* i16tostr4sign(const int16_t i) { | ||||
| const char* i16tostr4signrj(const int16_t i) { | ||||
|   const bool neg = i < 0; | ||||
|   const int ii = neg ? -i : i; | ||||
|   if (i >= 1000) { | ||||
| @@ -174,7 +174,7 @@ const char* ftostr12ns(const float &f) { | ||||
|   return &conv[3]; | ||||
| } | ||||
|  | ||||
| // Convert signed float to fixed-length string with 12.34 / -2.34 format or 123.45 / -23.45 format | ||||
| // Convert signed float to fixed-length string with 12.34 / -2.34 or 023.45 / -23.45 format | ||||
| const 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; | ||||
| @@ -198,12 +198,38 @@ const char* ftostr52(const float &f) { | ||||
|   return &conv[1]; | ||||
| } | ||||
|  | ||||
| // Convert signed float to fixed-length string with 12.345 / -2.345 or 023.456 / -23.456 format | ||||
| const char* ftostr43_53(const float &f) { | ||||
|   if (f <= -10 || f >= 100) return ftostr53(f); // need more digits | ||||
|   long i = (f * 10000 + (f < 0 ? -5: 5)) / 10; | ||||
|   conv[1] = (f >= 0 && f < 10) ? ' ' : MINUSOR(i, DIGIMOD(i, 10000)); | ||||
|   conv[2] = DIGIMOD(i, 1000); | ||||
|   conv[3] = '.'; | ||||
|   conv[4] = DIGIMOD(i, 100); | ||||
|   conv[5] = DIGIMOD(i, 10); | ||||
|   conv[6] = DIGIMOD(i, 1); | ||||
|   return &conv[1]; | ||||
| } | ||||
|  | ||||
| // Convert signed float to fixed-length string with 023.456 / -23.456 format | ||||
| const char* ftostr53(const float &f) { | ||||
|   long i = (f * 10000 + (f < 0 ? -5: 5)) / 10; | ||||
|   conv[0] = MINUSOR(i, DIGIMOD(i, 100000)); | ||||
|   conv[1] = DIGIMOD(i, 10000); | ||||
|   conv[2] = DIGIMOD(i, 1000); | ||||
|   conv[3] = '.'; | ||||
|   conv[4] = DIGIMOD(i, 100); | ||||
|   conv[5] = DIGIMOD(i, 10); | ||||
|   conv[6] = DIGIMOD(i, 1); | ||||
|   return &conv[0]; | ||||
| } | ||||
|  | ||||
| #if ENABLED(LCD_DECIMAL_SMALL_XY) | ||||
|  | ||||
|   // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format | ||||
|   const char* ftostr4sign(const float &f) { | ||||
|     const int i = (f * 100 + (f < 0 ? -5: 5)) / 10; | ||||
|     if (!WITHIN(i, -99, 999)) return i16tostr4sign((int)f); | ||||
|     if (!WITHIN(i, -99, 999)) return i16tostr4signrj((int)f); | ||||
|     const bool neg = i < 0; | ||||
|     const int ii = neg ? -i : i; | ||||
|     conv[3] = neg ? '-' : (ii >= 100 ? DIGIMOD(ii, 100) : ' '); | ||||
| @@ -255,7 +281,7 @@ const char* ftostr54sign(const float &f, char plus/*=' '*/) { | ||||
| // Convert unsigned float to rj string with 12345 format | ||||
| const char* ftostr5rj(const float &f) { | ||||
|   const long i = ((f < 0 ? -f : f) * 10 + 5) / 10; | ||||
|   return ui16tostr5(i); | ||||
|   return ui16tostr5rj(i); | ||||
| } | ||||
|  | ||||
| // Convert signed float to string with +1234.5 format | ||||
| @@ -284,7 +310,7 @@ const char* ftostr52sign(const float &f) { | ||||
|   return conv; | ||||
| } | ||||
|  | ||||
| // Convert unsigned float to string with 1234.5 format omitting trailing zeros | ||||
| // Convert unsigned float to string with ____4.5, __34.5, _234.5, 1234.5 format | ||||
| const char* ftostr51rj(const float &f) { | ||||
|   const long i = ((f < 0 ? -f : f) * 100 + 5) / 10; | ||||
|   conv[0] = ' '; | ||||
|   | ||||
| @@ -24,13 +24,13 @@ | ||||
| #include <stdint.h> | ||||
|  | ||||
| // Convert a full-range unsigned 8bit int to a percentage | ||||
| const char* ui8tostr4pct(const uint8_t i); | ||||
| const char* ui8tostr4pctrj(const uint8_t i); | ||||
|  | ||||
| // Convert uint8_t to string with 123 format | ||||
| const char* ui8tostr3(const uint8_t i); | ||||
| const char* ui8tostr3rj(const uint8_t i); | ||||
|  | ||||
| // Convert int8_t to string with 123 format | ||||
| const char* i8tostr3(const int8_t x); | ||||
| const char* i8tostr3rj(const int8_t x); | ||||
|  | ||||
| #if HAS_PRINT_PROGRESS_PERMYRIAD | ||||
|   // Convert 16-bit unsigned permyriad value to percent: 100 / 23 / 23.4 / 3.45 | ||||
| @@ -38,22 +38,22 @@ const char* i8tostr3(const int8_t x); | ||||
| #endif | ||||
|  | ||||
| // Convert uint16_t to string with 12345 format | ||||
| const char* ui16tostr5(const uint16_t x); | ||||
| const char* ui16tostr5rj(const uint16_t x); | ||||
|  | ||||
| // Convert uint16_t to string with 1234 format | ||||
| const char* ui16tostr4(const uint16_t x); | ||||
| const char* ui16tostr4rj(const uint16_t x); | ||||
|  | ||||
| // Convert uint16_t to string with 123 format | ||||
| const char* ui16tostr3(const uint16_t x); | ||||
| const char* ui16tostr3rj(const uint16_t x); | ||||
|  | ||||
| // Convert int16_t to string with 123 format | ||||
| const char* i16tostr3(const int16_t x); | ||||
| const char* i16tostr3rj(const int16_t x); | ||||
|  | ||||
| // Convert unsigned int to lj string with 123 format | ||||
| const char* i16tostr3left(const int16_t xx); | ||||
|  | ||||
| // Convert signed int to rj string with _123, -123, _-12, or __-1 format | ||||
| const char* i16tostr4sign(const int16_t x); | ||||
| const char* i16tostr4signrj(const int16_t x); | ||||
|  | ||||
| // Convert unsigned float to string with 1.23 format | ||||
| const char* ftostr12ns(const float &x); | ||||
| @@ -64,6 +64,12 @@ const char* ftostr42_52(const float &x); | ||||
| // Convert signed float to fixed-length string with 023.45 / -23.45 format | ||||
| const char* ftostr52(const float &x); | ||||
|  | ||||
| // Convert signed float to fixed-length string with 12.345 / -2.345 or 023.456 / -23.456 format | ||||
| const char* ftostr43_53(const float &x); | ||||
|  | ||||
| // Convert signed float to fixed-length string with 023.456 / -23.456 format | ||||
| const char* ftostr53(const float &x); | ||||
|  | ||||
| // Convert float to fixed-length string with +123.4 / -123.4 format | ||||
| const char* ftostr41sign(const float &x); | ||||
|  | ||||
| @@ -91,7 +97,7 @@ const char* ftostr51rj(const float &x); | ||||
| #include "../core/macros.h" | ||||
|  | ||||
| // Convert float to rj string with 123 or -12 format | ||||
| FORCE_INLINE const char* ftostr3(const float &x) { return i16tostr3(int16_t(x + (x < 0 ? -0.5f : 0.5f))); } | ||||
| FORCE_INLINE const char* ftostr3(const float &x) { return i16tostr3rj(int16_t(x + (x < 0 ? -0.5f : 0.5f))); } | ||||
|  | ||||
| #include "../inc/MarlinConfigPre.h" | ||||
|  | ||||
| @@ -100,5 +106,5 @@ FORCE_INLINE const char* ftostr3(const float &x) { return i16tostr3(int16_t(x + | ||||
|   const char* ftostr4sign(const float &fx); | ||||
| #else | ||||
|   // Convert float to rj string with 1234, _123, -123, __12, _-12, ___1, or __-1 format | ||||
|   FORCE_INLINE const char* ftostr4sign(const float &x) { return i16tostr4sign(int16_t(x + (x < 0 ? -0.5f : 0.5f))); } | ||||
|   FORCE_INLINE const char* ftostr4sign(const float &x) { return i16tostr4signrj(int16_t(x + (x < 0 ? -0.5f : 0.5f))); } | ||||
| #endif | ||||
|   | ||||
		Reference in New Issue
	
	Block a user