2018-10-28 03:10:25 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-10-28 03:10:25 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2018-10-28 03:10:25 -05: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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
|
|
|
// SD Card Menu
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "../../inc/MarlinConfigPre.h"
|
|
|
|
|
|
|
|
#if HAS_LCD_MENU && ENABLED(SDSUPPORT)
|
|
|
|
|
|
|
|
#include "menu.h"
|
|
|
|
#include "../../sd/cardreader.h"
|
|
|
|
|
|
|
|
#if !PIN_EXISTS(SD_DETECT)
|
|
|
|
void lcd_sd_refresh() {
|
|
|
|
encoderTopLine = 0;
|
2019-09-15 03:10:59 -05:00
|
|
|
card.mount();
|
2018-10-28 03:10:25 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void lcd_sd_updir() {
|
2019-09-28 15:28:05 -05:00
|
|
|
ui.encoderPosition = card.cdup() ? ENCODER_STEPS_PER_MENU_ITEM : 0;
|
2018-10-28 03:10:25 -05:00
|
|
|
encoderTopLine = 0;
|
|
|
|
screen_changed = true;
|
2018-11-11 12:16:24 -06:00
|
|
|
ui.refresh();
|
2018-10-28 03:10:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
|
2018-11-11 12:16:24 -06:00
|
|
|
|
2019-04-08 21:10:41 -05:00
|
|
|
uint16_t sd_encoder_position = 0xFFFF;
|
|
|
|
int8_t sd_top_line, sd_items;
|
2018-10-28 03:10:25 -05:00
|
|
|
|
2018-11-11 12:16:24 -06:00
|
|
|
void MarlinUI::reselect_last_file() {
|
2019-04-08 21:10:41 -05:00
|
|
|
if (sd_encoder_position == 0xFFFF) return;
|
2018-11-11 12:16:24 -06:00
|
|
|
//#if HAS_GRAPHICAL_LCD
|
|
|
|
// // This is a hack to force a screen update.
|
|
|
|
// ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
|
|
|
|
// ui.synchronize();
|
|
|
|
// safe_delay(50);
|
|
|
|
// ui.synchronize();
|
|
|
|
// ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
|
|
|
|
// ui.drawing_screen = screen_changed = true;
|
|
|
|
//#endif
|
|
|
|
|
2019-08-14 17:52:14 -05:00
|
|
|
goto_screen(menu_media, sd_encoder_position, sd_top_line, sd_items);
|
2019-04-08 21:10:41 -05:00
|
|
|
sd_encoder_position = 0xFFFF;
|
2018-10-28 03:10:25 -05:00
|
|
|
|
2019-03-23 16:30:43 -05:00
|
|
|
defer_status_screen();
|
2018-11-11 12:16:24 -06:00
|
|
|
|
|
|
|
//#if HAS_GRAPHICAL_LCD
|
|
|
|
// update();
|
|
|
|
//#endif
|
2018-10-28 03:10:25 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-04-08 13:44:35 -05:00
|
|
|
inline void sdcard_start_selected_file() {
|
|
|
|
card.openAndPrintFile(card.filename);
|
|
|
|
ui.return_to_status();
|
|
|
|
ui.reset_status();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(SD_MENU_CONFIRM_START)
|
|
|
|
|
|
|
|
void menu_sd_confirm() {
|
2019-09-27 04:38:43 -05:00
|
|
|
char * const longest = card.longest_filename();
|
|
|
|
char buffer[strlen(longest) + 2];
|
|
|
|
buffer[0] = ' ';
|
|
|
|
strcpy(buffer + 1, longest);
|
2019-04-24 10:13:44 -05:00
|
|
|
do_select_screen(
|
|
|
|
PSTR(MSG_BUTTON_PRINT), PSTR(MSG_BUTTON_CANCEL),
|
|
|
|
sdcard_start_selected_file, ui.goto_previous_screen,
|
2019-09-27 04:38:43 -05:00
|
|
|
PSTR(MSG_START_PRINT), buffer, PSTR("?")
|
2019-04-24 10:13:44 -05:00
|
|
|
);
|
2019-04-08 13:44:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-11-14 13:13:51 -06:00
|
|
|
class MenuItem_sdfile {
|
2018-11-05 22:51:10 -06:00
|
|
|
public:
|
2019-09-30 22:53:34 -05:00
|
|
|
static void action(PGM_P const pstr, CardReader &) {
|
2018-11-05 22:51:10 -06:00
|
|
|
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
|
2019-04-08 21:10:41 -05:00
|
|
|
// Save menu state for the selected file
|
|
|
|
sd_encoder_position = ui.encoderPosition;
|
2019-04-10 17:43:08 -05:00
|
|
|
sd_top_line = encoderTopLine;
|
|
|
|
sd_items = screen_items;
|
2018-11-05 22:51:10 -06:00
|
|
|
#endif
|
2019-04-08 13:44:35 -05:00
|
|
|
#if ENABLED(SD_MENU_CONFIRM_START)
|
2019-09-30 22:53:34 -05:00
|
|
|
MenuItem_submenu::action(pstr, menu_sd_confirm);
|
2019-04-08 13:44:35 -05:00
|
|
|
#else
|
|
|
|
sdcard_start_selected_file();
|
2019-09-30 21:44:07 -05:00
|
|
|
UNUSED(pstr);
|
2019-04-08 13:44:35 -05:00
|
|
|
#endif
|
2018-11-05 22:51:10 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-14 13:13:51 -06:00
|
|
|
class MenuItem_sdfolder {
|
2018-11-05 22:51:10 -06:00
|
|
|
public:
|
2019-09-30 22:53:34 -05:00
|
|
|
static void action(PGM_P const, CardReader &theCard) {
|
2019-09-28 15:28:05 -05:00
|
|
|
card.cd(theCard.filename);
|
2018-11-05 22:51:10 -06:00
|
|
|
encoderTopLine = 0;
|
2019-04-10 17:43:08 -05:00
|
|
|
ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);
|
2018-11-05 22:51:10 -06:00
|
|
|
screen_changed = true;
|
|
|
|
#if HAS_GRAPHICAL_LCD
|
2018-11-11 12:16:24 -06:00
|
|
|
ui.drawing_screen = false;
|
2018-11-05 22:51:10 -06:00
|
|
|
#endif
|
2018-11-11 12:16:24 -06:00
|
|
|
ui.refresh();
|
2018-11-05 22:51:10 -06:00
|
|
|
}
|
|
|
|
};
|
2018-10-28 03:10:25 -05:00
|
|
|
|
2019-08-14 17:52:14 -05:00
|
|
|
void menu_media() {
|
2018-11-11 12:16:24 -06:00
|
|
|
ui.encoder_direction_menus();
|
2018-10-28 03:10:25 -05:00
|
|
|
|
2019-09-12 18:06:07 -05:00
|
|
|
#if HAS_GRAPHICAL_LCD
|
|
|
|
static uint16_t fileCnt;
|
2019-09-16 17:49:55 -05:00
|
|
|
if (ui.first_page) fileCnt = card.get_num_Files();
|
2019-09-12 18:06:07 -05:00
|
|
|
#else
|
|
|
|
const uint16_t fileCnt = card.get_num_Files();
|
|
|
|
#endif
|
2018-10-28 03:10:25 -05:00
|
|
|
|
|
|
|
START_MENU();
|
2019-10-03 05:38:30 -05:00
|
|
|
BACK_ITEM(MSG_MAIN);
|
2019-09-16 17:49:55 -05:00
|
|
|
if (card.flag.workDirIsRoot) {
|
2018-10-28 03:10:25 -05:00
|
|
|
#if !PIN_EXISTS(SD_DETECT)
|
2019-10-03 05:38:30 -05:00
|
|
|
ACTION_ITEM(LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
|
2018-10-28 03:10:25 -05:00
|
|
|
#endif
|
|
|
|
}
|
2019-09-15 03:10:59 -05:00
|
|
|
else if (card.isMounted())
|
2019-10-03 05:38:30 -05:00
|
|
|
ACTION_ITEM(LCD_STR_FOLDER "..", lcd_sd_updir);
|
2018-10-28 03:10:25 -05:00
|
|
|
|
2019-01-08 23:08:20 -06:00
|
|
|
if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
|
2018-10-28 03:10:25 -05:00
|
|
|
if (_menuLineNr == _thisItemNr) {
|
|
|
|
const uint16_t nr =
|
|
|
|
#if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
|
|
|
|
fileCnt - 1 -
|
|
|
|
#endif
|
|
|
|
i;
|
|
|
|
|
2018-10-29 13:54:04 -05:00
|
|
|
card.getfilename_sorted(nr);
|
2018-10-28 03:10:25 -05:00
|
|
|
|
2018-11-16 22:39:16 -06:00
|
|
|
if (card.flag.filenameIsDir)
|
2019-08-14 17:52:14 -05:00
|
|
|
MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
|
2018-10-28 03:10:25 -05:00
|
|
|
else
|
2019-08-14 17:52:14 -05:00
|
|
|
MENU_ITEM(sdfile, MSG_MEDIA_MENU, card);
|
2018-10-28 03:10:25 -05:00
|
|
|
}
|
|
|
|
else {
|
2019-10-03 05:38:30 -05:00
|
|
|
SKIP_ITEM();
|
2018-10-28 03:10:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAS_LCD_MENU && SDSUPPORT
|