Skip to content

Commit

Permalink
Fix out-of-order M0 after SD printing
Browse files Browse the repository at this point in the history
Fixes MarlinFirmware#14774

Co-Authored-By: tol2cj <[email protected]>
  • Loading branch information
2 people authored and dchauran committed Oct 8, 2020
1 parent 05babb0 commit cb6778f
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,19 +566,35 @@ void GCodeQueue::get_serial_commands() {
while (length < BUFSIZE && !card_eof) {
const int16_t n = card.get();
card_eof = card.eof();
if (n < 0 && !card_eof) { SERIAL_ERROR_MSG(STR_SD_ERR_READ); continue; }

const char sd_char = (char)n;
const bool is_eol = ISEOL(sd_char);
if (is_eol || card_eof) {

// Reset stream state, terminate the buffer, and commit a non-empty command
if (!is_eol && sd_count) ++sd_count; // End of file with no newline
if (!process_line_done(sd_input_state, command_buffer[index_w], sd_count)) {
_commit_command(false);
#if ENABLED(POWER_LOSS_RECOVERY)
recovery.cmd_sdpos = card.getIndex(); // Prime for the NEXT _commit_command
#endif
if (card_eof || n == -1
|| sd_char == '\n' || sd_char == '\r'
|| ((sd_char == '#' || sd_char == ':') && !sd_comment_mode
#if ENABLED(PAREN_COMMENTS)
&& !sd_comment_paren_mode
#endif
)
) {
if (card_eof) {

card.printingHasFinished();

if (IS_SD_PRINTING())
sd_count = 0; // If a sub-file was printing, continue from call point
else {
SERIAL_ECHOLNPGM(MSG_FILE_PRINTED);
#if ENABLED(PRINTER_EVENT_LEDS)
printerEventLEDs.onPrintCompleted();
#if HAS_RESUME_CONTINUE
enqueue_now_P(PSTR("M0 Q S"
#if HAS_LCD_MENU
"1800"
#else
"60"
#endif
));
#endif
#endif
}
}

if (card_eof) card.fileHasFinished(); // Handle end of file reached
Expand Down

0 comments on commit cb6778f

Please sign in to comment.