Browse Source

Change XY formatting on LCD (PR#2740)

According to #123 negative values for XY at or below -100 are displaying incorrectly, dropping the first digit. Deltas can easily have XY values in this range. This PR adds a function to display floats/ints formatted like `_123`, `-123`, `_-12`, or `__-1` as appropriate and applies it to the XY coordinates on Hitachi displays. It also moves the Z value to the right to be consistent with the XY formatting.
AnHardt 9 years ago
parent
commit
be7167ed97
3 changed files with 42 additions and 15 deletions
  1. 31
    6
      Marlin/ultralcd.cpp
  2. 2
    0
      Marlin/ultralcd.h
  3. 9
    9
      Marlin/ultralcd_implementation_hitachi_HD44780.h

+ 31
- 6
Marlin/ultralcd.cpp View File

@@ -1882,10 +1882,11 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
1882 1882
 
1883 1883
 char conv[8];
1884 1884
 
1885
-// Convert float to string with +123.4 format
1886
-char* ftostr3(const float& x) {
1887
-  return itostr3((int)x);
1888
-}
1885
+// Convert float to rj string with 123 or -12 format
1886
+char *ftostr3(const float& x) { return itostr3((int)x); }
1887
+
1888
+// Convert float to rj string with _123, -123, _-12, or __-1 format
1889
+char *ftostr4sign(const float& x) { return itostr4sign((int)x); }
1889 1890
 
1890 1891
 // Convert int to string with 12 format
1891 1892
 char* itostr2(const uint8_t& x) {
@@ -1922,8 +1923,8 @@ char* ftostr31ns(const float& x) {
1922 1923
   return conv;
1923 1924
 }
1924 1925
 
1925
-// Convert float to string with 123.4 format
1926
-char* ftostr32(const float& x) {
1926
+// Convert float to string with 123.45 format
1927
+char *ftostr32(const float& x) {
1927 1928
   long xx = abs(x * 100);
1928 1929
   conv[0] = x >= 0 ? (xx / 10000) % 10 + '0' : '-';
1929 1930
   conv[1] = (xx / 1000) % 10 + '0';
@@ -2067,6 +2068,30 @@ char* itostr4(const int& xx) {
2067 2068
   return conv;
2068 2069
 }
2069 2070
 
2071
+// Convert int to rj string with _123, -123, _-12, or __-1 format
2072
+char *itostr4sign(const int& x) {
2073
+  int xx = abs(x);
2074
+  int sign = 0;
2075
+  if (xx >= 100) {
2076
+    conv[1] = (xx / 100) % 10 + '0';
2077
+    conv[2] = (xx / 10) % 10 + '0';
2078
+  }
2079
+  else if (xx >= 10) {
2080
+    conv[0] = ' ';
2081
+    sign = 1;
2082
+    conv[2] = (xx / 10) % 10 + '0';
2083
+  }
2084
+  else {
2085
+    conv[0] = ' ';
2086
+    conv[1] = ' ';
2087
+    sign = 2;
2088
+  }
2089
+  conv[sign] = x < 0 ? '-' : ' ';
2090
+  conv[3] = xx % 10 + '0';
2091
+  conv[4] = 0;
2092
+  return conv;
2093
+}
2094
+
2070 2095
 // Convert float to rj string with 12345 format
2071 2096
 char* ftostr5(const float& x) {
2072 2097
   long xx = abs(x);

+ 2
- 0
Marlin/ultralcd.h View File

@@ -121,8 +121,10 @@ char* itostr31(const int& xx);
121 121
 char* itostr3(const int& xx);
122 122
 char* itostr3left(const int& xx);
123 123
 char* itostr4(const int& xx);
124
+char* itostr4sign(const int& x);
124 125
 
125 126
 char* ftostr3(const float& x);
127
+char* ftostr4sign(const float& x);
126 128
 char* ftostr31ns(const float& x); // float to string without sign character
127 129
 char* ftostr31(const float& x);
128 130
 char* ftostr32(const float& x);

+ 9
- 9
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

@@ -504,7 +504,7 @@ Possible status screens:
504 504
        |0123456789012345|
505 505
 
506 506
 16x4   |000/000 B000/000|
507
-       |SD100%  Z000.00 |
507
+       |SD100%  Z 000.00|
508 508
        |F100%     T--:--|
509 509
        |0123456789012345|
510 510
 
@@ -512,12 +512,12 @@ Possible status screens:
512 512
        |01234567890123456789|
513 513
 
514 514
 20x4   |T000/000D B000/000D |
515
-       |X000  Y000  Z000.00 |
515
+       |X 000 Y 000 Z 000.00|
516 516
        |F100%  SD100% T--:--|
517 517
        |01234567890123456789|
518 518
 
519 519
 20x4   |T000/000D B000/000D |
520
-       |T000/000D   Z000.00 |
520
+       |T000/000D   Z 000.00|
521 521
        |F100%  SD100% T--:--|
522 522
        |01234567890123456789|
523 523
 */
@@ -618,22 +618,22 @@ static void lcd_implementation_status_screen() {
618 618
 
619 619
         lcd.print('X');
620 620
         if (axis_known_position[X_AXIS])
621
-          lcd.print(ftostr3(current_position[X_AXIS]));
621
+          lcd.print(ftostr4sign(current_position[X_AXIS]));
622 622
         else
623
-          lcd_printPGM(PSTR("---"));
623
+          lcd_printPGM(PSTR(" ---"));
624 624
 
625
-        lcd_printPGM(PSTR("  Y"));
625
+        lcd_printPGM(PSTR(" Y"));
626 626
         if (axis_known_position[Y_AXIS])
627
-          lcd.print(ftostr3(current_position[Y_AXIS]));
627
+          lcd.print(ftostr4sign(current_position[Y_AXIS]));
628 628
         else
629
-          lcd_printPGM(PSTR("---"));
629
+          lcd_printPGM(PSTR(" ---"));
630 630
 
631 631
       #endif // EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
632 632
 
633 633
     #endif // LCD_WIDTH >= 20
634 634
 
635 635
     lcd.setCursor(LCD_WIDTH - 8, 1);
636
-    lcd.print('Z');
636
+    lcd_printPGM(PSTR("Z "));
637 637
     if (axis_known_position[Z_AXIS])
638 638
       lcd.print(ftostr32sp(current_position[Z_AXIS] + 0.00001));
639 639
     else

Loading…
Cancel
Save