Browse Source

Cleanup and naming for num-to-string functions

Scott Lahteine 8 years ago
parent
commit
b23f710034
4 changed files with 161 additions and 182 deletions
  1. 11
    11
      Marlin/dogm_lcd_implementation.h
  2. 133
    152
      Marlin/ultralcd.cpp
  3. 6
    8
      Marlin/ultralcd.h
  4. 11
    11
      Marlin/ultralcd_implementation_hitachi_HD44780.h

+ 11
- 11
Marlin/dogm_lcd_implementation.h View File

413
   u8g.setPrintPos(83, XYZ_BASELINE);
413
   u8g.setPrintPos(83, XYZ_BASELINE);
414
   _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
414
   _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
415
   u8g.setPrintPos(91, XYZ_BASELINE);
415
   u8g.setPrintPos(91, XYZ_BASELINE);
416
-  lcd_print(ftostr32sp(current_position[Z_AXIS] + 0.00001));
416
+  lcd_print(ftostr52sp(current_position[Z_AXIS] + 0.00001));
417
 
417
 
418
   u8g.setColorIndex(1); // black on white
418
   u8g.setColorIndex(1); // black on white
419
 
419
 
500
 #define lcd_implementation_drawmenu_setting_edit_int3(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, itostr3(*(data)))
500
 #define lcd_implementation_drawmenu_setting_edit_int3(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, itostr3(*(data)))
501
 #define lcd_implementation_drawmenu_setting_edit_float3(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr3(*(data)))
501
 #define lcd_implementation_drawmenu_setting_edit_float3(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr3(*(data)))
502
 #define lcd_implementation_drawmenu_setting_edit_float32(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr32(*(data)))
502
 #define lcd_implementation_drawmenu_setting_edit_float32(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr32(*(data)))
503
-#define lcd_implementation_drawmenu_setting_edit_float43(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr43(*(data)))
504
-#define lcd_implementation_drawmenu_setting_edit_float5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5(*(data)))
505
-#define lcd_implementation_drawmenu_setting_edit_float52(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr52(*(data)))
506
-#define lcd_implementation_drawmenu_setting_edit_float51(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr51(*(data)))
507
-#define lcd_implementation_drawmenu_setting_edit_long5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5(*(data)))
503
+#define lcd_implementation_drawmenu_setting_edit_float43(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr43sign(*(data)))
504
+#define lcd_implementation_drawmenu_setting_edit_float5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5rj(*(data)))
505
+#define lcd_implementation_drawmenu_setting_edit_float52(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr52sign(*(data)))
506
+#define lcd_implementation_drawmenu_setting_edit_float51(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr51sign(*(data)))
507
+#define lcd_implementation_drawmenu_setting_edit_long5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5rj(*(data)))
508
 #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
508
 #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
509
 
509
 
510
 //Add version for callback functions
510
 //Add version for callback functions
511
 #define lcd_implementation_drawmenu_setting_edit_callback_int3(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, itostr3(*(data)))
511
 #define lcd_implementation_drawmenu_setting_edit_callback_int3(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, itostr3(*(data)))
512
 #define lcd_implementation_drawmenu_setting_edit_callback_float3(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr3(*(data)))
512
 #define lcd_implementation_drawmenu_setting_edit_callback_float3(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr3(*(data)))
513
 #define lcd_implementation_drawmenu_setting_edit_callback_float32(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr32(*(data)))
513
 #define lcd_implementation_drawmenu_setting_edit_callback_float32(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr32(*(data)))
514
-#define lcd_implementation_drawmenu_setting_edit_callback_float43(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr43(*(data)))
515
-#define lcd_implementation_drawmenu_setting_edit_callback_float5(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5(*(data)))
516
-#define lcd_implementation_drawmenu_setting_edit_callback_float52(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr52(*(data)))
517
-#define lcd_implementation_drawmenu_setting_edit_callback_float51(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr51(*(data)))
518
-#define lcd_implementation_drawmenu_setting_edit_callback_long5(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5(*(data)))
514
+#define lcd_implementation_drawmenu_setting_edit_callback_float43(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr43sign(*(data)))
515
+#define lcd_implementation_drawmenu_setting_edit_callback_float5(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5rj(*(data)))
516
+#define lcd_implementation_drawmenu_setting_edit_callback_float52(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr52sign(*(data)))
517
+#define lcd_implementation_drawmenu_setting_edit_callback_float51(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr51sign(*(data)))
518
+#define lcd_implementation_drawmenu_setting_edit_callback_long5(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5rj(*(data)))
519
 #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
