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.
This commit is contained in:
Yuri D'Elia 2022-06-28 21:06:39 +02:00
parent 8d9d367d6b
commit b3ca70a007
5 changed files with 78 additions and 49 deletions

View file

@ -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

View file

@ -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[];

View file

@ -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;
}
}

View file

@ -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()

View file

@ -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