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

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