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 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //
  23. // SD Card Menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if BOTH(HAS_LCD_MENU, SDSUPPORT)
  27. #include "menu.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. //#if HAS_GRAPHICAL_LCD
  41. // // This is a hack to force a screen update.
  42. // ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  43. // ui.synchronize();
  44. // safe_delay(50);
  45. // ui.synchronize();
  46. // ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  47. // ui.drawing_screen = ui.screen_changed = true;
  48. //#endif
  49. goto_screen(menu_media, sd_encoder_position, sd_top_line, sd_items);
  50. sd_encoder_position = 0xFFFF;
  51. defer_status_screen();
  52. //#if HAS_GRAPHICAL_LCD
  53. // update();
  54. //#endif
  55. }
  56. #endif
  57. inline void sdcard_start_selected_file() {
  58. card.openAndPrintFile(card.filename);
  59. ui.return_to_status();
  60. ui.reset_status();
  61. }
  62. class MenuItem_sdfile : public MenuItem_sdbase {
  63. public:
  64. static inline void draw(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard) {
  65. MenuItem_sdbase::draw(sel, row, pstr, theCard, false);
  66. }
  67. static void action(PGM_P const pstr, CardReader &) {
  68. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  69. // Save menu state for the selected file
  70. sd_encoder_position = ui.encoderPosition;
  71. sd_top_line = encoderTopLine;
  72. sd_items = screen_items;
  73. #endif
  74. #if ENABLED(SD_MENU_CONFIRM_START)
  75. MenuItem_submenu::action(pstr, []{
  76. char * const longest = card.longest_filename();
  77. char buffer[strlen(longest) + 2];
  78. buffer[0] = ' ';
  79. strcpy(buffer + 1, longest);
  80. MenuItem_confirm::select_screen(
  81. GET_TEXT(MSG_BUTTON_PRINT), GET_TEXT(MSG_BUTTON_CANCEL),
  82. sdcard_start_selected_file, ui.goto_previous_screen,
  83. GET_TEXT(MSG_START_PRINT), buffer, PSTR("?")
  84. );
  85. });
  86. #else
  87. sdcard_start_selected_file();
  88. UNUSED(pstr);
  89. #endif
  90. }
  91. };
  92. class MenuItem_sdfolder : public MenuItem_sdbase {
  93. public:
  94. static inline void draw(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard) {
  95. MenuItem_sdbase::draw(sel, row, pstr, theCard, true);
  96. }
  97. static void action(PGM_P const, CardReader &theCard) {
  98. card.cd(theCard.filename);
  99. encoderTopLine = 0;
  100. ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);
  101. ui.screen_changed = true;
  102. TERN_(HAS_GRAPHICAL_LCD, ui.drawing_screen = false);
  103. ui.refresh();
  104. }
  105. };
  106. void menu_media() {
  107. ui.encoder_direction_menus();
  108. #if HAS_GRAPHICAL_LCD
  109. static uint16_t fileCnt;
  110. if (ui.first_page) fileCnt = card.get_num_Files();
  111. #else
  112. const uint16_t fileCnt = card.get_num_Files();
  113. #endif
  114. START_MENU();
  115. BACK_ITEM(MSG_MAIN);
  116. if (card.flag.workDirIsRoot) {
  117. #if !PIN_EXISTS(SD_DETECT)
  118. ACTION_ITEM(MSG_REFRESH, []{ encoderTopLine = 0; card.mount(); });
  119. #endif
  120. }
  121. else if (card.isMounted())
  122. ACTION_ITEM_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  123. if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
  124. if (_menuLineNr == _thisItemNr) {
  125. const uint16_t nr =
  126. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  127. fileCnt - 1 -
  128. #endif
  129. i;
  130. card.getfilename_sorted(nr);
  131. if (card.flag.filenameIsDir)
  132. MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
  133. else
  134. MENU_ITEM(sdfile, MSG_MEDIA_MENU, card);
  135. }
  136. else {
  137. SKIP_ITEM();
  138. }
  139. }
  140. END_MENU();
  141. }
  142. #endif // HAS_LCD_MENU && SDSUPPORT