Browse Source

Additional numtostr functions

Scott Lahteine 4 years ago
parent
commit
13118dbd8d

+ 8
- 8
Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp View File

@@ -530,7 +530,7 @@ FORCE_INLINE void _draw_heater_status(const heater_ind_t heater, const char pref
530 530
 
531 531
   if (prefix >= 0) lcd_put_wchar(prefix);
532 532
 
533
-  lcd_put_u8str(i16tostr3(t1 + 0.5));
533
+  lcd_put_u8str(i16tostr3rj(t1 + 0.5));
534 534
   lcd_put_wchar('/');
535 535
 
536 536
   #if !HEATER_IDLE_HANDLER
@@ -582,7 +582,7 @@ FORCE_INLINE void _draw_bed_status(const bool blink) {
582 582
       #endif
583 583
     ));
584 584
     if (progress)
585
-      lcd_put_u8str(ui8tostr3(progress));
585
+      lcd_put_u8str(ui8tostr3rj(progress));
586 586
     else
587 587
       lcd_put_u8str_P(PSTR("---"));
588 588
     lcd_put_wchar('%');
@@ -631,7 +631,7 @@ void MarlinUI::draw_status_message(const bool blink) {
631 631
       lcd_put_u8str_P(PSTR("Dia "));
632 632
       lcd_put_u8str(ftostr12ns(filwidth.measured_mm));
633 633
       lcd_put_u8str_P(PSTR(" V"));
634
-      lcd_put_u8str(i16tostr3(planner.volumetric_percent(parser.volumetric_enabled)));
634
+      lcd_put_u8str(i16tostr3rj(planner.volumetric_percent(parser.volumetric_enabled)));
635 635
       lcd_put_wchar('%');
636 636
       return;
637 637
     }
@@ -863,7 +863,7 @@ void MarlinUI::draw_status_screen() {
863 863
     #if LCD_HEIGHT > 3
864 864
 
865 865
       lcd_put_wchar(0, 2, LCD_STR_FEEDRATE[0]);
866
-      lcd_put_u8str(i16tostr3(feedrate_percentage));
866
+      lcd_put_u8str(i16tostr3rj(feedrate_percentage));
867 867
       lcd_put_wchar('%');
868 868
 
869 869
       char buffer[14];
@@ -902,7 +902,7 @@ void MarlinUI::draw_status_screen() {
902 902
               #endif
903 903
             }
904 904
           lcd_put_wchar(c);
905
-          lcd_put_u8str(i16tostr3(per));
905
+          lcd_put_u8str(i16tostr3rj(per));
906 906
           lcd_put_wchar('%');
907 907
         #endif
908 908
       #endif
@@ -941,7 +941,7 @@ void MarlinUI::draw_status_screen() {
941 941
     #endif
942 942
 
943 943
     lcd_put_wchar(LCD_WIDTH - 9, 1, LCD_STR_FEEDRATE[0]);
944
-    lcd_put_u8str(i16tostr3(feedrate_percentage));
944
+    lcd_put_u8str(i16tostr3rj(feedrate_percentage));
945 945
     lcd_put_wchar('%');
946 946
 
947 947
     // ========== Line 3 ==========
@@ -1415,9 +1415,9 @@ void MarlinUI::draw_status_screen() {
1415 1415
        * Print plot position
1416 1416
        */
1417 1417
       lcd_put_wchar(_LCD_W_POS, 0, '(');
1418
-      lcd_put_u8str(ui8tostr3(x_plot));
1418
+      lcd_put_u8str(ui8tostr3rj(x_plot));
1419 1419
       lcd_put_wchar(',');
1420
-      lcd_put_u8str(ui8tostr3(y_plot));
1420
+      lcd_put_u8str(ui8tostr3rj(y_plot));
1421 1421
       lcd_put_wchar(')');
1422 1422
 
1423 1423
       #if LCD_HEIGHT <= 3   // 16x2 or 20x2 display

+ 6
- 6
Marlin/src/lcd/dogm/status_screen_DOGM.cpp View File

@@ -107,7 +107,7 @@
107 107
 #define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
108 108
 
109 109
 FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, const uint8_t ty) {
110
-  const char *str = i16tostr3(temp);
110
+  const char *str = i16tostr3rj(temp);
111 111
   const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
112 112
   lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]);
113 113
   lcd_put_wchar(LCD_STR_DEGREE[0]);
@@ -406,7 +406,7 @@ void MarlinUI::draw_status_screen() {
406 406
 
407 407
     #if ENABLED(FILAMENT_LCD_DISPLAY)
408 408
       strcpy(wstring, ftostr12ns(filwidth.measured_mm));
409
-      strcpy(mstring, i16tostr3(planner.volumetric_percent(parser.volumetric_enabled)));
409
+      strcpy(mstring, i16tostr3rj(planner.volumetric_percent(parser.volumetric_enabled)));
410 410
     #endif
411 411
 
412 412
     // Progress / elapsed / estimation updates and string formatting to avoid float math on each LCD draw
@@ -438,7 +438,7 @@ void MarlinUI::draw_status_screen() {
438 438
               #if ENABLED(PRINT_PROGRESS_SHOW_DECIMALS)
439 439
                 permyriadtostr4(progress)
440 440
               #else
441
-                ui8tostr3(progress / (PROGRESS_SCALE))
441
+                ui8tostr3rj(progress / (PROGRESS_SCALE))
442 442
               #endif
443 443
             ));
444 444
           }
