Skip to content

Commit

Permalink
Allow Status Message without LCD (MarlinFirmware#20246)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and dpreed committed Feb 5, 2021
1 parent 39e9270 commit 131f1e2
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 123 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/gcode/temp/M303.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void GcodeSuite::M303() {
KEEPALIVE_STATE(NOT_BUSY);
#endif

ui.set_status_P(GET_TEXT(MSG_PID_AUTOTUNE));
LCD_MESSAGEPGM(MSG_PID_AUTOTUNE);
thermalManager.PID_autotune(temp, e, c, u);
ui.reset_status();
}
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@
#endif
#endif

#if EITHER(HAS_DISPLAY, GLOBAL_STATUS_MESSAGE)
#define HAS_STATUS_MESSAGE 1
#endif

#if IS_ULTIPANEL && DISABLED(NO_LCD_MENUS)
#define HAS_LCD_MENU 1
#endif
Expand Down
213 changes: 114 additions & 99 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,59 +1332,16 @@ void MarlinUI::update() {

#endif // HAS_WIRED_LCD

#if HAS_DISPLAY

#if ENABLED(EXTENSIBLE_UI)
#include "extui/ui_api.h"
#endif
#if HAS_STATUS_MESSAGE

////////////////////////////////////////////
/////////////// Status Line ////////////////
////////////// Status Message //////////////
////////////////////////////////////////////

#if ENABLED(STATUS_MESSAGE_SCROLLING)
void MarlinUI::advance_status_scroll() {
// Advance by one UTF8 code-word
if (status_scroll_offset < utf8_strlen(status_message))
while (!START_OF_UTF8_CHAR(status_message[++status_scroll_offset]));
else
status_scroll_offset = 0;
}
char* MarlinUI::status_and_len(uint8_t &len) {
char *out = status_message + status_scroll_offset;
len = utf8_strlen(out);
return out;
}
#if ENABLED(EXTENSIBLE_UI)
#include "extui/ui_api.h"
#endif

void MarlinUI::finish_status(const bool persist) {

#if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE) > 0)
UNUSED(persist);
#endif

#if ENABLED(LCD_PROGRESS_BAR) || BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
const millis_t ms = millis();
#endif

#if ENABLED(LCD_PROGRESS_BAR) && !IS_TFTGLCD_PANEL
progress_bar_ms = ms;
#if PROGRESS_MSG_EXPIRE > 0
expire_status_ms = persist ? 0 : ms + PROGRESS_MSG_EXPIRE;
#endif
#endif

#if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
next_filament_display = ms + 5000UL; // Show status message for 5s
#endif

#if BOTH(HAS_WIRED_LCD, STATUS_MESSAGE_SCROLLING)
status_scroll_offset = 0;
#endif

TERN_(EXTENSIBLE_UI, ExtUI::onStatusChanged(status_message));
}

bool MarlinUI::has_status() { return (status_message[0] != '\0'); }

void MarlinUI::set_status(const char * const message, const bool persist) {
Expand Down Expand Up @@ -1414,16 +1371,45 @@ void MarlinUI::update() {
finish_status(persist);
}

#include <stdarg.h>
/**
* Reset the status message
*/
void MarlinUI::reset_status(const bool no_welcome) {
#if SERVICE_INTERVAL_1 > 0
static PGMSTR(service1, "> " SERVICE_NAME_1 "!");
#endif
#if SERVICE_INTERVAL_2 > 0
static PGMSTR(service2, "> " SERVICE_NAME_2 "!");
#endif
#if SERVICE_INTERVAL_3 > 0
static PGMSTR(service3, "> " SERVICE_NAME_3 "!");
#endif
PGM_P msg;
if (printingIsPaused())
msg = GET_TEXT(MSG_PRINT_PAUSED);
#if ENABLED(SDSUPPORT)
else if (IS_SD_PRINTING())
return set_status(card.longest_filename(), true);
#endif
else if (print_job_timer.isRunning())
msg = GET_TEXT(MSG_PRINTING);

void MarlinUI::status_printf_P(const uint8_t level, PGM_P const fmt, ...) {
if (level < alert_level) return;
alert_level = level;
va_list args;
va_start(args, fmt);
vsnprintf_P(status_message, MAX_MESSAGE_LENGTH, fmt, args);
va_end(args);
finish_status(level > 0);
#if SERVICE_INTERVAL_1 > 0
else if (print_job_timer.needsService(1)) msg = service1;
#endif
#if SERVICE_INTERVAL_2 > 0
else if (print_job_timer.needsService(2)) msg = service2;
#endif
#if SERVICE_INTERVAL_3 > 0
else if (print_job_timer.needsService(3)) msg = service3;
#endif

else if (!no_welcome)
msg = GET_TEXT(WELCOME_MSG);
else
return;

set_status_P(msg, -1);
}

void MarlinUI::set_status_P(PGM_P const message, int8_t level) {
Expand Down Expand Up @@ -1459,51 +1445,76 @@ void MarlinUI::update() {
TERN_(HAS_LCD_MENU, return_to_status());
}

PGM_P print_paused = GET_TEXT(MSG_PRINT_PAUSED);
#include <stdarg.h>

/**
* Reset the status message
*/
void MarlinUI::reset_status(const bool no_welcome) {
PGM_P printing = GET_TEXT(MSG_PRINTING);
PGM_P welcome = GET_TEXT(WELCOME_MSG);
#if SERVICE_INTERVAL_1 > 0
static PGMSTR(service1, "> " SERVICE_NAME_1 "!");
#endif
#if SERVICE_INTERVAL_2 > 0
static PGMSTR(service2, "> " SERVICE_NAME_2 "!");
#endif
#if SERVICE_INTERVAL_3 > 0
static PGMSTR(service3, "> " SERVICE_NAME_3 "!");
#endif
PGM_P msg;
if (printingIsPaused())
msg = print_paused;
#if ENABLED(SDSUPPORT)
else if (IS_SD_PRINTING())
return set_status(card.longest_filename(), true);
#endif
else if (print_job_timer.isRunning())
msg = printing;
void MarlinUI::status_printf_P(const uint8_t level, PGM_P const fmt, ...) {
if (level < alert_level) return;
alert_level = level;
va_list args;
va_start(args, fmt);
vsnprintf_P(status_message, MAX_MESSAGE_LENGTH, fmt, args);
va_end(args);
finish_status(level > 0);
}

#if SERVICE_INTERVAL_1 > 0
else if (print_job_timer.needsService(1)) msg = service1;
#endif
#if SERVICE_INTERVAL_2 > 0
else if (print_job_timer.needsService(2)) msg = service2;
#endif
#if SERVICE_INTERVAL_3 > 0
else if (print_job_timer.needsService(3)) msg = service3;
#endif
void MarlinUI::finish_status(const bool persist) {

else if (!no_welcome)
msg = welcome;
else
return;
#if HAS_SPI_LCD

set_status_P(msg, -1);
#if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE) > 0)
UNUSED(persist);
#endif

#if ENABLED(LCD_PROGRESS_BAR) || BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
const millis_t ms = millis();
#endif

#if ENABLED(LCD_PROGRESS_BAR)
progress_bar_ms = ms;
#if PROGRESS_MSG_EXPIRE > 0
expire_status_ms = persist ? 0 : ms + PROGRESS_MSG_EXPIRE;
#endif
#endif

#if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
next_filament_display = ms + 5000UL; // Show status message for 5s
#endif

#if ENABLED(STATUS_MESSAGE_SCROLLING)
status_scroll_offset = 0;
#endif

#endif

TERN_(EXTENSIBLE_UI, ExtUI::onStatusChanged(status_message));
}

#if ENABLED(STATUS_MESSAGE_SCROLLING)

void MarlinUI::advance_status_scroll() {
// Advance by one UTF8 code-word
if (status_scroll_offset < utf8_strlen(status_message))
while (!START_OF_UTF8_CHAR(status_message[++status_scroll_offset]));
else
status_scroll_offset = 0;
}

char* MarlinUI::status_and_len(uint8_t &len) {
char *out = status_message + status_scroll_offset;
len = utf8_strlen(out);
return out;
}

#endif

#endif

#if HAS_DISPLAY

#if ENABLED(SDSUPPORT)
extern bool wait_for_user, wait_for_heatup;
#endif

void MarlinUI::abort_print() {
#if ENABLED(SDSUPPORT)
wait_for_heatup = wait_for_user = false;
Expand All @@ -1514,7 +1525,7 @@ void MarlinUI::update() {
#endif
TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("UI Aborted"), DISMISS_STR));
print_job_timer.stop();
set_status_P(GET_TEXT(MSG_PRINT_ABORTED));
LCD_MESSAGEPGM(MSG_PRINT_ABORTED);
TERN_(HAS_LCD_MENU, return_to_status());
}

Expand All @@ -1530,7 +1541,7 @@ void MarlinUI::update() {

TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_PAUSE_RESUME, PSTR("UI Pause"), PSTR("Resume")));

set_status_P(print_paused);
LCD_MESSAGEPGM(MSG_PRINT_PAUSED);

#if ENABLED(PARK_HEAD_ON_PAUSE)
TERN_(HAS_WIRED_LCD, lcd_pause_show_message(PAUSE_MESSAGE_PARKING, PAUSE_MODE_PAUSE_PRINT)); // Show message immediately to let user know about pause in progress
Expand Down Expand Up @@ -1615,6 +1626,10 @@ void MarlinUI::update() {

#if ENABLED(SDSUPPORT)

#if ENABLED(EXTENSIBLE_UI)
#include "extui/ui_api.h"
#endif

void MarlinUI::media_changed(const uint8_t old_status, const uint8_t status) {
if (old_status == status) {
TERN_(EXTENSIBLE_UI, ExtUI::onMediaError()); // Failed to mount/unmount
Expand All @@ -1629,15 +1644,15 @@ void MarlinUI::update() {
quick_feedback();
goto_screen(MEDIA_MENU_GATEWAY);
#else
set_status_P(GET_TEXT(MSG_MEDIA_INSERTED));
LCD_MESSAGEPGM(MSG_MEDIA_INSERTED);
#endif
}
}
else {
if (old_status < 2) {
TERN_(EXTENSIBLE_UI, ExtUI::onMediaRemoved()); // ExtUI response
#if PIN_EXISTS(SD_DETECT)
set_status_P(GET_TEXT(MSG_MEDIA_REMOVED));
LCD_MESSAGEPGM(MSG_MEDIA_REMOVED);
#if HAS_LCD_MENU
if (!defer_return_to_status) return_to_status();
#endif
Expand Down
47 changes: 24 additions & 23 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,24 +373,38 @@ class MarlinUI {
static constexpr uint8_t get_progress_percent() { return 0; }
#endif

#if HAS_DISPLAY

static void init();
static void update();
static void set_alert_status_P(PGM_P const message);

#if HAS_STATUS_MESSAGE
static char status_message[];
static bool has_status();

static uint8_t alert_level; // Higher levels block lower levels
static inline void reset_alert_level() { alert_level = 0; }

#if ENABLED(STATUS_MESSAGE_SCROLLING)
static uint8_t status_scroll_offset;
static void advance_status_scroll();
static char* status_and_len(uint8_t &len);
#endif

static bool has_status();
static void reset_status(const bool no_welcome=false);
static void set_status(const char* const message, const bool persist=false);
static void set_status_P(PGM_P const message, const int8_t level=0);
static void status_printf_P(const uint8_t level, PGM_P const fmt, ...);
static void set_alert_status_P(PGM_P const message);
static inline void reset_alert_level() { alert_level = 0; }
#else
static constexpr bool has_status() { return false; }
static inline void reset_status(const bool=false) {}
static void set_status(const char* message, const bool=false);
static void set_status_P(PGM_P message, const int8_t=0);
static void status_printf_P(const uint8_t, PGM_P message, ...);
static inline void set_alert_status_P(PGM_P const) {}
static inline void reset_alert_level() {}
#endif

#if HAS_DISPLAY

static void init();
static void update();

static void abort_print();
static void pause_print();
static void resume_print();
Expand Down Expand Up @@ -481,25 +495,12 @@ class MarlinUI {
static bool get_blink();
static void kill_screen(PGM_P const lcd_error, PGM_P const lcd_component);
static void draw_kill_screen();
static void set_status(const char* const message, const bool persist=false);
static void set_status_P(PGM_P const message, const int8_t level=0);
static void status_printf_P(const uint8_t level, PGM_P const fmt, ...);
static void reset_status(const bool no_welcome=false);

#else // No LCD

// Send status to host as a notification
static void set_status(const char* message, const bool=false);
static void set_status_P(PGM_P message, const int8_t=0);
static void status_printf_P(const uint8_t, PGM_P message, ...);

static inline void init() {}
static inline void update() {}
static inline void return_to_status() {}
static inline void set_alert_status_P(PGM_P const) {}
static inline void reset_status(const bool=false) {}
static inline void reset_alert_level() {}
static constexpr bool has_status() { return false; }

#endif

Expand Down Expand Up @@ -702,7 +703,7 @@ class MarlinUI {

private:

#if HAS_DISPLAY
#if HAS_STATUS_MESSAGE
static void finish_status(const bool persist);
#endif

Expand Down

0 comments on commit 131f1e2

Please sign in to comment.