|
@@ -19,6 +19,7 @@ CardReader::CardReader()
|
19
|
19
|
logging = false;
|
20
|
20
|
autostart_atmillis=0;
|
21
|
21
|
workDirDepth = 0;
|
|
22
|
+ file_subcall_ctr=0;
|
22
|
23
|
memset(workDirParents, 0, sizeof(workDirParents));
|
23
|
24
|
|
24
|
25
|
autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
|
|
@@ -224,14 +225,71 @@ void CardReader::openLogFile(char* name)
|
224
|
225
|
openFile(name, false);
|
225
|
226
|
}
|
226
|
227
|
|
227
|
|
-void CardReader::openFile(char* name,bool read)
|
|
228
|
+void CardReader::getAbsFilename(char *t)
|
|
229
|
+{
|
|
230
|
+ uint8_t cnt=0;
|
|
231
|
+ *t='/';t++;cnt++;
|
|
232
|
+ for(uint8_t i=0;i<workDirDepth;i++)
|
|
233
|
+ {
|
|
234
|
+ workDirParents[i].getFilename(t); //SDBaseFile.getfilename!
|
|
235
|
+ while(*t!=0 && cnt< MAXPATHNAMELENGTH)
|
|
236
|
+ {t++;cnt++;} //crawl counter forward.
|
|
237
|
+ }
|
|
238
|
+ if(cnt<MAXPATHNAMELENGTH-13)
|
|
239
|
+ file.getFilename(t);
|
|
240
|
+ else
|
|
241
|
+ t[0]=0;
|
|
242
|
+}
|
|
243
|
+
|
|
244
|
+void CardReader::openFile(char* name,bool read, bool replace_current/*=true*/)
|
228
|
245
|
{
|
229
|
246
|
if(!cardOK)
|
230
|
247
|
return;
|
231
|
|
- file.close();
|
|
248
|
+ if(file.isOpen()) //replaceing current file by new file, or subfile call
|
|
249
|
+ {
|
|
250
|
+ if(!replace_current)
|
|
251
|
+ {
|
|
252
|
+ if((int)file_subcall_ctr>(int)SD_PROCEDURE_DEPTH-1)
|
|
253
|
+ {
|
|
254
|
+ SERIAL_ERROR_START;
|
|
255
|
+ SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:");
|
|
256
|
+ SERIAL_ERRORLN(SD_PROCEDURE_DEPTH);
|
|
257
|
+ kill();
|
|
258
|
+ return;
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+ SERIAL_ECHO_START;
|
|
262
|
+ SERIAL_ECHOPGM("SUBROUTINE CALL target:\"");
|
|
263
|
+ SERIAL_ECHO(name);
|
|
264
|
+ SERIAL_ECHOPGM("\" parent:\"");
|
|
265
|
+
|
|
266
|
+ //store current filename and position
|
|
267
|
+ getAbsFilename(filenames[file_subcall_ctr]);
|
|
268
|
+
|
|
269
|
+ SERIAL_ECHO(filenames[file_subcall_ctr]);
|
|
270
|
+ SERIAL_ECHOPGM("\" pos");
|
|
271
|
+ SERIAL_ECHOLN(sdpos);
|
|
272
|
+ filespos[file_subcall_ctr]=sdpos;
|
|
273
|
+ file_subcall_ctr++;
|
|
274
|
+ }
|
|
275
|
+ else
|
|
276
|
+ {
|
|
277
|
+ SERIAL_ECHO_START;
|
|
278
|
+ SERIAL_ECHOPGM("Now doing file: ");
|
|
279
|
+ SERIAL_ECHOLN(name);
|
|
280
|
+ }
|
|
281
|
+ file.close();
|
|
282
|
+ }
|
|
283
|
+ else //opening fresh file
|
|
284
|
+ {
|
|
285
|
+ file_subcall_ctr=0; //resetting procedure depth in case user cancels print while in procedure
|
|
286
|
+ SERIAL_ECHO_START;
|
|
287
|
+ SERIAL_ECHOPGM("Now fresh file: ");
|
|
288
|
+ SERIAL_ECHOLN(name);
|
|
289
|
+ }
|
232
|
290
|
sdprinting = false;
|
233
|
291
|
|
234
|
|
-
|
|
292
|
+
|
235
|
293
|
SdFile myDir;
|
236
|
294
|
curDir=&root;
|
237
|
295
|
char *fname=name;
|
|
@@ -547,14 +605,25 @@ void CardReader::updir()
|
547
|
605
|
void CardReader::printingHasFinished()
|
548
|
606
|
{
|
549
|
607
|
st_synchronize();
|
550
|
|
- quickStop();
|
551
|
|
- file.close();
|
552
|
|
- sdprinting = false;
|
553
|
|
- if(SD_FINISHED_STEPPERRELEASE)
|
|
608
|
+ if(file_subcall_ctr>0) //heading up to a parent file that called current as a procedure.
|
|
609
|
+ {
|
|
610
|
+ file.close();
|
|
611
|
+ file_subcall_ctr--;
|
|
612
|
+ openFile(filenames[file_subcall_ctr],true,true);
|
|
613
|
+ setIndex(filespos[file_subcall_ctr]);
|
|
614
|
+ startFileprint();
|
|
615
|
+ }
|
|
616
|
+ else
|
554
|
617
|
{
|
555
|
|
- //finishAndDisableSteppers();
|
556
|
|
- enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
|
|
618
|
+ quickStop();
|
|
619
|
+ file.close();
|
|
620
|
+ sdprinting = false;
|
|
621
|
+ if(SD_FINISHED_STEPPERRELEASE)
|
|
622
|
+ {
|
|
623
|
+ //finishAndDisableSteppers();
|
|
624
|
+ enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
|
|
625
|
+ }
|
|
626
|
+ autotempShutdown();
|
557
|
627
|
}
|
558
|
|
- autotempShutdown();
|
559
|
628
|
}
|
560
|
629
|
#endif //SDSUPPORT
|