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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef CARDREADER_H
  2. #define CARDREADER_H
  3. #ifdef SDSUPPORT
  4. #define MAX_DIR_DEPTH 10 // Maximum folder depth
  5. #define SORT_USES_RAM false // Buffer while sorting, else re-read from SD
  6. #define SORT_USES_MORE_RAM false // Always keep the directory in RAM
  7. #define SORT_LIMIT 64 // Maximum number of sorted items
  8. #define FOLDER_SORTING -1 // -1=above 0=none 1=below
  9. #include "SdFile.h"
  10. enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename};
  11. class CardReader
  12. {
  13. public:
  14. CardReader();
  15. void initsd();
  16. void write_command(char *buf);
  17. //files auto[0-9].g on the sd card are performed in a row
  18. //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
  19. void checkautostart(bool x);
  20. void openFile(char* name,bool read,bool replace_current=true);
  21. void openLogFile(char* name);
  22. void removeFile(char* name);
  23. void closefile(bool store_location=false);
  24. void release();
  25. void startFileprint();
  26. void pauseSDPrint();
  27. void getStatus();
  28. void printingHasFinished();
  29. void getfilename(const uint16_t nr);
  30. uint16_t getnrfilenames();
  31. void getAbsFilename(char *t);
  32. void ls();
  33. void chdir(const char * relpath);
  34. void updir();
  35. void setroot();
  36. #ifdef SDCARD_SORT_ALPHA
  37. void presort();
  38. void flush_presort();
  39. void getfilename_sorted(const uint16_t nr);
  40. #endif
  41. FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
  42. FORCE_INLINE bool eof() { return sdpos>=filesize ;};
  43. FORCE_INLINE int16_t get() { sdpos = file.curPosition();return (int16_t)file.read();};
  44. FORCE_INLINE void setIndex(long index) {sdpos = index;file.seekSet(index);};
  45. FORCE_INLINE uint8_t percentDone(){if(!isFileOpen()) return 0; if(filesize) return sdpos/((filesize+99)/100); else return 0;};
  46. FORCE_INLINE char* getWorkDirName(){workDir.getFilename(filename);return filename;};
  47. public:
  48. bool saving;
  49. bool logging;
  50. bool sdprinting;
  51. bool cardOK;
  52. char filename[FILENAME_LENGTH];
  53. char longFilename[LONG_FILENAME_LENGTH];
  54. bool filenameIsDir;
  55. int lastnr; //last number of the autostart;
  56. private:
  57. SdFile root,*curDir,workDir,workDirParents[MAX_DIR_DEPTH];
  58. uint16_t workDirDepth;
  59. #ifdef SDCARD_SORT_ALPHA
  60. uint16_t sort_count;
  61. uint8_t *sort_order;
  62. #if SORT_USES_MORE_RAM
  63. char **sortnames;
  64. uint8_t *isDir;
  65. #endif
  66. #endif
  67. Sd2Card card;
  68. SdVolume volume;
  69. SdFile file;
  70. #define SD_PROCEDURE_DEPTH 1
  71. #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1)
  72. uint8_t file_subcall_ctr;
  73. uint32_t filespos[SD_PROCEDURE_DEPTH];
  74. char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
  75. uint32_t filesize;
  76. //int16_t n;
  77. unsigned long autostart_atmillis;
  78. uint32_t sdpos ;
  79. bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
  80. LsAction lsAction; //stored for recursion.
  81. 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.
  82. char* diveDirName;
  83. void lsDive(const char *prepend,SdFile parent);
  84. };
  85. extern CardReader card;
  86. #define IS_SD_PRINTING (card.sdprinting)
  87. #if (SDCARDDETECT > -1)
  88. # ifdef SDCARDDETECTINVERTED
  89. # define IS_SD_INSERTED (READ(SDCARDDETECT)!=0)
  90. # else
  91. # define IS_SD_INSERTED (READ(SDCARDDETECT)==0)
  92. # endif //SDCARDTETECTINVERTED
  93. #else
  94. //If we don't have a card detect line, aways asume the card is inserted
  95. # define IS_SD_INSERTED true
  96. #endif
  97. #else
  98. #define IS_SD_PRINTING (false)
  99. #endif //SDSUPPORT
  100. #endif