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
bdf2c94bff
1 changed files with 1 additions and 15 deletions
  1. 1
    15
      Marlin/ultralcd.cpp

+ 1
- 15
Marlin/ultralcd.cpp View File

1445
 
1445
 
1446
 //  convert float to space-padded string with -_23.4_ format
1446
 //  convert float to space-padded string with -_23.4_ format
1447
 char *ftostr32np(const float &x) {
1447
 char *ftostr32np(const float &x) {
1448
-<<<<<<< HEAD
1449
   long xx = abs(x * 100);
1448
   long xx = abs(x * 100);
1450
   uint8_t dig;
1449
   uint8_t dig;
1451
 
1450
 
1472
   dig = xx % 10;
1471
   dig = xx % 10;
1473
   if (dig) { // 2 decimal places
1472
   if (dig) { // 2 decimal places
1474
     conv[5] = '0' + dig;
1473
     conv[5] = '0' + dig;
1475
-    dig = (xx / 10) % 10;
1476
-    conv[4] = '0' + dig;
1474
+    conv[4] = '0' + (xx / 10) % 10;
1477
     conv[3] = '.';
1475
     conv[3] = '.';
1478
   }
1476
   }
1479
   else { // 1 or 0 decimal place
1477
   else { // 1 or 0 decimal place
1489
   }
1487
   }
1490
   conv[6] = '\0';
1488
   conv[6] = '\0';
1491
   return conv;
1489
   return conv;
1492
-=======
1493
-  char *c = ftostr32(x);
1494
-  if (c[0] == '0' || c[0] == '-') {
1495
-    if (c[0] == '0') c[0] = ' ';
1496
-    if (c[1] == '0') c[1] = ' ';
1497
-  }
1498
-  if (c[5] == '0') {
1499
-    c[5] = ' ';
1500
-    if (c[4] == '0') c[4] = c[3] = ' ';
1501
-  }
1502
-  return c;
1503
->>>>>>> Patch to make Z look more like X and Y on UltraLCD
1504
 }
1490
 }
1505
 
1491
 
1506
 char *itostr31(const int &xx)
1492
 char *itostr31(const int &xx)

Loading…
Cancel
Save