519
 #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
520
 
520
 
521
 void lcd_implementation_drawedit(const char* pstr, const char* value=NULL) {
521
 void lcd_implementation_drawedit(const char* pstr, const char* value=NULL) {

+ 133
- 152
Marlin/ultralcd.cpp View File

995
     // Show message above on clicks instead
995
     // Show message above on clicks instead
996
     if (lcdDrawUpdate) {
996
     if (lcdDrawUpdate) {
997
       float v = current_position[Z_AXIS] - MESH_HOME_SEARCH_Z;
997
       float v = current_position[Z_AXIS] - MESH_HOME_SEARCH_Z;
998
-      lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43(v + (v < 0 ? -0.0001 : 0.0001), '+'));
998
+      lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
999
     }
999
     }
1000
 
1000
 
1001
   }
1001
   }
1237
     manual_move_to_current(axis);
1237
     manual_move_to_current(axis);
1238
     lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1238
     lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1239
   }
1239
   }
1240
-  if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
1240
+  if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis]));
1241
   if (LCD_CLICKED) lcd_goto_previous_menu(true);
1241
   if (LCD_CLICKED) lcd_goto_previous_menu(true);
1242
 }
1242
 }
1243
 #if ENABLED(DELTA)
1243
 #if ENABLED(DELTA)
1282
         #endif //EXTRUDERS > 2
1282
         #endif //EXTRUDERS > 2
1283
       }
1283
       }
1284
     #endif //EXTRUDERS > 1
1284
     #endif //EXTRUDERS > 1
1285
-    lcd_implementation_drawedit(pos_label, ftostr31(current_position[E_AXIS]));
1285
+    lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
1286
   }
1286
   }
1287
   if (LCD_CLICKED) lcd_goto_previous_menu(true);
1287
   if (LCD_CLICKED) lcd_goto_previous_menu(true);
1288
   #if EXTRUDERS > 1
1288
   #if EXTRUDERS > 1
1913
 menu_edit_type(int, int3, itostr3, 1);
1913
 menu_edit_type(int, int3, itostr3, 1);
1914
 menu_edit_type(float, float3, ftostr3, 1);
1914
 menu_edit_type(float, float3, ftostr3, 1);
1915
 menu_edit_type(float, float32, ftostr32, 100);
1915
 menu_edit_type(float, float32, ftostr32, 100);
1916
-menu_edit_type(float, float43, ftostr43, 1000);
1917
-menu_edit_type(float, float5, ftostr5, 0.01);
1918
-menu_edit_type(float, float51, ftostr51, 10);
1919
-menu_edit_type(float, float52, ftostr52, 100);
1920
-menu_edit_type(unsigned long, long5, ftostr5, 0.01);
1916
+menu_edit_type(float, float43, ftostr43sign, 1000);
1917
+menu_edit_type(float, float5, ftostr5rj, 0.01);
1918
+menu_edit_type(float, float51, ftostr51sign, 10);
1919
+menu_edit_type(float, float52, ftostr52sign, 100);
1920
+menu_edit_type(unsigned long, long5, ftostr5rj, 0.01);
1921
 
1921
 
1922
 /**
1922
 /**
1923
  *
1923
  *
2382
     i++;
2382
     i++;
2383
   }
2383
   }
2384
   while (j++ < n) s[i++] = ' ';
2384
   while (j++ < n) s[i++] = ' ';
2385
-  s[i] = 0;
2385
+  s[i] = '\0';
2386
 }
2386
 }
2387
 
2387
 
2388
 bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
2388
 bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
2556
 /** Number to string conversion **/
2556
 /** Number to string conversion **/
2557
 /*********************************/
2557
 /*********************************/
2558
 
2558
 
2559
+#define DIGIT(n) ('0' + (n))
2560
+#define DIGIMOD(n) DIGIT((n) % 10)
2561
+
2559
 char conv[8];
