My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

menu_media.cpp 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_LCD_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. }
  44. #endif
  45. inline void sdcard_start_selected_file() {
  46. card.openAndPrintFile(card.filename);
  47. ui.return_to_status();
  48. ui.reset_status();
  49. }
  50. class MenuItem_sdfile : public MenuItem_sdbase {
  51. public:
  52. static inline void draw(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard) {
  53. MenuItem_sdbase::draw(sel, row, pstr, theCard, false);
  54. }
  55. static void action(PGM_P const pstr, CardReader &) {
  56. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  57. // Save menu state for the selected file
  58. sd_encoder_position = ui.encoderPosition;
  59. sd_top_line = encoderTopLine;
  60. sd_items = screen_items;
  61. #endif
  62. #if ENABLED(SD_MENU_CONFIRM_START)
  63. MenuItem_submenu::action(pstr, []{
  64. char * const longest = card.longest_filename();
  65. char buffer[strlen(longest) + 2];
  66. buffer[0] = ' ';
  67. strcpy(buffer + 1, longest);
  68. MenuItem_confirm::select_screen(
  69. GET_TEXT(MSG_BUTTON_PRINT), GET_TEXT(MSG_BUTTON_CANCEL),
  70. sdcard_start_selected_file, ui.goto_previous_screen,
  71. GET_TEXT(MSG_START_PRINT), buffer, PSTR("?")
  72. );
  73. });
  74. #else
  75. sdcard_start_selected_file();
  76. UNUSED(pstr);
  77. #endif
  78. }
  79. };
  80. class MenuItem_sdfolder : public MenuItem_sdbase {
  81. public:
  82. static inline void draw(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard) {
  83. MenuItem_sdbase::draw(sel, row, pstr, theCard, true);
  84. }
  85. static void action(PGM_P const, CardReader &theCard) {
  86. card.cd(theCard.filename);
  87. encoderTopLine = 0;
  88. ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);
  89. ui.screen_changed = true;
  90. TERN_(HAS_GRAPHICAL_LCD, ui.drawing_screen = false);
  91. ui.refresh();
  92. }
  93. };
  94. void menu_media() {
  95. ui.encoder_direction_menus();
  96. #if HAS_GRAPHICAL_LCD
  97. static uint16_t fileCnt;
  98. if (ui.first_page) fileCnt = card.get_num_Files();
  99. #else
  100. const uint16_t fileCnt = card.get_num_Files();
  101. #endif
  102. START_MENU();
  103. BACK_ITEM(MSG_MAIN);
  104. if (card.flag.workDirIsRoot) {
  105. #if !PIN_EXISTS(SD_DETECT)
  106. ACTION_ITEM(MSG_REFRESH, []{ encoderTopLine = 0; card.mount(); });
  107. #endif
  108. }
  109. else if (card.isMounted())
  110. ACTION_ITEM_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  111. if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
  112. if (_menuLineNr == _thisItemNr) {
  113. card.getfilename_sorted(SD_ORDER(i, fileCnt));
  114. if (card.flag.filenameIsDir)
  115. MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
  116. else
  117. MENU_ITEM(sdfile, MSG_MEDIA_MENU, card);
  118. }
  119. else
  120. SKIP_ITEM();
  121. }
  122. END_MENU();
  123. }
  124. #endif // HAS_LCD_MENU && SDSUPPORT