cardreader.h

Thu, 07 Jul 2016 12:23:34 +0200

author
mbayer
date
Thu, 07 Jul 2016 12:23:34 +0200
changeset 2
b373b0288715
parent 0
2c8ba1964db7
permissions
-rw-r--r--

added missing sanguino files

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

mercurial