2562
 char conv[8];
2560
 
2563
 
2561
 // Convert float to rj string with 123 or -12 format
2564
 // Convert float to rj string with 123 or -12 format
2568
 char* itostr2(const uint8_t& x) {
2571
 char* itostr2(const uint8_t& x) {
2569
   //sprintf(conv,"%5.1f",x);
2572
   //sprintf(conv,"%5.1f",x);
2570
   int xx = x;
2573
   int xx = x;
2571
-  conv[0] = (xx / 10) % 10 + '0';
2572
-  conv[1] = xx % 10 + '0';
2573
-  conv[2] = 0;
2574
+  conv[0] = DIGIMOD(xx / 10);
2575
+  conv[1] = DIGIMOD(xx);
2576
+  conv[2] = '\0';
2574
   return conv;
2577
   return conv;
2575
 }
2578
 }
2576
 
2579
 
2577
 // Convert float to string with +123.4 / -123.4 format
2580
 // Convert float to string with +123.4 / -123.4 format
2578
-char* ftostr31(const float& x) {
2579
-  int xx = abs(x * 10);
2580
-  conv[0] = (x >= 0) ? '+' : '-';
2581
-  conv[1] = (xx / 1000) % 10 + '0';
2582
-  conv[2] = (xx / 100) % 10 + '0';
2583
-  conv[3] = (xx / 10) % 10 + '0';
2581
+char* ftostr41sign(const float& x) {
2582
+  int xx = int(abs(x * 10)) % 10000;
2583
+  conv[0] = x >= 0 ? '+' : '-';
2584
+  conv[1] = DIGIMOD(xx / 1000);
2585
+  conv[2] = DIGIMOD(xx / 100);
2586
+  conv[3] = DIGIMOD(xx / 10);
2584
   conv[4] = '.';
2587
   conv[4] = '.';
2585
-  conv[5] = xx % 10 + '0';
2586
-  conv[6] = 0;
2587
-  return conv;
2588
-}
2589
-
2590
-// Convert unsigned float to string with 123.4 format, dropping sign
2591
-char* ftostr31ns(const float& x) {
2592
-  int xx = abs(x * 10);
2593
-  conv[0] = (xx / 1000) % 10 + '0';
2594
-  conv[1] = (xx / 100) % 10 + '0';
2595
-  conv[2] = (xx / 10) % 10 + '0';
2596
-  conv[3] = '.';
2597
-  conv[4] = xx % 10 + '0';
2598
-  conv[5] = 0;
2588
+  conv[5] = DIGIMOD(xx);
2589
+  conv[6] = '\0';
2599
   return conv;
2590
   return conv;
2600
 }
2591
 }
2601
 
2592
 
2602
 // Convert signed float to string with 023.45 / -23.45 format
2593
 // Convert signed float to string with 023.45 / -23.45 format
2603
 char *ftostr32(const float& x) {
2594
 char *ftostr32(const float& x) {
2604
   long xx = abs(x * 100);
2595
   long xx = abs(x * 100);
2605
-  conv[0] = x >= 0 ? (xx / 10000) % 10 + '0' : '-';
2606
-  conv[1] = (xx / 1000) % 10 + '0';
2607
-  conv[2] = (xx / 100) % 10 + '0';
2596
+  conv[0] = x >= 0 ? DIGIMOD(xx / 10000) : '-';
2597
+  conv[1] = DIGIMOD(xx / 1000);
2598
+  conv[2] = DIGIMOD(xx / 100);
2608
   conv[3] = '.';
2599
   conv[3] = '.';
2609
-  conv[4] = (xx / 10) % 10 + '0';
2610
-  conv[5] = xx % 10 + '0';
2611
-  conv[6] = 0;
2600
+  conv[4] = DIGIMOD(xx / 10);
2601
+  conv[5] = DIGIMOD(xx);
2602
+  conv[6] = '\0';
2612
   return conv;
2603
   return conv;
2613
 }
2604
 }
2614
 
2605
 
2615
 // Convert signed float to string (6 digit) with -1.234 / _0.000 / +1.234 format
