cardreader.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 eof() { return sdpos>=filesize ;};
  30. FORCE_INLINE int16_t get() { sdpos = file.curPosition();return (int16_t)file.read();};
  31. FORCE_INLINE void setIndex(long index) {sdpos = index;file.seekSet(index);};
  32. FORCE_INLINE uint8_t percentDone(){if(!sdprinting) return 0; if(filesize) return sdpos*100/filesize; else return 0;};
  33. FORCE_INLINE char* getWorkDirName(){workDir.getFilename(filename);return filename;};
  34. public:
  35. bool saving;
  36. bool sdprinting ;
  37. bool cardOK ;
  38. char filename[12];
  39. bool filenameIsDir;
  40. int lastnr; //last number of the autostart;
  41. private:
  42. SdFile root,*curDir,workDir,workDirParent,workDirParentParent;
  43. Sd2Card card;
  44. SdVolume volume;
  45. SdFile file;
  46. uint32_t filesize;
  47. //int16_t n;
  48. unsigned long autostart_atmillis;
  49. uint32_t sdpos ;
  50. bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
  51. LsAction lsAction; //stored for recursion.
  52. 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.
  53. char* diveDirName;
  54. void lsDive(const char *prepend,SdFile parent);
  55. };
  56. #define IS_SD_PRINTING (card.sdprinting)
  57. #else
  58. #define IS_SD_PRINTING (false)
  59. #endif //SDSUPPORT
  60. #endif