Skip to content

Commit fbcd9e9

Browse files
committed
Declare SD printing finished later
1 parent 9cf850b commit fbcd9e9

File tree

13 files changed

+56
-53
lines changed

13 files changed

+56
-53
lines changed

Marlin/src/MarlinCore.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,12 @@ void disable_all_steppers() {
333333
/**
334334
* A Print Job exists when the timer is running or SD is printing
335335
*/
336-
bool printJobOngoing() {
337-
return print_job_timer.isRunning() || IS_SD_PRINTING();
338-
}
336+
bool printJobOngoing() { return print_job_timer.isRunning() || IS_SD_PRINTING(); }
339337

340338
/**
339+
* Printing is active when a job is underway but not paused
341340
*/
341+
bool printingIsActive() { return !did_pause_print && printJobOngoing(); }
342342

343343
/**
344344
* Printing is paused according to SD or host indicators
@@ -363,7 +363,7 @@ void startOrResumeJob() {
363363

364364
inline void abortSDPrinting() {
365365
IF_DISABLED(NO_SD_AUTOSTART, card.autofile_cancel());
366-
card.endFilePrint(TERN_(SD_RESORT, true));
366+
card.abortFilePrint(TERN_(SD_RESORT, true));
367367

368368
queue.clear();
369369
quickstop_stepper();
@@ -386,8 +386,8 @@ void startOrResumeJob() {
386386
}
387387

388388
inline void finishSDPrinting() {
389-
if (queue.enqueue_one_P(PSTR("M1001"))) {
390-
marlin_state = MF_RUNNING;
389+
if (queue.enqueue_one_P(PSTR("M1001"))) { // Keep trying until it gets queued
390+
marlin_state = MF_RUNNING; // Signal to stop trying
391391
TERN_(PASSWORD_AFTER_SD_PRINT_END, password.lock_machine());
392392
TERN_(DGUS_LCD_UI_MKS, ScreenHandler.SDPrintingFinished());
393393
}
@@ -897,7 +897,7 @@ void stop() {
897897
thermalManager.set_fans_paused(false); // Un-pause fans for safety
898898
#endif
899899

900-
if (IsRunning()) {
900+
if (!IsStopped()) {
901901
SERIAL_ERROR_MSG(STR_ERR_STOPPED);
902902
LCD_MESSAGEPGM(MSG_STOPPED);
903903
safe_delay(350); // allow enough time for messages to get out before stopping

Marlin/src/MarlinCore.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ void minkill(const bool steppers_off=false);
5656

5757
// Global State of the firmware
5858
enum MarlinState : uint8_t {
59-
MF_INITIALIZING = 0,
60-
MF_RUNNING = _BV(0),
61-
MF_PAUSED = _BV(1),
62-
MF_WAITING = _BV(2),
63-
MF_STOPPED = _BV(3),
64-
MF_SD_COMPLETE = _BV(4),
65-
MF_KILLED = _BV(7)
59+
MF_INITIALIZING = 0,
60+
MF_STOPPED,
61+
MF_KILLED,
62+
MF_RUNNING,
63+
MF_SD_COMPLETE,
64+
MF_PAUSED,
65+
MF_WAITING,
6666
};
6767

6868
extern MarlinState marlin_state;
69-
inline bool IsRunning() { return marlin_state == MF_RUNNING; }
70-
inline bool IsStopped() { return marlin_state != MF_RUNNING; }
69+
inline bool IsRunning() { return marlin_state >= MF_RUNNING; }
70+
inline bool IsStopped() { return marlin_state == MF_STOPPED; }
7171

7272
bool printingIsActive();
7373
bool printJobOngoing();

Marlin/src/gcode/queue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,8 @@ void GCodeQueue::get_serial_commands() {
550550
inline void GCodeQueue::get_sdcard_commands() {
551551
static uint8_t sd_input_state = PS_NORMAL;
552552

553-
if (!IS_SD_PRINTING()) return;
553+
// Get commands if there are more in the file
554+
if (!IS_SD_FETCHING()) return;
554555

555556
int sd_count = 0;
556557
while (!ring_buffer.full() && !card.eof()) {

Marlin/src/gcode/sd/M1001.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
* M1001: Execute actions for SD print completion
6565
*/
6666
void GcodeSuite::M1001() {
67+
// SD Printing is finished when the queue reaches M1001
68+
card.flag.sdprinting = card.flag.sdprintdone = false;
69+
6770
// If there's another auto#.g file to run...
6871
if (TERN(NO_SD_AUTOSTART, false, card.autofile_check())) return;
6972

Marlin/src/lcd/HD44780/marlinui_HD44780.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ inline uint8_t draw_elapsed_or_remaining_time(uint8_t timepos, const bool blink)
755755
char buffer[14];
756756

757757
#if ENABLED(SHOW_REMAINING_TIME)
758-
const bool show_remain = TERN1(ROTATE_PROGRESS_DISPLAY, blink) && (printingIsActive() || marlin_state == MF_SD_COMPLETE);
758+
const bool show_remain = TERN1(ROTATE_PROGRESS_DISPLAY, blink) && printingIsActive();
759759
if (show_remain) {
760760
#if ENABLED(USE_M73_REMAINING_TIME)
761761
duration_t remaining = ui.get_remaining_time();
@@ -889,7 +889,7 @@ void MarlinUI::draw_status_screen() {
889889

890890
#else // !HAS_DUAL_MIXING
891891

892-
const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive() || marlin_state == MF_SD_COMPLETE);
892+
const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive());
893893

894894
if (show_e_total) {
895895
#if ENABLED(LCD_SHOW_E_TOTAL)

Marlin/src/lcd/dogm/status_screen_DOGM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "../../gcode/parser.h" // for units (and volumetric)
4242

4343
#if ENABLED(LCD_SHOW_E_TOTAL)
44-
#include "../../MarlinCore.h" // for printingIsActive(), marlin_state and MF_SD_COMPLETE
44+
#include "../../MarlinCore.h" // for printingIsActive()
4545
#endif
4646

4747
#if ENABLED(FILAMENT_LCD_DISPLAY)
@@ -462,7 +462,7 @@ void MarlinUI::draw_status_screen() {
462462
#endif
463463
#endif
464464

465-
const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive() || marlin_state == MF_SD_COMPLETE);
465+
const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive());
466466

467467
// At the first page, generate new display values
468468
if (first_page) {

Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
9191
cur_name = strrchr(list_file.file_name[sel_id], '/');
9292

9393
SdFile file, *curDir;
94-
card.endFilePrint();
94+
card.abortFilePrint();
9595
const char * const fname = card.diveToFile(true, curDir, cur_name);
9696
if (!fname) return;
9797
if (file.open(curDir, fname, O_READ)) {

Marlin/src/lcd/extui/mks_ui/draw_ui.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -638,20 +638,17 @@ char *creat_title_text() {
638638
W25QXX.SPI_FLASH_BufferWrite(bmp_public_buf, BAK_VIEW_ADDR_TFT35 + row * 400, 400);
639639
#endif
640640
row++;
641+
card.abortFilePrint();
641642
if (row >= 200) {
642643
size = 809;
643644
row = 0;
644645

645646
gcode_preview_over = false;
646647

647-
card.closefile();
648-
char *cur_name;
649-
650-
cur_name = strrchr(list_file.file_name[sel_id], '/');
648+
char *cur_name = strrchr(list_file.file_name[sel_id], '/');
651649

652650
SdFile file;
653651
SdFile *curDir;
654-
card.endFilePrint();
655652
const char * const fname = card.diveToFile(true, curDir, cur_name);
656653
if (!fname) return;
657654
if (file.open(curDir, fname, O_READ)) {
@@ -675,7 +672,6 @@ char *creat_title_text() {
675672
}
676673
return;
677674
}
678-
card.closefile();
679675
#endif // SDSUPPORT
680676
}
681677

Marlin/src/lcd/extui/mks_ui/wifi_module.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,9 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
732732
if (!gcode_preview_over) {
733733
char *cur_name = strrchr(list_file.file_name[sel_id], '/');
734734

735-
card.endFilePrint();
736-
737735
SdFile file;
738736
SdFile *curDir;
739-
card.endFilePrint();
737+
card.abortFilePrint();
740738
const char * const fname = card.diveToFile(true, curDir, cur_name);
741739
if (!fname) return;
742740
if (file.open(curDir, fname, O_READ)) {

Marlin/src/lcd/extui/ui_api.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ namespace ExtUI {
106106
#if ENABLED(JOYSTICK)
107107
uint8_t jogging : 1;
108108
#endif
109-
#if ENABLED(SDSUPPORT)
110-
uint8_t was_sd_printing : 1;
111-
#endif
112109
} flags;
113110

114111
#ifdef __SAM3X8E__
@@ -1025,16 +1022,7 @@ namespace ExtUI {
10251022
return TERN0(SDSUPPORT, isPrintingFromMedia() && !IS_SD_PRINTING());
10261023
}
10271024

1028-
bool isPrintingFromMedia() {
1029-
#if ENABLED(SDSUPPORT)
1030-
// Account for when IS_SD_PRINTING() reports the end of the
1031-
// print when there is still SD card data in the planner.
1032-
flags.was_sd_printing = card.isFileOpen() || (flags.was_sd_printing && commandsInQueue());
1033-
return flags.was_sd_printing;
1034-
#else
1035-
return false;
1036-
#endif
1037-
}
1025+
bool isPrintingFromMedia() { return IS_SD_PRINTING(); }
10381026

10391027
bool isPrinting() {
10401028
return commandsInQueue() || isPrintingFromMedia() || printJobOngoing() || print_job_timer.isPaused();

0 commit comments

Comments
 (0)