From 8c40f0c6c79dbaff580fefb9425fb8962d77f475 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 13 Jul 2018 01:21:17 -0500 Subject: [PATCH] Reduce TQ message code size --- Marlin/src/lcd/malyanlcd.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/Marlin/src/lcd/malyanlcd.cpp b/Marlin/src/lcd/malyanlcd.cpp index d01d0367d2..39c1bc0bda 100644 --- a/Marlin/src/lcd/malyanlcd.cpp +++ b/Marlin/src/lcd/malyanlcd.cpp @@ -79,7 +79,6 @@ int inbound_count; // For sending print completion messages bool last_printing_status = false; -uint8_t last_percent_done = 100; // Everything written needs the high bit set. void write_to_lcd_P(const char * const message) { @@ -442,25 +441,18 @@ void lcd_update() { // The way last printing status works is simple: // The UI needs to see at least one TQ which is not 100% // and then when the print is complete, one which is. - if (card.sdprinting) { - if (card.percentDone() != last_percent_done) { - char message_buffer[10]; - last_percent_done = card.percentDone(); - sprintf_P(message_buffer, PSTR("{TQ:%03i}"), last_percent_done); - write_to_lcd(message_buffer); - - if (!last_printing_status) last_printing_status = true; - } - } - else { - // If there was a print in progress, we need to emit the final - // print status as {TQ:100}. Reset last percent done so a new print will - // issue a percent of 0. - if (last_printing_status) { - last_printing_status = false; - last_percent_done = 100; - write_to_lcd_P(PSTR("{TQ:100}")); - } + static uint8_t last_percent_done = 100; + + // If there was a print in progress, we need to emit the final + // print status as {TQ:100}. Reset last percent done so a new print will + // issue a percent of 0. + const uint8_t percent_done = card.sdprinting ? card.percentDone() : last_printing_status ? 100 : 0; + if (percent_done != last_percent_done) { + char message_buffer[10]; + sprintf_P(message_buffer, PSTR("{TQ:%03i}"), percent_done); + write_to_lcd(message_buffer); + last_percent_done = percent_done; + last_printing_status = card.sdprinting; } #endif }