@@ -571,7 +571,7 @@ void MarlinUI::draw_status_screen() {
571 571
     // Laser / Spindle
572 572
     #if DO_DRAW_CUTTER
573 573
       if (cutter.power && PAGE_CONTAINS(STATUS_CUTTER_TEXT_Y - INFO_FONT_ASCENT, STATUS_CUTTER_TEXT_Y - 1)) {
574
-        lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, i16tostr3(cutter.powerPercent(cutter.power)));
574
+        lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, i16tostr3rj(cutter.powerPercent(cutter.power)));
575 575
         lcd_put_wchar('%');
576 576
       }
577 577
     #endif
@@ -598,7 +598,7 @@ void MarlinUI::draw_status_screen() {
598 598
               c = '*';
599 599
             }
600 600
           #endif
601
-          lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3(thermalManager.fanPercent(spd)));
601
+          lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3rj(thermalManager.fanPercent(spd)));
602 602
           lcd_put_wchar(c);
603 603
         }
604 604
       }
@@ -768,7 +768,7 @@ void MarlinUI::draw_status_screen() {
768 768
     lcd_put_wchar(3, EXTRAS_2_BASELINE, LCD_STR_FEEDRATE[0]);
769 769
 
770 770
     set_font(FONT_STATUSMENU);
771
-    lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3(feedrate_percentage));
771
+    lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3rj(feedrate_percentage));
772 772
     lcd_put_wchar('%');
773 773
 
774 774
     //

+ 2
- 2
Marlin/src/lcd/dogm/ultralcd_DOGM.cpp View File

@@ -324,11 +324,11 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
324 324
       lcd_put_wchar(LCD_PIXEL_WIDTH - 11 * (MENU_FONT_WIDTH), row_y2, 'E');
325 325
       lcd_put_wchar((char)('1' + extruder));
326 326
       lcd_put_wchar(' ');
327
-      lcd_put_u8str(i16tostr3(thermalManager.degHotend(extruder)));
327
+      lcd_put_u8str(i16tostr3rj(thermalManager.degHotend(extruder)));
328 328
       lcd_put_wchar('/');
329 329
 
330 330
       if (get_blink() || !thermalManager.hotend_idle[extruder].timed_out)
331
-        lcd_put_u8str(i16tostr3(thermalManager.degTargetHotend(extruder)));
331
+        lcd_put_u8str(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
332 332
     }
333 333
 
334 334
   #endif // ADVANCED_PAUSE_FEATURE

+ 9
- 13
Marlin/src/lcd/menu/menu.cpp View File

