Skip to content

Commit 747b964

Browse files
authored
Clean up user-wait, SD completion (MarlinFirmware#17315)
1 parent a849909 commit 747b964

15 files changed

+178
-117
lines changed

Marlin/Configuration_adv.h

+4
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,10 @@
10491049

10501050
#define EVENT_GCODE_SD_STOP "G28XY" // G-code to run on Stop Print (e.g., "G28XY" or "G27")
10511051

1052+
#if ENABLED(PRINTER_EVENT_LEDS)
1053+
#define PE_LEDS_COMPLETED_TIME (30*60) // (seconds) Time to keep the LED "done" color before restoring normal illumination
1054+
#endif
1055+
10521056
/**
10531057
* Continue after Power-Loss (Creality3D)
10541058
*

Marlin/src/MarlinCore.cpp

+21-48
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ bool wait_for_heatup = true;
210210
// For M0/M1, this flag may be cleared (by M108) to exit the wait-for-user loop
211211
#if HAS_RESUME_CONTINUE
212212
bool wait_for_user; // = false;
213+
214+
void wait_for_user_response(millis_t ms/*=0*/, const bool no_sleep/*=false*/) {
215+
#if DISABLED(ADVANCED_PAUSE_FEATURE)
216+
UNUSED(no_sleep);
217+
#endif
218+
KEEPALIVE_STATE(PAUSED_FOR_USER);
219+
wait_for_user = true;
220+
if (ms) ms += millis(); // expire time
221+
while (wait_for_user && !(ms && ELAPSED(millis(), ms))) {
222+
idle(
223+
#if ENABLED(ADVANCED_PAUSE_FEATURE)
224+
no_sleep
225+
#endif
226+
);
227+
}
228+
wait_for_user = false;
229+
}
230+
213231
#endif
214232

215233
// Inactivity shutdown
@@ -418,53 +436,8 @@ void startOrResumeJob() {
418436
}
419437

420438
inline void finishSDPrinting() {
421-
422-
bool did_state = true;
423-
switch (card.sdprinting_done_state) {
424-
425-
case 1:
426-
if (print_job_timer.duration() > 60)
427-
did_state = queue.enqueue_one_P(PSTR("M31"));
428-
break;
429-
430-
case 2:
431-
did_state = queue.enqueue_one_P(PSTR("M77"));
432-
break;
433-
434-
case 3:
435-
#if ENABLED(LCD_SET_PROGRESS_MANUALLY)
436-
ui.set_progress_done();
437-
#endif
438-
break;
439-
440-
case 4: // Display "Click to Continue..."
441-
#if HAS_LEDS_OFF_FLAG // 30 min timeout with LCD, 1 min without
442-
did_state = queue.enqueue_one_P(
443-
print_job_timer.duration() < 60 ? PSTR("M0Q1P1") : PSTR("M0Q1S" TERN(HAS_LCD_MENU, "1800", "60"))
444-
);
445-
#endif
446-
break;
447-
448-
case 5:
449-
#if ENABLED(POWER_LOSS_RECOVERY)
450-
recovery.purge();
451-
#endif
452-
453-
#if ENABLED(SD_FINISHED_STEPPERRELEASE) && defined(SD_FINISHED_RELEASECOMMAND)
454-
planner.finish_and_disable();
455-
#endif
456-
457-
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
458-
ui.reselect_last_file();
459-
#endif
460-
461-
SERIAL_ECHOLNPGM(STR_FILE_PRINTED);
462-
463-
default:
464-
did_state = false;
465-
card.sdprinting_done_state = 0;
466-
}
467-
if (did_state) ++card.sdprinting_done_state;
439+
if (queue.enqueue_one_P(PSTR("M1001")))
440+
marlin_state = MF_RUNNING;
468441
}
469442

