Browse Source

Reduce TQ message code size

Scott Lahteine 7 years ago
parent
commit
8c40f0c6c7
1 changed files with 12 additions and 20 deletions
  1. 12
    20
      Marlin/src/lcd/malyanlcd.cpp

+ 12
- 20
Marlin/src/lcd/malyanlcd.cpp View File

79
 
79
 
80
 // For sending print completion messages
80
 // For sending print completion messages
81
 bool last_printing_status = false;
81
 bool last_printing_status = false;
82
-uint8_t last_percent_done = 100;
83
 
82
 
84
 // Everything written needs the high bit set.
83
 // Everything written needs the high bit set.
85
 void write_to_lcd_P(const char * const message) {
84
 void write_to_lcd_P(const char * const message) {
442
     // The way last printing status works is simple:
441
     // The way last printing status works is simple:
443
     // The UI needs to see at least one TQ which is not 100%
442
     // The UI needs to see at least one TQ which is not 100%
444
     // and then when the print is complete, one which is.
443
     // and then when the print is complete, one which is.
445
-    if (card.sdprinting) {
446
-      if (card.percentDone() != last_percent_done) {
447
-        char message_buffer[10];
448
-        last_percent_done = card.percentDone();
449
-        sprintf_P(message_buffer, PSTR("{TQ:%03i}"), last_percent_done);
450
-        write_to_lcd(message_buffer);
451
-
452
-        if (!last_printing_status) last_printing_status = true;
453
-      }
454
-    }
455
-    else {
456
-      // If there was a print in progress, we need to emit the final
457
-      // print status as {TQ:100}. Reset last percent done so a new print will
458
-      // issue a percent of 0.
459
-      if (last_printing_status) {
460
-        last_printing_status = false;
461
-        last_percent_done = 100;
462
-        write_to_lcd_P(PSTR("{TQ:100}"));
463
-      }
444
+    static uint8_t last_percent_done = 100;
445
+
446
+    // If there was a print in progress, we need to emit the final
447
+    // print status as {TQ:100}. Reset last percent done so a new print will
448
+    // issue a percent of 0.
449
+    const uint8_t percent_done = card.sdprinting ? card.percentDone() : last_printing_status ? 100 : 0;
450
+    if (percent_done != last_percent_done) {
451
+      char message_buffer[10];
452
+      sprintf_P(message_buffer, PSTR("{TQ:%03i}"), percent_done);
453
+      write_to_lcd(message_buffer);
454
+      last_percent_done = percent_done;
455
+      last_printing_status = card.sdprinting;
464
     }
456
     }
465
   #endif
457
   #endif
466
 }
458
 }

Loading…
Cancel
Save