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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef CARDREADER_H
  2. #define CARDREADER_H
  3. #ifdef SDSUPPORT
  4. #include "SdFile.h"
  5. enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename};
  6. class CardReader
  7. {
  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);
  16. void openLogFile(char* name);
  17. void removeFile(char* name);
  18. void closefile();
  19. void release();
  20. void startFileprint();
  21. void pauseSDPrint();
  22. void getStatus();
  23. void printingHasFinished();
  24. void getfilename(const uint8_t nr);
  25. uint16_t getnrfilenames();
  26. void ls();
  27. void chdir(const char * relpath);
  28. void updir();
  29. void setroot();
  30. FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
  31. FORCE_INLINE bool eof() { return sdpos>=filesize ;};
  32. FORCE_INLINE int16_t get() { sdpos = file.curPosition();return (int16_t)file.read();};
  33. FORCE_INLINE void setIndex(long index) {sdpos = index;file.seekSet(index);};
  34. FORCE_INLINE uint8_t percentDone(){if(!isFileOpen()) return 0; if(filesize) return sdpos/((filesize+99)/100); else return 0;};
  35. FORCE_INLINE char* getWorkDirName(){workDir.getFilename(filename);return filename;};
  36. public:
  37. bool saving;
  38. bool logging;
  39. bool sdprinting ;
  40. bool cardOK ;
  41. char filename[13];
  42. char longFilename[LONG_FILENAME_LENGTH];
  43. bool filenameIsDir;
  44. int lastnr; //last number of the autostart;
  45. private:
  46. SdFile root,*curDir,workDir,workDirParent,workDirParentParent;
  47. Sd2Card card;
  48. SdVolume volume;
  49. SdFile file;
  50. uint32_t filesize;
  51. //int16_t n;
  52. unsigned long autostart_atmillis;
  53. uint32_t sdpos ;
  54. bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
  55. LsAction lsAction; //stored for recursion.
  56. int16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
  57. char* diveDirName;
  58. void lsDive(const char *prepend,SdFile parent);
  59. };
  60. extern CardReader card;
  61. #define IS_SD_PRINTING (card.sdprinting)
  62. #if (SDCARDDETECT > -1)
  63. # ifdef SDCARDDETECTINVERTED
  64. # define IS_SD_INSERTED (READ(SDCARDDETECT)!=0)
  65. # else
  66. # define IS_SD_INSERTED (READ(SDCARDDETECT)==0)
  67. # endif //SDCARDTETECTINVERTED
  68. #else
  69. //If we don't have a card detect line, aways asume the card is inserted
  70. # define IS_SD_INSERTED true
  71. #endif
  72. #else
  73. #define IS_SD_PRINTING (false)
  74. #endif //SDSUPPORT
  75. #endif