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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef CARDREADER_H
  2. #define CARDREADER_H
  3. #ifdef SDSUPPORT
  4. #define MAX_DIR_DEPTH 10 // Maximum folder depth
  5. #include "SdFile.h"
  6. enum LsAction { LS_SerialPrint, LS_Count, LS_GetFilename };
  7. class CardReader {
  8. public:
  9. CardReader();
  10. void initsd();
  11. void write_command(char *buf);
  12. //files auto[0-9].g on the sd card are performed in a row
  13. //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
  14. void checkautostart(bool x);
  15. void openFile(char* name,bool read,bool replace_current=true);
  16. void openLogFile(char* name);
  17. void removeFile(char* name);
  18. void closefile(bool store_location=false);
  19. void release();
  20. void startFileprint();
  21. void pauseSDPrint();
  22. void getStatus();
  23. void printingHasFinished();
  24. void getfilename(uint16_t nr, const char* const match=NULL);
  25. uint16_t getnrfilenames();
  26. void getAbsFilename(char *t);
  27. void ls();
  28. void chdir(const char * relpath);
  29. void updir();
  30. void setroot();
  31. FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
  32. FORCE_INLINE bool eof() { return sdpos >= filesize; }
  33. FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
  34. FORCE_INLINE void setIndex(long index) { sdpos = index; file.seekSet(index); }
  35. FORCE_INLINE uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
  36. FORCE_INLINE char* getWorkDirName() { workDir.getFilename(filename); return filename; }
  37. public:
  38. bool saving, logging, sdprinting, cardOK, filenameIsDir;
  39. char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];
  40. int autostart_index;
  41. private:
  42. SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH];
  43. uint16_t workDirDepth;
  44. Sd2Card card;
  45. SdVolume volume;
  46. SdFile file;
  47. #define SD_PROCEDURE_DEPTH 1
  48. #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
  49. uint8_t file_subcall_ctr;
  50. uint32_t filespos[SD_PROCEDURE_DEPTH];
  51. char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
  52. uint32_t filesize;
  53. millis_t next_autostart_ms;
  54. uint32_t sdpos;
  55. bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
  56. LsAction lsAction; //stored for recursion.
  57. 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.
  58. char* diveDirName;
  59. void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
  60. };
  61. extern CardReader card;
  62. #define IS_SD_PRINTING (card.sdprinting)
  63. #if (SDCARDDETECT > -1)
  64. #ifdef SDCARDDETECTINVERTED
  65. #define IS_SD_INSERTED (READ(SDCARDDETECT) != 0)
  66. #else
  67. #define IS_SD_INSERTED (READ(SDCARDDETECT) == 0)
  68. #endif
  69. #else
  70. //No card detect line? Assume the card is inserted.
  71. #define IS_SD_INSERTED true
  72. #endif
  73. #else
  74. #define IS_SD_PRINTING (false)
  75. #endif //SDSUPPORT
  76. #endif //__CARDREADER_H