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.

cardreader.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #if ENABLED(SDSUPPORT)
  25. #define MAX_DIR_DEPTH 10 // Maximum folder depth
  26. #include "SdFile.h"
  27. enum LsAction { LS_SerialPrint, LS_Count, LS_GetFilename };
  28. class CardReader {
  29. public:
  30. CardReader();
  31. void initsd();
  32. void write_command(char *buf);
  33. //files auto[0-9].g on the sd card are performed in a row
  34. //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
  35. void checkautostart(bool x);
  36. void openFile(char* name, bool read, bool push_current=false);
  37. void openLogFile(char* name);
  38. void removeFile(char* name);
  39. void closefile(bool store_location=false);
  40. void release();
  41. void openAndPrintFile(const char *name);
  42. void startFileprint();
  43. void pauseSDPrint();
  44. void stopSDPrint();
  45. void getStatus();
  46. void printingHasFinished();
  47. #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
  48. void printLongPath(char *path);
  49. #endif
  50. void getfilename(uint16_t nr, const char* const match=NULL);
  51. uint16_t getnrfilenames();
  52. void getAbsFilename(char *t);
  53. void ls();
  54. void chdir(const char *relpath);
  55. void updir();
  56. void setroot();
  57. FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
  58. FORCE_INLINE bool eof() { return sdpos >= filesize; }
  59. FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
  60. FORCE_INLINE void setIndex(long index) { sdpos = index; file.seekSet(index); }
  61. FORCE_INLINE uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
  62. FORCE_INLINE char* getWorkDirName() { workDir.getFilename(filename); return filename; }
  63. public:
  64. bool saving, logging, sdprinting, cardOK, filenameIsDir;
  65. char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];
  66. int autostart_index;
  67. private:
  68. SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH];
  69. uint8_t workDirDepth;
  70. Sd2Card card;
  71. SdVolume volume;
  72. SdFile file;
  73. #define SD_PROCEDURE_DEPTH 1
  74. #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
  75. uint8_t file_subcall_ctr;
  76. uint32_t filespos[SD_PROCEDURE_DEPTH];
  77. char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
  78. uint32_t filesize;
  79. uint32_t sdpos;
  80. millis_t next_autostart_ms;
  81. bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
  82. LsAction lsAction; //stored for recursion.
  83. 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.
  84. char* diveDirName;
  85. void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
  86. };
  87. extern CardReader card;
  88. #define IS_SD_PRINTING (card.sdprinting)
  89. #if PIN_EXISTS(SD_DETECT)
  90. #if ENABLED(SD_DETECT_INVERTED)
  91. #define IS_SD_INSERTED (READ(SD_DETECT_PIN) != 0)
  92. #else
  93. #define IS_SD_INSERTED (READ(SD_DETECT_PIN) == 0)
  94. #endif
  95. #else
  96. //No card detect line? Assume the card is inserted.
  97. #define IS_SD_INSERTED true
  98. #endif
  99. #else
  100. #define IS_SD_PRINTING (false)
  101. #endif //SDSUPPORT
  102. #endif //__CARDREADER_H