Browse Source

Merge pull request #4747 from thinkyhead/rc_sd_show_percent

Option to show SD percent on Graphical LCD
Scott Lahteine 8 years ago
parent
commit
cbe9ab902c
2 changed files with 64 additions and 51 deletions
  1. 50
    32
      Marlin/ultralcd_impl_DOGM.h
  2. 14
    19
      Marlin/ultralcd_impl_HD44780.h

+ 50
- 32
Marlin/ultralcd_impl_DOGM.h View File

@@ -189,29 +189,32 @@ static void lcd_setFont(char font_nr) {
189 189
   }
190 190
 }
191 191
 
192
-char lcd_print(char c) {
192
+void lcd_print(char c) {
193
+  if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
194
+    u8g.setFont(FONT_SPECIAL_NAME);
195
+    u8g.print(c);
196
+    lcd_setFont(currentfont);
197
+  }
198
+  else charset_mapper(c);
199
+}
200
+
201
+char lcd_print_and_count(char c) {
193 202
   if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
194 203
     u8g.setFont(FONT_SPECIAL_NAME);
195 204
     u8g.print(c);
196 205
     lcd_setFont(currentfont);
197 206
     return 1;
198
-  } else {
199
-    return charset_mapper(c);
200 207
   }
208
+  else return charset_mapper(c);
201 209
 }
202 210
 
