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
 
530
 
531
   if (prefix >= 0) lcd_put_wchar(prefix);
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
   lcd_put_wchar('/');
534
   lcd_put_wchar('/');
535
 
535
 
536
   #if !HEATER_IDLE_HANDLER
536
   #if !HEATER_IDLE_HANDLER
582
       #endif
582
       #endif
583
     ));
583
     ));
584
     if (progress)
584
     if (progress)
585
-      lcd_put_u8str(ui8tostr3(progress));
585
+      lcd_put_u8str(ui8tostr3rj(progress));
586
     else
586
     else
587
       lcd_put_u8str_P(PSTR("---"));
587
       lcd_put_u8str_P(PSTR("---"));
588
     lcd_put_wchar('%');
588
     lcd_put_wchar('%');
631
       lcd_put_u8str_P(PSTR("Dia "));
631
       lcd_put_u8str_P(PSTR("Dia "));
632
       lcd_put_u8str(ftostr12ns(filwidth.measured_mm));
632
       lcd_put_u8str(ftostr12ns(filwidth.measured_mm));
633
       lcd_put_u8str_P(PSTR(" V"));
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
       lcd_put_wchar('%');
635
       lcd_put_wchar('%');
636
       return;
636
       return;
637
     }
637
     }
863
     #if LCD_HEIGHT > 3
863
     #if LCD_HEIGHT > 3
864
 
864
 
865
       lcd_put_wchar(0, 2, LCD_STR_FEEDRATE[0]);
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
       lcd_put_wchar('%');
867
       lcd_put_wchar('%');
868
 
868
 
869
       char buffer[14];
869
       char buffer[14];
902
               #endif
902
               #endif
903
             }
903
             }
904
           lcd_put_wchar(c);
904
           lcd_put_wchar(c);
905
-          lcd_put_u8str(i16tostr3(per));
905
+          lcd_put_u8str(i16tostr3rj(per));
906
           lcd_put_wchar('%');
906
           lcd_put_wchar('%');
907
         #endif
907
         #endif
908
       #endif
908
       #endif
941
     #endif
941
     #endif
942
 
942
 
943
     lcd_put_wchar(LCD_WIDTH - 9, 1, LCD_STR_FEEDRATE[0]);
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
     lcd_put_wchar('%');
945
     lcd_put_wchar('%');
946
 
946
 
947
     // ========== Line 3 ==========
947
     // ========== Line 3 ==========
1415
        * Print plot position
1415
        * Print plot position
1416
        */
1416
        */
1417
       lcd_put_wchar(_LCD_W_POS, 0, '(');
1417
       lcd_put_wchar(_LCD_W_POS, 0, '(');
1418
-      lcd_put_u8str(ui8tostr3(x_plot));
1418
+      lcd_put_u8str(ui8tostr3rj(x_plot));
1419
       lcd_put_wchar(',');
1419
       lcd_put_wchar(',');
1420
-      lcd_put_u8str(ui8tostr3(y_plot));
1420
+      lcd_put_u8str(ui8tostr3rj(y_plot));
1421
       lcd_put_wchar(')');
1421
       lcd_put_wchar(')');
1422
 
1422
 
1423
       #if LCD_HEIGHT <= 3   // 16x2 or 20x2 display
1423
       #if LCD_HEIGHT <= 3   // 16x2 or 20x2 display

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

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

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

324
       lcd_put_wchar(LCD_PIXEL_WIDTH - 11 * (MENU_FONT_WIDTH), row_y2, 'E');
324
       lcd_put_wchar(LCD_PIXEL_WIDTH - 11 * (MENU_FONT_WIDTH), row_y2, 'E');
325
       lcd_put_wchar((char)('1' + extruder));
325
       lcd_put_wchar((char)('1' + extruder));
326
       lcd_put_wchar(' ');
326
       lcd_put_wchar(' ');
327
-      lcd_put_u8str(i16tostr3(thermalManager.degHotend(extruder)));
327
+      lcd_put_u8str(i16tostr3rj(thermalManager.degHotend(extruder)));
328
       lcd_put_wchar('/');
328
       lcd_put_wchar('/');
329
 
329
 
330
       if (get_blink() || !thermalManager.hotend_idle[extruder].timed_out)
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
   #endif // ADVANCED_PAUSE_FEATURE
334
   #endif // ADVANCED_PAUSE_FEATURE

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

127
  *
127
  *
128
  * The prerequisite is that in the header the type was already declared:
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
  * For example, DEFINE_MENU_EDIT_ITEM(int3) expands into:
132
  * For example, DEFINE_MENU_EDIT_ITEM(int3) expands into:
133
  *
133
  *