2606
 // Convert signed float to string (6 digit) with -1.234 / _0.000 / +1.234 format
2616
-char* ftostr43(const float& x, char plus/*=' '*/) {
2607
+char* ftostr43sign(const float& x, char plus/*=' '*/) {
2617
   long xx = x * 1000;
2608
   long xx = x * 1000;
2618
   if (xx == 0)
2609
   if (xx == 0)
2619
     conv[0] = ' ';
2610
     conv[0] = ' ';
2623
     xx = -xx;
2614
     xx = -xx;
2624
     conv[0] = '-';
2615
     conv[0] = '-';
2625
   }
2616
   }
2626
-  conv[1] = (xx / 1000) % 10 + '0';
2617
+  conv[1] = DIGIMOD(xx / 1000);
2627
   conv[2] = '.';
2618
   conv[2] = '.';
2628
-  conv[3] = (xx / 100) % 10 + '0';
2629
-  conv[4] = (xx / 10) % 10 + '0';
2630
-  conv[5] = (xx) % 10 + '0';
2631
-  conv[6] = 0;
2619
+  conv[3] = DIGIMOD(xx / 100);
2620
+  conv[4] = DIGIMOD(xx / 10);
2621
+  conv[5] = DIGIMOD(xx);
2622
+  conv[6] = '\0';
2632
   return conv;
2623
   return conv;
2633
 }
2624
 }
2634
 
2625
 
2636
 char* ftostr12ns(const float& x) {
2627
 char* ftostr12ns(const float& x) {
2637
   long xx = x * 100;
2628
   long xx = x * 100;
2638
   xx = abs(xx);
2629
   xx = abs(xx);
2639
-  conv[0] = (xx / 100) % 10 + '0';
2630
+  conv[0] = DIGIMOD(xx / 100);
2640
   conv[1] = '.';
2631
   conv[1] = '.';
2641
-  conv[2] = (xx / 10) % 10 + '0';
2642
-  conv[3] = (xx) % 10 + '0';
2643
-  conv[4] = 0;
2644
-  return conv;
2645
-}
2646
-
2647
-// Convert signed float to space-padded string with -_23.4_ format
2648
-char* ftostr32sp(const float& x) {
2649
-  long xx = x * 100;
2650
-  uint8_t dig;
2651
-  if (xx < 0) { // negative val = -_0
2652
-    xx = -xx;
2653
-    conv[0] = '-';
2654
-    dig = (xx / 1000) % 10;
2655
-    conv[1] = dig ? '0' + dig : ' ';
2656
-  }
2657
-  else { // positive val = __0
2658
-    dig = (xx / 10000) % 10;
2659
-    if (dig) {
2660
-      conv[0] = '0' + dig;
2661
-      conv[1] = '0' + (xx / 1000) % 10;
2662
-    }
2663
-    else {
2664
-      conv[0] = ' ';
2665
-      dig = (xx / 1000) % 10;
2666
-      conv[1] = dig ? '0' + dig : ' ';
2667
-    }
2668
-  }
2669
-
2670
-  conv[2] = '0' + (xx / 100) % 10; // lsd always
2671
-
2672
-  dig = xx % 10;
2673
-  if (dig) { // 2 decimal places
2674
-    conv[5] = '0' + dig;
2675
-    conv[4] = '0' + (xx / 10) % 10;
2676
-    conv[3] = '.';
2677
-  }
2678
-  else { // 1 or 0 decimal place
2679
-    dig = (xx / 10) % 10;
2680
-    if (dig) {
2681
-      conv[4] = '0' + dig;
2682
-      conv[3] = '.';
2683
-    }
2684
-    else {
2685
-      conv[3] = conv[4] = ' ';
2686
-    }
2687
-    conv[5] = ' ';
2688
-  }
2689
-  conv[6] = '\0';
2632
+  conv[2] = DIGIMOD(xx / 10);
2633
+  conv[3] = DIGIMOD(xx);
2634
+  conv[4] = '\0';
2690
   return conv;
2635
   return conv;
2691
 }
2636
 }
2692
 
2637
 
2701
     conv[0] = '-';
2646
     conv[0] = '-';
2702
     xx = -x;
2647
     xx = -x;
2703
   }
2648
   }