203
-char lcd_print(const char* str) {
204
-  int i = 0;
205
-  char c, n = 0;
206
-  while ((c = str[i++])) n += lcd_print(c);
207
-  return n;
211
+void lcd_print(const char* str) {
212
+  for (uint8_t i = 0; char c = str[i]; ++i) lcd_print(c);
208 213
 }
209 214
 
210
-// Needed for Arduino < 1.0.0
211
-char lcd_printPGM(const char* str) {
212
-  char c, n = 0;
213
-  while ((c = pgm_read_byte(str++))) n += lcd_print(c);
214
-  return n;
215
+/* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
216
+void lcd_printPGM(const char* str) {
217
+  for (; char c = pgm_read_byte(str); ++str) lcd_print(c);
215 218
 }
216 219
 
217 220
 // Initialize or re-initializw the LCD
@@ -337,11 +340,11 @@ FORCE_INLINE void _draw_axis_label(AxisEnum axis, const char *pstr, bool blink)
337 340
     lcd_printPGM(pstr);
338 341
   else {
339 342
     if (!axis_homed[axis])
340
-      lcd_printPGM(PSTR("?"));
343
+      u8g.print('?');
341 344
     else {
342 345
       #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
343 346
         if (!axis_known_position[axis])
344
-          lcd_printPGM(PSTR(" "));
347
+          u8g.print(' ');
345 348
         else
346 349
       #endif
347 350
       lcd_printPGM(pstr);
@@ -349,6 +352,8 @@ FORCE_INLINE void _draw_axis_label(AxisEnum axis, const char *pstr, bool blink)
349 352
   }
350 353
 }
351 354
 
355
+//#define DOGM_SD_PERCENT
356
+
352 357
 static void lcd_implementation_status_screen() {
353 358
   u8g.setColorIndex(1); // black on white
354 359
 
@@ -380,6 +385,13 @@ static void lcd_implementation_status_screen() {
380 385
     if (IS_SD_PRINTING) {
381 386
       // Progress bar solid part
382 387
       u8g.drawBox(55, 50, (unsigned int)(71 * card.percentDone() * 0.01), 2 - (TALL_FONT_CORRECTION));
388
+    
389
+      #if ENABLED(DOGM_SD_PERCENT)
390
+        // Percent complete
391
+        u8g.setPrintPos(55, 48);
392
+        u8g.print(itostr3(card.percentDone()));
393
+        u8g.print('%');
394
+      #endif
383 395
     }
384 396
 
385 397
     char buffer[10];
@@ -387,7 +399,13 @@ static void lcd_implementation_status_screen() {
387 399
     bool has_days = (elapsed.value > 60*60*24L);
388 400
     elapsed.toDigital(buffer, has_days);
389 401
 
390
-    u8g.setPrintPos(has_days ? 71 : 80, 48);
402
+    #if DISABLED(DOGM_SD_PERCENT)
403
+      #define SD_DURATION_X 71
404
+    #else
405
+      #define SD_DURATION_X 89
406
+    #endif
407
+
408
+    u8g.setPrintPos(SD_DURATION_X + (has_days ? 0 : 9), 48);
391 409
     lcd_print(buffer);
392 410
 
393 411
   #endif
@@ -406,7 +424,7 @@ static void lcd_implementation_status_screen() {
406 424
     int per = ((fanSpeeds[0] + 1) * 100) / 256;
407 425
     if (per) {
408 426
       lcd_print(itostr3(per));
409
-      lcd_print('%');
427
+      u8g.print('%');
410 428
     }
411 429
   #endif
412 430
 
@@ -448,7 +466,7 @@ static void lcd_implementation_status_screen() {
448 466
   lcd_setFont(FONT_STATUSMENU);
449 467
   u8g.setPrintPos(12, 49);
450 468
   lcd_print(itostr3(feedrate_percentage));
451
-  lcd_print('%');
469
+  u8g.print('%');
452 470
 
453 471
   // Status line
454 472
   #if ENABLED(USE_SMALL_INFOFONT)
@@ -467,7 +485,7 @@ static void lcd_implementation_status_screen() {
467 485
       lcd_print(ftostr12ns(filament_width_meas));
468 486
       lcd_printPGM(PSTR(" factor:"));
469 487
       lcd_print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
470
-      lcd_print('%');
488
+      u8g.print('%');
471 489
     }
472 490
   #endif
473 491
 }
@@ -499,17 +517,17 @@ static void lcd_implementation_status_screen() {
499 517
 
500 518
       if (center && !valstr) {
501 519
         int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
502
-        while (--pad >= 0) { lcd_print(' '); n--; }
520
+        while (--pad >= 0) { u8g.print(' '); n--; }
503 521
       }
504 522
       while (n > 0 && (c = pgm_read_byte(pstr))) {
505
-        n -= lcd_print(c);
523
+        n -= lcd_print_and_count(c);
506 524
         pstr++;
507 525
       }
508 526
       if (valstr) while (n > 0 && (c = *valstr)) {
509
-        n -= lcd_print(c);
527
+        n -= lcd_print_and_count(c);
510 528
         valstr++;
511 529
       }
512
-      while (n-- > 0) lcd_print(' ');
530
+      while (n-- > 0) u8g.print(' ');
513 531
     }
514 532
 
515 533
   #endif // LCD_INFO_MENU || FILAMENT_CHANGE_FEATURE
@@ -524,13 +542,13 @@ static void lcd_implementation_status_screen() {
524 542
     lcd_implementation_mark_as_selected(row, isSelected);
525 543
 
526 544
     while (c = pgm_read_byte(pstr)) {
527
-      n -= lcd_print(c);
545
+      n -= lcd_print_and_count(c);
528 546
       pstr++;
529 547
     }
530
-    while (n--) lcd_print(' ');
548
+    while (n--) u8g.print(' ');
531 549
     u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), (row + 1) * (DOG_CHAR_HEIGHT));
532 550
     lcd_print(post_char);
533
-    lcd_print(' ');
551
+    u8g.print(' ');
534 552
   }
535 553
 
536 554
   // Macros for specific types of menu items
@@ -548,11 +566,11 @@ static void lcd_implementation_status_screen() {
548 566
     lcd_implementation_mark_as_selected(row, isSelected);
549 567
 
550 568
     while (c = pgm_read_byte(pstr)) {
551
-      n -= lcd_print(c);
569
+      n -= lcd_print_and_count(c);
552 570
       pstr++;
553 571
     }
554
-    lcd_print(':');
555
-    while (n--) lcd_print(' ');
572
+    u8g.print(':');
573
+    while (n--) u8g.print(' ');
556 574
     u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, (row + 1) * (DOG_CHAR_HEIGHT));
557 575
     if (pgm)  lcd_printPGM(data);  else  lcd_print((char*)data);
558 576
   }
@@ -606,7 +624,7 @@ static void lcd_implementation_status_screen() {
606 624
     u8g.setPrintPos(0, rowHeight + kHalfChar);
607 625
     lcd_printPGM(pstr);
608 626
     if (value != NULL) {
609
-      lcd_print(':');
627
+      u8g.print(':');
610 628
       u8g.setPrintPos((lcd_width - 1 - vallen) * char_width, rows * rowHeight + kHalfChar);
611 629
       lcd_print(value);
612 630
     }
@@ -628,10 +646,10 @@ static void lcd_implementation_status_screen() {
628 646
 
629 647
       if (isDir) lcd_print(LCD_STR_FOLDER[0]);
630 648
       while ((c = *filename)) {
631
-        n -= lcd_print(c);
649
+        n -= lcd_print_and_count(c);
632 650
         filename++;
633 651
       }
634
-      while (n--) lcd_print(' ');
652
+      while (n--) u8g.print(' ');
635 653
     }
636 654
 
637 655
     #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)

+ 14
- 19
Marlin/ultralcd_impl_HD44780.h View File

@@ -375,20 +375,15 @@ static void lcd_implementation_init(
375 375
 static void lcd_implementation_clear() { lcd.clear(); }
376 376
 
377 377
 /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
378
-char lcd_printPGM(const char* str) {
379
-  char c, n = 0;
380
-  while ((c = pgm_read_byte(str++))) n += charset_mapper(c);
381
-  return n;
378
+void lcd_printPGM(const char *str) {
379
+  for (; char c = pgm_read_byte(str); ++str) charset_mapper(c);
382 380
 }
383 381
 
384
-char lcd_print(const char* str) {
385
-  char c, n = 0;
386
-  unsigned char i = 0;
387
-  while ((c = str[i++])) n += charset_mapper(c);
388
-  return n;
382
+void lcd_print(const char* str) {
383
+  for (uint8_t i = 0; char c = str[i]; ++i) charset_mapper(c);
389 384
 }
390 385
 
391
-unsigned lcd_print(char c) { return charset_mapper(c); }
386
+void lcd_print(char c) { charset_mapper(c); }
392 387
 
393 388
 #if ENABLED(SHOW_BOOTSCREEN)
394 389
 
@@ -556,11 +551,11 @@ FORCE_INLINE void _draw_axis_label(AxisEnum axis, const char *pstr, bool blink)
556 551
     lcd_printPGM(pstr);
557 552
   else {
558 553
     if (!axis_homed[axis])
559
-      lcd_printPGM(PSTR("?"));
554
+      lcd.print('?');
560 555
     else {
561 556
       #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
562 557
         if (!axis_known_position[axis])
563
-          lcd_printPGM(PSTR(" "));
558
+          lcd.print(' ');
564 559
         else
565 560
       #endif
566 561
       lcd_printPGM(pstr);
@@ -694,7 +689,7 @@ static void lcd_implementation_status_screen() {
694 689
         _draw_axis_label(X_AXIS, PSTR(MSG_X), blink);
695 690
         lcd.print(ftostr4sign(current_position[X_AXIS]));
696 691
 
697
-        lcd_printPGM(PSTR(" "));
692
+        lcd.print(' ');
698 693
 
699 694
         _draw_axis_label(Y_AXIS, PSTR(MSG_Y), blink);
700 695
         lcd.print(ftostr4sign(current_position[Y_AXIS]));
@@ -803,11 +798,11 @@ static void lcd_implementation_status_screen() {
803 798
         while (--pad >= 0) { lcd.print(' '); n--; }
804 799
       }
805 800
       while (n > 0 && (c = pgm_read_byte(pstr))) {
806
-        n -= lcd_print(c);
801
+        n -= charset_mapper(c);
807 802
         pstr++;
808 803
       }
809 804
       if (valstr) while (n > 0 && (c = *valstr)) {
810
-        n -= lcd_print(c);
805
+        n -= charset_mapper(c);
811 806
         valstr++;
812 807
       }
813 808
       while (n-- > 0) lcd.print(' ');
@@ -821,7 +816,7 @@ static void lcd_implementation_status_screen() {
821 816
     lcd.setCursor(0, row);
822 817
     lcd.print(sel ? pre_char : ' ');
823 818
     while ((c = pgm_read_byte(pstr)) && n > 0) {
824
-      n -= lcd_print(c);
819
+      n -= charset_mapper(c);
825 820
       pstr++;
826 821
     }
827 822
     while (n--) lcd.print(' ');
@@ -834,7 +829,7 @@ static void lcd_implementation_status_screen() {
834 829
     lcd.setCursor(0, row);
835 830
     lcd.print(sel ? pre_char : ' ');
836 831
     while ((c = pgm_read_byte(pstr)) && n > 0) {
837
-      n -= lcd_print(c);
832
+      n -= charset_mapper(c);
838 833
       pstr++;
839 834
     }
840 835
     lcd.print(':');
@@ -847,7 +842,7 @@ static void lcd_implementation_status_screen() {
847 842
     lcd.setCursor(0, row);
848 843
     lcd.print(sel ? pre_char : ' ');
849 844
     while ((c = pgm_read_byte(pstr)) && n > 0) {
850
-      n -= lcd_print(c);
845
+      n -= charset_mapper(c);
851 846
       pstr++;
852 847
     }
853 848
     lcd.print(':');
@@ -899,7 +894,7 @@ static void lcd_implementation_status_screen() {
899 894
         longFilename[n] = '\0';
900 895
       }
901 896
       while ((c = *filename) && n > 0) {
902
-        n -= lcd_print(c);
897
+        n -= charset_mapper(c);
903 898
         filename++;
904 899
       }
905 900
       while (n--) lcd.print(' ');

Loading…
Cancel
Save