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 23KB

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