2704
-  conv[1] = (xx / 100) % 10 + '0';
2705
-  conv[2] = (xx / 10) % 10 + '0';
2706
-  conv[3] = xx % 10 + '0';
2649
+  conv[1] = DIGIMOD(xx / 100);
2650
+  conv[2] = DIGIMOD(xx / 10);
2651
+  conv[3] = DIGIMOD(xx);
2707
   conv[4] = '.';
2652
   conv[4] = '.';
2708
   conv[5] = '0';
2653
   conv[5] = '0';
2709
-  conv[6] = 0;
2654
+  conv[6] = '\0';
2710
   return conv;
2655
   return conv;
2711
 }
2656
 }
2712
 
2657
 
2718
     xx = -xx;
2663
     xx = -xx;
2719
   }
2664
   }
2720
   else
2665
   else
2721
-    conv[0] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
2666
+    conv[0] = xx >= 100 ? DIGIMOD(xx / 100) : ' ';
2722
 
2667
 
2723
-  conv[1] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
2724
-  conv[2] = xx % 10 + '0';
2725
-  conv[3] = 0;
2668
+  conv[1] = xx >= 10 ? DIGIMOD(xx / 10) : ' ';
2669
+  conv[2] = DIGIMOD(xx);
2670
+  conv[3] = '\0';
2726
   return conv;
2671
   return conv;
2727
 }
2672
 }
2728
 
2673
 
2729
 // Convert unsigned int to lj string with 123 format
2674
 // Convert unsigned int to lj string with 123 format
2730
-char* itostr3left(const int& x) {
2731
-  if (x >= 100) {
2732
-    conv[0] = (x / 100) % 10 + '0';
2733
-    conv[1] = (x / 10) % 10 + '0';
2734
-    conv[2] = x % 10 + '0';
2735
-    conv[3] = 0;
2736
-  }
2737
-  else if (x >= 10) {
2738
-    conv[0] = (x / 10) % 10 + '0';
2739
-    conv[1] = x % 10 + '0';
2740
-    conv[2] = 0;
2675
+char* itostr3left(const int& xx) {
2676
+  if (xx >= 100) {
2677
+    conv[0] = DIGIMOD(xx / 100);
2678
+    conv[1] = DIGIMOD(xx / 10);
2679
+    conv[2] = DIGIMOD(xx);
2680
+    conv[3] = '\0';
2681
+  }
2682
+  else if (xx >= 10) {
2683
+    conv[0] = DIGIMOD(xx / 10);
2684
+    conv[1] = DIGIMOD(xx);
2685
+    conv[2] = '\0';
2741
   }
2686
   }
2742
   else {
2687
   else {
2743
-    conv[0] = x % 10 + '0';
2744
-    conv[1] = 0;
2688
+    conv[0] = DIGIMOD(xx);
2689
+    conv[1] = '\0';
2745
   }
2690
   }
2746
   return conv;
2691
   return conv;
2747
 }
2692
 }
2748
 
2693
 
2749
-// Convert unsigned int to rj string with 1234 format
2750
-char* itostr4(const int& x) {
2751
-  conv[0] = x >= 1000 ? (x / 1000) % 10 + '0' : ' ';
2752
-  conv[1] = x >= 100 ? (x / 100) % 10 + '0' : ' ';
2753
-  conv[2] = x >= 10 ? (x / 10) % 10 + '0' : ' ';
2754
-  conv[3] = x % 10 + '0';
2755
-  conv[4] = 0;
2756
-  return conv;
2757
-}
2758
-
2759
 // Convert signed int to rj string with _123, -123, _-12, or __-1 format
2694
 // Convert signed int to rj string with _123, -123, _-12, or __-1 format
