diff --git a/Marlin/src/lcd/extensible_ui/ui_api.cpp b/Marlin/src/lcd/extensible_ui/ui_api.cpp index 017b652a0c..0871036118 100644 --- a/Marlin/src/lcd/extensible_ui/ui_api.cpp +++ b/Marlin/src/lcd/extensible_ui/ui_api.cpp @@ -831,35 +831,15 @@ namespace ExtUI { } void pausePrint() { - #if ENABLED(SDSUPPORT) - card.pauseSDPrint(); - print_job_timer.pause(); - #if ENABLED(PARK_HEAD_ON_PAUSE) - enqueue_and_echo_commands_P(PSTR("M125")); - #endif - ui.set_status_P(PSTR(MSG_PRINT_PAUSED)); - #endif + ui.pause_print(); } void resumePrint() { - #if ENABLED(SDSUPPORT) - ui.set_status_P(PSTR(MSG_FILAMENT_CHANGE_RESUME_1)); - #if ENABLED(PARK_HEAD_ON_PAUSE) - wait_for_heatup = wait_for_user = false; - enqueue_and_echo_commands_P(PSTR("M24")); - #else - card.startFileprint(); - print_job_timer.start(); - #endif - #endif + ui.resume_print(); } void stopPrint() { - #if ENABLED(SDSUPPORT) - wait_for_heatup = wait_for_user = false; - card.flag.abort_sd_printing = true; - ui.set_status_P(PSTR(MSG_PRINT_ABORTED)); - #endif + ui.stop_print(); } FileList::FileList() { refresh(); } diff --git a/Marlin/src/lcd/menu/menu_main.cpp b/Marlin/src/lcd/menu/menu_main.cpp index 93ebe75781..b3e811e3cd 100644 --- a/Marlin/src/lcd/menu/menu_main.cpp +++ b/Marlin/src/lcd/menu/menu_main.cpp @@ -39,10 +39,6 @@ #include "../../feature/power_loss_recovery.h" #endif -#if ENABLED(HOST_ACTION_COMMANDS) - #include "../../feature/host_actions.h" -#endif - #if HAS_GAMES #include "game/game.h" #endif @@ -50,61 +46,10 @@ #define MACHINE_CAN_STOP (EITHER(SDSUPPORT, HOST_PROMPT_SUPPORT) || defined(ACTION_ON_CANCEL)) #define MACHINE_CAN_PAUSE (ANY(SDSUPPORT, HOST_PROMPT_SUPPORT, PARK_HEAD_ON_PAUSE) || defined(ACTION_ON_PAUSE)) -#if MACHINE_CAN_PAUSE - - void lcd_pause_job() { - ui.synchronize(PSTR(MSG_PAUSE_PRINT)); - - #if ENABLED(POWER_LOSS_RECOVERY) - if (recovery.enabled) recovery.save(true, false); - #endif - - #if ENABLED(HOST_PROMPT_SUPPORT) - host_prompt_open(PROMPT_PAUSE_RESUME, PSTR("UI Pause"), PSTR("Resume")); - #endif - - #if ENABLED(PARK_HEAD_ON_PAUSE) - lcd_pause_show_message(PAUSE_MESSAGE_PAUSING, PAUSE_MODE_PAUSE_PRINT); // Show message immediately to let user know about pause in progress - enqueue_and_echo_commands_P(PSTR("M25 P\nM24")); - #elif ENABLED(SDSUPPORT) - enqueue_and_echo_commands_P(PSTR("M25")); - #elif defined(ACTION_ON_PAUSE) - host_action_pause(); - #endif - } - - void lcd_resume() { - #if ENABLED(SDSUPPORT) - if (card.isPaused()) enqueue_and_echo_commands_P(PSTR("M24")); - #endif - #ifdef ACTION_ON_RESUME - host_action_resume(); - #endif - } - -#endif // MACHINE_CAN_PAUSE - #if MACHINE_CAN_STOP - - void lcd_abort_job() { - #if ENABLED(SDSUPPORT) - wait_for_heatup = wait_for_user = false; - card.flag.abort_sd_printing = true; - #endif - #ifdef ACTION_ON_CANCEL - host_action_cancel(); - #endif - #if ENABLED(HOST_PROMPT_SUPPORT) - host_prompt_open(PROMPT_INFO, PSTR("UI Abort")); - #endif - ui.set_status_P(PSTR(MSG_PRINT_ABORTED), -1); - ui.return_to_status(); - } - void menu_abort_confirm() { - do_select_screen(PSTR(MSG_BUTTON_STOP), PSTR(MSG_BACK), lcd_abort_job, ui.goto_previous_screen, PSTR(MSG_STOP_PRINT), nullptr, PSTR("?")); + do_select_screen(PSTR(MSG_BUTTON_STOP), PSTR(MSG_BACK), ui.abort_print, ui.goto_previous_screen, PSTR(MSG_STOP_PRINT), nullptr, PSTR("?")); } - #endif // MACHINE_CAN_STOP #if ENABLED(PRUSA_MMU2) @@ -160,7 +105,7 @@ void menu_main() { if (busy) { #if MACHINE_CAN_PAUSE - MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_pause_job); + MENU_ITEM(function, MSG_PAUSE_PRINT, ui.pause_print); #endif #if MACHINE_CAN_STOP MENU_ITEM(submenu, MSG_STOP_PRINT, menu_abort_confirm); @@ -204,7 +149,7 @@ void menu_main() { || card.isPaused() #endif ); - if (paused) MENU_ITEM(function, MSG_RESUME_PRINT, lcd_resume); + if (paused) MENU_ITEM(function, MSG_RESUME_PRINT, ui.resume_print); #endif MENU_ITEM(submenu, MSG_MOTION, menu_motion); diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index a044886793..f0ebcefbb3 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -31,6 +31,9 @@ #if ENABLED(EXTENSIBLE_UI) #define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80u) #endif + #if ENABLED(HOST_ACTION_COMMANDS) + #include "../feature/host_actions.h" + #endif #endif #if HAS_SPI_LCD @@ -1358,6 +1361,63 @@ void MarlinUI::update() { set_status_P(msg, -1); } + void MarlinUI::abort_print() { + #if ENABLED(SDSUPPORT) + wait_for_heatup = wait_for_user = false; + card.flag.abort_sd_printing = true; + #endif + #ifdef ACTION_ON_CANCEL + host_action_cancel(); + #endif + #if ENABLED(HOST_PROMPT_SUPPORT) + host_prompt_open(PROMPT_INFO, PSTR("UI Abort")); + #endif + print_job_timer.stop(); + set_status_P(PSTR(MSG_PRINT_ABORTED)); + #if HAS_SPI_LCD + return_to_status(); + #endif + } + + void MarlinUI::pause_print() { + synchronize(PSTR(MSG_PAUSE_PRINT)); + + #if ENABLED(POWER_LOSS_RECOVERY) + if (recovery.enabled) recovery.save(true, false); + #endif + + #if ENABLED(HOST_PROMPT_SUPPORT) + host_prompt_open(PROMPT_PAUSE_RESUME, PSTR("UI Pause"), PSTR("Resume")); + #endif + + set_status_P(PSTR(MSG_PRINT_PAUSED)); + + #if ENABLED(PARK_HEAD_ON_PAUSE) + #if HAS_SPI_LCD + lcd_pause_show_message(PAUSE_MESSAGE_PAUSING, PAUSE_MODE_PAUSE_PRINT); // Show message immediately to let user know about pause in progress + #endif + enqueue_and_echo_commands_P(PSTR("M25 P\nM24")); + #elif ENABLED(SDSUPPORT) + enqueue_and_echo_commands_P(PSTR("M25")); + #elif defined(ACTION_ON_PAUSE) + host_action_pause(); + #endif + } + + void MarlinUI::resume_print() { + reset_status(); + #if ENABLED(PARK_HEAD_ON_PAUSE) + wait_for_heatup = wait_for_user = false; + #endif + #if ENABLED(SDSUPPORT) + if (card.isPaused()) enqueue_and_echo_commands_P(PSTR("M24")); + #endif + #ifdef ACTION_ON_RESUME + host_action_resume(); + #endif + print_job_timer.start(); // Also called by M24 + } + #if HAS_PRINT_PROGRESS uint8_t MarlinUI::get_progress() { #if ENABLED(LCD_SET_PROGRESS_MANUALLY) diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index fc573211b3..630539a986 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -286,6 +286,10 @@ public: static char* status_and_len(uint8_t &len); #endif + static void abort_print(); + static void pause_print(); + static void resume_print(); + #if HAS_PRINT_PROGRESS #if ENABLED(LCD_SET_PROGRESS_MANUALLY) static uint8_t progress_bar_percent;