470443
#endif // SDSUPPORT
@@ -1209,7 +1182,7 @@ void loop() {
12091182
#if ENABLED(SDSUPPORT)
12101183
card.checkautostart();
12111184
if (card.flag.abort_sd_printing) abortSDPrinting();
1212-
if (card.sdprinting_done_state) finishSDPrinting();
1185+
if (marlin_state == MF_SD_COMPLETE) finishSDPrinting();
12131186
#endif
12141187

12151188
queue.advance();

Marlin/src/MarlinCore.h

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ enum MarlinState : uint8_t {
8383
MF_PAUSED = _BV(1),
8484
MF_WAITING = _BV(2),
8585
MF_STOPPED = _BV(3),
86+
MF_SD_COMPLETE = _BV(4),
8687
MF_KILLED = _BV(7)
8788
};
8889

@@ -98,6 +99,7 @@ extern bool wait_for_heatup;
9899

99100
#if HAS_RESUME_CONTINUE
100101
extern bool wait_for_user;
102+
void wait_for_user_response(millis_t ms=0, const bool no_sleep=false);
101103
#endif
102104

103105
// Inactivity shutdown timer

Marlin/src/feature/mmu2/mmu2.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -707,14 +707,13 @@ void MMU2::filament_runout() {
707707
if (recover) {
708708
LCD_MESSAGEPGM(MSG_MMU2_EJECT_RECOVER);
709709
BUZZ(200, 404);
710-
wait_for_user = true;
711710
#if ENABLED(HOST_PROMPT_SUPPORT)
712711
host_prompt_do(PROMPT_USER_CONTINUE, PSTR("MMU2 Eject Recover"), CONTINUE_STR);
713712
#endif
714713
#if ENABLED(EXTENSIBLE_UI)
715714
ExtUI::onUserConfirmRequired_P(PSTR("MMU2 Eject Recover"));
716715
#endif
717-
while (wait_for_user) idle();
716+
wait_for_user_response();
718717
BUZZ(200, 404);
719718
BUZZ(200, 404);
720719

Marlin/src/feature/pause.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
184184
#endif
185185

186186
KEEPALIVE_STATE(PAUSED_FOR_USER);
187-
wait_for_user = true; // LCD click or M108 will clear this
188187
#if ENABLED(HOST_PROMPT_SUPPORT)
189188
const char tool = '0'
190189
#if NUM_RUNOUT_SENSORS > 1
@@ -246,13 +245,13 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
246245
if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_PURGE);
247246
#endif
248247

249-
wait_for_user = true;
250248
#if ENABLED(HOST_PROMPT_SUPPORT)
251249
host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Filament Purging..."), CONTINUE_STR);
252250
#endif
253251
#if ENABLED(EXTENSIBLE_UI)
254252
ExtUI::onUserConfirmRequired_P(PSTR("Filament Purging..."));
255253
#endif
254+
wait_for_user = true; // A click or M108 breaks the purge_length loop
256255
for (float purge_count = purge_length; purge_count > 0 && wait_for_user; --purge_count)
257256
do_pause_e_move(1, ADVANCED_PAUSE_PURGE_FEEDRATE);
258257
wait_for_user = false;
@@ -508,13 +507,13 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
508507

509508
// Wait for filament insert by user and press button
510509
KEEPALIVE_STATE(PAUSED_FOR_USER);
511-
wait_for_user = true; // LCD click or M108 will clear this
512510
#if ENABLED(HOST_PROMPT_SUPPORT)
513511
host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Nozzle Parked"), CONTINUE_STR);
514512
#endif
515513
#if ENABLED(EXTENSIBLE_UI)
516514
ExtUI::onUserConfirmRequired_P(PSTR("Nozzle Parked"));
517515
#endif
516+
wait_for_user = true; // LCD click or M108 will clear this
518517
while (wait_for_user) {
519518
#if HAS_BUZZER
520519
filament_change_beep(max_beep_count);
@@ -540,8 +539,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
540539
ExtUI::onUserConfirmRequired_P(PSTR("HeaterTimeout"));
541540
#endif
542541

543-
// Wait for LCD click or M108
544-
while (wait_for_user) idle_no_sleep();
542+
wait_for_user_response(0, true); // Wait for LCD click or M108
545543

546544
#if ENABLED(HOST_PROMPT_SUPPORT)
547545
host_prompt_do(PROMPT_INFO, PSTR("Reheating"));

Marlin/src/gcode/gcode.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,11 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
857857

858858
#if ENABLED(POWER_LOSS_RECOVERY)
859859
case 413: M413(); break; // M413: Enable/disable/query Power-Loss Recovery
860-
case 1000: M1000(); break; // M1000: Resume from power-loss
860+
case 1000: M1000(); break; // M1000: [INTERNAL] Resume from power-loss
861+
#endif
862+
863+
#if ENABLED(SDSUPPORT)
864+
case 1001: M1001(); break; // M1001: [INTERNAL] Handle SD completion
861865
#endif
862866

863867
#if ENABLED(MAX7219_GCODE)

Marlin/src/gcode/gcode.h

+4
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,10 @@ class GcodeSuite {
968968
static void M1000();
969969
#endif
970970

971+
#if ENABLED(SDSUPPORT)
972+
static void M1001();
973+
#endif
974+
971975
#if ENABLED(MAX7219_GCODE)
972976
static void M7219();
973977
#endif

Marlin/src/gcode/lcd/M0_M1.cpp

+13-36
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,19 @@
2424

2525
#if HAS_RESUME_CONTINUE
2626

27+
#include "../../inc/MarlinConfig.h"
28+
2729
#include "../gcode.h"
28-
#include "../../module/planner.h"
2930

30-
#include "../../inc/MarlinConfig.h"
31+
#include "../../module/planner.h" // for synchronize()
32+
#include "../../MarlinCore.h" // for wait_for_user_response()
3133

3234
#if HAS_LCD_MENU
3335
#include "../../lcd/ultralcd.h"
34-
#endif
35-
36-
#if ENABLED(EXTENSIBLE_UI)
36+
#elif ENABLED(EXTENSIBLE_UI)
3737
#include "../../lcd/extui/ui_api.h"
3838
#endif
3939

40-
#if HAS_LEDS_OFF_FLAG
41-
#include "../../feature/leds/printer_event_leds.h"
42-
#endif
43-
4440
#if ENABLED(HOST_PROMPT_SUPPORT)
4541
#include "../../feature/host_actions.h"
4642
#endif
@@ -56,31 +52,22 @@ void GcodeSuite::M0_M1() {
5652

5753
planner.synchronize();
5854

59-
#if HAS_LEDS_OFF_FLAG
60-
const bool seenQ = parser.seen('Q');
61-
if (seenQ) printerEventLEDs.onPrintCompleted(); // Change LED color for Print Completed
62-
#else
63-
constexpr bool seenQ = false;
64-
#endif
65-
6655
#if HAS_LCD_MENU
6756

6857
if (parser.string_arg)
6958
ui.set_status(parser.string_arg, true);
70-
else if (!seenQ) {
59+
else {
7160
LCD_MESSAGEPGM(MSG_USERWAIT);
7261
#if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
7362
ui.reset_progress_bar_timeout();
7463
#endif
7564
}
7665

7766
#elif ENABLED(EXTENSIBLE_UI)
78-
if (!seenQ) {
79-
if (parser.string_arg)
80-
ExtUI::onUserConfirmRequired(parser.string_arg); // Can this take an SRAM string??
81-
else
82-
ExtUI::onUserConfirmRequired_P(GET_TEXT(MSG_USERWAIT));
83-
}
67+
if (parser.string_arg)
68+
ExtUI::onUserConfirmRequired(parser.string_arg); // Can this take an SRAM string??
69+
else
70+
ExtUI::onUserConfirmRequired_P(GET_TEXT(MSG_USERWAIT));
8471
#else
8572

8673
if (parser.string_arg) {
@@ -90,25 +77,15 @@ void GcodeSuite::M0_M1() {
9077

9178
#endif
9279

93-
KEEPALIVE_STATE(PAUSED_FOR_USER);
94-
wait_for_user = true;
95-
9680
#if ENABLED(HOST_PROMPT_SUPPORT)
97-
if (!seenQ) host_prompt_do(PROMPT_USER_CONTINUE, parser.codenum ? PSTR("M1 Stop") : PSTR("M0 Stop"), CONTINUE_STR);
81+
host_prompt_do(PROMPT_USER_CONTINUE, parser.codenum ? PSTR("M1 Stop") : PSTR("M0 Stop"), CONTINUE_STR);
9882
#endif
9983

100-
if (ms > 0) ms += millis(); // wait until this time for a click
101-
while (wait_for_user && (ms == 0 || PENDING(millis(), ms))) idle();
102-
103-
#if HAS_LEDS_OFF_FLAG
104-
printerEventLEDs.onResumeAfterWait();
105-
#endif
84+
wait_for_user_response(ms);
10685

10786
#if HAS_LCD_MENU
108-
if (!seenQ) ui.reset_status();
87+
ui.reset_status();
10988
#endif
110-
111-
wait_for_user = false;
11289
}
11390

11491
#endif // HAS_RESUME_CONTINUE

0 commit comments

Comments
 (0)