2760
 char *itostr4sign(const int& x) {
2695
 char *itostr4sign(const int& x) {
2761
   int xx = abs(x);
2696
   int xx = abs(x);
2762
   int sign = 0;
2697
   int sign = 0;
2763
   if (xx >= 100) {
2698
   if (xx >= 100) {
2764
-    conv[1] = (xx / 100) % 10 + '0';
2765
-    conv[2] = (xx / 10) % 10 + '0';
2699
+    conv[1] = DIGIMOD(xx / 100);
2700
+    conv[2] = DIGIMOD(xx / 10);
2766
   }
2701
   }
2767
   else if (xx >= 10) {
2702
   else if (xx >= 10) {
2768
     conv[0] = ' ';
2703
     conv[0] = ' ';
2769
     sign = 1;
2704
     sign = 1;
2770
-    conv[2] = (xx / 10) % 10 + '0';
2705
+    conv[2] = DIGIMOD(xx / 10);
2771
   }
2706
   }
2772
   else {
2707
   else {
2773
     conv[0] = ' ';
2708
     conv[0] = ' ';
2775
     sign = 2;
2710
     sign = 2;
2776
   }
2711
   }
2777
   conv[sign] = x < 0 ? '-' : ' ';
2712
   conv[sign] = x < 0 ? '-' : ' ';
2778
-  conv[3] = xx % 10 + '0';
2779
-  conv[4] = 0;
2713
+  conv[3] = DIGIMOD(xx);
2714
+  conv[4] = '\0';
2780
   return conv;
2715
   return conv;
2781
 }
2716
 }
2782
 
2717
 
2783
 // Convert unsigned float to rj string with 12345 format
2718
 // Convert unsigned float to rj string with 12345 format
2784
-char* ftostr5(const float& x) {
2719
+char* ftostr5rj(const float& x) {
2785
   long xx = abs(x);
2720
   long xx = abs(x);
2786
-  conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
2787
-  conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
2788
-  conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
2789
-  conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
2790
-  conv[4] = xx % 10 + '0';
2791
-  conv[5] = 0;
2721
+  conv[0] = xx >= 10000 ? DIGIMOD(xx / 10000) : ' ';
2722
+  conv[1] = xx >= 1000 ? DIGIMOD(xx / 1000) : ' ';
2723
+  conv[2] = xx >= 100 ? DIGIMOD(xx / 100) : ' ';
2724
+  conv[3] = xx >= 10 ? DIGIMOD(xx / 10) : ' ';
2725
+  conv[4] = DIGIMOD(xx);
2726
+  conv[5] = '\0';
2792
   return conv;
2727
   return conv;
2793
 }
2728
 }
2794
 
2729
 
2795
 // Convert signed float to string with +1234.5 format
2730
 // Convert signed float to string with +1234.5 format
2796
-char* ftostr51(const float& x) {
2731
+char* ftostr51sign(const float& x) {
2797
   long xx = abs(x * 10);
2732
   long xx = abs(x * 10);
2798
   conv[0] = (x >= 0) ? '+' : '-';
2733
   conv[0] = (x >= 0) ? '+' : '-';
2799
-  conv[1] = (xx / 10000) % 10 + '0';
2800
-  conv[2] = (xx / 1000) % 10 + '0';
2801
-  conv[3] = (xx / 100) % 10 + '0';
2802
-  conv[4] = (xx / 10) % 10 + '0';
2734
+  conv[1] = DIGIMOD(xx / 10000);
2735
+  conv[2] = DIGIMOD(xx / 1000);
2736
+  conv[3] = DIGIMOD(xx / 100);
2737
+  conv[4] = DIGIMOD(xx / 10);
2803
   conv[5] = '.';
2738
   conv[5] = '.';
2804
-  conv[6] = xx % 10 + '0';
2805
-  conv[7] = 0;
2739
+  conv[6] = DIGIMOD(xx);
2740
+  conv[7] = '\0';
2806
   return conv;
2741
   return conv;
2807
 }
2742
 }
2808
 
2743
 
2809
 // Convert signed float to string with +123.45 format
2744
 // Convert signed float to string with +123.45 format
