My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

cardreader.h 3.1KB

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