My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

menu_media.cpp 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.mount();
  33. }
  34. #endif
  35. void lcd_sd_updir() {
  36. ui.encoderPosition = card.cdup() ? 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_media, 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. char * const longest = card.longest_filename();
  71. char buffer[strlen(longest) + 2];
  72. buffer[0] = ' ';
  73. strcpy(buffer + 1, longest);
  74. do_select_screen(
  75. PSTR(MSG_BUTTON_PRINT), PSTR(MSG_BUTTON_CANCEL),
  76. sdcard_start_selected_file, ui.goto_previous_screen,
  77. PSTR(MSG_START_PRINT), buffer, PSTR("?")
  78. );
  79. }
  80. #endif
  81. class MenuItem_sdfile {
  82. public:
  83. static void action(CardReader &) {
  84. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  85. // Save menu state for the selected file
  86. sd_encoder_position = ui.encoderPosition;
  87. sd_top_line = encoderTopLine;
  88. sd_items = screen_items;
  89. #endif
  90. #if ENABLED(SD_MENU_CONFIRM_START)
  91. MenuItem_submenu::action(menu_sd_confirm);
  92. #else
  93. sdcard_start_selected_file();
  94. #endif
  95. }
  96. };
  97. class MenuItem_sdfolder {
  98. public:
  99. static void action(CardReader &theCard) {
  100. card.cd(theCard.filename);
  101. encoderTopLine = 0;
  102. ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);
  103. screen_changed = true;
  104. #if HAS_GRAPHICAL_LCD
  105. ui.drawing_screen = false;
  106. #endif
  107. ui.refresh();
  108. }
  109. };
  110. void menu_media() {
  111. ui.encoder_direction_menus();
  112. #if HAS_GRAPHICAL_LCD
  113. static uint16_t fileCnt;
  114. if (ui.first_page) fileCnt = card.get_num_Files();
  115. #else
  116. const uint16_t fileCnt = card.get_num_Files();
  117. #endif
  118. START_MENU();
  119. MENU_BACK(MSG_MAIN);
  120. if (card.flag.workDirIsRoot) {
  121. #if !PIN_EXISTS(SD_DETECT)
  122. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  123. #endif
  124. }
  125. else if (card.isMounted())
  126. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  127. if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
  128. if (_menuLineNr == _thisItemNr) {
  129. const uint16_t nr =
  130. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  131. fileCnt - 1 -
  132. #endif
  133. i;
  134. card.getfilename_sorted(nr);
  135. if (card.flag.filenameIsDir)
  136. MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
  137. else
  138. MENU_ITEM(sdfile, MSG_MEDIA_MENU, card);
  139. }
  140. else {
  141. MENU_ITEM_DUMMY();
  142. }
  143. }
  144. END_MENU();
  145. }
  146. #endif // HAS_LCD_MENU && SDSUPPORT