2810
-char* ftostr52(const float& x) {
2811
-  conv[0] = (x >= 0) ? '+' : '-';
2745
+char* ftostr52sign(const float& x) {
2812
   long xx = abs(x * 100);
2746
   long xx = abs(x * 100);
2813
-  conv[1] = (xx / 10000) % 10 + '0';
2814
-  conv[2] = (xx / 1000) % 10 + '0';
2815
-  conv[3] = (xx / 100) % 10 + '0';
2747
+  conv[0] = (x >= 0) ? '+' : '-';
2748
+  conv[1] = DIGIMOD(xx / 10000);
2749
+  conv[2] = DIGIMOD(xx / 1000);
2750
+  conv[3] = DIGIMOD(xx / 100);
2816
   conv[4] = '.';
2751
   conv[4] = '.';
2817
-  conv[5] = (xx / 10) % 10 + '0';
2818
-  conv[6] = xx % 10 + '0';
2819
-  conv[7] = 0;
2752
+  conv[5] = DIGIMOD(xx / 10);
2753
+  conv[6] = DIGIMOD(xx);
2754
+  conv[7] = '\0';
2755
+  return conv;
2756
+}
2757
+
2758
+// Convert signed float to space-padded string with -_23.4_ format
2759
+char* ftostr52sp(const float& x) {
2760
+  long xx = x * 100;
2761
+  uint8_t dig;
2762
+  if (xx < 0) { // negative val = -_0
2763
+    xx = -xx;
2764
+    conv[0] = '-';
2765
+    dig = (xx / 1000) % 10;
2766
+    conv[1] = dig ? DIGIT(dig) : ' ';
2767
+  }
2768
+  else { // positive val = __0
2769
+    dig = (xx / 10000) % 10;
2770
+    if (dig) {
2771
+      conv[0] = DIGIT(dig);
2772
+      conv[1] = DIGIMOD(xx / 1000);
2773
+    }
2774
+    else {
2775
+      conv[0] = ' ';
2776
+      dig = (xx / 1000) % 10;
2777
+      conv[1] = dig ? DIGIT(dig) : ' ';
2778
+    }
2779
+  }
2780
+
2781
+  conv[2] = DIGIMOD(xx / 100); // lsd always
2782
+
2783
+  dig = xx % 10;
2784
+  if (dig) { // 2 decimal places
2785
+    conv[5] = DIGIT(dig);
2786
+    conv[4] = DIGIMOD(xx / 10);
2787
+    conv[3] = '.';
2788
+  }
2789
+  else { // 1 or 0 decimal place
2790
+    dig = (xx / 10) % 10;
2791
+    if (dig) {
2792
+      conv[4] = DIGIT(dig);
2793
+      conv[3] = '.';
2794
+    }
2795
+    else {
2796
+      conv[3] = conv[4] = ' ';
2797
+    }
2798
+    conv[5] = ' ';
2799
+  }
2800
+  conv[6] = '\0';
2820
   return conv;
2801
   return conv;
2821
 }
2802
 }
2822
 
2803
 

+ 6
- 8
Marlin/ultralcd.h View File

165
 char* itostr3sign(const int& x);
165
 char* itostr3sign(const int& x);
166
 char* itostr3(const int& x);
166
 char* itostr3(const int& x);
167
 char* itostr3left(const int& x);
167
 char* itostr3left(const int& x);
168
-char* itostr4(const int& x);
169
 char* itostr4sign(const int& x);
168
 char* itostr4sign(const int& x);
170
 
169
 
171
 char* ftostr3(const float& x);
170
 char* ftostr3(const float& x);
172
 char* ftostr4sign(const float& x);
171
 char* ftostr4sign(const float& x);
173
-char* ftostr31ns(const float& x); // float to string without sign character
174
-char* ftostr31(const float& x);
172
+char* ftostr41sign(const float& x);
175
 char* ftostr32(const float& x);
173
 char* ftostr32(const float& x);
176
-char* ftostr43(const float& x, char plus=' ');
174
+char* ftostr43sign(const float& x, char plus=' ');
177
 char* ftostr12ns(const float& x);
175
 char* ftostr12ns(const float& x);
178
-char* ftostr32sp(const float& x); // remove zero-padding from ftostr32
179
-char* ftostr5(const float& x);
180
-char* ftostr51(const float& x);
181
-char* ftostr52(const float& x);
176
+char* ftostr5rj(const float& x);
177
+char* ftostr51sign(const float& x);
178
+char* ftostr52sign(const float& x);
179
+char* ftostr52sp(const float& x); // remove zero-padding from ftostr32
182
 
180
 
183
 #endif //ULTRALCD_H
181
 #endif //ULTRALCD_H

+ 11
- 11
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

