Преглед изворни кода

Fix auto#.g file handling, add NO_SD_AUTOSTART (#20071)

Scott Lahteine пре 3 година
родитељ
комит
7f20184ebc
No account linked to committer's email address

+ 1
- 0
Marlin/Configuration_adv.h Прегледај датотеку

@@ -1197,6 +1197,7 @@
1197 1197
 
1198 1198
   #define SD_MENU_CONFIRM_START             // Confirm the selected SD file before printing
1199 1199
 
1200
+  //#define NO_SD_AUTOSTART                 // Remove auto#.g file support completely to save some Flash, SRAM
1200 1201
   //#define MENU_ADDAUTOSTART               // Add a menu option to run auto#.g files
1201 1202
 
1202 1203
   //#define BROWSE_MEDIA_ON_INSERT          // Open the file browser when media is inserted

+ 2
- 2
Marlin/src/MarlinCore.cpp Прегледај датотеку

@@ -460,6 +460,7 @@ void startOrResumeJob() {
460 460
 #if ENABLED(SDSUPPORT)
461 461
 
462 462
   inline void abortSDPrinting() {
463
+    IF_DISABLED(NO_SD_AUTOSTART, card.autofile_cancel());
463 464
     card.endFilePrint(TERN_(SD_RESORT, true));
464 465
     queue.clear();
465 466
     quickstop_stepper();
@@ -585,7 +586,7 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
585 586
       if (ELAPSED(ms, next_home_key_ms)) {
586 587
         next_home_key_ms = ms + HOME_DEBOUNCE_DELAY;
587 588
         LCD_MESSAGEPGM(MSG_AUTO_HOME);
588
-        queue.enqueue_now_P(G28_STR);
589
+        queue.inject_P(G28_STR);
589 590
       }
590 591
     }
591 592
   #endif
@@ -1354,7 +1355,6 @@ void loop() {
1354 1355
     idle();
1355 1356
 
1356 1357
     #if ENABLED(SDSUPPORT)
1357
-      card.checkautostart();
1358 1358
       if (card.flag.abort_sd_printing) abortSDPrinting();
1359 1359
       if (marlin_state == MF_SD_COMPLETE) finishSDPrinting();
1360 1360
     #endif

+ 1
- 1
Marlin/src/feature/powerloss.h Прегледај датотеку

@@ -152,7 +152,7 @@ class PrintJobRecovery {
152 152
     static void resume();
153 153
     static void purge();
154 154
 
155
-    static inline void cancel() { purge(); card.autostart_index = 0; }
155
+    static inline void cancel() { purge(); IF_DISABLED(NO_SD_AUTOSTART, card.autofile_begin()); }
156 156
 
157 157
     static void load();
158 158
     static void save(const bool force=ENABLED(SAVE_EACH_CMD_MODE), const float zraise=0);

+ 10
- 4
Marlin/src/gcode/sd/M1001.cpp Прегледај датотеку

@@ -27,6 +27,10 @@
27 27
 #include "../gcode.h"
28 28
 #include "../../module/printcounter.h"
29 29
 
30
+#if DISABLED(NO_SD_AUTOSTART)
31
+  #include "../../sd/cardreader.h"
32
+#endif
33
+
30 34
 #ifdef SD_FINISHED_RELEASECOMMAND
31 35
   #include "../queue.h"
32 36
 #endif
@@ -60,6 +64,11 @@
60 64
  * M1001: Execute actions for SD print completion
61 65
  */
62 66
 void GcodeSuite::M1001() {
67
+  // If there's another auto#.g file to run...
68
+  if (TERN(NO_SD_AUTOSTART, false, card.autofile_check())) return;
69
+
70
+  // Purge the recovery file...
71
+  TERN_(POWER_LOSS_RECOVERY, recovery.purge());
63 72
 
64 73
   // Report total print time
65 74
   const bool long_print = print_job_timer.duration() > 60;
@@ -71,9 +80,6 @@ void GcodeSuite::M1001() {
71 80
   // Set the progress bar "done" state
72 81
   TERN_(LCD_SET_PROGRESS_MANUALLY, ui.set_progress_done());
73 82
 
74
-  // Purge the recovery file
75
-  TERN_(POWER_LOSS_RECOVERY, recovery.purge());
76
-
77 83
   // Announce SD file completion
78 84
   {
79 85
     PORT_REDIRECT(SERIAL_BOTH);
@@ -93,7 +99,7 @@ void GcodeSuite::M1001() {
93 99
 
94 100
   // Inject SD_FINISHED_RELEASECOMMAND, if any
95 101
   #ifdef SD_FINISHED_RELEASECOMMAND
96
-    queue.inject_P(PSTR(SD_FINISHED_RELEASECOMMAND));
102
+    gcode.process_subcommands_now_P(PSTR(SD_FINISHED_RELEASECOMMAND));
97 103
   #endif
98 104
 
99 105
   TERN_(EXTENSIBLE_UI, ExtUI::onPrintFinished());

+ 4
- 0
Marlin/src/inc/Conditionals_adv.h Прегледај датотеку

@@ -142,6 +142,10 @@
142 142
   #undef SD_FINISHED_RELEASECOMMAND
143 143
 #endif
144 144
 
145
+#if ENABLED(NO_SD_AUTOSTART)
146
+  #undef MENU_ADDAUTOSTART
147
+#endif
148
+
145 149
 #if EITHER(SDSUPPORT, LCD_SET_PROGRESS_MANUALLY)
146 150
   #define HAS_PRINT_PROGRESS 1
147 151
 #endif

+ 2
- 2
Marlin/src/lcd/menu/menu_main.cpp Прегледај датотеку

@@ -136,7 +136,7 @@ void menu_main() {
136 136
       // Run Auto Files
137 137
       //
138 138
       #if ENABLED(MENU_ADDAUTOSTART)
139
-        ACTION_ITEM(MSG_RUN_AUTO_FILES, card.beginautostart);
139
+        ACTION_ITEM(MSG_RUN_AUTO_FILES, card.autofile_begin);
140 140
       #endif
141 141
 
142 142
       if (card_detected) {
@@ -238,7 +238,7 @@ void menu_main() {
238 238
       // Autostart
239 239
       //
240 240
       #if ENABLED(MENU_ADDAUTOSTART)
241
-        ACTION_ITEM(MSG_RUN_AUTO_FILES, card.beginautostart);
241
+        ACTION_ITEM(MSG_RUN_AUTO_FILES, card.autofile_begin);
242 242
       #endif
243 243
 
244 244
       if (card_detected) {

+ 53
- 44
Marlin/src/sd/cardreader.cpp Прегледај датотеку

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

+ 6
- 4
Marlin/src/sd/cardreader.h Прегледај датотеку

@@ -90,10 +90,12 @@ public:
90 90
   static void openLogFile(char * const path);
91 91
   static void write_command(char * const buf);
92 92
 
93
-  // Auto-Start files
94
-  static int8_t autostart_index;                    // Index of autoX.g files
95
-  static void beginautostart();
96
-  static void checkautostart();
93
+  #if DISABLED(NO_SD_AUTOSTART)     // Auto-Start auto#.g file handling
94
+    static uint8_t autofile_index;  // Next auto#.g index to run, plus one. Ignored by autofile_check when zero.
95
+    static void autofile_begin();   // Begin check. Called automatically after boot-up.
96
+    static bool autofile_check();   // Check for the next auto-start file and run it.
97
+    static inline void autofile_cancel() { autofile_index = 0; }
98
+  #endif
97 99
 
98 100
   // Basic file ops
99 101
   static void openFileRead(char * const path, const uint8_t subcall=0);

+ 1
- 1
buildroot/tests/mega2560-tests Прегледај датотеку

@@ -49,7 +49,7 @@ opt_set TEMP_SENSOR_4 1000
49 49
 opt_set TEMP_SENSOR_BED 1
50 50
 opt_enable AUTO_BED_LEVELING_UBL RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT SKEW_CORRECTION \
51 51
            REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI STATUS_MESSAGE_SCROLLING BOOT_MARLIN_LOGO_SMALL \
52
-           SDSUPPORT SDCARD_SORT_ALPHA USB_FLASH_DRIVE_SUPPORT SCROLL_LONG_FILENAMES CANCEL_OBJECTS \
52
+           SDSUPPORT SDCARD_SORT_ALPHA USB_FLASH_DRIVE_SUPPORT SCROLL_LONG_FILENAMES CANCEL_OBJECTS NO_SD_AUTOSTART \
53 53
            EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_USER_MENUS \
54 54
            MULTI_NOZZLE_DUPLICATION CLASSIC_JERK LIN_ADVANCE QUICK_HOME \
55 55
            LCD_SET_PROGRESS_MANUALLY PRINT_PROGRESS_SHOW_DECIMALS SHOW_REMAINING_TIME \

Loading…
Откажи
Сачувај