Переглянути джерело

Clean up autostart handling

Scott Lahteine 6 роки тому
джерело
коміт
05fca752d6

+ 5
- 7
Marlin/src/Marlin.cpp Переглянути файл

@@ -894,19 +894,17 @@ void setup() {
894 894
  *
895 895
  *  - Save or log commands to SD
896 896
  *  - Process available commands (if not saving)
897
- *  - Call heater manager
898
- *  - Call inactivity manager
899 897
  *  - Call endstop manager
900
- *  - Call LCD update
898
+ *  - Call inactivity manager
901 899
  */
902 900
 void loop() {
903 901
 
904
-  #if ENABLED(SDSUPPORT)
905
-    card.checkautostart(false);
906
-  #endif
907
-
908 902
   for (;;) {
909 903
 
904
+    #if ENABLED(SDSUPPORT)
905
+      card.checkautostart();
906
+    #endif
907
+
910 908
     #if ENABLED(SDSUPPORT) && ENABLED(ULTIPANEL)
911 909
       if (abort_sd_printing) {
912 910
         abort_sd_printing = false;

+ 0
- 1
Marlin/src/gcode/queue.cpp Переглянути файл

@@ -458,7 +458,6 @@ inline void get_serial_commands() {
458 458
                 leds.set_off();
459 459
               #endif
460 460
             #endif // PRINTER_EVENT_LEDS
461
-            card.checkautostart(true);
462 461
           }
463 462
         }
464 463
         else if (n == -1) {

+ 6
- 7
Marlin/src/lcd/ultralcd.cpp Переглянути файл

@@ -1814,11 +1814,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
1814 1814
 
1815 1815
   #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
1816 1816
 
1817
-    void lcd_autostart_sd() {
1818
-      card.autostart_index = 0;
1819
-      card.setroot();
1820
-      card.checkautostart(true);
1821
-    }
1817
+    void lcd_autostart_sd() { card.beginautostart(); }
1822 1818
 
1823 1819
   #endif
1824 1820
 
@@ -5131,9 +5127,12 @@ void lcd_update() {
5131 5127
       lcd_sd_status = sd_status;
5132 5128
 
5133 5129
       if (sd_status) {
5134
-        safe_delay(1000); // some boards need a delay or the LCD won't show the new status
5130
+        safe_delay(500); // Some boards need a delay to get settled
5135 5131
         card.initsd();
5136
-        if (old_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
5132
+        if (old_sd_status == 2)
5133
+          card.beginautostart();  // Initial boot
5134
+        else
5135
+          LCD_MESSAGEPGM(MSG_SD_INSERTED);
5137 5136
       }
5138 5137
       else {
5139 5138
         card.release();

+ 31
- 31
Marlin/src/sd/cardreader.cpp Переглянути файл

@@ -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;

+ 4
- 9
Marlin/src/sd/cardreader.h Переглянути файл

@@ -39,16 +39,14 @@ public:
39 39
 
40 40
   void initsd();
41 41
   void write_command(char *buf);
42
-  // Files auto[0-9].g on the sd card are performed in sequence.
43
-  // This is to delay autostart and hence the initialisation of
44
-  // the sd card to some seconds after the normal init, so the
45
-  // device is available soon after a reset.
46 42
 
47
-  void checkautostart(bool x);
43
+  void beginautostart();
44
+  void checkautostart();
45
+
48 46
   void openFile(char* name, const bool read, const bool subcall=false);
49 47
   void openLogFile(char* name);
50 48
   void removeFile(const char * const name);
51
-  void closefile(bool store_location=false);
49
+  void closefile(const bool store_location=false);
52 50
   void release();
53 51
   void openAndPrintFile(const char *name);
54 52
   void startFileprint();
@@ -212,9 +210,6 @@ private:
212 210
   char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
213 211
   uint32_t filesize, sdpos;
214 212
 
215
-  millis_t next_autostart_ms;
216
-  bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
217
-
218 213
   LsAction lsAction; //stored for recursion.
219 214
   uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
220 215
   char* diveDirName;

Завантаження…
Відмінити
Зберегти