Shutdown Host Action (#22908)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
aalku 2021-10-30 07:17:20 +02:00 committed by Scott Lahteine
parent 8562f0ec44
commit 7b9e01eb2b
12 changed files with 40 additions and 23 deletions

View File

@ -3844,7 +3844,8 @@
#if ENABLED(HOST_ACTION_COMMANDS) #if ENABLED(HOST_ACTION_COMMANDS)
//#define HOST_PAUSE_M76 //#define HOST_PAUSE_M76
//#define HOST_PROMPT_SUPPORT //#define HOST_PROMPT_SUPPORT
//#define HOST_START_MENU_ITEM // Add a menu item that tells the host to start //#define HOST_START_MENU_ITEM // Add a menu item that tells the host to start
//#define HOST_SHUTDOWN_MENU_ITEM // Add a menu item that tells the host to shut down
#endif #endif
/** /**

View File

@ -80,6 +80,10 @@ void HostUI::action(FSTR_P const fstr, const bool eol) {
#endif #endif
#endif #endif
#ifdef SHUTDOWN_ACTION
void HostUI::shutdown() { action(F(SHUTDOWN_ACTION)); }
#endif
#if ENABLED(HOST_PROMPT_SUPPORT) #if ENABLED(HOST_PROMPT_SUPPORT)
PromptReason HostUI::host_prompt_reason = PROMPT_NOT_DEFINED; PromptReason HostUI::host_prompt_reason = PROMPT_NOT_DEFINED;

View File

@ -71,6 +71,9 @@ class HostUI {
#ifdef ACTION_ON_START #ifdef ACTION_ON_START
static void start(); static void start();
#endif #endif
#ifdef SHUTDOWN_ACTION
static void shutdown();
#endif
#if ENABLED(G29_RETRY_AND_RECOVER) #if ENABLED(G29_RETRY_AND_RECOVER)
#ifdef ACTION_ON_G29_RECOVER #ifdef ACTION_ON_G29_RECOVER

View File

@ -701,6 +701,9 @@
#ifndef ACTION_ON_KILL #ifndef ACTION_ON_KILL
#define ACTION_ON_KILL "poweroff" #define ACTION_ON_KILL "poweroff"
#endif #endif
#ifndef SHUTDOWN_ACTION
#define SHUTDOWN_ACTION "shutdown"
#endif
#if HAS_FILAMENT_SENSOR #if HAS_FILAMENT_SENSOR
#ifndef ACTION_ON_FILAMENT_RUNOUT #ifndef ACTION_ON_FILAMENT_RUNOUT
#define ACTION_ON_FILAMENT_RUNOUT "filament_runout" #define ACTION_ON_FILAMENT_RUNOUT "filament_runout"

View File

@ -745,6 +745,8 @@ namespace Language_en {
LSTR MSG_SD_CARD = _UxGT("SD Card"); LSTR MSG_SD_CARD = _UxGT("SD Card");
LSTR MSG_USB_DISK = _UxGT("USB Disk"); LSTR MSG_USB_DISK = _UxGT("USB Disk");
LSTR MSG_HOST_SHUTDOWN = _UxGT("Host Shutdown");
// These strings can be the same in all languages // These strings can be the same in all languages
LSTR MSG_MARLIN = _UxGT("Marlin"); LSTR MSG_MARLIN = _UxGT("Marlin");
LSTR MSG_SHORT_DAY = _UxGT("d"); // One character only LSTR MSG_SHORT_DAY = _UxGT("d"); // One character only

View File

@ -213,7 +213,7 @@ static void _lcd_level_bed_corners_get_next_position() {
if (!ui.should_draw()) return; if (!ui.should_draw()) return;
MenuItem_confirm::confirm_screen( MenuItem_confirm::confirm_screen(
[]{ queue.inject(TERN(HAS_LEVELING, F("G29N"), FPSTR(G28_STR))); ui.return_to_status(); } []{ queue.inject(TERN(HAS_LEVELING, F("G29N"), FPSTR(G28_STR))); ui.return_to_status(); }
, []{ ui.goto_previous_screen_no_defer(); } , ui.goto_previous_screen_no_defer
, GET_TEXT(MSG_BED_TRAMMING_IN_RANGE) , GET_TEXT(MSG_BED_TRAMMING_IN_RANGE)
, (const char*)nullptr, PSTR("?") , (const char*)nullptr, PSTR("?")
); );

View File

@ -47,7 +47,7 @@ static void lcd_cancel_object_confirm() {
ui.completion_feedback(); ui.completion_feedback();
ui.goto_previous_screen(); ui.goto_previous_screen();
}, },
ui.goto_previous_screen, nullptr,
GET_TEXT(MSG_CANCEL_OBJECT), item_num, PSTR("?") GET_TEXT(MSG_CANCEL_OBJECT), item_num, PSTR("?")
); );
} }

View File

@ -64,9 +64,7 @@ void menu_advanced_settings();
static int8_t bar_percent = 0; static int8_t bar_percent = 0;
if (ui.use_click()) { if (ui.use_click()) {
ui.goto_previous_screen(); ui.goto_previous_screen();
#if HAS_MARLINUI_HD44780 TERN_(HAS_MARLINUI_HD44780, ui.set_custom_characters(CHARSET_MENU));
ui.set_custom_characters(CHARSET_MENU);
#endif
return; return;
} }
bar_percent += (int8_t)ui.encoderPosition; bar_percent += (int8_t)ui.encoderPosition;
@ -79,9 +77,7 @@ void menu_advanced_settings();
void _progress_bar_test() { void _progress_bar_test() {
ui.goto_screen(progress_bar_test); ui.goto_screen(progress_bar_test);
#if HAS_MARLINUI_HD44780 TERN_(HAS_MARLINUI_HD44780, ui.set_custom_characters(CHARSET_INFO));
ui.set_custom_characters(CHARSET_INFO);
#endif
} }
#endif // LCD_PROGRESS_BAR_TEST #endif // LCD_PROGRESS_BAR_TEST
@ -363,8 +359,7 @@ void menu_advanced_settings();
#define _CUSTOM_ITEM_CONF_CONFIRM(N) \ #define _CUSTOM_ITEM_CONF_CONFIRM(N) \
SUBMENU_P(PSTR(CONFIG_MENU_ITEM_##N##_DESC), []{ \ SUBMENU_P(PSTR(CONFIG_MENU_ITEM_##N##_DESC), []{ \
MenuItem_confirm::confirm_screen( \ MenuItem_confirm::confirm_screen( \
GCODE_LAMBDA_CONF(N), \ GCODE_LAMBDA_CONF(N), nullptr, \
ui.goto_previous_screen, \
PSTR(CONFIG_MENU_ITEM_##N##_DESC "?") \ PSTR(CONFIG_MENU_ITEM_##N##_DESC "?") \
); \ ); \
}) })

View File

@ -58,7 +58,7 @@
#include "../../feature/password/password.h" #include "../../feature/password/password.h"
#endif #endif
#if ENABLED(HOST_START_MENU_ITEM) && defined(ACTION_ON_START) #if (ENABLED(HOST_START_MENU_ITEM) && defined(ACTION_ON_START)) || (ENABLED(HOST_SHUTDOWN_MENU_ITEM) && defined(SHUTDOWN_ACTION))
#include "../../feature/host_actions.h" #include "../../feature/host_actions.h"
#endif #endif
@ -128,8 +128,7 @@ void menu_configuration();
#define _CUSTOM_ITEM_MAIN_CONFIRM(N) \ #define _CUSTOM_ITEM_MAIN_CONFIRM(N) \
SUBMENU_P(PSTR(MAIN_MENU_ITEM_##N##_DESC), []{ \ SUBMENU_P(PSTR(MAIN_MENU_ITEM_##N##_DESC), []{ \
MenuItem_confirm::confirm_screen( \ MenuItem_confirm::confirm_screen( \
GCODE_LAMBDA_MAIN(N), \ GCODE_LAMBDA_MAIN(N), nullptr, \
ui.goto_previous_screen, \
PSTR(MAIN_MENU_ITEM_##N##_DESC "?") \ PSTR(MAIN_MENU_ITEM_##N##_DESC "?") \
); \ ); \
}) })
@ -274,7 +273,7 @@ void menu_main() {
SUBMENU(MSG_STOP_PRINT, []{ SUBMENU(MSG_STOP_PRINT, []{
MenuItem_confirm::select_screen( MenuItem_confirm::select_screen(
GET_TEXT(MSG_BUTTON_STOP), GET_TEXT(MSG_BACK), GET_TEXT(MSG_BUTTON_STOP), GET_TEXT(MSG_BACK),
ui.abort_print, ui.goto_previous_screen, ui.abort_print, nullptr,
GET_TEXT(MSG_STOP_PRINT), (const char *)nullptr, PSTR("?") GET_TEXT(MSG_STOP_PRINT), (const char *)nullptr, PSTR("?")
); );
}); });
@ -346,7 +345,7 @@ void menu_main() {
#if ENABLED(ADVANCED_PAUSE_FEATURE) #if ENABLED(ADVANCED_PAUSE_FEATURE)
#if E_STEPPERS == 1 && DISABLED(FILAMENT_LOAD_UNLOAD_GCODES) #if E_STEPPERS == 1 && DISABLED(FILAMENT_LOAD_UNLOAD_GCODES)
YESNO_ITEM(MSG_FILAMENTCHANGE, YESNO_ITEM(MSG_FILAMENTCHANGE,
menu_change_filament, ui.goto_previous_screen, menu_change_filament, nullptr,
GET_TEXT(MSG_FILAMENTCHANGE), (const char *)nullptr, PSTR("?") GET_TEXT(MSG_FILAMENTCHANGE), (const char *)nullptr, PSTR("?")
); );
#else #else
@ -370,7 +369,7 @@ void menu_main() {
#if ENABLED(PS_OFF_CONFIRM) #if ENABLED(PS_OFF_CONFIRM)
CONFIRM_ITEM(MSG_SWITCH_PS_OFF, CONFIRM_ITEM(MSG_SWITCH_PS_OFF,
MSG_YES, MSG_NO, MSG_YES, MSG_NO,
ui.poweroff, ui.goto_previous_screen, ui.poweroff, nullptr,
GET_TEXT(MSG_SWITCH_PS_OFF), (const char *)nullptr, PSTR("?") GET_TEXT(MSG_SWITCH_PS_OFF), (const char *)nullptr, PSTR("?")
); );
#else #else
@ -394,21 +393,21 @@ void menu_main() {
#if SERVICE_INTERVAL_1 > 0 #if SERVICE_INTERVAL_1 > 0
CONFIRM_ITEM_P(PSTR(SERVICE_NAME_1), CONFIRM_ITEM_P(PSTR(SERVICE_NAME_1),
MSG_BUTTON_RESET, MSG_BUTTON_CANCEL, MSG_BUTTON_RESET, MSG_BUTTON_CANCEL,
[]{ _service_reset(1); }, ui.goto_previous_screen, []{ _service_reset(1); }, nullptr,
GET_TEXT(MSG_SERVICE_RESET), F(SERVICE_NAME_1), PSTR("?") GET_TEXT(MSG_SERVICE_RESET), F(SERVICE_NAME_1), PSTR("?")
); );
#endif #endif
#if SERVICE_INTERVAL_2 > 0 #if SERVICE_INTERVAL_2 > 0
CONFIRM_ITEM_P(PSTR(SERVICE_NAME_2), CONFIRM_ITEM_P(PSTR(SERVICE_NAME_2),
MSG_BUTTON_RESET, MSG_BUTTON_CANCEL, MSG_BUTTON_RESET, MSG_BUTTON_CANCEL,
[]{ _service_reset(2); }, ui.goto_previous_screen, []{ _service_reset(2); }, nullptr,
GET_TEXT(MSG_SERVICE_RESET), F(SERVICE_NAME_2), PSTR("?") GET_TEXT(MSG_SERVICE_RESET), F(SERVICE_NAME_2), PSTR("?")
); );
#endif #endif
#if SERVICE_INTERVAL_3 > 0 #if SERVICE_INTERVAL_3 > 0
CONFIRM_ITEM_P(PSTR(SERVICE_NAME_3), CONFIRM_ITEM_P(PSTR(SERVICE_NAME_3),
MSG_BUTTON_RESET, MSG_BUTTON_CANCEL, MSG_BUTTON_RESET, MSG_BUTTON_CANCEL,
[]{ _service_reset(3); }, ui.goto_previous_screen, []{ _service_reset(3); }, nullptr,
GET_TEXT(MSG_SERVICE_RESET), F(SERVICE_NAME_3), PSTR("?") GET_TEXT(MSG_SERVICE_RESET), F(SERVICE_NAME_3), PSTR("?")
); );
#endif #endif
@ -442,6 +441,16 @@ void menu_main() {
SUBMENU(LANGUAGE, menu_language); SUBMENU(LANGUAGE, menu_language);
#endif #endif
#if ENABLED(HOST_SHUTDOWN_MENU_ITEM) && defined(SHUTDOWN_ACTION)
SUBMENU(MSG_HOST_SHUTDOWN, []{
MenuItem_confirm::select_screen(
GET_TEXT(MSG_BUTTON_PROCEED), GET_TEXT(MSG_BUTTON_CANCEL),
[]{ ui.return_to_status(); hostui.shutdown(); }, nullptr,
GET_TEXT(MSG_HOST_SHUTDOWN), (const char *)nullptr, PSTR("?")
);
});
#endif
END_MENU(); END_MENU();
} }

View File

@ -79,7 +79,7 @@ class MenuItem_sdfile : public MenuItem_sdbase {
strcpy(buffer + 1, longest); strcpy(buffer + 1, longest);
MenuItem_confirm::select_screen( MenuItem_confirm::select_screen(
GET_TEXT(MSG_BUTTON_PRINT), GET_TEXT(MSG_BUTTON_CANCEL), GET_TEXT(MSG_BUTTON_PRINT), GET_TEXT(MSG_BUTTON_CANCEL),
sdcard_start_selected_file, ui.goto_previous_screen, sdcard_start_selected_file, nullptr,
GET_TEXT(MSG_START_PRINT), buffer, PSTR("?") GET_TEXT(MSG_START_PRINT), buffer, PSTR("?")
); );
}); });

View File

@ -210,7 +210,7 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int
ui.goto_screen([]{ ui.goto_screen([]{
MenuItem_confirm::select_screen( MenuItem_confirm::select_screen(
GET_TEXT(MSG_BUTTON_PROCEED), GET_TEXT(MSG_BACK), GET_TEXT(MSG_BUTTON_PROCEED), GET_TEXT(MSG_BACK),
_goto_menu_move_distance_e, ui.goto_previous_screen, _goto_menu_move_distance_e, nullptr,
GET_TEXT(MSG_HOTEND_TOO_COLD), (const char *)nullptr, PSTR("!") GET_TEXT(MSG_HOTEND_TOO_COLD), (const char *)nullptr, PSTR("!")
); );
}); });

View File

@ -66,7 +66,7 @@ static void _menu_single_probe() {
STATIC_ITEM(MSG_BED_TRAMMING, SS_LEFT); STATIC_ITEM(MSG_BED_TRAMMING, SS_LEFT);
STATIC_ITEM(MSG_LAST_VALUE_SP, SS_LEFT, z_isvalid[tram_index] ? ftostr42_52(z_measured[reference_index] - z_measured[tram_index]) : "---"); STATIC_ITEM(MSG_LAST_VALUE_SP, SS_LEFT, z_isvalid[tram_index] ? ftostr42_52(z_measured[reference_index] - z_measured[tram_index]) : "---");
ACTION_ITEM(MSG_UBL_BC_INSERT2, []{ if (probe_single_point()) ui.refresh(); }); ACTION_ITEM(MSG_UBL_BC_INSERT2, []{ if (probe_single_point()) ui.refresh(); });
ACTION_ITEM(MSG_BUTTON_DONE, []{ ui.goto_previous_screen(); }); ACTION_ITEM(MSG_BUTTON_DONE, ui.goto_previous_screen);
END_MENU(); END_MENU();
} }