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
 
1882
 
1883
 char conv[8];
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
 // Convert int to string with 12 format
1891
 // Convert int to string with 12 format
1891
 char* itostr2(const uint8_t& x) {
1892
 char* itostr2(const uint8_t& x) {
1922
   return conv;
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
   long xx = abs(x * 100);
1928
   long xx = abs(x * 100);
1928
   conv[0] = x >= 0 ? (xx / 10000) % 10 + '0' : '-';
1929
   conv[0] = x >= 0 ? (xx / 10000) % 10 + '0' : '-';
1929
   conv[1] = (xx / 1000) % 10 + '0';
1930
   conv[1] = (xx / 1000) % 10 + '0';
2067
   return conv;
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
 // Convert float to rj string with 12345 format
2095
 // Convert float to rj string with 12345 format
2071
 char* ftostr5(const float& x) {
2096
 char* ftostr5(const float& x) {
2072
   long xx = abs(x);
2097
   long xx = abs(x);

+ 2
- 0
Marlin/ultralcd.h View File

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

+ 9
- 9
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

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

Loading…
Cancel
Save