My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

menu_media.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //
  23. // SD Card Menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if BOTH(HAS_MARLINUI_MENU, SDSUPPORT)
  27. #include "menu_item.h"
  28. #include "../../sd/cardreader.h"
  29. void lcd_sd_updir() {
  30. ui.encoderPosition = card.cdup() ? ENCODER_STEPS_PER_MENU_ITEM : 0;
  31. encoderTopLine = 0;
  32. ui.screen_changed = true;
  33. ui.refresh();
  34. }
  35. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  36. uint16_t sd_encoder_position = 0xFFFF;
  37. int8_t sd_top_line, sd_items;
  38. void MarlinUI::reselect_last_file() {
  39. if (sd_encoder_position == 0xFFFF) return;
  40. goto_screen(menu_media, sd_encoder_position, sd_top_line, sd_items);
  41. sd_encoder_position = 0xFFFF;
  42. defer_status_screen();
  43. TERN_(HAS_TOUCH_SLEEP, ui.wakeup_screen());
  44. }
  45. #endif
  46. inline void sdcard_start_selected_file() {
  47. card.openAndPrintFile(card.filename);
  48. ui.return_to_status();
  49. ui.reset_status();
  50. }
  51. class MenuItem_sdfile : public MenuItem_sdbase {
  52. public:
  53. static inline void draw(const bool sel, const uint8_t row, FSTR_P const fstr, CardReader &theCard) {
  54. MenuItem_sdbase::draw(sel, row, fstr, theCard, false);
  55. }
  56. static void action(FSTR_P const fstr, CardReader &) {
  57. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  58. // Save menu state for the selected file
  59. sd_encoder_position = ui.encoderPosition;
  60. sd_top_line = encoderTopLine;
  61. sd_items = screen_items;
  62. #endif
  63. #if ENABLED(SD_MENU_CONFIRM_START)
  64. MenuItem_submenu::action(fstr, []{
  65. char * const longest = card.longest_filename();
  66. char buffer[strlen(longest) + 2];
  67. buffer[0] = ' ';
  68. strcpy(buffer + 1, longest);
  69. MenuItem_confirm::select_screen(
  70. GET_TEXT_F(MSG_BUTTON_PRINT), GET_TEXT_F(MSG_BUTTON_CANCEL),
  71. sdcard_start_selected_file, nullptr,
  72. GET_TEXT_F(MSG_START_PRINT), buffer, F("?")
  73. );
  74. });
  75. #else
  76. sdcard_start_selected_file();
  77. UNUSED(fstr);
  78. #endif
  79. }
  80. };
  81. class MenuItem_sdfolder : public MenuItem_sdbase {
  82. public:
  83. static inline void draw(const bool sel, const uint8_t row, FSTR_P const fstr, CardReader &theCard) {
  84. MenuItem_sdbase::draw(sel, row, fstr, theCard, true);
  85. }
  86. static void action(FSTR_P const, CardReader &theCard) {
  87. card.cd(theCard.filename);
  88. encoderTopLine = 0;
  89. ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);
  90. ui.screen_changed = true;
  91. TERN_(HAS_MARLINUI_U8GLIB, ui.drawing_screen = false);
  92. ui.refresh();
  93. }
  94. };
  95. void menu_media_filelist() {
  96. ui.encoder_direction_menus();
  97. #if HAS_MARLINUI_U8GLIB
  98. static uint16_t fileCnt;
  99. if (ui.first_page) fileCnt = card.get_num_Files();
  100. #else
  101. const uint16_t fileCnt = card.get_num_Files();
  102. #endif
  103. START_MENU();
  104. #if ENABLED(MULTI_VOLUME)
  105. ACTION_ITEM(MSG_BACK, []{ ui.goto_screen(menu_media); });
  106. #else
  107. BACK_ITEM_F(TERN1(BROWSE_MEDIA_ON_INSERT, screen_history_depth) ? GET_TEXT_F(MSG_MAIN) : GET_TEXT_F(MSG_BACK));
  108. #endif
  109. if (card.flag.workDirIsRoot) {
  110. #if !PIN_EXISTS(SD_DETECT)
  111. ACTION_ITEM(MSG_REFRESH, []{ encoderTopLine = 0; card.mount(); });
  112. #endif
  113. }
  114. else if (card.isMounted())
  115. ACTION_ITEM_F(F(LCD_STR_FOLDER " .."), lcd_sd_updir);
  116. if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
  117. if (_menuLineNr == _thisItemNr) {
  118. card.getfilename_sorted(SD_ORDER(i, fileCnt));
  119. if (card.flag.filenameIsDir)
  120. MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
  121. else
  122. MENU_ITEM(sdfile, MSG_MEDIA_MENU, card);
  123. }
  124. else
  125. SKIP_ITEM();
  126. }
  127. END_MENU();
  128. }
  129. #if ENABLED(MULTI_VOLUME)
  130. void menu_media_select() {
  131. START_MENU();
  132. BACK_ITEM_F(TERN1(BROWSE_MEDIA_ON_INSERT, screen_history_depth) ? GET_TEXT_F(MSG_MAIN) : GET_TEXT_F(MSG_BACK));
  133. #if ENABLED(VOLUME_SD_ONBOARD)
  134. ACTION_ITEM(MSG_SD_CARD, []{ card.changeMedia(&card.media_driver_sdcard); card.mount(); ui.goto_screen(menu_media_filelist); });
  135. #endif
  136. #if ENABLED(VOLUME_USB_FLASH_DRIVE)
  137. ACTION_ITEM(MSG_USB_DISK, []{ card.changeMedia(&card.media_driver_usbFlash); card.mount(); ui.goto_screen(menu_media_filelist); });
  138. #endif
  139. END_MENU();
  140. }
  141. #endif
  142. void menu_media() {
  143. TERN(MULTI_VOLUME, menu_media_select, menu_media_filelist)();
  144. }
  145. #endif // HAS_MARLINUI_MENU && SDSUPPORT