723
 
723
 
724
     lcd.setCursor(LCD_WIDTH - 8, 1);
724
     lcd.setCursor(LCD_WIDTH - 8, 1);
725
     _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
725
     _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
726
-    lcd.print(ftostr32sp(current_position[Z_AXIS] + 0.00001));
726
+    lcd.print(ftostr52sp(current_position[Z_AXIS] + 0.00001));
727
 
727
 
728
   #endif // LCD_HEIGHT > 2
728
   #endif // LCD_HEIGHT > 2
729
 
729
 
855
 #define lcd_implementation_drawmenu_setting_edit_int3(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', itostr3(*(data)))
855
 #define lcd_implementation_drawmenu_setting_edit_int3(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', itostr3(*(data)))
856
 #define lcd_implementation_drawmenu_setting_edit_float3(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr3(*(data)))
856
 #define lcd_implementation_drawmenu_setting_edit_float3(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr3(*(data)))
857
 #define lcd_implementation_drawmenu_setting_edit_float32(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr32(*(data)))
857
 #define lcd_implementation_drawmenu_setting_edit_float32(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr32(*(data)))
858
-#define lcd_implementation_drawmenu_setting_edit_float43(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr43(*(data)))
859
-#define lcd_implementation_drawmenu_setting_edit_float5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr5(*(data)))
860
-#define lcd_implementation_drawmenu_setting_edit_float52(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr52(*(data)))
861
-#define lcd_implementation_drawmenu_setting_edit_float51(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr51(*(data)))
862
-#define lcd_implementation_drawmenu_setting_edit_long5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr5(*(data)))
858
+#define lcd_implementation_drawmenu_setting_edit_float43(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr43sign(*(data)))
859
+#define lcd_implementation_drawmenu_setting_edit_float5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr5rj(*(data)))
860
+#define lcd_implementation_drawmenu_setting_edit_float52(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr52sign(*(data)))
861
+#define lcd_implementation_drawmenu_setting_edit_float51(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr51sign(*(data)))
862
+#define lcd_implementation_drawmenu_setting_edit_long5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr5rj(*(data)))
863
 #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
863
 #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
864
 
864
 
865
 //Add version for callback functions
865
 //Add version for callback functions
866
 #define lcd_implementation_drawmenu_setting_edit_callback_int3(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', itostr3(*(data)))
866
 #define lcd_implementation_drawmenu_setting_edit_callback_int3(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', itostr3(*(data)))
867
 #define lcd_implementation_drawmenu_setting_edit_callback_float3(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr3(*(data)))
867
 #define lcd_implementation_drawmenu_setting_edit_callback_float3(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr3(*(data)))
868
 #define lcd_implementation_drawmenu_setting_edit_callback_float32(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr32(*(data)))
868
 #define lcd_implementation_drawmenu_setting_edit_callback_float32(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr32(*(data)))
869
-#define lcd_implementation_drawmenu_setting_edit_callback_float43(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr43(*(data)))
870
-#define lcd_implementation_drawmenu_setting_edit_callback_float5(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr5(*(data)))
871
-#define lcd_implementation_drawmenu_setting_edit_callback_float52(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr52(*(data)))
872
-#define lcd_implementation_drawmenu_setting_edit_callback_float51(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr51(*(data)))
873
-#define lcd_implementation_drawmenu_setting_edit_callback_long5(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr5(*(data)))
869
+#define lcd_implementation_drawmenu_setting_edit_callback_float43(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr43sign(*(data)))
870
+#define lcd_implementation_drawmenu_setting_edit_callback_float5(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr5rj(*(data)))
871
+#define lcd_implementation_drawmenu_setting_edit_callback_float52(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr52sign(*(data)))
872
+#define lcd_implementation_drawmenu_setting_edit_callback_float51(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr51sign(*(data)))
873
+#define lcd_implementation_drawmenu_setting_edit_callback_long5(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', ftostr5rj(*(data)))
874
 #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
874
 #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
875
 
875
 
876
 void lcd_implementation_drawedit(const char* pstr, const char* value=NULL) {
876
 void lcd_implementation_drawedit(const char* pstr, const char* value=NULL) {

Loading…
Cancel
Save