396
   void lcd_babystep_zoffset() {
396
   void lcd_babystep_zoffset() {
397
     if (ui.use_click()) return ui.goto_previous_screen_no_defer();
397
     if (ui.use_click()) return ui.goto_previous_screen_no_defer();
398
     ui.defer_status_screen();
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
     if (ui.encoderPosition) {
400
     if (ui.encoderPosition) {
405
       const int16_t babystep_increment = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR_Z);
401
       const int16_t babystep_increment = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR_Z);
406
       ui.encoderPosition = 0;
402
       ui.encoderPosition = 0;
429
     if (ui.should_draw()) {
425
     if (ui.should_draw()) {
430
       #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
426
       #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
431
         if (!do_probe)
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
       #endif
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
 #endif
48
 #endif
49
 
49
 
50
 #if Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9
50
 #if Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9
51
+  // Only values from -9.999 to 9.999
51
   #define LCD_Z_OFFSET_FUNC(N) ftostr54sign(N)
52
   #define LCD_Z_OFFSET_FUNC(N) ftostr54sign(N)
52
   #define LCD_Z_OFFSET_TYPE float43
53
   #define LCD_Z_OFFSET_TYPE float43
53
 #else
54
 #else
55
+  // Values from -99.99 to 99.99
54
   #define LCD_Z_OFFSET_FUNC(N) ftostr52sign(N)
56
   #define LCD_Z_OFFSET_FUNC(N) ftostr52sign(N)
55
   #define LCD_Z_OFFSET_TYPE float52
57
   #define LCD_Z_OFFSET_TYPE float52
56
 #endif
58
 #endif
266
 // Provide a set of Edit Item Types which encompass a primitive
268
 // Provide a set of Edit Item Types which encompass a primitive
267
 // type, a string function, and a scale factor for edit and display.
269
 // type, a string function, and a scale factor for edit and display.
268
 // These items call the Edit Item draw method passing the prepared string.
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
   struct MenuEditItemInfo_##NAME { \
274
   struct MenuEditItemInfo_##NAME { \
271
     typedef TYPE type_t; \
275
     typedef TYPE type_t; \
272
     static inline float scale(const float value)   { return value * (SCALE) + (V+0); } \
276
     static inline float scale(const float value)   { return value * (SCALE) + (V+0); } \
273
     static inline float unscale(const float value) { return value / (SCALE) + (V+0); } \
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
   typedef TMenuEditItem<MenuEditItemInfo_##NAME> MenuItem_##NAME
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
 class MenuItem_bool : public MenuEditItemBase {
303
 class MenuItem_bool : public MenuEditItemBase {
300
   public:
304
   public:

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

33
 #define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-'))
33
 #define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-'))
34
 
34
 
35
 // Convert a full-range unsigned 8bit int to a percentage
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
   const uint8_t n = ui8_to_percent(i);
37
   const uint8_t n = ui8_to_percent(i);
38
   conv[3] = RJDIGIT(n, 100);
38
   conv[3] = RJDIGIT(n, 100);
39
   conv[4] = RJDIGIT(n, 10);
39
   conv[4] = RJDIGIT(n, 10);
43
 }
43
 }
44
 
44
 
45
 // Convert unsigned 8bit int to string 123 format
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
   conv[4] = RJDIGIT(i, 100);
47
   conv[4] = RJDIGIT(i, 100);
48
   conv[5] = RJDIGIT(i, 10);
48
   conv[5] = RJDIGIT(i, 10);
49
   conv[6] = DIGIMOD(i, 1);
49
   conv[6] = DIGIMOD(i, 1);
51
 }
51
 }
52
 
52
 
53
 // Convert signed 8bit int to rj string with 123 or -12 format
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
   int xx = x;
55
   int xx = x;
56
   conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
56
   conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
57
   conv[5] = RJDIGIT(xx, 10);
57
   conv[5] = RJDIGIT(xx, 10);
88
 #endif
88
 #endif
89
 
89
 
90
 // Convert unsigned 16bit int to string 12345 format
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
   conv[2] = RJDIGIT(xx, 10000);
92
   conv[2] = RJDIGIT(xx, 10000);
93
   conv[3] = RJDIGIT(xx, 1000);
93
   conv[3] = RJDIGIT(xx, 1000);
94
   conv[4] = RJDIGIT(xx, 100);
94
   conv[4] = RJDIGIT(xx, 100);
98
 }
98
 }
99
 
99
 
100
 // Convert unsigned 16bit int to string 1234 format
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
   conv[3] = RJDIGIT(xx, 1000);
102
   conv[3] = RJDIGIT(xx, 1000);
103
   conv[4] = RJDIGIT(xx, 100);
103
   conv[4] = RJDIGIT(xx, 100);
104
   conv[5] = RJDIGIT(xx, 10);
104
   conv[5] = RJDIGIT(xx, 10);
107
 }
107
 }
108
 
108
 
109
 // Convert unsigned 16bit int to string 123 format
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
   conv[4] = RJDIGIT(xx, 100);
111
   conv[4] = RJDIGIT(xx, 100);
112
   conv[5] = RJDIGIT(xx, 10);
112
   conv[5] = RJDIGIT(xx, 10);
113
   conv[6] = DIGIMOD(xx, 1);
113
   conv[6] = DIGIMOD(xx, 1);
115
 }
115
 }
116
 
116
 
117
 // Convert signed 16bit int to rj string with 123 or -12 format
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
   int xx = x;
119
   int xx = x;
120
   conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
120
   conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
121
   conv[5] = RJDIGIT(xx, 10);
