cardreader.h

changeset 0
2c8ba1964db7
equal deleted inserted replaced
-1:000000000000 0:2c8ba1964db7
1 #ifndef CARDREADER_H
2 #define CARDREADER_H
3
4 #ifdef SDSUPPORT
5
6 #include "SdFile.h"
7 enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename};
8 class CardReader
9 {
10 public:
11 CardReader();
12
13 void initsd();
14 void write_command(char *buf);
15 //files auto[0-9].g on the sd card are performed in a row
16 //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
17
18 void checkautostart(bool x);
19 void openFile(char* name,bool read);
20 void removeFile(char* name);
21 void closefile();
22 void release();
23 void startFileprint();
24 void pauseSDPrint();
25 void getStatus();
26 void printingHasFinished();
27
28 void getfilename(const uint8_t nr);
29 uint16_t getnrfilenames();
30
31
32 void ls();
33 void chdir(const char * relpath);
34 void updir();
35 void setroot();
36
37 void fast_xfer(char* strchr_pointer);
38
39
40 FORCE_INLINE bool eof() { return sdpos>=filesize ;};
41 FORCE_INLINE int16_t get() { sdpos = file.curPosition();return (int16_t)file.read();};
42 FORCE_INLINE void setIndex(long index) {sdpos = index;file.seekSet(index);};
43 FORCE_INLINE uint8_t percentDone(){if(!sdprinting) return 0; if(filesize) return sdpos*100/filesize; else return 0;};
44 FORCE_INLINE char* getWorkDirName(){workDir.getFilename(filename);return filename;};
45
46 public:
47 bool saving;
48 bool sdprinting ;
49 bool cardOK ;
50 char filename[12];
51 bool filenameIsDir;
52 int lastnr; //last number of the autostart;
53 char fastxferbuffer[SD_FAST_XFER_CHUNK_SIZE + 1];
54 private:
55 SdFile root,*curDir,workDir,workDirParent,workDirParentParent;
56 Sd2Card card;
57 SdVolume volume;
58 SdFile file;
59 uint32_t filesize;
60 //int16_t n;
61 unsigned long autostart_atmillis;
62 uint32_t sdpos ;
63
64 bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
65
66 LsAction lsAction; //stored for recursion.
67 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.
68 char* diveDirName;
69 void lsDive(const char *prepend,SdFile parent);
70 int lastxferchar;
71 long xferbytes;
72 };
73 #define IS_SD_PRINTING (card.sdprinting)
74
75 #else
76
77 #define IS_SD_PRINTING (false)
78
79 #endif //SDSUPPORT
80 #endif

mercurial