My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cardreader.h 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. #ifndef _CARDREADER_H_
  23. #define _CARDREADER_H_
  24. #include "MarlinConfig.h"
  25. #if ENABLED(SDSUPPORT)
  26. #define MAX_DIR_DEPTH 10 // Maximum folder depth
  27. #include "SdFile.h"
  28. #include "types.h"
  29. #include "enum.h"
  30. class CardReader {
  31. public:
  32. CardReader();
  33. void initsd();
  34. void write_command(char *buf);
  35. // Files auto[0-9].g on the sd card are performed in sequence.
  36. // This is to delay autostart and hence the initialisation of
  37. // the sd card to some seconds after the normal init, so the
  38. // device is available soon after a reset.
  39. void checkautostart(bool x);
  40. void openFile(char* name, const bool read, const bool subcall=false);
  41. void openLogFile(char* name);
  42. void removeFile(const char * const name);
  43. void closefile(bool store_location=false);
  44. void release();
  45. void openAndPrintFile(const char *name);
  46. void startFileprint();
  47. void stopSDPrint();
  48. void getStatus();
  49. void printingHasFinished();
  50. #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
  51. void printLongPath(char *path);
  52. #endif
  53. void getfilename(uint16_t nr, const char* const match=NULL);
  54. uint16_t getnrfilenames();
  55. void getAbsFilename(char *t);
  56. void ls();
  57. void chdir(const char *relpath);
  58. void updir();
  59. void setroot();
  60. uint16_t get_num_Files();
  61. #if ENABLED(SDCARD_SORT_ALPHA)
  62. void presort();
  63. void getfilename_sorted(const uint16_t nr);
  64. #if ENABLED(SDSORT_GCODE)
  65. FORCE_INLINE void setSortOn(bool b) { sort_alpha = b; presort(); }
  66. FORCE_INLINE void setSortFolders(int i) { sort_folders = i; presort(); }
  67. //FORCE_INLINE void setSortReverse(bool b) { sort_reverse = b; }
  68. #endif
  69. #endif
  70. FORCE_INLINE void pauseSDPrint() { sdprinting = false; }
  71. FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
  72. FORCE_INLINE bool eof() { return sdpos >= filesize; }
  73. FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
  74. FORCE_INLINE void setIndex(long index) { sdpos = index; file.seekSet(index); }
  75. FORCE_INLINE uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
  76. FORCE_INLINE char* getWorkDirName() { workDir.getFilename(filename); return filename; }
  77. public:
  78. bool saving, logging, sdprinting, cardOK, filenameIsDir;
  79. char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];
  80. int autostart_index;
  81. private:
  82. SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH];
  83. uint8_t workDirDepth;
  84. // Sort files and folders alphabetically.
  85. #if ENABLED(SDCARD_SORT_ALPHA)
  86. uint16_t sort_count; // Count of sorted items in the current directory
  87. #if ENABLED(SDSORT_GCODE)
  88. bool sort_alpha; // Flag to enable / disable the feature
  89. int sort_folders; // Flag to enable / disable folder sorting
  90. //bool sort_reverse; // Flag to enable / disable reverse sorting
  91. #endif
  92. // By default the sort index is static
  93. #if ENABLED(SDSORT_DYNAMIC_RAM)
  94. uint8_t *sort_order;
  95. #else
  96. uint8_t sort_order[SDSORT_LIMIT];
  97. #endif
  98. #if ENABLED(SDSORT_USES_RAM) && ENABLED(SDSORT_CACHE_NAMES) && DISABLED(SDSORT_DYNAMIC_RAM)
  99. #define SORTED_LONGNAME_MAXLEN ((SDSORT_CACHE_VFATS) * (FILENAME_LENGTH) + 1)
  100. #else
  101. #define SORTED_LONGNAME_MAXLEN LONG_FILENAME_LENGTH
  102. #endif
  103. // Cache filenames to speed up SD menus.
  104. #if ENABLED(SDSORT_USES_RAM)
  105. // If using dynamic ram for names, allocate on the heap.
  106. #if ENABLED(SDSORT_CACHE_NAMES)
  107. #if ENABLED(SDSORT_DYNAMIC_RAM)
  108. char **sortshort, **sortnames;
  109. #else
  110. char sortshort[SDSORT_LIMIT][FILENAME_LENGTH];
  111. char sortnames[SDSORT_LIMIT][SORTED_LONGNAME_MAXLEN];
  112. #endif
  113. #elif DISABLED(SDSORT_USES_STACK)
  114. char sortnames[SDSORT_LIMIT][SORTED_LONGNAME_MAXLEN];
  115. #endif
  116. // Folder sorting uses an isDir array when caching items.
  117. #if HAS_FOLDER_SORTING
  118. #if ENABLED(SDSORT_DYNAMIC_RAM)
  119. uint8_t *isDir;
  120. #elif ENABLED(SDSORT_CACHE_NAMES) || DISABLED(SDSORT_USES_STACK)
  121. uint8_t isDir[(SDSORT_LIMIT+7)>>3];
  122. #endif
  123. #endif
  124. #endif // SDSORT_USES_RAM
  125. #endif // SDCARD_SORT_ALPHA
  126. Sd2Card card;
  127. SdVolume volume;
  128. SdFile file;
  129. #define SD_PROCEDURE_DEPTH 1
  130. #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
  131. uint8_t file_subcall_ctr;
  132. uint32_t filespos[SD_PROCEDURE_DEPTH];
  133. char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
  134. uint32_t filesize, sdpos;
  135. millis_t next_autostart_ms;
  136. bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
  137. LsAction lsAction; //stored for recursion.
  138. uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
  139. char* diveDirName;
  140. void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
  141. #if ENABLED(SDCARD_SORT_ALPHA)
  142. void flush_presort();
  143. #endif
  144. };
  145. #if PIN_EXISTS(SD_DETECT)
  146. #if ENABLED(SD_DETECT_INVERTED)
  147. #define IS_SD_INSERTED (READ(SD_DETECT_PIN) == HIGH)
  148. #else
  149. #define IS_SD_INSERTED (READ(SD_DETECT_PIN) == LOW)
  150. #endif
  151. #else
  152. // No card detect line? Assume the card is inserted.
  153. #define IS_SD_INSERTED true
  154. #endif
  155. extern CardReader card;
  156. #endif // SDSUPPORT
  157. #if ENABLED(SDSUPPORT)
  158. #define IS_SD_PRINTING (card.sdprinting)
  159. #define IS_SD_FILE_OPEN (card.isFileOpen())
  160. #else
  161. #define IS_SD_PRINTING (false)
  162. #define IS_SD_FILE_OPEN (false)
  163. #endif
  164. #endif // _CARDREADER_H_