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_sdcard.cpp 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //
  23. // SD Card Menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if HAS_LCD_MENU && ENABLED(SDSUPPORT)
  27. #include "menu.h"
  28. #include "../../sd/cardreader.h"
  29. #if !PIN_EXISTS(SD_DETECT)
  30. void lcd_sd_refresh() {
  31. encoderTopLine = 0;
  32. card.initsd();
  33. }
  34. #endif
  35. void lcd_sd_updir() {
  36. ui.encoderPosition = card.updir() ? ENCODER_STEPS_PER_MENU_ITEM : 0;
  37. encoderTopLine = 0;
  38. screen_changed = true;
  39. ui.refresh();
  40. }
  41. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  42. uint16_t sd_encoder_position = 0xFFFF;
  43. int8_t sd_top_line, sd_items;
  44. void MarlinUI::reselect_last_file() {
  45. if (sd_encoder_position == 0xFFFF) return;
  46. //#if HAS_GRAPHICAL_LCD
  47. // // This is a hack to force a screen update.
  48. // ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  49. // ui.synchronize();
  50. // safe_delay(50);
  51. // ui.synchronize();
  52. // ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  53. // ui.drawing_screen = screen_changed = true;
  54. //#endif
  55. goto_screen(menu_sdcard, sd_encoder_position, sd_top_line, sd_items);
  56. sd_encoder_position = 0xFFFF;
  57. defer_status_screen();
  58. //#if HAS_GRAPHICAL_LCD
  59. // update();
  60. //#endif
  61. }
  62. #endif
  63. inline void sdcard_start_selected_file() {
  64. card.openAndPrintFile(card.filename);
  65. ui.return_to_status();
  66. ui.reset_status();
  67. }
  68. #if ENABLED(SD_MENU_CONFIRM_START)
  69. void menu_sd_confirm() {
  70. do_select_screen(
  71. PSTR(MSG_BUTTON_PRINT), PSTR(MSG_BUTTON_CANCEL),
  72. sdcard_start_selected_file, ui.goto_previous_screen,
  73. PSTR(MSG_START_PRINT " "), card.longest_filename(), PSTR("?")
  74. );
  75. }
  76. #endif
  77. class MenuItem_sdfile {
  78. public:
  79. static void action(CardReader &theCard) {
  80. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  81. // Save menu state for the selected file
  82. sd_encoder_position = ui.encoderPosition;
  83. sd_top_line = encoderTopLine;
  84. sd_items = screen_items;
  85. #endif
  86. #if ENABLED(SD_MENU_CONFIRM_START)
  87. MenuItem_submenu::action(menu_sd_confirm);
  88. #else
  89. sdcard_start_selected_file();
  90. #endif
  91. }
  92. };
  93. class MenuItem_sdfolder {
  94. public:
  95. static void action(CardReader &theCard) {
  96. card.chdir(theCard.filename);
  97. encoderTopLine = 0;
  98. ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);
  99. screen_changed = true;
  100. #if HAS_GRAPHICAL_LCD
  101. ui.drawing_screen = false;
  102. #endif
  103. ui.refresh();
  104. }
  105. };
  106. void menu_sdcard() {
  107. ui.encoder_direction_menus();
  108. const uint16_t fileCnt = card.get_num_Files();
  109. START_MENU();
  110. MENU_BACK(MSG_MAIN);
  111. card.getWorkDirName();
  112. if (card.filename[0] == '/') {
  113. #if !PIN_EXISTS(SD_DETECT)
  114. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  115. #endif
  116. }
  117. else if (card.isDetected())
  118. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  119. if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
  120. if (_menuLineNr == _thisItemNr) {
  121. const uint16_t nr =
  122. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  123. fileCnt - 1 -
  124. #endif
  125. i;
  126. card.getfilename_sorted(nr);
  127. if (card.flag.filenameIsDir)
  128. MENU_ITEM(sdfolder, MSG_CARD_MENU, card);
  129. else
  130. MENU_ITEM(sdfile, MSG_CARD_MENU, card);
  131. }
  132. else {
  133. MENU_ITEM_DUMMY();
  134. }
  135. }
  136. END_MENU();
  137. }
  138. #endif // HAS_LCD_MENU && SDSUPPORT