2018-10-28 03:10:25 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* 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() {
|
|
|
|
card.initsd();
|
|
|
|
encoderTopLine = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void lcd_sd_updir() {
|
2018-11-11 12:16:24 -06:00
|
|
|
ui.encoderPosition = card.updir() ? 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
|
|
|
|
2018-10-28 03:10:25 -05:00
|
|
|
uint32_t last_sdfile_encoderPosition = 0xFFFF;
|
|
|
|
|
2018-11-11 12:16:24 -06:00
|
|
|
void MarlinUI::reselect_last_file() {
|
2018-10-28 03:10:25 -05:00
|
|
|
if (last_sdfile_encoderPosition == 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
|
|
|
|
|
|
|
|
goto_screen(menu_sdcard, last_sdfile_encoderPosition);
|
2018-10-28 03:10:25 -05:00
|
|
|
last_sdfile_encoderPosition = 0xFFFF;
|
|
|
|
|
2018-11-11 12:16:24 -06:00
|
|
|
defer_status_screen(true);
|
|
|
|
|
|
|
|
//#if HAS_GRAPHICAL_LCD
|
|
|
|
// update();
|
|
|
|
//#endif
|
2018-10-28 03:10:25 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-14 13:13:51 -06:00
|
|
|
class MenuItem_sdfile {
|
2018-11-05 22:51:10 -06:00
|
|
|
public:
|
|
|
|
static void action(CardReader &theCard) {
|
|
|
|
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
|
2018-11-11 12:16:24 -06:00
|
|
|
last_sdfile_encoderPosition = ui.encoderPosition; // Save which file was selected for later use
|
2018-11-05 22:51:10 -06:00
|
|
|
#endif
|
|
|
|
card.openAndPrintFile(theCard.filename);
|
2018-11-11 12:16:24 -06:00
|
|
|
ui.return_to_status();
|
|
|
|
ui.reset_status();
|
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:
|
|
|
|
static void action(CardReader &theCard) {
|
|
|
|
card.chdir(theCard.filename);
|
|
|
|
encoderTopLine = 0;
|
2018-11-11 12:16:24 -06: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
|
|
|
|
|
|
|
void menu_sdcard() {
|
2018-11-11 12:16:24 -06:00
|
|
|
ui.encoder_direction_menus();
|
2018-10-28 03:10:25 -05:00
|
|
|
|
|
|
|
const uint16_t fileCnt = card.get_num_Files();
|
|
|
|
|
|
|
|
START_MENU();
|
|
|
|
MENU_BACK(MSG_MAIN);
|
|
|
|
card.getWorkDirName();
|
|
|
|
if (card.filename[0] == '/') {
|
|
|
|
#if !PIN_EXISTS(SD_DETECT)
|
|
|
|
MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint16_t i = 0; i < fileCnt; i++) {
|
|
|
|
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)
|
2018-11-11 12:16:24 -06:00
|
|
|
MENU_ITEM(sdfolder, MSG_CARD_MENU, card);
|
2018-10-28 03:10:25 -05:00
|
|
|
else
|
|
|
|
MENU_ITEM(sdfile, MSG_CARD_MENU, card);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
MENU_ITEM_DUMMY();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAS_LCD_MENU && SDSUPPORT
|