|
@@ -62,15 +62,13 @@ CardReader::CardReader() {
|
62
|
62
|
workDirDepth = 0;
|
63
|
63
|
ZERO(workDirParents);
|
64
|
64
|
|
65
|
|
- autostart_stilltocheck = true; //the SD start is delayed, because otherwise the serial cannot answer fast enough to make contact with the host software.
|
66
|
|
- autostart_index = 0;
|
|
65
|
+ // Disable autostart until card is initialized
|
|
66
|
+ autostart_index = -1;
|
67
|
67
|
|
68
|
68
|
//power to SD reader
|
69
|
69
|
#if SDPOWER > -1
|
70
|
70
|
OUT_WRITE(SDPOWER, HIGH);
|
71
|
|
- #endif // SDPOWER
|
72
|
|
-
|
73
|
|
- next_autostart_ms = millis() + 5000;
|
|
71
|
+ #endif
|
74
|
72
|
}
|
75
|
73
|
|
76
|
74
|
char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
|
|
@@ -607,40 +605,42 @@ void CardReader::write_command(char *buf) {
|
607
|
605
|
}
|
608
|
606
|
}
|
609
|
607
|
|
610
|
|
-void CardReader::checkautostart(bool force) {
|
611
|
|
- if (!force && (!autostart_stilltocheck || PENDING(millis(), next_autostart_ms)))
|
612
|
|
- return;
|
613
|
|
-
|
614
|
|
- autostart_stilltocheck = false;
|
|
608
|
+//
|
|
609
|
+// Run the next autostart file. Called:
|
|
610
|
+// - On boot after successful card init
|
|
611
|
+// - After finishing the previous autostart file
|
|
612
|
+// - From the LCD command to run the autostart file
|
|
613
|
+//
|
615
|
614
|
|
616
|
|
- if (!cardOK) {
|
617
|
|
- initsd();
|
618
|
|
- if (!cardOK) return; // fail
|
619
|
|
- }
|
620
|
|
-
|
621
|
|
- char autoname[10];
|
622
|
|
- sprintf_P(autoname, PSTR("auto%i.g"), autostart_index);
|
623
|
|
- for (int8_t i = 0; i < (int8_t)strlen(autoname); i++) autoname[i] = tolower(autoname[i]);
|
|
615
|
+void CardReader::checkautostart() {
|
624
|
616
|
|
625
|
|
- dir_t p;
|
|
617
|
+ if (autostart_index < 0 || sdprinting) return;
|
626
|
618
|
|
627
|
|
- root.rewind();
|
|
619
|
+ if (!cardOK) initsd();
|
628
|
620
|
|
629
|
|
- bool found = false;
|
630
|
|
- while (root.readDir(p, NULL) > 0) {
|
631
|
|
- for (int8_t i = (int8_t)strlen((char*)p.name); i--;) p.name[i] = tolower(p.name[i]);
|
632
|
|
- if (p.name[9] != '~' && strncmp((char*)p.name, autoname, 5) == 0) {
|
633
|
|
- openAndPrintFile(autoname);
|
634
|
|
- found = true;
|
|
621
|
+ if (cardOK) {
|
|
622
|
+ char autoname[10];
|
|
623
|
+ sprintf_P(autoname, PSTR("auto%i.g"), autostart_index);
|
|
624
|
+ dir_t p;
|
|
625
|
+ root.rewind();
|
|
626
|
+ while (root.readDir(p, NULL) > 0) {
|
|
627
|
+ for (int8_t i = (int8_t)strlen((char*)p.name); i--;) p.name[i] = tolower(p.name[i]);
|
|
628
|
+ if (p.name[9] != '~' && strncmp((char*)p.name, autoname, 5) == 0) {
|
|
629
|
+ openAndPrintFile(autoname);
|
|
630
|
+ autostart_index++;
|
|
631
|
+ return;
|
|
632
|
+ }
|
635
|
633
|
}
|
636
|
634
|
}
|
637
|
|
- if (!found)
|
638
|
|
- autostart_index = -1;
|
639
|
|
- else
|
640
|
|
- autostart_index++;
|
|
635
|
+ autostart_index = -1;
|
|
636
|
+}
|
|
637
|
+
|
|
638
|
+void CardReader::beginautostart() {
|
|
639
|
+ autostart_index = 0;
|
|
640
|
+ setroot();
|
641
|
641
|
}
|
642
|
642
|
|
643
|
|
-void CardReader::closefile(bool store_location) {
|
|
643
|
+void CardReader::closefile(const bool store_location) {
|
644
|
644
|
file.sync();
|
645
|
645
|
file.close();
|
646
|
646
|
saving = logging = false;
|