Browse Source

Least stack-usage self-contained ftostr32np()

This is the optimal code for a self-contained formatter, although the
original code is crafty in being smaller and simpler, and can be
evaluated as using the original output as a scratch pad for state,
making the final formatter more straightforward. While this code is
longer, all code-paths are minimal.
Scott Lahteine 10 years ago
parent
commit
10e1b6ef8b
1 changed files with 1 additions and 15 deletions
  1. 1
    15
      Marlin/ultralcd.cpp

+ 1
- 15
Marlin/ultralcd.cpp View File

1498
 
1498
 
1499
 //  convert float to space-padded string with -_23.4_ format
1499
 //  convert float to space-padded string with -_23.4_ format
1500
 char *ftostr32np(const float &x) {
1500
 char *ftostr32np(const float &x) {
1501
-<<<<<<< HEAD
1502
   long xx = abs(x * 100);
1501
   long xx = abs(x * 100);
1503
   uint8_t dig;
1502
   uint8_t dig;
1504
 
1503
 
1525
   dig = xx % 10;
1524
   dig = xx % 10;
1526
   if (dig) { // 2 decimal places
1525
   if (dig) { // 2 decimal places
1527
     conv[5] = '0' + dig;
1526
     conv[5] = '0' + dig;
1528
-    dig = (xx / 10) % 10;
1529
-    conv[4] = '0' + dig;
1527
+    conv[4] = '0' + (xx / 10) % 10;
1530
     conv[3] = '.';
1528
     conv[3] = '.';
1531
   }
1529
   }
1532
   else { // 1 or 0 decimal place
1530
   else { // 1 or 0 decimal place
1542
   }
1540
   }
1543
   conv[6] = '\0';
1541
   conv[6] = '\0';
1544
   return conv;
1542
   return conv;
1545
-=======
1546
-  char *c = ftostr32(x);
1547
-  if (c[0] == '0' || c[0] == '-') {
1548
-    if (c[0] == '0') c[0] = ' ';
1549
-    if (c[1] == '0') c[1] = ' ';
1550
-  }
1551
-  if (c[5] == '0') {
1552
-    c[5] = ' ';
1553
-    if (c[4] == '0') c[4] = c[3] = ' ';
1554
-  }
1555
-  return c;
1556
->>>>>>> Patch to make Z look more like X and Y on UltraLCD
1557
 }
1543
 }
1558
 
1544
 
1559
 char *itostr31(const int &xx)
1545
 char *itostr31(const int &xx)

Loading…
Cancel
Save