My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

cardreader.h 3.7KB

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