Update do_select_screen for general use (#13800)

This commit is contained in:
Scott Lahteine
2019-04-24 10:13:44 -05:00
committed by GitHub
parent 63f6ad3fd2
commit 5051909c3c
16 changed files with 144 additions and 123 deletions

View File

@ -268,6 +268,8 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
#if HAS_GRAPHICAL_LCD
drawing_screen = false;
#endif
set_ui_selection(false);
}
}
@ -436,12 +438,21 @@ void _lcd_draw_homing() {
void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(!planner.leveling_active); }
#endif
void do_select_screen(PGM_P const yes, PGM_P const no, bool &yesno, PGM_P const pref, const char * const string, PGM_P const suff) {
//
// Selection screen presents a prompt and two options
//
bool ui_selection; // = false
void set_ui_selection(const bool sel) { ui_selection = sel; }
void do_select_screen(PGM_P const yes, PGM_P const no, selectFunc_t yesFunc, selectFunc_t noFunc, PGM_P const pref, const char * const string/*=NULL*/, PGM_P const suff/*=NULL*/) {
if (ui.encoderPosition) {
yesno = int16_t(ui.encoderPosition) > 0;
ui_selection = int16_t(ui.encoderPosition) > 0;
ui.encoderPosition = 0;
}
draw_select_screen(yes, no, yesno, pref, string, suff);
const bool got_click = ui.use_click();
if (got_click || ui.should_draw()) {
draw_select_screen(yes, no, ui_selection, pref, string, suff);
if (got_click) { ui_selection ? yesFunc() : noFunc(); }
}
}
#endif // HAS_LCD_MENU

View File

@ -65,12 +65,15 @@ DECLARE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01f ); // 123
///////// Menu Item Draw Functions /////////
////////////////////////////////////////////
void draw_edit_screen(PGM_P const pstr, const char* const value=NULL);
typedef void (*selectFunc_t)();
void draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string, PGM_P const suff);
void do_select_screen(PGM_P const yes, PGM_P const no, bool &yesno, PGM_P const pref, const char * const string=NULL, PGM_P const suff=NULL);
inline void do_select_screen_yn(bool &yesno, PGM_P const pref, const char * const string, PGM_P const suff) {
do_select_screen(PSTR(MSG_YES), PSTR(MSG_NO), yesno, pref, string, suff);
void set_ui_selection(const bool sel);
void do_select_screen(PGM_P const yes, PGM_P const no, selectFunc_t yesFunc, selectFunc_t noFunc, PGM_P const pref, const char * const string=NULL, PGM_P const suff=NULL);
inline void do_select_screen_yn(selectFunc_t yesFunc, selectFunc_t noFunc, PGM_P const pref, const char * const string=NULL, PGM_P const suff=NULL) {
do_select_screen(PSTR(MSG_YES), PSTR(MSG_NO), yesFunc, noFunc, pref, string, suff);
}
void draw_edit_screen(PGM_P const pstr, const char* const value=NULL);
void draw_menu_item(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char);
void draw_menu_item_static(const uint8_t row, PGM_P const pstr, const bool center=true, const bool invert=false, const char *valstr=NULL);
void _draw_menu_item_edit(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm);

View File

@ -604,16 +604,13 @@ void menu_backlash();
#include "../../module/configuration_store.h"
static void lcd_init_eeprom() {
ui.completion_feedback(settings.init_eeprom());
ui.goto_previous_screen();
}
static void lcd_init_eeprom_confirm() {
START_MENU();
MENU_BACK(MSG_ADVANCED_SETTINGS);
MENU_ITEM(function, MSG_INIT_EEPROM, lcd_init_eeprom);
END_MENU();
do_select_screen(
PSTR(MSG_BUTTON_INIT), PSTR(MSG_BUTTON_CANCEL),
[]{ ui.completion_feedback(settings.init_eeprom()); },
ui.goto_previous_screen,
PSTR(MSG_INIT_EEPROM), NULL, PSTR("?")
);
}
#endif

View File

@ -50,13 +50,6 @@ static_assert(LEVEL_CORNERS_Z_HOP >= 0, "LEVEL_CORNERS_Z_HOP must be >= 0. Pleas
static bool leveling_was_active = false;
#endif
static inline void _lcd_level_bed_corners_back() {
#if HAS_LEVELING
set_bed_leveling_enabled(leveling_was_active);
#endif
ui.goto_previous_screen_no_defer();
}
/**
* Level corners, starting in the front-left corner.
*/
@ -94,17 +87,23 @@ static inline void _lcd_goto_next_corner() {
}
static inline void menu_level_bed_corners() {
START_MENU();
MENU_ITEM(function,
#if ENABLED(LEVEL_CENTER_TOO)
MSG_LEVEL_BED_NEXT_POINT
#else
MSG_NEXT_CORNER
#endif
, _lcd_goto_next_corner
do_select_screen(
PSTR(MSG_BUTTON_NEXT), PSTR(MSG_BUTTON_DONE),
_lcd_goto_next_corner,
[]{
#if HAS_LEVELING
set_bed_leveling_enabled(leveling_was_active);
#endif
ui.goto_previous_screen_no_defer();
},
PSTR(
#if ENABLED(LEVEL_CENTER_TOO)
MSG_LEVEL_BED_NEXT_POINT
#else
MSG_NEXT_CORNER
#endif
), NULL, PSTR("?")
);
MENU_ITEM(function, MSG_BACK, _lcd_level_bed_corners_back);
END_MENU();
}
static inline void _lcd_level_bed_corners_homing() {
@ -112,6 +111,7 @@ static inline void _lcd_level_bed_corners_homing() {
if (all_axes_homed()) {
bed_corner = 0;
ui.goto_screen(menu_level_bed_corners);
set_ui_selection(true);
_lcd_goto_next_corner();
}
}

View File

@ -44,6 +44,8 @@ static void lcd_power_loss_recovery_cancel() {
ui.return_to_status();
}
// TODO: Display long filename with Cancel/Resume buttons
// Requires supporting methods in PLR class.
void menu_job_recovery() {
ui.defer_status_screen();
START_MENU();

View File

@ -101,10 +101,7 @@
}
void menu_abort_confirm() {
START_MENU();
MENU_BACK(MSG_MAIN);
MENU_ITEM(function, MSG_STOP_PRINT, lcd_abort_job);
END_MENU();
do_select_screen(PSTR(MSG_BUTTON_STOP), PSTR(MSG_BACK), lcd_abort_job, ui.goto_previous_screen, PSTR(MSG_STOP_PRINT), NULL, PSTR("?"));
}
#endif // MACHINE_CAN_STOP

View File

@ -250,17 +250,17 @@ void lcd_mixer_mix_edit() {
//
// Reset All V-Tools
//
inline void _lcd_reset_vtools() {
LCD_MESSAGEPGM(MSG_VTOOLS_RESET);
ui.return_to_status();
mixer.reset_vtools();
}
void menu_mixer_vtools_reset_confirm() {
START_MENU();
MENU_BACK(MSG_BACK);
MENU_ITEM(function, MSG_RESET_VTOOLS, _lcd_reset_vtools);
END_MENU();
do_select_screen(
PSTR(MSG_BUTTON_RESET), PSTR(MSG_BUTTON_CANCEL),
[]{
mixer.reset_vtools();
LCD_MESSAGEPGM(MSG_VTOOLS_RESET);
ui.return_to_status();
},
ui.goto_previous_screen,
PSTR(MSG_RESET_VTOOLS), NULL, PSTR("?")
);
}
void menu_mixer() {

View File

@ -81,17 +81,12 @@ inline void sdcard_start_selected_file() {
#if ENABLED(SD_MENU_CONFIRM_START)
bool do_print_file;
void menu_sd_confirm() {
if (ui.should_draw())
do_select_screen(PSTR(MSG_BUTTON_PRINT), PSTR(MSG_BUTTON_CANCEL), do_print_file, PSTR(MSG_START_PRINT " "), card.longest_filename(), PSTR("?"));
if (ui.use_click()) {
if (do_print_file)
sdcard_start_selected_file();
else
ui.goto_previous_screen();
}
do_select_screen(
PSTR(MSG_BUTTON_PRINT), PSTR(MSG_BUTTON_CANCEL),
sdcard_start_selected_file, ui.goto_previous_screen,
PSTR(MSG_START_PRINT " "), card.longest_filename(), PSTR("?")
);
}
#endif
@ -106,7 +101,6 @@ class MenuItem_sdfile {
sd_items = screen_items;
#endif
#if ENABLED(SD_MENU_CONFIRM_START)
do_print_file = false;
MenuItem_submenu::action(menu_sd_confirm);
#else
sdcard_start_selected_file();

View File

@ -31,52 +31,32 @@
#include "menu.h"
#include "../../module/printcounter.h"
inline void _lcd_reset_service(const int index) {
print_job_timer.resetServiceInterval(index);
BUZZ(200, 404);
ui.reset_status();
ui.return_to_status();
inline void _menu_service(const int index, PGM_P const name) {
char sram[30];
strncpy_P(sram, name, 29);
do_select_screen(
PSTR(MSG_BUTTON_RESET), PSTR(MSG_BUTTON_CANCEL),
[]{
print_job_timer.resetServiceInterval(index);
ui.completion_feedback(true);
ui.reset_status();
ui.return_to_status();
},
ui.goto_previous_screen,
PSTR(MSG_SERVICE_RESET), sram, PSTR("?")
);
}
#if SERVICE_INTERVAL_1 > 0
void menu_action_reset_service1() { _lcd_reset_service(1); }
void menu_service1() { _menu_service(1, PSTR(SERVICE_NAME_1)); }
#endif
#if SERVICE_INTERVAL_2 > 0
void menu_action_reset_service2() { _lcd_reset_service(2); }
void menu_service2() { _menu_service(2, PSTR(SERVICE_NAME_2)); }
#endif
#if SERVICE_INTERVAL_3 > 0
void menu_action_reset_service3() { _lcd_reset_service(3); }
#endif
inline void _menu_service(const int index) {
START_MENU();
MENU_BACK(MSG_MAIN);
switch (index) {
#if SERVICE_INTERVAL_1 > 0
case 1: MENU_ITEM(function, MSG_SERVICE_RESET, menu_action_reset_service1); break;
#endif
#if SERVICE_INTERVAL_2 > 0
case 2: MENU_ITEM(function, MSG_SERVICE_RESET, menu_action_reset_service2); break;
#endif
#if SERVICE_INTERVAL_3 > 0
case 3: MENU_ITEM(function, MSG_SERVICE_RESET, menu_action_reset_service3); break;
#endif
}
END_MENU();
}
#if SERVICE_INTERVAL_1 > 0
void menu_service1() { _menu_service(1); }
#endif
#if SERVICE_INTERVAL_2 > 0
void menu_service2() { _menu_service(2); }
#endif
#if SERVICE_INTERVAL_3 > 0
void menu_service3() { _menu_service(3); }
void menu_service3() { _menu_service(3, PSTR(SERVICE_NAME_3)); }
#endif
#endif // HAS_LCD_MENU && HAS_SERVICE_INTERVALS && PRINTCOUNTER