From b3ca70a0077e8c77ff32a71adb88d13f1f30f1d3 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 28 Jun 2022 21:06:39 +0200 Subject: [PATCH] Show thermal warnings using the new LCD_MESSAGE_INFO priority Add a new LCD_MESSAGE_INFO priority which can be overridden by regular status updates, but only if a certain amount of time has passed. Assign a time stamp to all message updates, so that the time since the last update can be determined. Also switch the message type to Status, so that the message always becomes visibile. Always show status or info messages when printing via SD if the message is recent enough. --- Firmware/messages.cpp | 3 ++ Firmware/messages.h | 3 ++ Firmware/temperature.cpp | 20 ++++----- Firmware/ultralcd.cpp | 88 ++++++++++++++++++++++++---------------- Firmware/ultralcd.h | 13 ++++-- 5 files changed, 78 insertions(+), 49 deletions(-) diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 35a7e3bf8..5cec8102c 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -159,6 +159,9 @@ const char MSG_IR_04_OR_NEWER[] PROGMEM_I1 = ISTR(" 0.4 or newer");////MSG_IR_04 const char MSG_IR_03_OR_OLDER[] PROGMEM_I1 = ISTR(" 0.3 or older");////MSG_IR_03_OR_OLDER c=18 const char MSG_IR_UNKNOWN[] PROGMEM_I1 = ISTR("unknown state");////MSG_IR_UNKNOWN c=18 #endif +#ifdef TEMP_MODEL +extern const char MSG_THERMAL_ANOMALY[] PROGMEM_I1 = ISTR("THERMAL ANOMALY");////c=20 +#endif //not internationalized messages const char MSG_AUTO_DEPLETE[] PROGMEM_N1 = ISTR("SpoolJoin"); ////MSG_AUTO_DEPLETE c=13 diff --git a/Firmware/messages.h b/Firmware/messages.h index 2c9a4a5fc..b5116776c 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -168,6 +168,9 @@ extern const char MSG_IR_04_OR_NEWER[]; extern const char MSG_IR_03_OR_OLDER[]; extern const char MSG_IR_UNKNOWN[]; #endif +#ifdef TEMP_MODEL +extern const char MSG_THERMAL_ANOMALY[]; +#endif //not internationalized messages extern const char MSG_BROWNOUT_RESET[]; diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 5d04e3db7..b261c5f2a 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -34,6 +34,7 @@ #include "menu.h" #include "sound.h" #include "fancheck.h" +#include "messages.h" #include "SdFatUtil.h" @@ -2406,23 +2407,22 @@ void handle_warning() } dT_err /= TEMP_MGR_INTV; // per-sample => K/s - // TODO: alert the user on the lcd printf_P(PSTR("TM: error |%f|>%f\n"), (double)dT_err, (double)warn); - static bool beeper = false; + static bool first = true; if(warning_state.assert) { - if(warn_beep) { - // beep periodically - beeper = !beeper; - WRITE(BEEPER, beeper); + if (first) { + lcd_setalertstatuspgm(MSG_THERMAL_ANOMALY, LCD_STATUS_INFO); + if(warn_beep) WRITE(BEEPER, HIGH); + first = false; + } else { + if(warn_beep) TOGGLE(BEEPER); } } else { // warning cleared, reset state warning_state.warning = false; - if(warn_beep) { - beeper = false; - WRITE(BEEPER, LOW); - } + if(warn_beep) WRITE(BEEPER, LOW); + first = true; } } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index b952d8e72..9fecee9af 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -94,14 +94,15 @@ static bool lcd_autoDeplete; static float manual_feedrate[] = MANUAL_FEEDRATE; +/* LCD message status */ +static LongTimer lcd_status_message_timeout; +static uint8_t lcd_status_message_level; +static char lcd_status_message[LCD_WIDTH + 1] = WELCOME_MSG; + /* !Configuration settings */ -uint8_t lcd_status_message_level; -char lcd_status_message[LCD_WIDTH + 1] = WELCOME_MSG; - static uint8_t lay1cal_filament = 0; - static const char separator[] PROGMEM = "--------------------"; /** forward declarations **/ @@ -597,7 +598,12 @@ void lcdui_print_status_line(void) break; } } - else if ((IS_SD_PRINTING) && (custom_message_type == CustomMsg::Status)) { // If printing from SD, show what we are printing + else if ((IS_SD_PRINTING) && + (custom_message_type == CustomMsg::Status) && + (lcd_status_message_level <= LCD_STATUS_INFO) && + lcd_status_message_timeout.expired_cont(LCD_STATUS_INFO_TIMEOUT)) + { + // If printing from SD, show what we are printing const char* longFilenameOLD = (card.longFilename[0] ? card.longFilename : card.filename); if(strlen(longFilenameOLD) > LCD_WIDTH) { uint8_t gh = scrollstuff; @@ -7949,58 +7955,70 @@ void lcd_finishstatus() { } -void lcd_setstatus(const char* message) +static bool lcd_message_check(uint8_t priority) { - if (lcd_status_message_level > 0) - return; - lcd_updatestatus(message); + // regular priority check + if (priority >= lcd_status_message_level) + return true; + + // check if we can override an info message yet + if (lcd_status_message_level == LCD_STATUS_INFO) { + return lcd_status_message_timeout.expired_cont(LCD_STATUS_INFO_TIMEOUT); + } + + return false; } -static void lcd_updatestatuspgm(const char *message){ - strncpy_P(lcd_status_message, message, LCD_WIDTH); +static void lcd_updatestatus(const char *message, bool progmem = false) +{ + if (progmem) + strncpy_P(lcd_status_message, message, LCD_WIDTH); + else + strncpy(lcd_status_message, message, LCD_WIDTH); + lcd_status_message[LCD_WIDTH] = 0; lcd_finishstatus(); // hack lcd_draw_update to 1, i.e. without clear lcd_draw_update = 1; } +void lcd_setstatus(const char* message) +{ + if (lcd_message_check(LCD_STATUS_NONE)) + lcd_updatestatus(message); +} + void lcd_setstatuspgm(const char* message) { - if (lcd_status_message_level > 0) - return; - lcd_updatestatuspgm(message); + if (lcd_message_check(LCD_STATUS_NONE)) + lcd_updatestatus(message, true); } -static void lcd_updatestatus(const char *message) +void lcd_setalertstatus_(const char* message, uint8_t severity, bool progmem) { - strncpy(lcd_status_message, message, LCD_WIDTH); - lcd_status_message[LCD_WIDTH] = 0; - lcd_finishstatus(); - // hack lcd_draw_update to 1, i.e. without clear - lcd_draw_update = 1; -} - -void lcd_setalertstatuspgm(const char* message, uint8_t severity) -{ - if (severity > lcd_status_message_level) { - lcd_updatestatuspgm(message); - lcd_status_message_level = severity; - lcd_return_to_status(); - } + if (lcd_message_check(severity)) { + lcd_updatestatus(message, progmem); + lcd_status_message_timeout.start(); + lcd_status_message_level = severity; + custom_message_type = CustomMsg::Status; + custom_message_state = 0; + lcd_return_to_status(); + } } void lcd_setalertstatus(const char* message, uint8_t severity) { - if (severity > lcd_status_message_level) { - lcd_updatestatus(message); - lcd_status_message_level = severity; - lcd_return_to_status(); - } + lcd_setalertstatus_(message, severity, false); +} + +void lcd_setalertstatuspgm(const char* message, uint8_t severity) +{ + lcd_setalertstatus_(message, severity, true); } void lcd_reset_alert_level() { - lcd_status_message_level = 0; + lcd_status_message_level = 0; } uint8_t get_message_level() diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 713225d51..d3c94e897 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -9,14 +9,19 @@ extern void menu_lcd_lcdupdate_func(void); // Call with a false parameter to suppress the LCD update from various places like the planner or the temp control. void ultralcd_init(); -void lcd_setstatus(const char* message); -void lcd_setstatuspgm(const char* message); //! LCD status severities -#define LCD_STATUS_CRITICAL 2 //< Heater failure -#define LCD_STATUS_ALERT 1 //< Other hardware issue +#define LCD_STATUS_CRITICAL 3 //< Heater failure +#define LCD_STATUS_ALERT 2 //< Other hardware issue +#define LCD_STATUS_INFO 1 //< Message times out after a while #define LCD_STATUS_NONE 0 //< No alert message set +#define LCD_STATUS_INFO_TIMEOUT 20000 + +// Set the current status message (equivalent to LCD_STATUS_NONE) +void lcd_setstatus(const char* message); +void lcd_setstatuspgm(const char* message); + //! return to the main status screen and display the alert message //! Beware - it has sideeffects: //! - always returns the display to the main status screen