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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. card.initsd();
  32. encoderTopLine = 0;
  33. }
  34. #endif
  35. void lcd_sd_updir() {
  36. encoderPosition = card.updir() ? ENCODER_STEPS_PER_MENU_ITEM : 0;
  37. encoderTopLine = 0;
  38. screen_changed = true;
  39. lcd_refresh();
  40. }
  41. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  42. uint32_t last_sdfile_encoderPosition = 0xFFFF;
  43. void lcd_reselect_last_file() {
  44. if (last_sdfile_encoderPosition == 0xFFFF) return;
  45. #if HAS_GRAPHICAL_LCD
  46. // Some of this is a hack to force the screen update to work.
  47. // TODO: Fix the real issue that causes this!
  48. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  49. lcd_synchronize();
  50. safe_delay(50);
  51. lcd_synchronize();
  52. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  53. drawing_screen = screen_changed = true;
  54. #endif
  55. lcd_goto_screen(menu_sdcard, last_sdfile_encoderPosition);
  56. defer_return_to_status = true;
  57. last_sdfile_encoderPosition = 0xFFFF;
  58. #if HAS_GRAPHICAL_LCD
  59. lcd_update();
  60. #endif
  61. }
  62. #endif
  63. void menu_action_sdfile(CardReader &theCard) {
  64. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  65. last_sdfile_encoderPosition = encoderPosition; // Save which file was selected for later use
  66. #endif
  67. card.openAndPrintFile(theCard.filename);
  68. lcd_return_to_status();
  69. lcd_reset_status();
  70. }
  71. void menu_action_sddirectory(CardReader &theCard) {
  72. card.chdir(theCard.filename);
  73. encoderTopLine = 0;
  74. encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
  75. screen_changed = true;
  76. #if HAS_GRAPHICAL_LCD
  77. drawing_screen = false;
  78. #endif
  79. lcd_refresh();
  80. }
  81. void menu_sdcard() {
  82. ENCODER_DIRECTION_MENUS();
  83. const uint16_t fileCnt = card.get_num_Files();
  84. START_MENU();
  85. MENU_BACK(MSG_MAIN);
  86. card.getWorkDirName();
  87. if (card.filename[0] == '/') {
  88. #if !PIN_EXISTS(SD_DETECT)
  89. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  90. #endif
  91. }
  92. else {
  93. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  94. }
  95. for (uint16_t i = 0; i < fileCnt; i++) {
  96. if (_menuLineNr == _thisItemNr) {
  97. const uint16_t nr =
  98. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  99. fileCnt - 1 -
  100. #endif
  101. i;
  102. card.getfilename_sorted(nr);
  103. if (card.filenameIsDir)
  104. MENU_ITEM(sddirectory, MSG_CARD_MENU, card);
  105. else
  106. MENU_ITEM(sdfile, MSG_CARD_MENU, card);
  107. }
  108. else {
  109. MENU_ITEM_DUMMY();
  110. }
  111. }
  112. END_MENU();
  113. }
  114. #endif // HAS_LCD_MENU && SDSUPPORT