|
@@ -418,7 +418,7 @@ void CardReader::stopSDPrint(
|
418
|
418
|
|
419
|
419
|
void CardReader::openLogFile(char * const path) {
|
420
|
420
|
flag.logging = true;
|
421
|
|
- openFile(path, false);
|
|
421
|
+ openFileWrite(path);
|
422
|
422
|
}
|
423
|
423
|
|
424
|
424
|
//
|
|
@@ -444,16 +444,42 @@ void CardReader::getAbsFilename(char *dst) {
|
444
|
444
|
*dst = '\0';
|
445
|
445
|
}
|
446
|
446
|
|
|
447
|
+void openFailed(const char * const fname) {
|
|
448
|
+ SERIAL_ECHOLNPAIR(MSG_SD_OPEN_FILE_FAIL, fname, ".");
|
|
449
|
+}
|
|
450
|
+
|
|
451
|
+void announceOpen(const uint8_t doing, const char * const path) {
|
|
452
|
+ if (doing) {
|
|
453
|
+ SERIAL_ECHO_START();
|
|
454
|
+ SERIAL_ECHOPGM("Now ");
|
|
455
|
+ serialprintPGM(doing == 1 ? PSTR("doing") : PSTR("fresh"));
|
|
456
|
+ SERIAL_ECHOLNPAIR(" file: ", path);
|
|
457
|
+ }
|
|
458
|
+}
|
|
459
|
+
|
447
|
460
|
//
|
448
|
|
-// Open a file by DOS path - for read or write
|
|
461
|
+// Open a file by DOS path for read
|
|
462
|
+// The 'subcall_type' flag indicates...
|
|
463
|
+// - 0 : Standard open from host or user interface.
|
|
464
|
+// - 1 : (file open) Opening a new sub-procedure.
|
|
465
|
+// - 1 : (no file open) Opening a macro (M98).
|
|
466
|
+// - 2 : Resuming from a sub-procedure
|
449
|
467
|
//
|
450
|
|
-void CardReader::openFile(char * const path, const bool read, const bool subcall/*=false*/) {
|
451
|
|
-
|
|
468
|
+void CardReader::openFileRead(char * const path, const uint8_t subcall_type/*=0*/) {
|
452
|
469
|
if (!isMounted()) return;
|
453
|
470
|
|
454
|
|
- uint8_t doing = 0;
|
455
|
|
- if (isFileOpen()) { // Replacing current file or doing a subroutine
|
456
|
|
- if (subcall) {
|
|
471
|
+ switch (subcall_type) {
|
|
472
|
+ case 0: // Starting a new print. "Now fresh file: ..."
|
|
473
|
+ announceOpen(2, path);
|
|
474
|
+ file_subcall_ctr = 0;
|
|
475
|
+ break;
|
|
476
|
+
|
|
477
|
+ case 1: // Starting a sub-procedure
|
|
478
|
+
|
|
479
|
+ // With no file is open it's a simple macro. "Now doing file: ..."
|
|
480
|
+ if (!isFileOpen()) { announceOpen(1, path); break; }
|
|
481
|
+
|
|
482
|
+ // Too deep? The firmware has to bail.
|
457
|
483
|
if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) {
|
458
|
484
|
SERIAL_ERROR_MSG("trying to call sub-gcode files with too many levels. MAX level is:" STRINGIFY(SD_PROCEDURE_DEPTH));
|
459
|
485
|
kill();
|
|
@@ -464,25 +490,15 @@ void CardReader::openFile(char * const path, const bool read, const bool subcall
|
464
|
490
|
getAbsFilename(proc_filenames[file_subcall_ctr]);
|
465
|
491
|
filespos[file_subcall_ctr] = sdpos;
|
466
|
492
|
|
|
493
|
+ // For sub-procedures say 'SUBROUTINE CALL target: "..." parent: "..." pos12345'
|
467
|
494
|
SERIAL_ECHO_START();
|
468
|
495
|
SERIAL_ECHOLNPAIR("SUBROUTINE CALL target:\"", path, "\" parent:\"", proc_filenames[file_subcall_ctr], "\" pos", sdpos);
|
469
|
496
|
file_subcall_ctr++;
|
470
|
|
- }
|
471
|
|
- else
|
472
|
|
- doing = 1;
|
473
|
|
- }
|
474
|
|
- else if (subcall) // Returning from a subcall?
|
475
|
|
- SERIAL_ECHO_MSG("END SUBROUTINE");
|
476
|
|
- else { // Opening fresh file
|
477
|
|
- doing = 2;
|
478
|
|
- file_subcall_ctr = 0; // Reset procedure depth in case user cancels print while in procedure
|
479
|
|
- }
|
|
497
|
+ break;
|
480
|
498
|
|
481
|
|
- if (doing) {
|
482
|
|
- SERIAL_ECHO_START();
|
483
|
|
- SERIAL_ECHOPGM("Now ");
|
484
|
|
- serialprintPGM(doing == 1 ? PSTR("doing") : PSTR("fresh"));
|
485
|
|
- SERIAL_ECHOLNPAIR(" file: ", path);
|
|
499
|
+ case 2: // Resuming previous file after sub-procedure
|
|
500
|
+ SERIAL_ECHO_MSG("END SUBROUTINE");
|
|
501
|
+ break;
|
486
|
502
|
}
|
487
|
503
|
|
488
|
504
|
stopSDPrint();
|
|
@@ -491,35 +507,45 @@ void CardReader::openFile(char * const path, const bool read, const bool subcall
|
491
|
507
|
const char * const fname = diveToFile(curDir, path);
|
492
|
508
|
if (!fname) return;
|
493
|
509
|
|
494
|
|
- if (read) {
|
495
|
|
- if (file.open(curDir, fname, O_READ)) {
|
496
|
|
- filesize = file.fileSize();
|
497
|
|
- sdpos = 0;
|
498
|
|
- SERIAL_ECHOLNPAIR(MSG_SD_FILE_OPENED, fname, MSG_SD_SIZE, filesize);
|
499
|
|
- SERIAL_ECHOLNPGM(MSG_SD_FILE_SELECTED);
|
500
|
|
-
|
501
|
|
- selectFileByName(fname);
|
502
|
|
- ui.set_status(longFilename[0] ? longFilename : fname);
|
503
|
|
- //if (longFilename[0]) {
|
504
|
|
- // SERIAL_ECHOPAIR(MSG_SD_FILE_LONG_NAME, longFilename);
|
505
|
|
- //}
|
506
|
|
- }
|
507
|
|
- else
|
508
|
|
- SERIAL_ECHOLNPAIR(MSG_SD_OPEN_FILE_FAIL, fname, ".");
|
|
510
|
+ if (file.open(curDir, fname, O_READ)) {
|
|
511
|
+ filesize = file.fileSize();
|
|
512
|
+ sdpos = 0;
|
|
513
|
+ SERIAL_ECHOLNPAIR(MSG_SD_FILE_OPENED, fname, MSG_SD_SIZE, filesize);
|
|
514
|
+ SERIAL_ECHOLNPGM(MSG_SD_FILE_SELECTED);
|
|
515
|
+
|
|
516
|
+ selectFileByName(fname);
|
|
517
|
+ ui.set_status(longFilename[0] ? longFilename : fname);
|
509
|
518
|
}
|
510
|
|
- else { //write
|
511
|
|
- if (!file.open(curDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
|
512
|
|
- SERIAL_ECHOLNPAIR(MSG_SD_OPEN_FILE_FAIL, fname, ".");
|
513
|
|
- else {
|
514
|
|
- flag.saving = true;
|
515
|
|
- selectFileByName(fname);
|
516
|
|
- #if ENABLED(EMERGENCY_PARSER)
|
517
|
|
- emergency_parser.disable();
|
518
|
|
- #endif
|
519
|
|
- SERIAL_ECHOLNPAIR(MSG_SD_WRITE_TO_FILE, fname);
|
520
|
|
- ui.set_status(fname);
|
521
|
|
- }
|
|
519
|
+ else
|
|
520
|
+ openFailed(fname);
|
|
521
|
+}
|
|
522
|
+
|
|
523
|
+//
|
|
524
|
+// Open a file by DOS path for write
|
|
525
|
+//
|
|
526
|
+void CardReader::openFileWrite(char * const path) {
|
|
527
|
+ if (!isMounted()) return;
|
|
528
|
+
|
|
529
|
+ announceOpen(2, path);
|
|
530
|
+ file_subcall_ctr = 0;
|
|
531
|
+
|
|
532
|
+ stopSDPrint();
|
|
533
|
+
|
|
534
|
+ SdFile *curDir;
|
|
535
|
+ const char * const fname = diveToFile(curDir, path);
|
|
536
|
+ if (!fname) return;
|
|
537
|
+
|
|
538
|
+ if (file.open(curDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) {
|
|
539
|
+ flag.saving = true;
|
|
540
|
+ selectFileByName(fname);
|
|
541
|
+ #if ENABLED(EMERGENCY_PARSER)
|
|
542
|
+ emergency_parser.disable();
|
|
543
|
+ #endif
|
|
544
|
+ SERIAL_ECHOLNPAIR(MSG_SD_WRITE_TO_FILE, fname);
|
|
545
|
+ ui.set_status(fname);
|
522
|
546
|
}
|
|
547
|
+ else
|
|
548
|
+ openFailed(fname);
|
523
|
549
|
}
|
524
|
550
|
|
525
|
551
|
//
|
|
@@ -1035,9 +1061,9 @@ uint16_t CardReader::get_num_Files() {
|
1035
|
1061
|
void CardReader::printingHasFinished() {
|
1036
|
1062
|
planner.synchronize();
|
1037
|
1063
|
file.close();
|
1038
|
|
- if (file_subcall_ctr > 0) { // Heading up to a parent file that called current as a procedure.
|
|
1064
|
+ if (file_subcall_ctr > 0) { // Resume calling file after closing procedure
|
1039
|
1065
|
file_subcall_ctr--;
|
1040
|
|
- openFile(proc_filenames[file_subcall_ctr], true, true);
|
|
1066
|
+ openFileRead(proc_filenames[file_subcall_ctr], 2); // 2 = Returning from sub-procedure
|
1041
|
1067
|
setIndex(filespos[file_subcall_ctr]);
|
1042
|
1068
|
startFileprint();
|
1043
|
1069
|
}
|