Преглед изворни кода

Merge pull request #1276 from thinkyhead/lcd_z_reformat

Format Z like XY on LCD
Bo Herrmannsen пре 10 година
родитељ
комит
878b5557a1
3 измењених фајлова са 48 додато и 2 уклоњено
  1. 46
    1
      Marlin/ultralcd.cpp
  2. 1
    0
      Marlin/ultralcd.h
  3. 1
    1
      Marlin/ultralcd_implementation_hitachi_HD44780.h

+ 46
- 1
Marlin/ultralcd.cpp Прегледај датотеку

@@ -1496,7 +1496,52 @@ char *ftostr12ns(const float &x)
1496 1496
   return conv;
1497 1497
 }
1498 1498
 
1499
-// Convert int to lj string with +123.0 format
1499
+//  convert float to space-padded string with -_23.4_ format
1500
+char *ftostr32sp(const float &x) {
1501
+  long xx = abs(x * 100);
1502
+  uint8_t dig;
1503
+
1504
+  if (x < 0) { // negative val = -_0
1505
+    conv[0] = '-';
1506
+    dig = (xx / 1000) % 10;
1507
+    conv[1] = dig ? '0' + dig : ' ';
1508
+  }
1509
+  else { // positive val = __0
1510
+    dig = (xx / 10000) % 10;
1511
+    if (dig) {
1512
+      conv[0] = '0' + dig;
1513
+      conv[1] = '0' + (xx / 1000) % 10;
1514
+    }
1515
+    else {
1516
+      conv[0] = ' ';
1517
+      dig = (xx / 1000) % 10;
1518
+      conv[1] = dig ? '0' + dig : ' ';
1519
+    }
1520
+  }
1521
+
1522
+  conv[2] = '0' + (xx / 100) % 10; // lsd always
1523
+
1524
+  dig = xx % 10;
1525
+  if (dig) { // 2 decimal places
1526
+    conv[5] = '0' + dig;
1527
+    conv[4] = '0' + (xx / 10) % 10;
1528
+    conv[3] = '.';
1529
+  }
1530
+  else { // 1 or 0 decimal place
1531
+    dig = (xx / 10) % 10;
1532
+    if (dig) {
1533
+      conv[4] = '0' + dig;
1534
+      conv[3] = '.';
1535
+    }
1536
+    else {
1537
+      conv[3] = conv[4] = ' ';
1538
+    }
1539
+    conv[5] = ' ';
1540
+  }
1541
+  conv[6] = '\0';
1542
+  return conv;
1543
+}
1544
+
1500 1545
 char *itostr31(const int &xx)
1501 1546
 {
1502 1547
   conv[0]=(xx>=0)?'+':'-';

+ 1
- 0
Marlin/ultralcd.h Прегледај датотеку

@@ -119,6 +119,7 @@ char *ftostr31ns(const float &x); // float to string without sign character
119 119
 char *ftostr31(const float &x);
120 120
 char *ftostr32(const float &x);
121 121
 char *ftostr12ns(const float &x); 
122
+char *ftostr32sp(const float &x); // remove zero-padding from ftostr32
122 123
 char *ftostr5(const float &x);
123 124
 char *ftostr51(const float &x);
124 125
 char *ftostr52(const float &x);

+ 1
- 1
Marlin/ultralcd_implementation_hitachi_HD44780.h Прегледај датотеку

@@ -548,7 +548,7 @@ static void lcd_implementation_status_screen()
548 548
 # endif//LCD_WIDTH > 19
549 549
     lcd.setCursor(LCD_WIDTH - 8, 1);
550 550
     lcd.print('Z');
551
-    lcd.print(ftostr32(current_position[Z_AXIS] + 0.00001));
551
+    lcd.print(ftostr32sp(current_position[Z_AXIS] + 0.00001));
552 552
 #endif//LCD_HEIGHT > 2
553 553
 
554 554
 #if LCD_HEIGHT > 3

Loading…
Откажи
Сачувај