@@ -127,7 +127,7 @@ void MenuItem_gcode::action(PGM_P const, PGM_P const pgcode) { queue.inject_P(pg
127 127
  *
128 128
  * The prerequisite is that in the header the type was already declared:
129 129
  *
130
- *   DEFINE_MENU_EDIT_ITEM_TYPE(int16_t, int3, i16tostr3, 1)
130
+ *   DEFINE_MENU_EDIT_ITEM_TYPE(int3, int16_t, i16tostr3rj, 1)
131 131
  *
132 132
  * For example, DEFINE_MENU_EDIT_ITEM(int3) expands into:
133 133
  *
@@ -396,11 +396,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
396 396
   void lcd_babystep_zoffset() {
397 397
     if (ui.use_click()) return ui.goto_previous_screen_no_defer();
398 398
     ui.defer_status_screen();
399
-    #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
400
-      const bool do_probe = (active_extruder == 0);
401
-    #else
402
-      constexpr bool do_probe = true;
403
-    #endif
399
+    const bool do_probe = DISABLED(BABYSTEP_HOTEND_Z_OFFSET) || active_extruder == 0;
404 400
     if (ui.encoderPosition) {
405 401
       const int16_t babystep_increment = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR_Z);
406 402
       ui.encoderPosition = 0;
@@ -429,14 +425,14 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
429 425
     if (ui.should_draw()) {
430 426
       #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
431 427
         if (!do_probe)
432
-          MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), LCD_Z_OFFSET_FUNC(hotend_offset[active_extruder].z));
433
-        else
434
-      #endif
435
-          MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), LCD_Z_OFFSET_FUNC(probe.offset.z));
436
-
437
-      #if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY)
438
-        if (do_probe) _lcd_zoffset_overlay_gfx(probe.offset.z);
428
+          MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), ftostr54sign(hotend_offset[active_extruder].z));
439 429
       #endif
430
+      if (do_probe) {
431
+        MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), ftostr52sign(probe.offset.z));
432
+        #if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY)
433
+          _lcd_zoffset_overlay_gfx(probe.offset.z);
434
+        #endif
435
+      }
440 436
     }
441 437
   }
442 438
 

+ 26
- 22
Marlin/src/lcd/menu/menu.h View File

@@ -48,9 +48,11 @@ typedef void (*selectFunc_t)();
48 48
 #endif
49 49
 
50 50
 #if Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9
51
+  // Only values from -9.999 to 9.999
51 52
   #define LCD_Z_OFFSET_FUNC(N) ftostr54sign(N)
52 53
   #define LCD_Z_OFFSET_TYPE float43
53 54
 #else
55
+  // Values from -99.99 to 99.99
54 56
   #define LCD_Z_OFFSET_FUNC(N) ftostr52sign(N)
55 57
   #define LCD_Z_OFFSET_TYPE float52
56 58
 #endif
@@ -266,35 +268,37 @@ class TMenuEditItem : MenuEditItemBase {
266 268
 // Provide a set of Edit Item Types which encompass a primitive
267 269
 // type, a string function, and a scale factor for edit and display.
268 270
 // These items call the Edit Item draw method passing the prepared string.
269
-#define DEFINE_MENU_EDIT_ITEM_TYPE(TYPE, NAME, FIX, STRFUNC, SCALE, V...) \
271
+#define __DOFIXfloat PROBE()
272
+#define _DOFIX(TYPE,V) TYPE(TERN(IS_PROBE(__DOFIX##TYPE),FIXFLOAT(V),(V)))
273
+#define DEFINE_MENU_EDIT_ITEM_TYPE(NAME, TYPE, STRFUNC, SCALE, V...) \
270 274
   struct MenuEditItemInfo_##NAME { \
271 275
     typedef TYPE type_t; \
272 276
     static inline float scale(const float value)   { return value * (SCALE) + (V+0); } \
273 277
     static inline float unscale(const float value) { return value / (SCALE) + (V+0); } \
274
-    static inline const char* strfunc(const float value) { return STRFUNC((TYPE)(FIX ? FIXFLOAT(value) : value)); } \
278
+    static inline const char* strfunc(const float value) { return STRFUNC(_DOFIX(TYPE,value)); } \
275 279
   }; \
276 280
   typedef TMenuEditItem<MenuEditItemInfo_##NAME> MenuItem_##NAME
277 281
 
