My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pause.cpp 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * feature/pause.cpp - Pause feature support functions
  24. * This may be combined with related G-codes if features are consolidated.
  25. */
  26. #include "../inc/MarlinConfigPre.h"
  27. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  28. //#define DEBUG_PAUSE_RESUME
  29. #include "../MarlinCore.h"
  30. #include "../gcode/gcode.h"
  31. #include "../module/motion.h"
  32. #include "../module/planner.h"
  33. #include "../module/stepper.h"
  34. #include "../module/printcounter.h"
  35. #include "../module/temperature.h"
  36. #if ENABLED(AUTO_BED_LEVELING_UBL)
  37. #include "bedlevel/bedlevel.h"
  38. #endif
  39. #if ENABLED(FWRETRACT)
  40. #include "fwretract.h"
  41. #endif
  42. #if HAS_FILAMENT_SENSOR
  43. #include "runout.h"
  44. #endif
  45. #if ENABLED(HOST_ACTION_COMMANDS)
  46. #include "host_actions.h"
  47. #endif
  48. #if ENABLED(EXTENSIBLE_UI)
  49. #include "../lcd/extui/ui_api.h"
  50. #elif ENABLED(DWIN_LCD_PROUI)
  51. #include "../lcd/e3v2/proui/dwin.h"
  52. #endif
  53. #include "../lcd/marlinui.h"
  54. #if HAS_BUZZER
  55. #include "../libs/buzzer.h"
  56. #endif
  57. #if ENABLED(POWER_LOSS_RECOVERY)
  58. #include "powerloss.h"
  59. #endif
  60. #include "../libs/nozzle.h"
  61. #include "pause.h"
  62. #define DEBUG_OUT ENABLED(DEBUG_PAUSE_RESUME)
  63. #include "../core/debug_out.h"
  64. // private:
  65. static xyze_pos_t resume_position;
  66. #if M600_PURGE_MORE_RESUMABLE
  67. PauseMenuResponse pause_menu_response;
  68. PauseMode pause_mode = PAUSE_MODE_PAUSE_PRINT;
  69. #endif
  70. fil_change_settings_t fc_settings[EXTRUDERS];
  71. #if ENABLED(SDSUPPORT)
  72. #include "../sd/cardreader.h"
  73. #endif
  74. #if ENABLED(EMERGENCY_PARSER)
  75. #define _PMSG(L) L##_M108
  76. #else
  77. #define _PMSG(L) L##_LCD
  78. #endif
  79. #if HAS_BUZZER
  80. static void impatient_beep(const int8_t max_beep_count, const bool restart=false) {
  81. if (TERN0(HAS_MARLINUI_MENU, pause_mode == PAUSE_MODE_PAUSE_PRINT)) return;
  82. static millis_t next_buzz = 0;
  83. static int8_t runout_beep = 0;
  84. if (restart) next_buzz = runout_beep = 0;
  85. const bool always = max_beep_count < 0;
  86. const millis_t ms = millis();
  87. if (ELAPSED(ms, next_buzz)) {
  88. if (always || runout_beep < max_beep_count + 5) { // Only beep as long as we're supposed to
  89. next_buzz = ms + ((always || runout_beep < max_beep_count) ? 1000 : 500);
  90. BUZZ(50, 880 - (runout_beep & 1) * 220);
  91. runout_beep++;
  92. }
  93. }
  94. }
  95. inline void first_impatient_beep(const int8_t max_beep_count) { impatient_beep(max_beep_count, true); }
  96. #else
  97. inline void impatient_beep(const int8_t, const bool=false) {}
  98. inline void first_impatient_beep(const int8_t) {}
  99. #endif
  100. /**
  101. * Ensure a safe temperature for extrusion
  102. *
  103. * - Fail if the TARGET temperature is too low
  104. * - Display LCD placard with temperature status
  105. * - Return when heating is done or aborted
  106. *
  107. * Returns 'true' if heating was completed, 'false' for abort
  108. */
  109. static bool ensure_safe_temperature(const bool wait=true, const PauseMode mode=PAUSE_MODE_SAME) {
  110. DEBUG_SECTION(est, "ensure_safe_temperature", true);
  111. DEBUG_ECHOLNPGM("... wait:", wait, " mode:", mode);
  112. #if ENABLED(PREVENT_COLD_EXTRUSION)
  113. if (!DEBUGGING(DRYRUN) && thermalManager.targetTooColdToExtrude(active_extruder))
  114. thermalManager.setTargetHotend(thermalManager.extrude_min_temp, active_extruder);
  115. #endif
  116. ui.pause_show_message(PAUSE_MESSAGE_HEATING, mode); UNUSED(mode);
  117. if (wait) return thermalManager.wait_for_hotend(active_extruder);
  118. // Allow interruption by Emergency Parser M108
  119. wait_for_heatup = TERN1(PREVENT_COLD_EXTRUSION, !thermalManager.allow_cold_extrude);
  120. while (wait_for_heatup && ABS(thermalManager.wholeDegHotend(active_extruder) - thermalManager.degTargetHotend(active_extruder)) > (TEMP_WINDOW))
  121. idle();
  122. wait_for_heatup = false;
  123. #if ENABLED(PREVENT_COLD_EXTRUSION)
  124. // A user can cancel wait-for-heating with M108
  125. if (!DEBUGGING(DRYRUN) && thermalManager.targetTooColdToExtrude(active_extruder)) {
  126. SERIAL_ECHO_MSG(STR_ERR_HOTEND_TOO_COLD);
  127. return false;
  128. }
  129. #endif
  130. return true;
  131. }
  132. /**
  133. * Load filament into the hotend
  134. *
  135. * - Fail if the a safe temperature was not reached
  136. * - If pausing for confirmation, wait for a click or M108
  137. * - Show "wait for load" placard
  138. * - Load and purge filament
  139. * - Show "Purge more" / "Continue" menu
  140. * - Return when "Continue" is selected
  141. *
  142. * Returns 'true' if load was completed, 'false' for abort
  143. */
  144. bool load_filament(const_float_t slow_load_length/*=0*/, const_float_t fast_load_length/*=0*/, const_float_t purge_length/*=0*/, const int8_t max_beep_count/*=0*/,
  145. const bool show_lcd/*=false*/, const bool pause_for_user/*=false*/,
  146. const PauseMode mode/*=PAUSE_MODE_PAUSE_PRINT*/
  147. DXC_ARGS
  148. ) {
  149. DEBUG_SECTION(lf, "load_filament", true);
  150. DEBUG_ECHOLNPGM("... slowlen:", slow_load_length, " fastlen:", fast_load_length, " purgelen:", purge_length, " maxbeep:", max_beep_count, " showlcd:", show_lcd, " pauseforuser:", pause_for_user, " pausemode:", mode DXC_SAY);
  151. if (!ensure_safe_temperature(false, mode)) {
  152. if (show_lcd) ui.pause_show_message(PAUSE_MESSAGE_STATUS, mode);
  153. return false;
  154. }
  155. if (pause_for_user) {
  156. if (show_lcd) ui.pause_show_message(PAUSE_MESSAGE_INSERT, mode);
  157. SERIAL_ECHO_MSG(_PMSG(STR_FILAMENT_CHANGE_INSERT));
  158. first_impatient_beep(max_beep_count);
  159. KEEPALIVE_STATE(PAUSED_FOR_USER);
  160. wait_for_user = true; // LCD click or M108 will clear this
  161. TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired(F("Load Filament")));
  162. #if ENABLED(HOST_PROMPT_SUPPORT)
  163. const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, active_extruder);
  164. hostui.prompt_do(PROMPT_USER_CONTINUE, F("Load Filament T"), tool, FPSTR(CONTINUE_STR));
  165. #endif
  166. while (wait_for_user) {
  167. impatient_beep(max_beep_count);
  168. #if BOTH(FILAMENT_CHANGE_RESUME_ON_INSERT, FILAMENT_RUNOUT_SENSOR)
  169. #if ENABLED(MULTI_FILAMENT_SENSOR)
  170. #define _CASE_INSERTED(N) case N-1: if (READ(FIL_RUNOUT##N##_PIN) != FIL_RUNOUT##N##_STATE) wait_for_user = false; break;
  171. switch (active_extruder) {
  172. REPEAT_1(NUM_RUNOUT_SENSORS, _CASE_INSERTED)
  173. }
  174. #else
  175. if (READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_STATE) wait_for_user = false;
  176. #endif
  177. #endif
  178. idle_no_sleep();
  179. }
  180. }
  181. if (show_lcd) ui.pause_show_message(PAUSE_MESSAGE_LOAD, mode);
  182. #if ENABLED(DUAL_X_CARRIAGE)
  183. const int8_t saved_ext = active_extruder;
  184. const bool saved_ext_dup_mode = extruder_duplication_enabled;
  185. set_duplication_enabled(false, DXC_ext);
  186. #endif
  187. TERN_(BELTPRINTER, do_blocking_move_to_xy(0.00, 50.00));
  188. // Slow Load filament
  189. if (slow_load_length) unscaled_e_move(slow_load_length, FILAMENT_CHANGE_SLOW_LOAD_FEEDRATE);
  190. // Fast Load Filament
  191. if (fast_load_length) {
  192. #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0
  193. const float saved_acceleration = planner.settings.retract_acceleration;
  194. planner.settings.retract_acceleration = FILAMENT_CHANGE_FAST_LOAD_ACCEL;
  195. #endif
  196. unscaled_e_move(fast_load_length, FILAMENT_CHANGE_FAST_LOAD_FEEDRATE);
  197. #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0
  198. planner.settings.retract_acceleration = saved_acceleration;
  199. #endif
  200. }
  201. #if ENABLED(DUAL_X_CARRIAGE) // Tie the two extruders movement back together.
  202. set_duplication_enabled(saved_ext_dup_mode, saved_ext);
  203. #endif
  204. #if ENABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE)
  205. if (show_lcd) ui.pause_show_message(PAUSE_MESSAGE_PURGE);
  206. TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_FILAMENT_CHANGE_PURGE)));
  207. TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_do(PROMPT_USER_CONTINUE, GET_TEXT_F(MSG_FILAMENT_CHANGE_PURGE), FPSTR(CONTINUE_STR)));
  208. wait_for_user = true; // A click or M108 breaks the purge_length loop
  209. for (float purge_count = purge_length; purge_count > 0 && wait_for_user; --purge_count)
  210. unscaled_e_move(1, ADVANCED_PAUSE_PURGE_FEEDRATE);
  211. wait_for_user = false;
  212. #else
  213. do {
  214. if (purge_length > 0) {
  215. // "Wait for filament purge"
  216. if (show_lcd) ui.pause_show_message(PAUSE_MESSAGE_PURGE);
  217. // Extrude filament to get into hotend
  218. unscaled_e_move(purge_length, ADVANCED_PAUSE_PURGE_FEEDRATE);
  219. }
  220. TERN_(HOST_PROMPT_SUPPORT, hostui.filament_load_prompt()); // Initiate another host prompt.
  221. #if M600_PURGE_MORE_RESUMABLE
  222. if (show_lcd) {
  223. // Show "Purge More" / "Resume" menu and wait for reply
  224. KEEPALIVE_STATE(PAUSED_FOR_USER);
  225. wait_for_user = false;
  226. #if EITHER(HAS_MARLINUI_MENU, DWIN_LCD_PROUI)
  227. ui.pause_show_message(PAUSE_MESSAGE_OPTION); // Also sets PAUSE_RESPONSE_WAIT_FOR
  228. #else
  229. pause_menu_response = PAUSE_RESPONSE_WAIT_FOR;
  230. #endif
  231. while (pause_menu_response == PAUSE_RESPONSE_WAIT_FOR) idle_no_sleep();
  232. }
  233. #endif
  234. // Keep looping if "Purge More" was selected
  235. } while (TERN0(M600_PURGE_MORE_RESUMABLE, pause_menu_response == PAUSE_RESPONSE_EXTRUDE_MORE));
  236. #endif
  237. TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_end());
  238. return true;
  239. }
  240. /**
  241. * Disabling E steppers for manual filament change should be fine
  242. * as long as users don't spin the E motor ridiculously fast and
  243. * send current back to their board, potentially frying it.
  244. */
  245. inline void disable_active_extruder() {
  246. #if HAS_EXTRUDERS
  247. stepper.DISABLE_EXTRUDER(active_extruder);
  248. safe_delay(100);
  249. #endif
  250. }
  251. /**
  252. * Unload filament from the hotend
  253. *
  254. * - Fail if the a safe temperature was not reached
  255. * - Show "wait for unload" placard
  256. * - Retract, pause, then unload filament
  257. * - Disable E stepper (on most machines)
  258. *
  259. * Returns 'true' if unload was completed, 'false' for abort
  260. */
  261. bool unload_filament(const_float_t unload_length, const bool show_lcd/*=false*/,
  262. const PauseMode mode/*=PAUSE_MODE_PAUSE_PRINT*/
  263. #if BOTH(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER)
  264. , const_float_t mix_multiplier/*=1.0*/
  265. #endif
  266. ) {
  267. DEBUG_SECTION(uf, "unload_filament", true);
  268. DEBUG_ECHOLNPGM("... unloadlen:", unload_length, " showlcd:", show_lcd, " mode:", mode
  269. #if BOTH(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER)
  270. , " mixmult:", mix_multiplier
  271. #endif
  272. );
  273. #if !BOTH(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER)
  274. constexpr float mix_multiplier = 1.0f;
  275. #endif
  276. if (!ensure_safe_temperature(false, mode)) {
  277. if (show_lcd) ui.pause_show_message(PAUSE_MESSAGE_STATUS);
  278. return false;
  279. }
  280. if (show_lcd) ui.pause_show_message(PAUSE_MESSAGE_UNLOAD, mode);
  281. // Retract filament
  282. unscaled_e_move(-(FILAMENT_UNLOAD_PURGE_RETRACT) * mix_multiplier, (PAUSE_PARK_RETRACT_FEEDRATE) * mix_multiplier);
  283. // Wait for filament to cool
  284. safe_delay(FILAMENT_UNLOAD_PURGE_DELAY);
  285. // Quickly purge
  286. unscaled_e_move((FILAMENT_UNLOAD_PURGE_RETRACT + FILAMENT_UNLOAD_PURGE_LENGTH) * mix_multiplier,
  287. (FILAMENT_UNLOAD_PURGE_FEEDRATE) * mix_multiplier);
  288. // Unload filament
  289. #if FILAMENT_CHANGE_UNLOAD_ACCEL > 0
  290. const float saved_acceleration = planner.settings.retract_acceleration;
  291. planner.settings.retract_acceleration = FILAMENT_CHANGE_UNLOAD_ACCEL;
  292. #endif
  293. unscaled_e_move(unload_length * mix_multiplier, (FILAMENT_CHANGE_UNLOAD_FEEDRATE) * mix_multiplier);
  294. #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0
  295. planner.settings.retract_acceleration = saved_acceleration;
  296. #endif
  297. // Disable the Extruder for manual change
  298. disable_active_extruder();
  299. return true;
  300. }
  301. // public:
  302. /**
  303. * Pause procedure
  304. *
  305. * - Abort if already paused
  306. * - Send host action for pause, if configured
  307. * - Abort if TARGET temperature is too low
  308. * - Display "wait for start of filament change" (if a length was specified)
  309. * - Initial retract, if current temperature is hot enough
  310. * - Park the nozzle at the given position
  311. * - Call unload_filament (if a length was specified)
  312. *
  313. * Return 'true' if pause was completed, 'false' for abort
  314. */
  315. uint8_t did_pause_print = 0;
  316. bool pause_print(const_float_t retract, const xyz_pos_t &park_point, const bool show_lcd/*=false*/, const_float_t unload_length/*=0*/ DXC_ARGS) {
  317. DEBUG_SECTION(pp, "pause_print", true);
  318. DEBUG_ECHOLNPGM("... park.x:", park_point.x, " y:", park_point.y, " z:", park_point.z, " unloadlen:", unload_length, " showlcd:", show_lcd DXC_SAY);
  319. UNUSED(show_lcd);
  320. if (did_pause_print) return false; // already paused
  321. #if ENABLED(HOST_ACTION_COMMANDS)
  322. #ifdef ACTION_ON_PAUSED
  323. hostui.paused();
  324. #elif defined(ACTION_ON_PAUSE)
  325. hostui.pause();
  326. #endif
  327. #endif
  328. TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_open(PROMPT_INFO, F("Pause"), FPSTR(DISMISS_STR)));
  329. // Indicate that the printer is paused
  330. ++did_pause_print;
  331. // Pause the print job and timer
  332. #if ENABLED(SDSUPPORT)
  333. const bool was_sd_printing = IS_SD_PRINTING();
  334. if (was_sd_printing) {
  335. card.pauseSDPrint();
  336. ++did_pause_print; // Indicate SD pause also
  337. }
  338. #endif
  339. print_job_timer.pause();
  340. // Save current position
  341. resume_position = current_position;
  342. // Will the nozzle be parking?
  343. const bool do_park = !axes_should_home();
  344. #if ENABLED(POWER_LOSS_RECOVERY)
  345. // Save PLR info in case the power goes out while parked
  346. const float park_raise = do_park ? nozzle.park_mode_0_height(park_point.z) - current_position.z : POWER_LOSS_ZRAISE;
  347. if (was_sd_printing && recovery.enabled) recovery.save(true, park_raise, do_park);
  348. #endif
  349. // Wait for buffered blocks to complete
  350. planner.synchronize();
  351. #if ENABLED(ADVANCED_PAUSE_FANS_PAUSE) && HAS_FAN
  352. thermalManager.set_fans_paused(true);
  353. #endif
  354. // Initial retract before move to filament change position
  355. if (retract && thermalManager.hotEnoughToExtrude(active_extruder)) {
  356. DEBUG_ECHOLNPGM("... retract:", retract);
  357. #if ENABLED(AUTO_BED_LEVELING_UBL)
  358. const bool leveling_was_enabled = planner.leveling_active; // save leveling state
  359. set_bed_leveling_enabled(false); // turn off leveling
  360. #endif
  361. unscaled_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);
  362. TERN_(AUTO_BED_LEVELING_UBL, set_bed_leveling_enabled(leveling_was_enabled)); // restore leveling
  363. }
  364. // If axes don't need to home then the nozzle can park
  365. if (do_park) nozzle.park(0, park_point); // Park the nozzle by doing a Minimum Z Raise followed by an XY Move
  366. #if ENABLED(DUAL_X_CARRIAGE)
  367. const int8_t saved_ext = active_extruder;
  368. const bool saved_ext_dup_mode = extruder_duplication_enabled;
  369. set_duplication_enabled(false, DXC_ext);
  370. #endif
  371. // Unload the filament, if specified
  372. if (unload_length)
  373. unload_filament(unload_length, show_lcd, PAUSE_MODE_CHANGE_FILAMENT);
  374. #if ENABLED(DUAL_X_CARRIAGE)
  375. set_duplication_enabled(saved_ext_dup_mode, saved_ext);
  376. #endif
  377. // Disable the Extruder for manual change
  378. disable_active_extruder();
  379. return true;
  380. }
  381. /**
  382. * For Paused Print:
  383. * - Show "Press button (or M108) to resume"
  384. *
  385. * For Filament Change:
  386. * - Show "Insert filament and press button to continue"
  387. *
  388. * - Wait for a click before returning
  389. * - Heaters can time out and must reheat before continuing
  390. *
  391. * Used by M125 and M600
  392. */
  393. void show_continue_prompt(const bool is_reload) {
  394. DEBUG_SECTION(scp, "pause_print", true);
  395. DEBUG_ECHOLNPGM("... is_reload:", is_reload);
  396. ui.pause_show_message(is_reload ? PAUSE_MESSAGE_INSERT : PAUSE_MESSAGE_WAITING);
  397. SERIAL_ECHO_START();
  398. SERIAL_ECHOF(is_reload ? F(_PMSG(STR_FILAMENT_CHANGE_INSERT) "\n") : F(_PMSG(STR_FILAMENT_CHANGE_WAIT) "\n"));
  399. }
  400. void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep_count/*=0*/ DXC_ARGS) {
  401. DEBUG_SECTION(wfc, "wait_for_confirmation", true);
  402. DEBUG_ECHOLNPGM("... is_reload:", is_reload, " maxbeep:", max_beep_count DXC_SAY);
  403. bool nozzle_timed_out = false;
  404. show_continue_prompt(is_reload);
  405. first_impatient_beep(max_beep_count);
  406. // Start the heater idle timers
  407. const millis_t nozzle_timeout = SEC_TO_MS(PAUSE_PARK_NOZZLE_TIMEOUT);
  408. HOTEND_LOOP() thermalManager.heater_idle[e].start(nozzle_timeout);
  409. #if ENABLED(DUAL_X_CARRIAGE)
  410. const int8_t saved_ext = active_extruder;
  411. const bool saved_ext_dup_mode = extruder_duplication_enabled;
  412. set_duplication_enabled(false, DXC_ext);
  413. #endif
  414. // Wait for filament insert by user and press button
  415. KEEPALIVE_STATE(PAUSED_FOR_USER);
  416. TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_do(PROMPT_USER_CONTINUE, GET_TEXT_F(MSG_NOZZLE_PARKED), FPSTR(CONTINUE_STR)));
  417. TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_NOZZLE_PARKED)));
  418. wait_for_user = true; // LCD click or M108 will clear this
  419. while (wait_for_user) {
  420. impatient_beep(max_beep_count);
  421. // If the nozzle has timed out...
  422. if (!nozzle_timed_out)
  423. HOTEND_LOOP() nozzle_timed_out |= thermalManager.heater_idle[e].timed_out;
  424. // Wait for the user to press the button to re-heat the nozzle, then
  425. // re-heat the nozzle, re-show the continue prompt, restart idle timers, start over
  426. if (nozzle_timed_out) {
  427. ui.pause_show_message(PAUSE_MESSAGE_HEAT);
  428. SERIAL_ECHO_MSG(_PMSG(STR_FILAMENT_CHANGE_HEAT));
  429. TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_do(PROMPT_USER_CONTINUE, GET_TEXT_F(MSG_HEATER_TIMEOUT), GET_TEXT_F(MSG_REHEAT)));
  430. TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_HEATER_TIMEOUT)));
  431. TERN_(HAS_RESUME_CONTINUE, wait_for_user_response(0, true)); // Wait for LCD click or M108
  432. TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_do(PROMPT_INFO, GET_TEXT_F(MSG_REHEATING)));
  433. TERN_(EXTENSIBLE_UI, ExtUI::onStatusChanged(GET_TEXT_F(MSG_REHEATING)));
  434. TERN_(DWIN_LCD_PROUI, LCD_MESSAGE(MSG_REHEATING));
  435. // Re-enable the heaters if they timed out
  436. HOTEND_LOOP() thermalManager.reset_hotend_idle_timer(e);
  437. // Wait for the heaters to reach the target temperatures
  438. ensure_safe_temperature(false);
  439. // Show the prompt to continue
  440. show_continue_prompt(is_reload);
  441. // Start the heater idle timers
  442. const millis_t nozzle_timeout = SEC_TO_MS(PAUSE_PARK_NOZZLE_TIMEOUT);
  443. HOTEND_LOOP() thermalManager.heater_idle[e].start(nozzle_timeout);
  444. TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_do(PROMPT_USER_CONTINUE, GET_TEXT_F(MSG_REHEATDONE), FPSTR(CONTINUE_STR)));
  445. TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired(GET_TEXT_F(MSG_REHEATDONE)));
  446. TERN_(DWIN_LCD_PROUI, LCD_MESSAGE(MSG_REHEATDONE));
  447. IF_DISABLED(PAUSE_REHEAT_FAST_RESUME, wait_for_user = true);
  448. nozzle_timed_out = false;
  449. first_impatient_beep(max_beep_count);
  450. }
  451. idle_no_sleep();
  452. }
  453. #if ENABLED(DUAL_X_CARRIAGE)
  454. set_duplication_enabled(saved_ext_dup_mode, saved_ext);
  455. #endif
  456. }
  457. /**
  458. * Resume or Start print procedure
  459. *
  460. * - If not paused, do nothing and return
  461. * - Reset heater idle timers
  462. * - Load filament if specified, but only if:
  463. * - a nozzle timed out, or
  464. * - the nozzle is already heated.
  465. * - Display "wait for print to resume"
  466. * - Retract to prevent oozing
  467. * - Move the nozzle back to resume_position
  468. * - Unretract
  469. * - Re-prime the nozzle...
  470. * - FWRETRACT: Recover/prime from the prior G10.
  471. * - !FWRETRACT: Retract by resume_position.e, if negative.
  472. * Not sure how this logic comes into use.
  473. * - Sync the planner E to resume_position.e
  474. * - Send host action for resume, if configured
  475. * - Resume the current SD print job, if any
  476. */
  477. void resume_print(const_float_t slow_load_length/*=0*/, const_float_t fast_load_length/*=0*/, const_float_t purge_length/*=ADVANCED_PAUSE_PURGE_LENGTH*/, const int8_t max_beep_count/*=0*/, const celsius_t targetTemp/*=0*/ DXC_ARGS) {
  478. DEBUG_SECTION(rp, "resume_print", true);
  479. DEBUG_ECHOLNPGM("... slowlen:", slow_load_length, " fastlen:", fast_load_length, " purgelen:", purge_length, " maxbeep:", max_beep_count, " targetTemp:", targetTemp DXC_SAY);
  480. /*
  481. SERIAL_ECHOLNPGM(
  482. "start of resume_print()\ndual_x_carriage_mode:", dual_x_carriage_mode,
  483. "\nextruder_duplication_enabled:", extruder_duplication_enabled,
  484. "\nactive_extruder:", active_extruder,
  485. "\n"
  486. );
  487. //*/
  488. if (!did_pause_print) return;
  489. // Re-enable the heaters if they timed out
  490. bool nozzle_timed_out = false;
  491. HOTEND_LOOP() {
  492. nozzle_timed_out |= thermalManager.heater_idle[e].timed_out;
  493. thermalManager.reset_hotend_idle_timer(e);
  494. }
  495. if (targetTemp > thermalManager.degTargetHotend(active_extruder))
  496. thermalManager.setTargetHotend(targetTemp, active_extruder);
  497. // Load the new filament
  498. load_filament(slow_load_length, fast_load_length, purge_length, max_beep_count, true, nozzle_timed_out, PAUSE_MODE_SAME DXC_PASS);
  499. if (targetTemp > 0) {
  500. thermalManager.setTargetHotend(targetTemp, active_extruder);
  501. thermalManager.wait_for_hotend(active_extruder, false);
  502. }
  503. ui.pause_show_message(PAUSE_MESSAGE_RESUME);
  504. // Check Temperature before moving hotend
  505. ensure_safe_temperature(DISABLED(BELTPRINTER));
  506. // Retract to prevent oozing
  507. unscaled_e_move(-(PAUSE_PARK_RETRACT_LENGTH), feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE));
  508. if (!axes_should_home()) {
  509. // Move XY back to saved position
  510. destination.set(resume_position.x, resume_position.y, current_position.z, current_position.e);
  511. prepare_internal_move_to_destination(NOZZLE_PARK_XY_FEEDRATE);
  512. // Move Z back to saved position
  513. destination.z = resume_position.z;
  514. prepare_internal_move_to_destination(NOZZLE_PARK_Z_FEEDRATE);
  515. }
  516. #if ENABLED(AUTO_BED_LEVELING_UBL)
  517. const bool leveling_was_enabled = planner.leveling_active; // save leveling state
  518. set_bed_leveling_enabled(false); // turn off leveling
  519. #endif
  520. // Unretract
  521. unscaled_e_move(PAUSE_PARK_RETRACT_LENGTH, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE));
  522. TERN_(AUTO_BED_LEVELING_UBL, set_bed_leveling_enabled(leveling_was_enabled)); // restore leveling
  523. // Intelligent resuming
  524. #if ENABLED(FWRETRACT)
  525. // If retracted before goto pause
  526. if (fwretract.retracted[active_extruder])
  527. unscaled_e_move(-fwretract.settings.retract_length, fwretract.settings.retract_feedrate_mm_s);
  528. #endif
  529. // If resume_position is negative
  530. if (resume_position.e < 0) unscaled_e_move(resume_position.e, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE));
  531. #if ADVANCED_PAUSE_RESUME_PRIME != 0
  532. unscaled_e_move(ADVANCED_PAUSE_RESUME_PRIME, feedRate_t(ADVANCED_PAUSE_PURGE_FEEDRATE));
  533. #endif
  534. // Now all extrusion positions are resumed and ready to be confirmed
  535. // Set extruder to saved position
  536. planner.set_e_position_mm((destination.e = current_position.e = resume_position.e));
  537. ui.pause_show_message(PAUSE_MESSAGE_STATUS);
  538. #ifdef ACTION_ON_RESUMED
  539. hostui.resumed();
  540. #elif defined(ACTION_ON_RESUME)
  541. hostui.resume();
  542. #endif
  543. --did_pause_print;
  544. TERN_(HOST_PROMPT_SUPPORT, hostui.prompt_open(PROMPT_INFO, F("Resuming"), FPSTR(DISMISS_STR)));
  545. // Resume the print job timer if it was running
  546. if (print_job_timer.isPaused()) print_job_timer.start();
  547. #if ENABLED(SDSUPPORT)
  548. if (did_pause_print) {
  549. --did_pause_print;
  550. card.startOrResumeFilePrinting();
  551. // Write PLR now to update the z axis value
  552. TERN_(POWER_LOSS_RECOVERY, if (recovery.enabled) recovery.save(true));
  553. }
  554. #endif
  555. #if ENABLED(ADVANCED_PAUSE_FANS_PAUSE) && HAS_FAN
  556. thermalManager.set_fans_paused(false);
  557. #endif
  558. TERN_(HAS_FILAMENT_SENSOR, runout.reset());
  559. TERN_(HAS_STATUS_MESSAGE, ui.reset_status());
  560. TERN_(HAS_MARLINUI_MENU, ui.return_to_status());
  561. TERN_(DWIN_LCD_PROUI, HMI_ReturnScreen());
  562. }
  563. #endif // ADVANCED_PAUSE_FEATURE