cardreader.cpp

Fri, 17 Nov 2017 10:13:31 +0100

author
mdd
date
Fri, 17 Nov 2017 10:13:31 +0100
changeset 3
770b218a4931
parent 0
2c8ba1964db7
permissions
-rw-r--r--

proper configuration, homing and planner optimization

0
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
1 #include "Marlin.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
2 #include "cardreader.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
3 #include "ultralcd.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
4 #include "stepper.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
5 #include "temperature.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
6 #include "language.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
7
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
8 #ifdef SDSUPPORT
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
9
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
10
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
11
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
12 CardReader::CardReader()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
13 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
14 filesize = 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
15 sdpos = 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
16 sdprinting = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
17 cardOK = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
18 saving = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
19 autostart_atmillis=0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
20
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
21 autostart_stilltocheck=true; //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
22 lastnr=0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
23 //power to SD reader
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
24 #if SDPOWER > -1
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
25 SET_OUTPUT(SDPOWER);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
26 WRITE(SDPOWER,HIGH);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
27 #endif //SDPOWER
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
28
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
29 autostart_atmillis=millis()+5000;
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 char *createFilename(char *buffer,const dir_t &p) //buffer>12characters
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
33 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
34 char *pos=buffer;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
35 for (uint8_t i = 0; i < 11; i++)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
36 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
37 if (p.name[i] == ' ')continue;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
38 if (i == 8)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
39 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
40 *pos++='.';
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
41 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
42 *pos++=p.name[i];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
43 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
44 *pos++=0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
45 return buffer;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
46 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
47
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
48
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
49 void CardReader::lsDive(const char *prepend,SdFile parent)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
50 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
51 dir_t p;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
52 uint8_t cnt=0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
53
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
54 while (parent.readDir(p) > 0)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
55 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
56 if( DIR_IS_SUBDIR(&p) && lsAction!=LS_Count && lsAction!=LS_GetFilename) // hence LS_SerialPrint
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
57 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
58
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
59 char path[13*2];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
60 char lfilename[13];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
61 createFilename(lfilename,p);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
62
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
63 path[0]=0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
64 if(strlen(prepend)==0) //avoid leading / if already in prepend
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
65 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
66 strcat(path,"/");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
67 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
68 strcat(path,prepend);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
69 strcat(path,lfilename);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
70 strcat(path,"/");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
71
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
72 //Serial.print(path);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
73
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
74 SdFile dir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
75 if(!dir.open(parent,lfilename, O_READ))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
76 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
77 if(lsAction==LS_SerialPrint)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
78 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
79 SERIAL_ECHO_START;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
80 SERIAL_ECHOLN(MSG_SD_CANT_OPEN_SUBDIR);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
81 SERIAL_ECHOLN(lfilename);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
82 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
83 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
84 lsDive(path,dir);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
85 //close done automatically by destructor of SdFile
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
86
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
87
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
88 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
89 else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
90 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
91 if (p.name[0] == DIR_NAME_FREE) break;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
92 if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
93 if ( p.name[0] == '.')
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
94 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
95 if ( p.name[1] != '.')
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
96 continue;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
97 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
98
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
99 if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
100 filenameIsDir=DIR_IS_SUBDIR(&p);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
101
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
102
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
103 if(!filenameIsDir)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
104 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
105 if(p.name[8]!='G') continue;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
106 if(p.name[9]=='~') continue;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
107 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
108 //if(cnt++!=nr) continue;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
109 createFilename(filename,p);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
110 if(lsAction==LS_SerialPrint)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
111 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
112 SERIAL_PROTOCOL(prepend);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
113 SERIAL_PROTOCOLLN(filename);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
114 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
115 else if(lsAction==LS_Count)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
116 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
117 nrFiles++;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
118 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
119 else if(lsAction==LS_GetFilename)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
120 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
121 if(cnt==nrFiles)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
122 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
123 cnt++;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
124
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
125 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
126 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
127 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
128 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
129
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
130 void CardReader::ls()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
131 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
132 lsAction=LS_SerialPrint;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
133 if(lsAction==LS_Count)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
134 nrFiles=0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
135
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
136 root.rewind();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
137 lsDive("",root);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
138 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
139
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
140
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
141 void CardReader::initsd()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
142 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
143 cardOK = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
144 if(root.isOpen())
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
145 root.close();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
146 if (!card.init(SPI_FULL_SPEED,SDSS))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
147 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
148 //if (!card.init(SPI_HALF_SPEED,SDSS))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
149 SERIAL_ECHO_START;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
150 SERIAL_ECHOLNPGM(MSG_SD_INIT_FAIL);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
151 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
152 else if (!volume.init(&card))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
153 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
154 SERIAL_ERROR_START;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
155 SERIAL_ERRORLNPGM(MSG_SD_VOL_INIT_FAIL);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
156 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
157 else if (!root.openRoot(&volume))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
158 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
159 SERIAL_ERROR_START;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
160 SERIAL_ERRORLNPGM(MSG_SD_OPENROOT_FAIL);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
161 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
162 else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
163 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
164 cardOK = true;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
165 SERIAL_ECHO_START;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
166 SERIAL_ECHOLNPGM(MSG_SD_CARD_OK);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
167 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
168 workDir=root;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
169 curDir=&root;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
170 /*
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
171 if(!workDir.openRoot(&volume))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
172 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
173 SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
174 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
175 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
176
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
177 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
178
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
179 void CardReader::setroot()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
180 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
181 /*if(!workDir.openRoot(&volume))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
182 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
183 SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
184 }*/
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
185 workDir=root;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
186
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
187 curDir=&workDir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
188 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
189 void CardReader::release()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
190 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
191 sdprinting = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
192 cardOK = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
193 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
194
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
195 void CardReader::startFileprint()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
196 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
197 if(cardOK)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
198 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
199 sdprinting = true;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
200
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
201 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
202 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
203
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
204 void CardReader::pauseSDPrint()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
205 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
206 if(sdprinting)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
207 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
208 sdprinting = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
209 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
210 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
211
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
212
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
213
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
214 void CardReader::openFile(char* name,bool read)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
215 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
216 if(!cardOK)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
217 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
218 file.close();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
219 sdprinting = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
220
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
221
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
222 SdFile myDir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
223 curDir=&root;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
224 char *fname=name;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
225
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
226 char *dirname_start,*dirname_end;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
227 if(name[0]=='/')
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
228 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
229 dirname_start=strchr(name,'/')+1;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
230 while(dirname_start>0)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
231 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
232 dirname_end=strchr(dirname_start,'/');
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
233 //SERIAL_ECHO("start:");SERIAL_ECHOLN((int)(dirname_start-name));
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
234 //SERIAL_ECHO("end :");SERIAL_ECHOLN((int)(dirname_end-name));
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
235 if(dirname_end>0 && dirname_end>dirname_start)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
236 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
237 char subdirname[13];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
238 strncpy(subdirname, dirname_start, dirname_end-dirname_start);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
239 subdirname[dirname_end-dirname_start]=0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
240 SERIAL_ECHOLN(subdirname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
241 if(!myDir.open(curDir,subdirname,O_READ))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
242 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
243 SERIAL_PROTOCOLPGM(MSG_SD_OPEN_FILE_FAIL);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
244 SERIAL_PROTOCOL(subdirname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
245 SERIAL_PROTOCOLLNPGM(".");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
246 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
247 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
248 else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
249 ;//SERIAL_ECHOLN("dive ok");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
250
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
251 curDir=&myDir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
252 dirname_start=dirname_end+1;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
253 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
254 else // the reminder after all /fsa/fdsa/ is the filename
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
255 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
256 fname=dirname_start;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
257 //SERIAL_ECHOLN("remaider");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
258 //SERIAL_ECHOLN(fname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
259 break;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
260 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
261
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
262 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
263 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
264 else //relative path
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
265 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
266 curDir=&workDir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
267 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
268 if(read)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
269 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
270 if (file.open(curDir, fname, O_READ))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
271 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
272 filesize = file.fileSize();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
273 SERIAL_PROTOCOLPGM(MSG_SD_FILE_OPENED);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
274 SERIAL_PROTOCOL(fname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
275 SERIAL_PROTOCOLPGM(MSG_SD_SIZE);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
276 SERIAL_PROTOCOLLN(filesize);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
277 sdpos = 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
278
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
279 SERIAL_PROTOCOLLNPGM(MSG_SD_FILE_SELECTED);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
280 LCD_MESSAGE(fname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
281 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
282 else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
283 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
284 SERIAL_PROTOCOLPGM(MSG_SD_OPEN_FILE_FAIL);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
285 SERIAL_PROTOCOL(fname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
286 SERIAL_PROTOCOLLNPGM(".");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
287 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
288 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
289 else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
290 { //write
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
291 if (!file.open(curDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
292 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
293 SERIAL_PROTOCOLPGM(MSG_SD_OPEN_FILE_FAIL);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
294 SERIAL_PROTOCOL(fname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
295 SERIAL_PROTOCOLLNPGM(".");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
296 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
297 else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
298 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
299 saving = true;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
300 SERIAL_PROTOCOLPGM(MSG_SD_WRITE_TO_FILE);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
301 SERIAL_PROTOCOLLN(name);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
302 LCD_MESSAGE(fname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
303 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
304 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
305
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
306 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
307
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
308 void CardReader::removeFile(char* name)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
309 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
310 if(!cardOK)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
311 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
312 file.close();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
313 sdprinting = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
314
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
315
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
316 SdFile myDir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
317 curDir=&root;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
318 char *fname=name;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
319
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
320 char *dirname_start,*dirname_end;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
321 if(name[0]=='/')
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
322 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
323 dirname_start=strchr(name,'/')+1;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
324 while(dirname_start>0)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
325 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
326 dirname_end=strchr(dirname_start,'/');
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
327 //SERIAL_ECHO("start:");SERIAL_ECHOLN((int)(dirname_start-name));
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
328 //SERIAL_ECHO("end :");SERIAL_ECHOLN((int)(dirname_end-name));
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
329 if(dirname_end>0 && dirname_end>dirname_start)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
330 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
331 char subdirname[13];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
332 strncpy(subdirname, dirname_start, dirname_end-dirname_start);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
333 subdirname[dirname_end-dirname_start]=0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
334 SERIAL_ECHOLN(subdirname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
335 if(!myDir.open(curDir,subdirname,O_READ))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
336 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
337 SERIAL_PROTOCOLPGM("open failed, File: ");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
338 SERIAL_PROTOCOL(subdirname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
339 SERIAL_PROTOCOLLNPGM(".");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
340 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
341 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
342 else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
343 ;//SERIAL_ECHOLN("dive ok");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
344
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
345 curDir=&myDir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
346 dirname_start=dirname_end+1;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
347 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
348 else // the reminder after all /fsa/fdsa/ is the filename
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
349 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
350 fname=dirname_start;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
351 //SERIAL_ECHOLN("remaider");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
352 //SERIAL_ECHOLN(fname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
353 break;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
354 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
355
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
356 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
357 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
358 else //relative path
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
359 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
360 curDir=&workDir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
361 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
362 if (file.remove(curDir, fname))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
363 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
364 SERIAL_PROTOCOLPGM("File deleted:");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
365 SERIAL_PROTOCOL(fname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
366 sdpos = 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
367 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
368 else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
369 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
370 SERIAL_PROTOCOLPGM("Deletion failed, File: ");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
371 SERIAL_PROTOCOL(fname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
372 SERIAL_PROTOCOLLNPGM(".");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
373 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
374
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
375 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
376
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
377 void CardReader::getStatus()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
378 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
379 if(cardOK){
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
380 SERIAL_PROTOCOLPGM(MSG_SD_PRINTING_BYTE);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
381 SERIAL_PROTOCOL(sdpos);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
382 SERIAL_PROTOCOLPGM("/");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
383 SERIAL_PROTOCOLLN(filesize);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
384 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
385 else{
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
386 SERIAL_PROTOCOLLNPGM(MSG_SD_NOT_PRINTING);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
387 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
388 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
389 void CardReader::write_command(char *buf)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
390 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
391 char* begin = buf;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
392 char* npos = 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
393 char* end = buf + strlen(buf) - 1;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
394
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
395 file.writeError = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
396 if((npos = strchr(buf, 'N')) != NULL)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
397 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
398 begin = strchr(npos, ' ') + 1;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
399 end = strchr(npos, '*') - 1;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
400 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
401 end[1] = '\r';
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
402 end[2] = '\n';
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
403 end[3] = '\0';
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
404 file.write(begin);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
405 if (file.writeError)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
406 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
407 SERIAL_ERROR_START;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
408 SERIAL_ERRORLNPGM(MSG_SD_ERR_WRITE_TO_FILE);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
409 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
410 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
411
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
412
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
413 void CardReader::checkautostart(bool force)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
414 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
415 if(!force)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
416 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
417 if(!autostart_stilltocheck)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
418 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
419 if(autostart_atmillis<millis())
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
420 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
421 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
422 autostart_stilltocheck=false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
423 if(!cardOK)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
424 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
425 initsd();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
426 if(!cardOK) //fail
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
427 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
428 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
429
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
430 char autoname[30];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
431 sprintf(autoname,"auto%i.g",lastnr);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
432 for(int8_t i=0;i<(int)strlen(autoname);i++)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
433 autoname[i]=tolower(autoname[i]);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
434 dir_t p;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
435
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
436 root.rewind();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
437
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
438 bool found=false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
439 while (root.readDir(p) > 0)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
440 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
441 for(int8_t i=0;i<(int)strlen((char*)p.name);i++)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
442 p.name[i]=tolower(p.name[i]);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
443 //Serial.print((char*)p.name);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
444 //Serial.print(" ");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
445 //Serial.println(autoname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
446 if(p.name[9]!='~') //skip safety copies
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
447 if(strncmp((char*)p.name,autoname,5)==0)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
448 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
449 char cmd[30];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
450
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
451 sprintf(cmd,"M23 %s",autoname);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
452 enquecommand(cmd);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
453 enquecommand("M24");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
454 found=true;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
455 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
456 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
457 if(!found)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
458 lastnr=-1;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
459 else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
460 lastnr++;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
461 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
462
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
463 void CardReader::closefile()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
464 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
465 file.sync();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
466 file.close();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
467 saving = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
468 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
469
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
470 void CardReader::getfilename(const uint8_t nr)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
471 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
472 curDir=&workDir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
473 lsAction=LS_GetFilename;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
474 nrFiles=nr;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
475 curDir->rewind();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
476 lsDive("",*curDir);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
477
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
478 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
479
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
480 uint16_t CardReader::getnrfilenames()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
481 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
482 curDir=&workDir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
483 lsAction=LS_Count;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
484 nrFiles=0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
485 curDir->rewind();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
486 lsDive("",*curDir);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
487 //SERIAL_ECHOLN(nrFiles);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
488 return nrFiles;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
489 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
490
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
491 void CardReader::chdir(const char * relpath)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
492 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
493 SdFile newfile;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
494 SdFile *parent=&root;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
495
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
496 if(workDir.isOpen())
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
497 parent=&workDir;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
498
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
499 if(!newfile.open(*parent,relpath, O_READ))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
500 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
501 SERIAL_ECHO_START;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
502 SERIAL_ECHOPGM(MSG_SD_CANT_ENTER_SUBDIR);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
503 SERIAL_ECHOLN(relpath);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
504 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
505 else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
506 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
507 workDirParentParent=workDirParent;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
508 workDirParent=*parent;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
509
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
510 workDir=newfile;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
511 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
512 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
513
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
514 void CardReader::updir()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
515 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
516 if(!workDir.isRoot())
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
517 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
518 workDir=workDirParent;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
519 workDirParent=workDirParentParent;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
520 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
521 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
522
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
523
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
524 void CardReader::printingHasFinished()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
525 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
526 st_synchronize();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
527 quickStop();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
528 sdprinting = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
529 if(SD_FINISHED_STEPPERRELEASE)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
530 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
531 //finishAndDisableSteppers();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
532 enquecommand(SD_FINISHED_RELEASECOMMAND);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
533 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
534 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
535 void CardReader::fast_xfer(char* strchr_pointer)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
536 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
537 char *pstr;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
538 boolean done = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
539
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
540 //force heater pins low
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
541 if(HEATER_0_PIN > -1) WRITE(HEATER_0_PIN,LOW);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
542 if(HEATER_BED_PIN > -1) WRITE(HEATER_BED_PIN,LOW);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
543
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
544 lastxferchar = 1;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
545 xferbytes = 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
546
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
547 pstr = strstr(strchr_pointer, " ");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
548 //pstr = strchr_pointer;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
549
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
550 if(pstr == NULL)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
551 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
552 SERIAL_ECHOLN("invalid command");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
553 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
554 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
555
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
556 *pstr = '\0';
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
557
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
558 //check mode (currently only RAW is supported
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
559 if(strcmp(strchr_pointer, "RAW") != 0)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
560 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
561 SERIAL_ECHOLN("Invalid transfer codec");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
562 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
563 }else{
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
564 SERIAL_ECHOPGM("Selected codec: ");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
565 SERIAL_ECHOLN(strchr_pointer+4);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
566 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
567
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
568 if (!file.open(&root, pstr+1, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
569 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
570 SERIAL_ECHOPGM("open failed, File: ");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
571 SERIAL_ECHOLN(pstr+1);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
572 SERIAL_ECHOPGM(".");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
573 }else{
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
574 SERIAL_ECHOPGM("Writing to file: ");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
575 SERIAL_ECHOLN(pstr+1);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
576 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
577
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
578 SERIAL_ECHOLN("ok");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
579
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
580 //RAW transfer codec
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
581 //Host sends \0 then up to SD_FAST_XFER_CHUNK_SIZE then \0
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
582 //when host is done, it sends \0\0.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
583 //if a non \0 character is recieved at the beginning, host has failed somehow, kill the transfer.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
584
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
585 //read SD_FAST_XFER_CHUNK_SIZE bytes (or until \0 is recieved)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
586 while(!done)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
587 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
588 while(!MYSERIAL.available())
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
589 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
590 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
591 if(MYSERIAL.peek() != 0)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
592 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
593 //host has failed, this isn't a RAW chunk, it's an actual command
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
594 file.sync();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
595 file.close();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
596 SERIAL_ECHOLN("Not RAW data");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
597 return;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
598 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
599 //clear the initial 0
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
600 MYSERIAL.read();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
601 for(int i=0;i<SD_FAST_XFER_CHUNK_SIZE+1;i++)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
602 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
603 while(!MYSERIAL.available())
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
604 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
605 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
606 lastxferchar = MYSERIAL.read();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
607 //buffer the data...
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
608 fastxferbuffer[i] = lastxferchar;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
609
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
610 xferbytes++;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
611
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
612 if(lastxferchar == 0)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
613 break;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
614 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
615
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
616 if(fastxferbuffer[0] != 0)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
617 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
618 fastxferbuffer[SD_FAST_XFER_CHUNK_SIZE] = 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
619 file.write(fastxferbuffer);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
620 SERIAL_ECHOLN("ok");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
621 }else{
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
622 SERIAL_ECHOPGM("Wrote ");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
623 SERIAL_ECHO(xferbytes);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
624 SERIAL_ECHOLN(" bytes.");
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
625 done = true;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
626 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
627 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
628
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
629 file.sync();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
630 file.close();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
631 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
632
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
633 #endif //SDSUPPORT

mercurial