278
-//                         TYPE      NAME         STRFUNC       SCALE
279
-DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t,  percent,     0, ui8tostr4pct, 100.0/255, 0.5);  // 100%   right-justified
280
-DEFINE_MENU_EDIT_ITEM_TYPE(int16_t,  int3,        0, i16tostr3,       1     );   // 123, -12   right-justified
281
-DEFINE_MENU_EDIT_ITEM_TYPE(int16_t,  int4,        0, i16tostr4sign,   1     );   // 1234, -123 right-justified
282
-DEFINE_MENU_EDIT_ITEM_TYPE(int8_t,   int8,        0, i8tostr3,        1     );   // 123, -12   right-justified
283
-DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t,  uint8,       0, ui8tostr3,       1     );   // 123        right-justified
284
-DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_3,    0, ui16tostr3,      1     );   // 123        right-justified
285
-DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_4,    0, ui16tostr4,      0.1   );   // 1234       right-justified
286
-DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_5,    0, ui16tostr5,      0.01  );   // 12345      right-justified
287
-DEFINE_MENU_EDIT_ITEM_TYPE(float,    float3,      1, ftostr3,         1     );   // 123        right-justified
288
-DEFINE_MENU_EDIT_ITEM_TYPE(float,    float52,     1, ftostr42_52,   100     );   // _2.34, 12.34, -2.34 or 123.45, -23.45
289
-DEFINE_MENU_EDIT_ITEM_TYPE(float,    float43,     1, ftostr43sign, 1000     );   // 1.234
290
-DEFINE_MENU_EDIT_ITEM_TYPE(float,    float5,      1, ftostr5rj,       1     );   // 12345      right-justified
291
-DEFINE_MENU_EDIT_ITEM_TYPE(float,    float5_25,   1, ftostr5rj,       0.04f );   // 12345      right-justified (25 increment)
292
-DEFINE_MENU_EDIT_ITEM_TYPE(float,    float51,     1, ftostr51rj,     10     );   // 1234.5     right-justified
293
-DEFINE_MENU_EDIT_ITEM_TYPE(float,    float41sign, 1, ftostr41sign,   10     );   // +123.4
294
-DEFINE_MENU_EDIT_ITEM_TYPE(float,    float51sign, 1, ftostr51sign,   10     );   // +1234.5
295
-DEFINE_MENU_EDIT_ITEM_TYPE(float,    float52sign, 1, ftostr52sign,  100     );   // +123.45
296
-DEFINE_MENU_EDIT_ITEM_TYPE(uint32_t, long5,       0, ftostr5rj,       0.01f );   // 12345      right-justified
297
-DEFINE_MENU_EDIT_ITEM_TYPE(uint32_t, long5_25,    0, ftostr5rj,       0.04f );   // 12345      right-justified (25 increment)
282
+//                         NAME         TYPE      STRFUNC          SCALE         +ROUND
283
+DEFINE_MENU_EDIT_ITEM_TYPE(percent     ,uint8_t  ,ui8tostr4pctrj  , 100.f/255.f, 0.5f);  // 100%   right-justified
284
+DEFINE_MENU_EDIT_ITEM_TYPE(int3        ,int16_t  ,i16tostr3rj     ,   1     );   // 123, -12   right-justified
285
+DEFINE_MENU_EDIT_ITEM_TYPE(int4        ,int16_t  ,i16tostr4signrj ,   1     );   // 1234, -123 right-justified
286
+DEFINE_MENU_EDIT_ITEM_TYPE(int8        ,int8_t   ,i8tostr3rj      ,   1     );   // 123, -12   right-justified
287
+DEFINE_MENU_EDIT_ITEM_TYPE(uint8       ,uint8_t  ,ui8tostr3rj     ,   1     );   // 123        right-justified
288
+DEFINE_MENU_EDIT_ITEM_TYPE(uint16_3    ,uint16_t ,ui16tostr3rj    ,   1     );   // 123        right-justified
289
+DEFINE_MENU_EDIT_ITEM_TYPE(uint16_4    ,uint16_t ,ui16tostr4rj    ,   0.1f  );   // 1234       right-justified
290
+DEFINE_MENU_EDIT_ITEM_TYPE(uint16_5    ,uint16_t ,ui16tostr5rj    ,   0.01f );   // 12345      right-justified
291
+DEFINE_MENU_EDIT_ITEM_TYPE(float3      ,float    ,ftostr3         ,   1     );   // 123        right-justified
292
+DEFINE_MENU_EDIT_ITEM_TYPE(float52     ,float    ,ftostr42_52     , 100     );   // _2.34, 12.34, -2.34 or 123.45, -23.45
293
+DEFINE_MENU_EDIT_ITEM_TYPE(float43     ,float    ,ftostr43sign    ,1000     );   // -1.234, _1.234, +1.234
294
+DEFINE_MENU_EDIT_ITEM_TYPE(float5      ,float    ,ftostr5rj       ,   1     );   // 12345      right-justified
295
+DEFINE_MENU_EDIT_ITEM_TYPE(float5_25   ,float    ,ftostr5rj       ,   0.04f );   // 12345      right-justified (25 increment)
296
+DEFINE_MENU_EDIT_ITEM_TYPE(float51     ,float    ,ftostr51rj      ,  10     );   // 1234.5     right-justified
297
+DEFINE_MENU_EDIT_ITEM_TYPE(float41sign ,float    ,ftostr41sign    ,  10     );   // +123.4
298
+DEFINE_MENU_EDIT_ITEM_TYPE(float51sign ,float    ,ftostr51sign    ,  10     );   // +1234.5
299
+DEFINE_MENU_EDIT_ITEM_TYPE(float52sign ,float    ,ftostr52sign    , 100     );   // +123.45
300
+DEFINE_MENU_EDIT_ITEM_TYPE(long5       ,uint32_t ,ftostr5rj       ,   0.01f );   // 12345      right-justified
301
+DEFINE_MENU_EDIT_ITEM_TYPE(long5_25    ,uint32_t ,ftostr5rj       ,   0.04f );   // 12345      right-justified (25 increment)
298 302
 
