Skip to content

Commit

Permalink
✨ Shutdown Host Action (MarlinFirmware#22908)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
aalku and thinkyhead committed Dec 25, 2021
1 parent 8562f0e commit 7b9e01e
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 23 deletions.
3 changes: 2 additions & 1 deletion Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3844,7 +3844,8 @@
#if ENABLED(HOST_ACTION_COMMANDS)
//#define HOST_PAUSE_M76
//#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

/**
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/feature/host_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ void HostUI::action(FSTR_P const fstr, const bool eol) {
#endif
#endif

#ifdef SHUTDOWN_ACTION
void HostUI::shutdown() { action(F(SHUTDOWN_ACTION)); }
#endif

#if ENABLED(HOST_PROMPT_SUPPORT)

PromptReason HostUI::host_prompt_reason = PROMPT_NOT_DEFINED;
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/feature/host_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class HostUI {
#ifdef ACTION_ON_START
static void start();
#endif
#ifdef SHUTDOWN_ACTION
static void shutdown();
#endif

#if ENABLED(G29_RETRY_AND_RECOVER)
#ifdef ACTION_ON_G29_RECOVER
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,9 @@
#ifndef ACTION_ON_KILL
#define ACTION_ON_KILL "poweroff"
#endif
#ifndef SHUTDOWN_ACTION
#define SHUTDOWN_ACTION "shutdown"
#endif
#if HAS_FILAMENT_SENSOR
#ifndef ACTION_ON_FILAMENT_RUNOUT
#define ACTION_ON_FILAMENT_RUNOUT "filament_runout"
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ namespace Language_en {
LSTR MSG_SD_CARD = _UxGT("SD Card");
LSTR MSG_USB_DISK = _UxGT("USB Disk");

LSTR MSG_HOST_SHUTDOWN = _UxGT("Host Shutdown");

// These strings can be the same in all languages
LSTR MSG_MARLIN = _UxGT("Marlin");
LSTR MSG_SHORT_DAY = _UxGT("d"); // One character only
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_bed_corners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static void _lcd_level_bed_corners_get_next_position() {
if (!ui.should_draw()) return;
MenuItem_confirm::confirm_screen(
[]{ 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)
, (const char*)nullptr, PSTR("?")
);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_cancelobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void lcd_cancel_object_confirm() {
ui.completion_feedback();
ui.goto_previous_screen();
},
ui.goto_previous_screen,
nullptr,
GET_TEXT(MSG_CANCEL_OBJECT), item_num, PSTR("?")
);
}
Expand Down
11 changes: 3 additions & 8 deletions Marlin/src/lcd/menu/menu_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ void menu_advanced_settings();
static int8_t bar_percent = 0;
if (ui.use_click()) {
ui.goto_previous_screen();
#if HAS_MARLINUI_HD44780
ui.set_custom_characters(CHARSET_MENU);
#endif
TERN_(HAS_MARLINUI_HD44780, ui.set_custom_characters(CHARSET_MENU));
return;
}
bar_percent += (int8_t)ui.encoderPosition;
Expand All @@ -79,9 +77,7 @@ void menu_advanced_settings();

void _progress_bar_test() {
ui.goto_screen(progress_bar_test);
#if HAS_MARLINUI_HD44780
ui.set_custom_characters(CHARSET_INFO);
#endif
TERN_(HAS_MARLINUI_HD44780, ui.set_custom_characters(CHARSET_INFO));
}

#endif // LCD_PROGRESS_BAR_TEST
Expand Down Expand Up @@ -363,8 +359,7 @@ void menu_advanced_settings();
#define _CUSTOM_ITEM_CONF_CONFIRM(N) \
SUBMENU_P(PSTR(CONFIG_MENU_ITEM_##N##_DESC), []{ \
MenuItem_confirm::confirm_screen( \
GCODE_LAMBDA_CONF(N), \
ui.goto_previous_screen, \
GCODE_LAMBDA_CONF(N), nullptr, \
PSTR(CONFIG_MENU_ITEM_##N##_DESC "?") \
); \
})
Expand Down
27 changes: 18 additions & 9 deletions Marlin/src/lcd/menu/menu_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#include "../../feature/password/password.h"
#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"
#endif

Expand Down Expand Up @@ -128,8 +128,7 @@ void menu_configuration();
#define _CUSTOM_ITEM_MAIN_CONFIRM(N) \
SUBMENU_P(PSTR(MAIN_MENU_ITEM_##N##_DESC), []{ \
MenuItem_confirm::confirm_screen( \
GCODE_LAMBDA_MAIN(N), \
ui.goto_previous_screen, \
GCODE_LAMBDA_MAIN(N), nullptr, \
PSTR(MAIN_MENU_ITEM_##N##_DESC "?") \
); \
})
Expand Down Expand Up @@ -274,7 +273,7 @@ void menu_main() {
SUBMENU(MSG_STOP_PRINT, []{
MenuItem_confirm::select_screen(
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("?")
);
});
Expand Down Expand Up @@ -346,7 +345,7 @@ void menu_main() {
#if ENABLED(ADVANCED_PAUSE_FEATURE)
#if E_STEPPERS == 1 && DISABLED(FILAMENT_LOAD_UNLOAD_GCODES)
YESNO_ITEM(MSG_FILAMENTCHANGE,
menu_change_filament, ui.goto_previous_screen,
menu_change_filament, nullptr,
GET_TEXT(MSG_FILAMENTCHANGE), (const char *)nullptr, PSTR("?")
);
#else
Expand All @@ -370,7 +369,7 @@ void menu_main() {
#if ENABLED(PS_OFF_CONFIRM)
CONFIRM_ITEM(MSG_SWITCH_PS_OFF,
MSG_YES, MSG_NO,
ui.poweroff, ui.goto_previous_screen,
ui.poweroff, nullptr,
GET_TEXT(MSG_SWITCH_PS_OFF), (const char *)nullptr, PSTR("?")
);
#else
Expand All @@ -394,21 +393,21 @@ void menu_main() {
#if SERVICE_INTERVAL_1 > 0
CONFIRM_ITEM_P(PSTR(SERVICE_NAME_1),
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("?")
);
#endif
#if SERVICE_INTERVAL_2 > 0
CONFIRM_ITEM_P(PSTR(SERVICE_NAME_2),
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("?")
);
#endif
#if SERVICE_INTERVAL_3 > 0
CONFIRM_ITEM_P(PSTR(SERVICE_NAME_3),
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("?")
);
#endif
Expand Down Expand Up @@ -442,6 +441,16 @@ void menu_main() {
SUBMENU(LANGUAGE, menu_language);
#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();
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MenuItem_sdfile : public MenuItem_sdbase {
strcpy(buffer + 1, longest);
MenuItem_confirm::select_screen(
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("?")
);
});
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int
ui.goto_screen([]{
MenuItem_confirm::select_screen(
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("!")
);
});
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_tramming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static void _menu_single_probe() {
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]) : "---");
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();
}

Expand Down

0 comments on commit 7b9e01e

Please sign in to comment.