2018-10-28 09:10:25 +01:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-10-28 09:10:25 +01:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2018-10-28 09:10:25 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-10-28 09:10:25 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
|
|
|
// SD Card Menu
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "../../inc/MarlinConfigPre.h"
|
|
|
|
|
2020-04-24 04:42:38 +02:00
|
|
|
#if BOTH(HAS_LCD_MENU, SDSUPPORT)
|
2018-10-28 09:10:25 +01:00
|
|
|
|
2020-08-21 12:21:34 +02:00
|
|
|
#include "menu_item.h"
|
2018-10-28 09:10:25 +01:00
|
|
|
#include "../../sd/cardreader.h"
|
|
|
|
|
|
|
|
void lcd_sd_updir() {
|
2019-09-28 22:28:05 +02:00
|
|
|
ui.encoderPosition = card.cdup() ? ENCODER_STEPS_PER_MENU_ITEM : 0;
|
2018-10-28 09:10:25 +01:00
|
|
|
encoderTopLine = 0;
|
2019-11-15 03:30:30 +01:00
|
|
|
ui.screen_changed = true;
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.refresh();
|
2018-10-28 09:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
|
2018-11-11 19:16:24 +01:00
|
|
|
|
2019-04-09 04:10:41 +02:00
|
|
|
uint16_t sd_encoder_position = 0xFFFF;
|
|
|
|
int8_t sd_top_line, sd_items;
|
2018-10-28 09:10:25 +01:00
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
void MarlinUI::reselect_last_file() {
|
2019-04-09 04:10:41 +02:00
|
|
|
if (sd_encoder_position == 0xFFFF) return;
|
2019-08-15 00:52:14 +02:00
|
|
|
goto_screen(menu_media, sd_encoder_position, sd_top_line, sd_items);
|
2019-04-09 04:10:41 +02:00
|
|
|
sd_encoder_position = 0xFFFF;
|
2019-03-23 22:30:43 +01:00
|
|
|
defer_status_screen();
|
2018-10-28 09:10:25 +01:00
|
|
|
}
|
2020-04-28 06:52:11 +02:00
|
|
|
|
2018-10-28 09:10:25 +01:00
|
|
|
#endif
|
|
|
|
|
2019-04-08 20:44:35 +02:00
|
|
|
inline void sdcard_start_selected_file() {
|
|
|
|
card.openAndPrintFile(card.filename);
|
|
|
|
ui.return_to_status();
|
|
|
|
ui.reset_status();
|
|
|
|
}
|
|
|
|
|
2019-11-02 13:28:20 +01:00
|
|
|
class MenuItem_sdfile : public MenuItem_sdbase {
|
2018-11-06 05:51:10 +01:00
|
|
|
public:
|
2019-11-02 13:28:20 +01:00
|
|
|
static inline void draw(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard) {
|
|
|
|
MenuItem_sdbase::draw(sel, row, pstr, theCard, false);
|
|
|
|
}
|
2019-10-01 05:53:34 +02:00
|
|
|
static void action(PGM_P const pstr, CardReader &) {
|
2018-11-06 05:51:10 +01:00
|
|
|
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
|
2019-04-09 04:10:41 +02:00
|
|
|
// Save menu state for the selected file
|
|
|
|
sd_encoder_position = ui.encoderPosition;
|
2019-04-11 00:43:08 +02:00
|
|
|
sd_top_line = encoderTopLine;
|
|
|
|
sd_items = screen_items;
|
2018-11-06 05:51:10 +01:00
|
|
|
#endif
|
2019-04-08 20:44:35 +02:00
|
|
|
#if ENABLED(SD_MENU_CONFIRM_START)
|
2019-11-07 07:28:33 +01:00
|
|
|
MenuItem_submenu::action(pstr, []{
|
|
|
|
char * const longest = card.longest_filename();
|
|
|
|
char buffer[strlen(longest) + 2];
|
|
|
|
buffer[0] = ' ';
|
|
|
|
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,
|
|
|
|
GET_TEXT(MSG_START_PRINT), buffer, PSTR("?")
|
|
|
|
);
|
|
|
|
});
|
2019-04-08 20:44:35 +02:00
|
|
|
#else
|
|
|
|
sdcard_start_selected_file();
|
2019-10-01 04:44:07 +02:00
|
|
|
UNUSED(pstr);
|
2019-04-08 20:44:35 +02:00
|
|
|
#endif
|
2018-11-06 05:51:10 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-02 13:28:20 +01:00
|
|
|
class MenuItem_sdfolder : public MenuItem_sdbase {
|
2018-11-06 05:51:10 +01:00
|
|
|
public:
|
2019-11-02 13:28:20 +01:00
|
|
|
static inline void draw(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard) {
|
|
|
|
MenuItem_sdbase::draw(sel, row, pstr, theCard, true);
|
|
|
|
}
|
2019-10-01 05:53:34 +02:00
|
|
|
static void action(PGM_P const, CardReader &theCard) {
|
2019-09-28 22:28:05 +02:00
|
|
|
card.cd(theCard.filename);
|
2018-11-06 05:51:10 +01:00
|
|
|
encoderTopLine = 0;
|
2019-04-11 00:43:08 +02:00
|
|
|
ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);
|
2019-11-15 03:30:30 +01:00
|
|
|
ui.screen_changed = true;
|
2020-09-28 08:13:27 +02:00
|
|
|
TERN_(HAS_MARLINUI_U8GLIB, ui.drawing_screen = false);
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.refresh();
|
2018-11-06 05:51:10 +01:00
|
|
|
}
|
|
|
|
};
|
2018-10-28 09:10:25 +01:00
|
|
|
|
2019-08-15 00:52:14 +02:00
|
|
|
void menu_media() {
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.encoder_direction_menus();
|
2018-10-28 09:10:25 +01:00
|
|
|
|
2020-09-28 08:13:27 +02:00
|
|
|
#if HAS_MARLINUI_U8GLIB
|
2019-09-13 01:06:07 +02:00
|
|
|
static uint16_t fileCnt;
|
2019-09-17 00:49:55 +02:00
|
|
|
if (ui.first_page) fileCnt = card.get_num_Files();
|
2019-09-13 01:06:07 +02:00
|
|
|
#else
|
|
|
|
const uint16_t fileCnt = card.get_num_Files();
|
|
|
|
#endif
|
2018-10-28 09:10:25 +01:00
|
|
|
|
|
|
|
START_MENU();
|
2020-11-18 05:30:32 +01:00
|
|
|
BACK_ITEM_P(TERN1(BROWSE_MEDIA_ON_INSERT, screen_history_depth) ? GET_TEXT(MSG_MAIN) : GET_TEXT(MSG_BACK));
|
2019-09-17 00:49:55 +02:00
|
|
|
if (card.flag.workDirIsRoot) {
|
2018-10-28 09:10:25 +01:00
|
|
|
#if !PIN_EXISTS(SD_DETECT)
|
2019-11-02 06:05:05 +01:00
|
|
|
ACTION_ITEM(MSG_REFRESH, []{ encoderTopLine = 0; card.mount(); });
|
2018-10-28 09:10:25 +01:00
|
|
|
#endif
|
|
|
|
}
|
2019-09-15 10:10:59 +02:00
|
|
|
else if (card.isMounted())
|
2019-10-10 02:46:10 +02:00
|
|
|
ACTION_ITEM_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
|
2018-10-28 09:10:25 +01:00
|
|
|
|
2019-01-09 06:08:20 +01:00
|
|
|
if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
|
2018-10-28 09:10:25 +01:00
|
|
|
if (_menuLineNr == _thisItemNr) {
|
2020-07-17 05:20:55 +02:00
|
|
|
card.getfilename_sorted(SD_ORDER(i, fileCnt));
|
2020-04-29 21:52:42 +02:00
|
|
|
if (card.flag.filenameIsDir)
|
2019-08-15 00:52:14 +02:00
|
|
|
MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
|
2020-04-29 21:52:42 +02:00
|
|
|
else
|
2019-08-15 00:52:14 +02:00
|
|
|
MENU_ITEM(sdfile, MSG_MEDIA_MENU, card);
|
2018-10-28 09:10:25 +01:00
|
|
|
}
|
2020-04-28 06:52:11 +02:00
|
|
|
else
|
2019-10-03 12:38:30 +02:00
|
|
|
SKIP_ITEM();
|
2018-10-28 09:10:25 +01:00
|
|
|
}
|
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAS_LCD_MENU && SDSUPPORT
|