Skip to content

Commit

Permalink
Abort print on media removal (MarlinFirmware#20200)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhapsodyv authored and dpreed committed Feb 5, 2021
1 parent 72ae6ae commit 4f31bd6
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Marlin/src/sd/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,28 @@ void CardReader::manage_media() {
DEBUG_ECHOLNPGM("SD: No UI Detected.");
}

/**
* "Release" the media by clearing the 'mounted' flag.
* Used by M22, "Release Media", manage_media.
*/
void CardReader::release() {
endFilePrint();
// Card removed while printing? Abort!
if (IS_SD_PRINTING())
card.flag.abort_sd_printing = true;
else
endFilePrint();

flag.mounted = false;
flag.workDirIsRoot = true;
#if ALL(SDCARD_SORT_ALPHA, SDSORT_USES_RAM, SDSORT_CACHE_NAMES)
nrFiles = 0;
#endif
}

/**
* Open a G-code file and set Marlin to start processing it.
* Enqueues M23 and M24 commands to initiate a media print.
*/
void CardReader::openAndPrintFile(const char *name) {
char cmd[4 + strlen(name) + 1]; // Room for "M23 ", filename, and null
extern const char M23_STR[];
Expand All @@ -472,13 +485,22 @@ void CardReader::openAndPrintFile(const char *name) {
queue.enqueue_now_P(M24_STR);
}

/**
* Start or resume a media print by setting the sdprinting flag.
* The file browser pre-sort is also purged to free up memory,
* since you cannot browse files during active printing.
* Used by M24 and anywhere Start / Resume applies.
*/
void CardReader::startFileprint() {
if (isMounted()) {
flag.sdprinting = true;
TERN_(SD_RESORT, flush_presort());
}
}

//
// Run tasks upon finishing or aborting a file print.
//
void CardReader::endFilePrint(TERN_(SD_RESORT, const bool re_sort/*=false*/)) {
TERN_(ADVANCED_PAUSE_FEATURE, did_pause_print = 0);
TERN_(DWIN_CREALITY_LCD, HMI_flag.print_finish = flag.sdprinting);
Expand Down

0 comments on commit 4f31bd6

Please sign in to comment.