Skip to content

Commit

Permalink
Open File Browser on Media Insert (option) (MarlinFirmware#20151)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
2 people authored and FhlostonParadise committed Nov 21, 2020
1 parent f3bd4fa commit 447e9a9
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,8 @@

//#define MENU_ADDAUTOSTART // Add a menu option to run auto#.g files

//#define BROWSE_MEDIA_ON_INSERT // Open the file browser when media is inserted

#define EVENT_GCODE_SD_ABORT "G28XY" // G-code to run on SD Abort Print (e.g., "G28XY" or "G27")

#if ENABLED(PRINTER_EVENT_LEDS)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/password/password.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Password {
static void start_over();

static void digit_entered();
static void set_password_done();
static void set_password_done(const bool with_set=true);
static void menu_password_report();

static void remove_password();
Expand Down
8 changes: 2 additions & 6 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,8 @@ class GcodeSuite {

#if ENABLED(PASSWORD_FEATURE)
static void M510();
#if ENABLED(PASSWORD_UNLOCK_GCODE)
static void M511();
#endif
#if ENABLED(PASSWORD_CHANGE_GCODE)
static void M512();
#endif
TERN_(PASSWORD_UNLOCK_GCODE, static void M511());
TERN_(PASSWORD_CHANGE_GCODE, static void M512());
#endif

TERN_(SDSUPPORT, static void M524());
Expand Down
11 changes: 10 additions & 1 deletion Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include "../feature/host_actions.h"
#endif

#if ENABLED(BROWSE_MEDIA_ON_INSERT, PASSWORD_ON_SD_PRINT_MENU)
#include "../feature/password/password.h"
#endif

// All displays share the MarlinUI class
#include "marlinui.h"
MarlinUI ui;
Expand Down Expand Up @@ -1620,7 +1624,12 @@ void MarlinUI::update() {
if (status) {
if (old_status < 2) {
TERN_(EXTENSIBLE_UI, ExtUI::onMediaInserted()); // ExtUI response
set_status_P(GET_TEXT(MSG_MEDIA_INSERTED));
#if ENABLED(BROWSE_MEDIA_ON_INSERT)
quick_feedback();
goto_screen(MEDIA_MENU_GATEWAY);
#else
set_status_P(GET_TEXT(MSG_MEDIA_INSERTED));
#endif
}
}
else {
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class MarlinUI {
#endif

#if ENABLED(SDSUPPORT)
#define MEDIA_MENU_GATEWAY TERN(PASSWORD_ON_SD_PRINT_MENU, password.media_gatekeeper, menu_media)
static void media_changed(const uint8_t old_stat, const uint8_t stat);
#endif

Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/menu/menu_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ class MenuItem_bool : public MenuEditItemBase {
#define MENU_ITEM_P(TYPE, PLABEL, V...) _MENU_ITEM_P(TYPE, false, PLABEL, ##V)
#define MENU_ITEM(TYPE, LABEL, V...) MENU_ITEM_P(TYPE, GET_TEXT(LABEL), ##V)

#define BACK_ITEM_P(PLABEL) MENU_ITEM_P(back, PLABEL)
#define BACK_ITEM(LABEL) MENU_ITEM(back, LABEL)

#define ACTION_ITEM_N_S_P(N, S, PLABEL, ACTION) MENU_ITEM_N_S_P(function, N, S, PLABEL, ACTION)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void menu_main() {

if (card_detected) {
if (!card_open) {
SUBMENU(MSG_MEDIA_MENU, TERN(PASSWORD_ON_SD_PRINT_MENU, password.media_gatekeeper, menu_media));
SUBMENU(MSG_MEDIA_MENU, MEDIA_MENU_GATEWAY);
#if PIN_EXISTS(SD_DETECT)
GCODES_ITEM(MSG_CHANGE_MEDIA, M21_STR);
#else
Expand Down Expand Up @@ -248,7 +248,7 @@ void menu_main() {
#else
GCODES_ITEM(MSG_RELEASE_MEDIA, PSTR("M22"));
#endif
SUBMENU(MSG_MEDIA_MENU, TERN(PASSWORD_ON_SD_PRINT_MENU, password.media_gatekeeper, menu_media));
SUBMENU(MSG_MEDIA_MENU, MEDIA_MENU_GATEWAY);
}
}
else {
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/lcd/menu/menu_media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class MenuItem_sdfolder : public MenuItem_sdbase {
}
};

extern uint8_t screen_history_depth;

void menu_media() {
ui.encoder_direction_menus();

Expand All @@ -115,7 +117,7 @@ void menu_media() {
#endif

START_MENU();
BACK_ITEM(MSG_MAIN);
BACK_ITEM_P(TERN1(BROWSE_MEDIA_ON_INSERT, screen_history_depth) ? GET_TEXT(MSG_MAIN) : GET_TEXT(MSG_BACK));
if (card.flag.workDirIsRoot) {
#if !PIN_EXISTS(SD_DETECT)
ACTION_ITEM(MSG_REFRESH, []{ encoderTopLine = 0; card.mount(); });
Expand Down
8 changes: 3 additions & 5 deletions Marlin/src/lcd/menu/menu_password.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,17 @@ void Password::menu_password_report() {
END_SCREEN();
}

void Password::set_password_done() {
is_set = true;
void Password::set_password_done(const bool with_set/*=true*/) {
is_set = with_set;
value = value_entry;
ui.completion_feedback(true);
ui.goto_screen(menu_password_report);
}

void Password::remove_password() {
is_set = false;
string[0] = '0';
string[1] = '\0';
ui.completion_feedback(true);
ui.goto_screen(menu_password_report);
set_password_done(false);
}

//
Expand Down

0 comments on commit 447e9a9

Please sign in to comment.