Browse Source

Show more decimals in Display, if possible

_123, -123, _-12, __-1  plus  1234, 12.3, -1.2
Guthenberg 7 years ago
parent
commit
bfb8d3b53e
2 changed files with 26 additions and 2 deletions
  1. 24
    0
      Marlin/utility.cpp
  2. 2
    2
      Marlin/utility.h

+ 24
- 0
Marlin/utility.cpp View File

@@ -129,6 +129,30 @@ void safe_delay(millis_t ms) {
129 129
     return conv;
130 130
   }
131 131
 
132
+  // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
133
+  char *ftostr4sign(const float& fx) { 
134
+    int x = fx * 10, xx = abs(x);
135
+    bool ispos = x >= 0,
136
+         isten = xx >= 100,
137
+         ishun = xx >= 1000;
138
+    if (!isten || (ispos && !ishun)) {
139
+      // 12.3, _1.2, -1.2
140
+      conv[0] = ispos ? (isten ? DIGIMOD(xx, 100) : ' ') : '-';
141
+      conv[1] = DIGIMOD(xx, 10);
142
+      conv[2] = '.';
143
+      conv[3] = DIGIMOD(xx, 1);
144
+    }
145
+    else {
146
+      // 1234, _123, -123, _-12
147
+      conv[0] = ispos ? (xx >= 10000 ? DIGIMOD(xx, 10000) : ' ') : (ishun ? '-' : ' ');
148
+      conv[1] = ishun ? DIGIMOD(xx, 1000) : '-';
149
+      conv[2] = DIGIMOD(xx, 100);
150
+      conv[3] = DIGIMOD(xx, 10);
151
+    }
152
+    conv[4] = '\0';
153
+    return conv;
154
+  }
155
+
132 156
   // Convert float to fixed-length string with +123.4 / -123.4 format
133 157
   char* ftostr41sign(const float& x) {
134 158
     int xx = x * 10;

+ 2
- 2
Marlin/utility.h View File

@@ -69,8 +69,8 @@ void safe_delay(millis_t ms);
69 69
   // Convert float to rj string with 123 or -12 format
70 70
   FORCE_INLINE char *ftostr3(const float& x) { return itostr3((int)x); }
71 71
 
72
-  // Convert float to rj string with _123, -123, _-12, or __-1 format
73
-  FORCE_INLINE char *ftostr4sign(const float& x) { return itostr4sign((int)x); }
72
+  // Convert float to rj string with 1234, _123, 12.3, _1.2, -123, _-12, or -1.2 format
73
+  char *ftostr4sign(const float& fx);
74 74
 
75 75
 #endif // ULTRA_LCD
76 76
 

Loading…
Cancel
Save