299 303
 class MenuItem_bool : public MenuEditItemBase {
300 304
   public:

+ 38
- 12
Marlin/src/libs/numtostr.cpp View File

@@ -33,7 +33,7 @@ char conv[8] = { 0 };
33 33
 #define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-'))
34 34
 
35 35
 // Convert a full-range unsigned 8bit int to a percentage
36
-const char* ui8tostr4pct(const uint8_t i) {
36
+const char* ui8tostr4pctrj(const uint8_t i) {
37 37
   const uint8_t n = ui8_to_percent(i);
38 38
   conv[3] = RJDIGIT(n, 100);
39 39
   conv[4] = RJDIGIT(n, 10);
@@ -43,7 +43,7 @@ const char* ui8tostr4pct(const uint8_t i) {
43 43
 }
44 44
 
45 45
 // Convert unsigned 8bit int to string 123 format
46
-const char* ui8tostr3(const uint8_t i) {
46
+const char* ui8tostr3rj(const uint8_t i) {
47 47
   conv[4] = RJDIGIT(i, 100);
48 48
   conv[5] = RJDIGIT(i, 10);
49 49
   conv[6] = DIGIMOD(i, 1);
@@ -51,7 +51,7 @@ const char* ui8tostr3(const uint8_t i) {
51 51
 }
52 52
 
53 53
 // Convert signed 8bit int to rj string with 123 or -12 format
54
-const char* i8tostr3(const int8_t x) {
54
+const char* i8tostr3rj(const int8_t x) {
55 55
   int xx = x;
56 56
   conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
57 57
   conv[5] = RJDIGIT(xx, 10);
@@ -88,7 +88,7 @@ const char* i8tostr3(const int8_t x) {
88 88
 #endif
89 89
 
90 90
 // Convert unsigned 16bit int to string 12345 format
91
-const char* ui16tostr5(const uint16_t xx) {
91
+const char* ui16tostr5rj(const uint16_t xx) {
92 92
   conv[2] = RJDIGIT(xx, 10000);
93 93
   conv[3] = RJDIGIT(xx, 1000);
94 94
   conv[4] = RJDIGIT(xx, 100);
@@ -98,7 +98,7 @@ const char* ui16tostr5(const uint16_t xx) {
98 98
 }
99 99
 
100 100
 // Convert unsigned 16bit int to string 1234 format
101
-const char* ui16tostr4(const uint16_t xx) {
101
+const char* ui16tostr4rj(const uint16_t xx) {
102 102
   conv[3] = RJDIGIT(xx, 1000);
103 103
   conv[4] = RJDIGIT(xx, 100);
104 104
   conv[5] = RJDIGIT(xx, 10);
@@ -107,7 +107,7 @@ const char* ui16tostr4(const uint16_t xx) {
107 107
 }
108 108
 
109 109
 // Convert unsigned 16bit int to string 123 format
110
-const char* ui16tostr3(const uint16_t xx) {
110
+const char* ui16tostr3rj(const uint16_t xx) {
111 111
   conv[4] = RJDIGIT(xx, 100);
112 112
   conv[5] = RJDIGIT(xx, 10);
113 113
   conv[6] = DIGIMOD(xx, 1);
@@ -115,7 +115,7 @@ const char* ui16tostr3(const uint16_t xx) {
115 115
 }
116 116
 
117 117
 // Convert signed 16bit int to rj string with 123 or -12 format
118
-const char* i16tostr3(const int16_t x) {
118
+const char* i16tostr3rj(const int16_t x) {
119 119
   int xx = x;
120 120
   conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
121 121
   conv[5] = RJDIGIT(xx, 10);
@@ -136,7 +136,7 @@ const char* i16tostr3left(const int16_t i) {
136 136
 }
137 137
 
138 138
 // Convert signed 16bit int to rj string with 1234, _123, -123, _-12, or __-1 format
139
-const char* i16tostr4sign(const int16_t i) {
139
+const char* i16tostr4signrj(const int16_t i) {
140 140
   const bool neg = i < 0;
141 141
   const int ii = neg ? -i : i;
142 142
   if (i >= 1000) {
@@ -174,7 +174,7 @@ const char* ftostr12ns(const float &f) {
174 174
   return &conv[3];
175 175
 }
176 176
 
177
-// Convert signed float to fixed-length string with 12.34 / -2.34 format or 123.45 / -23.45 format
177
+// Convert signed float to fixed-length string with 12.34 / -2.34 or 023.45 / -23.45 format
178 178
 const char* ftostr42_52(const float &f) {
179 179
   if (f <= -10 || f >= 100) return ftostr52(f); // need more digits
180 180
   long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
@@ -198,12 +198,38 @@ const char* ftostr52(const float &f) {
198 198
   return &conv[1];
199 199
 }
200 200
 
201
+// Convert signed float to fixed-length string with 12.345 / -2.345 or 023.456 / -23.456 format
202
+const char* ftostr43_53(const float &f) {
203
+  if (f <= -10 || f >= 100) return ftostr53(f); // need more digits
204
+  long i = (f * 10000 + (f < 0 ? -5: 5)) / 10;
205
+  conv[1] = (f >= 0 && f < 10) ? ' ' : MINUSOR(i, DIGIMOD(i, 10000));
206
+  conv[2] = DIGIMOD(i, 1000);
207
+  conv[3] = '.';
208
+  conv[4] = DIGIMOD(i, 100);
209
+  conv[5] = DIGIMOD(i, 10);
210
+  conv[6] = DIGIMOD(i, 1);
211
+  return &conv[1];
212
+}
213
+
214
+// Convert signed float to fixed-length string with 023.456 / -23.456 format
215
+const char* ftostr53(const float &f) {
216
+  long i = (f * 10000 + (f < 0 ? -5: 5)) / 10;
217
+  conv[0] = MINUSOR(i, DIGIMOD(i, 100000));
218
+  conv[1] = DIGIMOD(i, 10000);
219
+  conv[2] = DIGIMOD(i, 1000);
220
+  conv[3] = '.';
221
+  conv[4] = DIGIMOD(i, 100);
222
+  conv[5] = DIGIMOD(i, 10);
223
+  conv[6] = DIGIMOD(i, 1);
224
+  return &conv[0];
225
+}
226
+
201 227
 #if ENABLED(LCD_DECIMAL_SMALL_XY)
202 228
 
203 229
   // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
204 230
   const char* ftostr4sign(const float &f) {
205 231
     const int i = (f * 100 + (f < 0 ? -5: 5)) / 10;
206
-    if (!WITHIN(i, -99, 999)) return i16tostr4sign((int)f);
232
+    if (!WITHIN(i, -99, 999)) return i16tostr4signrj((int)f);
207 233
     const bool neg = i < 0;
208 234
     const int ii = neg ? -i : i;
209 235
     conv[3] = neg ? '-' : (ii >= 100 ? DIGIMOD(ii, 100) : ' ');
@@ -255,7 +281,7 @@ const char* ftostr54sign(const float &f, char plus/*=' '*/) {
255 281
 // Convert unsigned float to rj string with 12345 format
256 282
 const char* ftostr5rj(const float &f) {
257 283
   const long i = ((f < 0 ? -f : f) * 10 + 5) / 10;
258
-  return ui16tostr5(i);
284
+  return ui16tostr5rj(i);
259 285
 }
260 286
 
261 287
 // Convert signed float to string with +1234.5 format
@@ -284,7 +310,7 @@ const char* ftostr52sign(const float &f) {
284 310
   return conv;
285 311
 }
286 312
 
287
-// Convert unsigned float to string with 1234.5 format omitting trailing zeros
313
+// Convert unsigned float to string with ____4.5, __34.5, _234.5, 1234.5 format
288 314
 const char* ftostr51rj(const float &f) {
289 315
   const long i = ((f < 0 ? -f : f) * 100 + 5) / 10;
290 316
   conv[0] = ' ';

+ 16
- 10
Marlin/src/libs/numtostr.h View File

@@ -24,13 +24,13 @@
24 24
 #include <stdint.h>
25 25
 
26 26
 // Convert a full-range unsigned 8bit int to a percentage
27
-const char* ui8tostr4pct(const uint8_t i);
27
+const char* ui8tostr4pctrj(const uint8_t i);
28 28
 
29 29
 // Convert uint8_t to string with 123 format
30
-const char* ui8tostr3(const uint8_t i);
30
+const char* ui8tostr3rj(const uint8_t i);
31 31
 
32 32
 // Convert int8_t to string with 123 format
33
-const char* i8tostr3(const int8_t x);
33
+const char* i8tostr3rj(const int8_t x);
34 34
 
35 35
 #if HAS_PRINT_PROGRESS_PERMYRIAD
36 36
   // 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);
38 38
 #endif
39 39
 
40 40
 // Convert uint16_t to string with 12345 format
41
-const char* ui16tostr5(const uint16_t x);
41
+const char* ui16tostr5rj(const uint16_t x);
42 42
 
43 43
 // Convert uint16_t to string with 1234 format
44
-const char* ui16tostr4(const uint16_t x);
44
+const char* ui16tostr4rj(const uint16_t x);
45 45
 
46 46
 // Convert uint16_t to string with 123 format
47
-const char* ui16tostr3(const uint16_t x);
47
+const char* ui16tostr3rj(const uint16_t x);
48 48
 
49 49
 // Convert int16_t to string with 123 format
50
-const char* i16tostr3(const int16_t x);
50
+const char* i16tostr3rj(const int16_t x);
51 51
 
52 52
 // Convert unsigned int to lj string with 123 format
53 53
 const char* i16tostr3left(const int16_t xx);
54 54
 
55 55
 // Convert signed int to rj string with _123, -123, _-12, or __-1 format
56
-const char* i16tostr4sign(const int16_t x);
56
+const char* i16tostr4signrj(const int16_t x);
57 57
 
58 58
 // Convert unsigned float to string with 1.23 format
59 59
 const char* ftostr12ns(const float &x);
@@ -64,6 +64,12 @@ const char* ftostr42_52(const float &x);
64 64
 // Convert signed float to fixed-length string with 023.45 / -23.45 format
65 65
 const char* ftostr52(const float &x);
66 66
 
67
+// Convert signed float to fixed-length string with 12.345 / -2.345 or 023.456 / -23.456 format
68
+const char* ftostr43_53(const float &x);
69
+
70
+// Convert signed float to fixed-length string with 023.456 / -23.456 format
71
+const char* ftostr53(const float &x);
72
+
67 73
 // Convert float to fixed-length string with +123.4 / -123.4 format
68 74
 const char* ftostr41sign(const float &x);
69 75
 
@@ -91,7 +97,7 @@ const char* ftostr51rj(const float &x);
91 97
 #include "../core/macros.h"
92 98
 
93 99
 // Convert float to rj string with 123 or -12 format
94
-FORCE_INLINE const char* ftostr3(const float &x) { return i16tostr3(int16_t(x + (x < 0 ? -0.5f : 0.5f))); }
100
+FORCE_INLINE const char* ftostr3(const float &x) { return i16tostr3rj(int16_t(x + (x < 0 ? -0.5f : 0.5f))); }
95 101
 
96 102
 #include "../inc/MarlinConfigPre.h"
97 103
 
@@ -100,5 +106,5 @@ FORCE_INLINE const char* ftostr3(const float &x) { return i16tostr3(int16_t(x +
100 106
   const char* ftostr4sign(const float &fx);
101 107
 #else
102 108
   // Convert float to rj string with 1234, _123, -123, __12, _-12, ___1, or __-1 format
103
-  FORCE_INLINE const char* ftostr4sign(const float &x) { return i16tostr4sign(int16_t(x + (x < 0 ? -0.5f : 0.5f))); }
109
+  FORCE_INLINE const char* ftostr4sign(const float &x) { return i16tostr4signrj(int16_t(x + (x < 0 ? -0.5f : 0.5f))); }
104 110
 #endif

Loading…
Cancel
Save