My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

cardreader.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #ifdef LONG_FILENAME_HOST_SUPPORT
  25. void printLongPath(char *path);
  26. #endif
  27. void getfilename(uint16_t nr, const char* const match=NULL);
  28. uint16_t getnrfilenames();
  29. void getAbsFilename(char *t);
  30. void ls();
  31. void chdir(const char * relpath);
  32. void updir();
  33. void setroot();
  34. FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
  35. FORCE_INLINE bool eof() { return sdpos >= filesize; }
  36. FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
  37. FORCE_INLINE void setIndex(long index) { sdpos = index; file.seekSet(index); }
  38. FORCE_INLINE uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
  39. FORCE_INLINE char* getWorkDirName() { workDir.getFilename(filename); return filename; }
  40. public:
  41. bool saving, logging, sdprinting, cardOK, filenameIsDir;
  42. char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];
  43. int autostart_index;
  44. private:
  45. SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH];
  46. uint16_t workDirDepth;
  47. Sd2Card card;
  48. SdVolume volume;
  49. SdFile file;
  50. #define SD_PROCEDURE_DEPTH 1
  51. #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
  52. uint8_t file_subcall_ctr;
  53. uint32_t filespos[SD_PROCEDURE_DEPTH];
  54. char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
  55. uint32_t filesize;
  56. millis_t next_autostart_ms;
  57. uint32_t sdpos;
  58. bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
  59. LsAction lsAction; //stored for recursion.
  60. 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.
  61. char* diveDirName;
  62. void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
  63. };
  64. extern CardReader card;
  65. #define IS_SD_PRINTING (card.sdprinting)
  66. #if (SDCARDDETECT > -1)
  67. #ifdef SDCARDDETECTINVERTED
  68. #define IS_SD_INSERTED (READ(SDCARDDETECT) != 0)
  69. #else
  70. #define IS_SD_INSERTED (READ(SDCARDDETECT) == 0)
  71. #endif
  72. #else
  73. //No card detect line? Assume the card is inserted.
  74. #define IS_SD_INSERTED true
  75. #endif
  76. #else
  77. #define IS_SD_PRINTING (false)
  78. #endif //SDSUPPORT
  79. #endif //__CARDREADER_H