121
   conv[5] = RJDIGIT(xx, 10);
136
 }
136
 }
137
 
137
 
138
 // Convert signed 16bit int to rj string with 1234, _123, -123, _-12, or __-1 format
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
   const bool neg = i < 0;
140
   const bool neg = i < 0;
141
   const int ii = neg ? -i : i;
141
   const int ii = neg ? -i : i;
142
   if (i >= 1000) {
142
   if (i >= 1000) {
174
   return &conv[3];
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
 const char* ftostr42_52(const float &f) {
178
 const char* ftostr42_52(const float &f) {
179
   if (f <= -10 || f >= 100) return ftostr52(f); // need more digits
179
   if (f <= -10 || f >= 100) return ftostr52(f); // need more digits
180
   long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
180
   long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
198
   return &conv[1];
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
 #if ENABLED(LCD_DECIMAL_SMALL_XY)
227
 #if ENABLED(LCD_DECIMAL_SMALL_XY)
202
 
228
 
203
   // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
229
   // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
204
   const char* ftostr4sign(const float &f) {
230
   const char* ftostr4sign(const float &f) {
205
     const int i = (f * 100 + (f < 0 ? -5: 5)) / 10;
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
     const bool neg = i < 0;
233
     const bool neg = i < 0;
208
     const int ii = neg ? -i : i;
234
     const int ii = neg ? -i : i;
209
     conv[3] = neg ? '-' : (ii >= 100 ? DIGIMOD(ii, 100) : ' ');
235
     conv[3] = neg ? '-' : (ii >= 100 ? DIGIMOD(ii, 100) : ' ');
255
 // Convert unsigned float to rj string with 12345 format
281
 // Convert unsigned float to rj string with 12345 format
256
 const char* ftostr5rj(const float &f) {
282
 const char* ftostr5rj(const float &f) {
257
   const long i = ((f < 0 ? -f : f) * 10 + 5) / 10;
283
   const long i = ((f < 0 ? -f : f) * 10 + 5) / 10;
258
-  return ui16tostr5(i);
284
+  return ui16tostr5rj(i);
259
 }
285
 }
260
 
286
 
261
 // Convert signed float to string with +1234.5 format
287
 // Convert signed float to string with +1234.5 format
284
   return conv;
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
 const char* ftostr51rj(const float &f) {
314
 const char* ftostr51rj(const float &f) {
289
   const long i = ((f < 0 ? -f : f) * 100 + 5) / 10;
315
   const long i = ((f < 0 ? -f : f) * 100 + 5) / 10;
290
   conv[0] = ' ';
316
   conv[0] = ' ';

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

24
 #include <stdint.h>
24
 #include <stdint.h>
25
 
25
 
26
 // Convert a full-range unsigned 8bit int to a percentage
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
 // Convert uint8_t to string with 123 format
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
 // Convert int8_t to string with 123 format
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
 #if HAS_PRINT_PROGRESS_PERMYRIAD
35
 #if HAS_PRINT_PROGRESS_PERMYRIAD
36
   // Convert 16-bit unsigned permyriad value to percent: 100 / 23 / 23.4 / 3.45
36
   // Convert 16-bit unsigned permyriad value to percent: 100 / 23 / 23.4 / 3.45
38
 #endif
38
 #endif
39
 
39
 
40
 // Convert uint16_t to string with 12345 format
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
 // Convert uint16_t to string with 1234 format
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
 // Convert uint16_t to string with 123 format
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
 // Convert int16_t to string with 123 format
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
 // Convert unsigned int to lj string with 123 format
52
 // Convert unsigned int to lj string with 123 format
53
 const char* i16tostr3left(const int16_t xx);
53
 const char* i16tostr3left(const int16_t xx);
54
 
54
 
55
 // Convert signed int to rj string with _123, -123, _-12, or __-1 format
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
 // Convert unsigned float to string with 1.23 format
58
 // Convert unsigned float to string with 1.23 format
59
 const char* ftostr12ns(const float &x);
59
 const char* ftostr12ns(const float &x);
64
 // Convert signed float to fixed-length string with 023.45 / -23.45 format
64
 // Convert signed float to fixed-length string with 023.45 / -23.45 format
65
 const char* ftostr52(const float &x);
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
 // Convert float to fixed-length string with +123.4 / -123.4 format
73
 // Convert float to fixed-length string with +123.4 / -123.4 format
68
 const char* ftostr41sign(const float &x);
74
 const char* ftostr41sign(const float &x);
69
 
75
 
91
 #include "../core/macros.h"
97
 #include "../core/macros.h"
92
 
98
 
93
 // Convert float to rj string with 123 or -12 format
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
 #include "../inc/MarlinConfigPre.h"
102
 #include "../inc/MarlinConfigPre.h"
97
 
103
 
100
   const char* ftostr4sign(const float &fx);
106
   const char* ftostr4sign(const float &fx);
101
 #else
107
 #else
102
   // Convert float to rj string with 1234, _123, -123, __12, _-12, ___1, or __-1 format
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
 #endif
110
 #endif

Loading…
Cancel
Save