Browse Source

Abort print on media removal (#20200)

Victor Oliveira 3 years ago
parent
commit
08c5557026
No account linked to committer's email address
1 changed files with 23 additions and 1 deletions
  1. 23
    1
      Marlin/src/sd/cardreader.cpp

+ 23
- 1
Marlin/src/sd/cardreader.cpp View File

454
     DEBUG_ECHOLNPGM("SD: No UI Detected.");
454
     DEBUG_ECHOLNPGM("SD: No UI Detected.");
455
 }
455
 }
456
 
456
 
457
+/**
458
+ * "Release" the media by clearing the 'mounted' flag.
459
+ * Used by M22, "Release Media", manage_media.
460
+ */
457
 void CardReader::release() {
461
 void CardReader::release() {
458
-  endFilePrint();
462
+  // Card removed while printing? Abort!
463
+  if (IS_SD_PRINTING())
464
+    card.flag.abort_sd_printing = true;
465
+  else
466
+    endFilePrint();
467
+
459
   flag.mounted = false;
468
   flag.mounted = false;
460
   flag.workDirIsRoot = true;
469
   flag.workDirIsRoot = true;
461
   #if ALL(SDCARD_SORT_ALPHA, SDSORT_USES_RAM, SDSORT_CACHE_NAMES)
470
   #if ALL(SDCARD_SORT_ALPHA, SDSORT_USES_RAM, SDSORT_CACHE_NAMES)
463
   #endif
472
   #endif
464
 }
473
 }
465
 
474
 
475
+/**
476
+ * Open a G-code file and set Marlin to start processing it.
477
+ * Enqueues M23 and M24 commands to initiate a media print.
478
+ */
466
 void CardReader::openAndPrintFile(const char *name) {
479
 void CardReader::openAndPrintFile(const char *name) {
467
   char cmd[4 + strlen(name) + 1]; // Room for "M23 ", filename, and null
480
   char cmd[4 + strlen(name) + 1]; // Room for "M23 ", filename, and null
468
   extern const char M23_STR[];
481
   extern const char M23_STR[];
472
   queue.enqueue_now_P(M24_STR);
485
   queue.enqueue_now_P(M24_STR);
473
 }
486
 }
474
 
487
 
488
+/**
489
+ * Start or resume a media print by setting the sdprinting flag.
490
+ * The file browser pre-sort is also purged to free up memory,
491
+ * since you cannot browse files during active printing.
492
+ * Used by M24 and anywhere Start / Resume applies.
493
+ */
475
 void CardReader::startFileprint() {
494
 void CardReader::startFileprint() {
476
   if (isMounted()) {
495
   if (isMounted()) {
477
     flag.sdprinting = true;
496
     flag.sdprinting = true;
479
   }
498
   }
480
 }
499
 }
481
 
500
 
501
+//
502
+// Run tasks upon finishing or aborting a file print.
503
+//
482
 void CardReader::endFilePrint(TERN_(SD_RESORT, const bool re_sort/*=false*/)) {
504
 void CardReader::endFilePrint(TERN_(SD_RESORT, const bool re_sort/*=false*/)) {
483
   TERN_(ADVANCED_PAUSE_FEATURE, did_pause_print = 0);
505
   TERN_(ADVANCED_PAUSE_FEATURE, did_pause_print = 0);
484
   TERN_(DWIN_CREALITY_LCD, HMI_flag.print_finish = flag.sdprinting);
506
   TERN_(DWIN_CREALITY_LCD, HMI_flag.print_finish = flag.sdprinting);

Loading…
Cancel
Save