|
@@ -61,7 +61,8 @@
|
61
|
61
|
|
62
|
62
|
card_flags_t CardReader::flag;
|
63
|
63
|
char CardReader::filename[FILENAME_LENGTH], CardReader::longFilename[LONG_FILENAME_LENGTH];
|
64
|
|
-int8_t CardReader::autostart_index;
|
|
64
|
+
|
|
65
|
+IF_DISABLED(NO_SD_AUTOSTART, uint8_t CardReader::autofile_index); // = 0
|
65
|
66
|
|
66
|
67
|
#if BOTH(HAS_MULTI_SERIAL, BINARY_FILE_TRANSFER)
|
67
|
68
|
int8_t CardReader::transfer_port_index;
|
|
@@ -135,17 +136,17 @@ CardReader::CardReader() {
|
135
|
136
|
//sort_reverse = false;
|
136
|
137
|
#endif
|
137
|
138
|
#endif
|
|
139
|
+
|
138
|
140
|
flag.sdprinting = flag.mounted = flag.saving = flag.logging = false;
|
139
|
141
|
filesize = sdpos = 0;
|
140
|
142
|
|
141
|
143
|
TERN_(HAS_MEDIA_SUBCALLS, file_subcall_ctr = 0);
|
142
|
144
|
|
|
145
|
+ IF_DISABLED(NO_SD_AUTOSTART, autofile_cancel());
|
|
146
|
+
|
143
|
147
|
workDirDepth = 0;
|
144
|
148
|
ZERO(workDirParents);
|
145
|
149
|
|
146
|
|
- // Disable autostart until card is initialized
|
147
|
|
- autostart_index = -1;
|
148
|
|
-
|
149
|
150
|
#if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
|
150
|
151
|
SET_INPUT_PULLUP(SD_DETECT_PIN);
|
151
|
152
|
#endif
|
|
@@ -442,12 +443,14 @@ void CardReader::manage_media() {
|
442
|
443
|
|
443
|
444
|
if (stat) {
|
444
|
445
|
TERN_(SDCARD_EEPROM_EMULATION, settings.first_load());
|
445
|
|
- if (old_stat == 2) // First mount?
|
|
446
|
+ if (old_stat == 2) { // First mount?
|
446
|
447
|
DEBUG_ECHOLNPGM("First mount.");
|
447
|
|
- TERN(POWER_LOSS_RECOVERY,
|
448
|
|
- recovery.check(), // Check for PLR file. (If not there it will beginautostart)
|
449
|
|
- beginautostart() // Look for auto0.g on the next loop
|
450
|
|
- );
|
|
448
|
+ #if ENABLED(POWER_LOSS_RECOVERY)
|
|
449
|
+ recovery.check(); // Check for PLR file. (If not there then call autofile_begin)
|
|
450
|
+ #elif DISABLED(NO_SD_AUTOSTART)
|
|
451
|
+ autofile_begin(); // Look for auto0.g on the next loop
|
|
452
|
+ #endif
|
|
453
|
+ }
|
451
|
454
|
}
|
452
|
455
|
}
|
453
|
456
|
else
|
|
@@ -477,12 +480,12 @@ void CardReader::release() {
|
477
|
480
|
* Enqueues M23 and M24 commands to initiate a media print.
|
478
|
481
|
*/
|
479
|
482
|
void CardReader::openAndPrintFile(const char *name) {
|
480
|
|
- char cmd[4 + strlen(name) + 1]; // Room for "M23 ", filename, and null
|
|
483
|
+ char cmd[4 + strlen(name) + 1 + 3 + 1]; // Room for "M23 ", filename, "\n", "M24", and null
|
481
|
484
|
extern const char M23_STR[];
|
482
|
485
|
sprintf_P(cmd, M23_STR, name);
|
483
|
486
|
for (char *c = &cmd[4]; *c; c++) *c = tolower(*c);
|
484
|
|
- queue.enqueue_one_now(cmd);
|
485
|
|
- queue.enqueue_now_P(M24_STR);
|
|
487
|
+ strcat_P(cmd, PSTR("\nM24"));
|
|
488
|
+ queue.inject(cmd);
|
486
|
489
|
}
|
487
|
490
|
|
488
|
491
|
/**
|
|
@@ -511,7 +514,7 @@ void CardReader::endFilePrint(TERN_(SD_RESORT, const bool re_sort/*=false*/)) {
|
511
|
514
|
|
512
|
515
|
void CardReader::openLogFile(char * const path) {
|
513
|
516
|
flag.logging = DISABLED(SDCARD_READONLY);
|
514
|
|
- TERN(SDCARD_READONLY,,openFileWrite(path));
|
|
517
|
+ IF_DISABLED(SDCARD_READONLY, openFileWrite(path));
|
515
|
518
|
}
|
516
|
519
|
|
517
|
520
|
//
|
|
@@ -735,42 +738,48 @@ void CardReader::write_command(char * const buf) {
|
735
|
738
|
if (file.writeError) SERIAL_ERROR_MSG(STR_SD_ERR_WRITE_TO_FILE);
|
736
|
739
|
}
|
737
|
740
|
|
738
|
|
-//
|
739
|
|
-// Run the next autostart file. Called:
|
740
|
|
-// - On boot after successful card init
|
741
|
|
-// - After finishing the previous autostart file
|
742
|
|
-// - From the LCD command to run the autostart file
|
743
|
|
-//
|
744
|
|
-
|
745
|
|
-void CardReader::checkautostart() {
|
746
|
|
-
|
747
|
|
- if (autostart_index < 0 || flag.sdprinting) return;
|
748
|
|
-
|
749
|
|
- if (!isMounted()) mount();
|
750
|
|
- TERN_(SDCARD_EEPROM_EMULATION, else settings.first_load());
|
|
741
|
+#if DISABLED(NO_SD_AUTOSTART)
|
|
742
|
+ /**
|
|
743
|
+ * Run all the auto#.g files. Called:
|
|
744
|
+ * - On boot after successful card init.
|
|
745
|
+ * - From the LCD command to Run Auto Files
|
|
746
|
+ */
|
|
747
|
+ void CardReader::autofile_begin() {
|
|
748
|
+ autofile_index = 1;
|
|
749
|
+ (void)autofile_check();
|
|
750
|
+ }
|
751
|
751
|
|
752
|
|
- // Don't run auto#.g when a PLR file exists
|
753
|
|
- if (isMounted() && TERN1(POWER_LOSS_RECOVERY, !recovery.valid())) {
|
754
|
|
- char autoname[8];
|
755
|
|
- sprintf_P(autoname, PSTR("auto%c.g"), autostart_index + '0');
|
756
|
|
- dir_t p;
|
757
|
|
- root.rewind();
|
758
|
|
- while (root.readDir(&p, nullptr) > 0) {
|
759
|
|
- for (int8_t i = (int8_t)strlen((char*)p.name); i--;) p.name[i] = tolower(p.name[i]);
|
760
|
|
- if (p.name[9] != '~' && strncmp((char*)p.name, autoname, 5) == 0) {
|
|
752
|
+ /**
|
|
753
|
+ * Run the next auto#.g file. Called:
|
|
754
|
+ * - On boot after successful card init
|
|
755
|
+ * - After finishing the previous auto#.g file
|
|
756
|
+ * - From the LCD command to begin the auto#.g files
|
|
757
|
+ *
|
|
758
|
+ * Return 'true' if there was nothing to do
|
|
759
|
+ */
|
|
760
|
+ bool CardReader::autofile_check() {
|
|
761
|
+ if (!autofile_index) return true;
|
|
762
|
+
|
|
763
|
+ if (!isMounted())
|
|
764
|
+ mount();
|
|
765
|
+ else if (ENABLED(SDCARD_EEPROM_EMULATION))
|
|
766
|
+ settings.first_load();
|
|
767
|
+
|
|
768
|
+ // Don't run auto#.g when a PLR file exists
|
|
769
|
+ if (isMounted() && TERN1(POWER_LOSS_RECOVERY, !recovery.valid())) {
|
|
770
|
+ char autoname[10];
|
|
771
|
+ sprintf_P(autoname, PSTR("/auto%c.g"), '0' + autofile_index - 1);
|
|
772
|
+ if (fileExists(autoname)) {
|
|
773
|
+ cdroot();
|
761
|
774
|
openAndPrintFile(autoname);
|
762
|
|
- autostart_index++;
|
763
|
|
- return;
|
|
775
|
+ autofile_index++;
|
|
776
|
+ return false;
|
764
|
777
|
}
|
765
|
778
|
}
|
|
779
|
+ autofile_cancel();
|
|
780
|
+ return true;
|
766
|
781
|
}
|
767
|
|
- autostart_index = -1;
|
768
|
|
-}
|
769
|
|
-
|
770
|
|
-void CardReader::beginautostart() {
|
771
|
|
- autostart_index = 0;
|
772
|
|
- cdroot();
|
773
|
|
-}
|
|
782
|
+#endif
|
774
|
783
|
|
775
|
784
|
void CardReader::closefile(const bool store_location/*=false*/) {
|
776
|
785
|
file.sync();
|