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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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 <http://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. #include "../MarlinCore.h"
  29. #include "../gcode/gcode.h"
  30. #include "../module/motion.h"
  31. #include "../module/planner.h"
  32. #include "../module/stepper.h"
  33. #include "../module/printcounter.h"
  34. #include "../module/temperature.h"
  35. #if ENABLED(FWRETRACT)
  36. #include "fwretract.h"
  37. #endif
  38. #if HAS_FILAMENT_SENSOR
  39. #include "runout.h"
  40. #endif
  41. #if ENABLED(HOST_ACTION_COMMANDS)
  42. #include "host_actions.h"
  43. #endif
  44. #if ENABLED(EXTENSIBLE_UI)
  45. #include "../lcd/extui/ui_api.h"
  46. #endif
  47. #include "../lcd/ultralcd.h"
  48. #if HAS_BUZZER
  49. #include "../libs/buzzer.h"
  50. #endif
  51. #include "../libs/nozzle.h"
  52. #include "pause.h"
  53. // private:
  54. static xyze_pos_t resume_position;
  55. #if HAS_LCD_MENU
  56. PauseMenuResponse pause_menu_response;
  57. PauseMode pause_mode = PAUSE_MODE_PAUSE_PRINT;
  58. #endif
  59. fil_change_settings_t fc_settings[EXTRUDERS];
  60. #if ENABLED(SDSUPPORT)
  61. #include "../sd/cardreader.h"
  62. #endif
  63. #if ENABLED(EMERGENCY_PARSER)
  64. #define _PMSG(L) L##_M108
  65. #else
  66. #define _PMSG(L) L##_LCD
  67. #endif
  68. #if HAS_BUZZER
  69. static void filament_change_beep(const int8_t max_beep_count, const bool init=false) {
  70. if (TERN0(HAS_LCD_MENU, pause_mode == PAUSE_MODE_PAUSE_PRINT)) return;
  71. static millis_t next_buzz = 0;
  72. static int8_t runout_beep = 0;
  73. if (init) next_buzz = runout_beep = 0;
  74. const millis_t ms = millis();
  75. if (ELAPSED(ms, next_buzz)) {
  76. if (max_beep_count < 0 || runout_beep < max_beep_count + 5) { // Only beep as long as we're supposed to
  77. next_buzz = ms + ((max_beep_count < 0 || runout_beep < max_beep_count) ? 1000 : 500);
  78. BUZZ(50, 880 - (runout_beep & 1) * 220);
  79. runout_beep++;
  80. }
  81. }
  82. }
  83. #endif
  84. /**
  85. * Ensure a safe temperature for extrusion
  86. *
  87. * - Fail if the TARGET temperature is too low
  88. * - Display LCD placard with temperature status
  89. * - Return when heating is done or aborted
  90. *
  91. * Returns 'true' if heating was completed, 'false' for abort
  92. */
  93. static bool ensure_safe_temperature(const PauseMode mode=PAUSE_MODE_SAME) {
  94. #if ENABLED(PREVENT_COLD_EXTRUSION)
  95. if (!DEBUGGING(DRYRUN) && thermalManager.targetTooColdToExtrude(active_extruder)) {
  96. SERIAL_ECHO_MSG(STR_ERR_HOTEND_TOO_COLD);
  97. return false;
  98. }
  99. #endif
  100. #if HAS_LCD_MENU
  101. lcd_pause_show_message(PAUSE_MESSAGE_HEATING, mode);
  102. #else
  103. UNUSED(mode);
  104. #endif
  105. return thermalManager.wait_for_hotend(active_extruder);
  106. }
  107. /**
  108. * Load filament into the hotend
  109. *
  110. * - Fail if the a safe temperature was not reached
  111. * - If pausing for confirmation, wait for a click or M108
  112. * - Show "wait for load" placard
  113. * - Load and purge filament
  114. * - Show "Purge more" / "Continue" menu
  115. * - Return when "Continue" is selected
  116. *
  117. * Returns 'true' if load was completed, 'false' for abort
  118. */
  119. bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_length/*=0*/, const float &purge_length/*=0*/, const int8_t max_beep_count/*=0*/,
  120. const bool show_lcd/*=false*/, const bool pause_for_user/*=false*/,
  121. const PauseMode mode/*=PAUSE_MODE_PAUSE_PRINT*/
  122. DXC_ARGS
  123. ) {
  124. #if !HAS_LCD_MENU
  125. UNUSED(show_lcd);
  126. #endif
  127. if (!ensure_safe_temperature(mode)) {
  128. #if HAS_LCD_MENU
  129. if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_STATUS, mode);
  130. #endif
  131. return false;
  132. }
  133. if (pause_for_user) {
  134. #if HAS_LCD_MENU
  135. if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_INSERT, mode);
  136. #endif
  137. SERIAL_ECHO_MSG(_PMSG(STR_FILAMENT_CHANGE_INSERT));
  138. #if HAS_BUZZER
  139. filament_change_beep(max_beep_count, true);
  140. #else
  141. UNUSED(max_beep_count);
  142. #endif
  143. KEEPALIVE_STATE(PAUSED_FOR_USER);
  144. #if ENABLED(HOST_PROMPT_SUPPORT)
  145. const char tool = '0'
  146. #if NUM_RUNOUT_SENSORS > 1
  147. + active_extruder
  148. #endif
  149. ;
  150. host_action_prompt_begin(PROMPT_USER_CONTINUE, PSTR("Load Filament T"), tool);
  151. host_action_prompt_button(CONTINUE_STR);
  152. host_action_prompt_show();
  153. #endif
  154. TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("Load Filament")));
  155. while (wait_for_user) {
  156. TERN_(HAS_BUZZER, filament_change_beep(max_beep_count));
  157. idle_no_sleep();
  158. }
  159. }
  160. #if HAS_LCD_MENU
  161. if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_LOAD, mode);
  162. #endif
  163. #if ENABLED(DUAL_X_CARRIAGE)
  164. const int8_t saved_ext = active_extruder;
  165. const bool saved_ext_dup_mode = extruder_duplication_enabled;
  166. active_extruder = DXC_ext;
  167. extruder_duplication_enabled = false;
  168. #endif
  169. // Slow Load filament
  170. if (slow_load_length) unscaled_e_move(slow_load_length, FILAMENT_CHANGE_SLOW_LOAD_FEEDRATE);
  171. // Fast Load Filament
  172. if (fast_load_length) {
  173. #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0
  174. const float saved_acceleration = planner.settings.retract_acceleration;
  175. planner.settings.retract_acceleration = FILAMENT_CHANGE_FAST_LOAD_ACCEL;
  176. #endif
  177. unscaled_e_move(fast_load_length, FILAMENT_CHANGE_FAST_LOAD_FEEDRATE);
  178. #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0
  179. planner.settings.retract_acceleration = saved_acceleration;
  180. #endif
  181. }
  182. #if ENABLED(DUAL_X_CARRIAGE) // Tie the two extruders movement back together.
  183. active_extruder = saved_ext;
  184. extruder_duplication_enabled = saved_ext_dup_mode;
  185. stepper.set_directions();
  186. #endif
  187. #if ENABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE)
  188. #if HAS_LCD_MENU
  189. if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_PURGE);
  190. #endif
  191. TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Filament Purging..."), CONTINUE_STR));
  192. TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("Filament Purging...")));
  193. wait_for_user = true; // A click or M108 breaks the purge_length loop
  194. for (float purge_count = purge_length; purge_count > 0 && wait_for_user; --purge_count)
  195. unscaled_e_move(1, ADVANCED_PAUSE_PURGE_FEEDRATE);
  196. wait_for_user = false;
  197. #else
  198. do {
  199. if (purge_length > 0) {
  200. // "Wait for filament purge"
  201. #if HAS_LCD_MENU
  202. if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_PURGE);
  203. #endif
  204. // Extrude filament to get into hotend
  205. unscaled_e_move(purge_length, ADVANCED_PAUSE_PURGE_FEEDRATE);
  206. }
  207. TERN_(HOST_PROMPT_SUPPORT, filament_load_host_prompt()); // Initiate another host prompt. (NOTE: host_response_handler may also do this!)
  208. #if HAS_LCD_MENU
  209. if (show_lcd) {
  210. // Show "Purge More" / "Resume" menu and wait for reply
  211. KEEPALIVE_STATE(PAUSED_FOR_USER);
  212. wait_for_user = false;
  213. lcd_pause_show_message(PAUSE_MESSAGE_OPTION);
  214. while (pause_menu_response == PAUSE_RESPONSE_WAIT_FOR) idle_no_sleep();
  215. }
  216. #endif
  217. // Keep looping if "Purge More" was selected
  218. } while (TERN0(HAS_LCD_MENU, show_lcd && pause_menu_response == PAUSE_RESPONSE_EXTRUDE_MORE));
  219. #endif
  220. return true;
  221. }
  222. /**
  223. * Unload filament from the hotend
  224. *
  225. * - Fail if the a safe temperature was not reached
  226. * - Show "wait for unload" placard
  227. * - Retract, pause, then unload filament
  228. * - Disable E stepper (on most machines)
  229. *
  230. * Returns 'true' if unload was completed, 'false' for abort
  231. */
  232. bool unload_filament(const float &unload_length, const bool show_lcd/*=false*/,
  233. const PauseMode mode/*=PAUSE_MODE_PAUSE_PRINT*/
  234. #if BOTH(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER)
  235. , const float &mix_multiplier/*=1.0*/
  236. #endif
  237. ) {
  238. #if !HAS_LCD_MENU
  239. UNUSED(show_lcd);
  240. #endif
  241. #if !BOTH(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER)
  242. constexpr float mix_multiplier = 1.0;
  243. #endif
  244. if (!ensure_safe_temperature(mode)) {
  245. #if HAS_LCD_MENU
  246. if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_STATUS);
  247. #endif
  248. return false;
  249. }
  250. #if HAS_LCD_MENU
  251. if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_UNLOAD, mode);
  252. #endif
  253. // Retract filament
  254. unscaled_e_move(-(FILAMENT_UNLOAD_PURGE_RETRACT) * mix_multiplier, (PAUSE_PARK_RETRACT_FEEDRATE) * mix_multiplier);
  255. // Wait for filament to cool
  256. safe_delay(FILAMENT_UNLOAD_PURGE_DELAY);
  257. // Quickly purge
  258. unscaled_e_move((FILAMENT_UNLOAD_PURGE_RETRACT + FILAMENT_UNLOAD_PURGE_LENGTH) * mix_multiplier,
  259. (FILAMENT_UNLOAD_PURGE_FEEDRATE) * mix_multiplier);
  260. // Unload filament
  261. #if FILAMENT_CHANGE_UNLOAD_ACCEL > 0
  262. const float saved_acceleration = planner.settings.retract_acceleration;
  263. planner.settings.retract_acceleration = FILAMENT_CHANGE_UNLOAD_ACCEL;
  264. #endif
  265. unscaled_e_move(unload_length * mix_multiplier, (FILAMENT_CHANGE_UNLOAD_FEEDRATE) * mix_multiplier);
  266. #if FILAMENT_CHANGE_FAST_LOAD_ACCEL > 0
  267. planner.settings.retract_acceleration = saved_acceleration;
  268. #endif
  269. // Disable E steppers for manual change
  270. #if HAS_E_STEPPER_ENABLE
  271. disable_e_stepper(active_extruder);
  272. safe_delay(100);
  273. #endif
  274. return true;
  275. }
  276. // public:
  277. /**
  278. * Pause procedure
  279. *
  280. * - Abort if already paused
  281. * - Send host action for pause, if configured
  282. * - Abort if TARGET temperature is too low
  283. * - Display "wait for start of filament change" (if a length was specified)
  284. * - Initial retract, if current temperature is hot enough
  285. * - Park the nozzle at the given position
  286. * - Call unload_filament (if a length was specified)
  287. *
  288. * Return 'true' if pause was completed, 'false' for abort
  289. */
  290. uint8_t did_pause_print = 0;
  291. bool pause_print(const float &retract, const xyz_pos_t &park_point, const float &unload_length/*=0*/, const bool show_lcd/*=false*/ DXC_ARGS) {
  292. #if !HAS_LCD_MENU
  293. UNUSED(show_lcd);
  294. #endif
  295. if (did_pause_print) return false; // already paused
  296. #if ENABLED(HOST_ACTION_COMMANDS)
  297. #ifdef ACTION_ON_PAUSED
  298. host_action_paused();
  299. #elif defined(ACTION_ON_PAUSE)
  300. host_action_pause();
  301. #endif
  302. #endif
  303. TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("Pause"), DISMISS_STR));
  304. if (!DEBUGGING(DRYRUN) && unload_length && thermalManager.targetTooColdToExtrude(active_extruder)) {
  305. SERIAL_ECHO_MSG(STR_ERR_HOTEND_TOO_COLD);
  306. #if HAS_LCD_MENU
  307. if (show_lcd) { // Show status screen
  308. lcd_pause_show_message(PAUSE_MESSAGE_STATUS);
  309. LCD_MESSAGEPGM(MSG_M600_TOO_COLD);
  310. }
  311. #endif
  312. return false; // unable to reach safe temperature
  313. }
  314. // Indicate that the printer is paused
  315. ++did_pause_print;
  316. // Pause the print job and timer
  317. #if ENABLED(SDSUPPORT)
  318. if (IS_SD_PRINTING()) {
  319. card.pauseSDPrint();
  320. ++did_pause_print; // Indicate SD pause also
  321. }
  322. #endif
  323. print_job_timer.pause();
  324. // Save current position
  325. resume_position = current_position;
  326. // Wait for buffered blocks to complete
  327. planner.synchronize();
  328. #if ENABLED(ADVANCED_PAUSE_FANS_PAUSE) && HAS_FAN
  329. thermalManager.set_fans_paused(true);
  330. #endif
  331. // Initial retract before move to filament change position
  332. if (retract && thermalManager.hotEnoughToExtrude(active_extruder))
  333. unscaled_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);
  334. // Park the nozzle by moving up by z_lift and then moving to (x_pos, y_pos)
  335. if (!axes_need_homing())
  336. nozzle.park(0, park_point);
  337. #if ENABLED(DUAL_X_CARRIAGE)
  338. const int8_t saved_ext = active_extruder;
  339. const bool saved_ext_dup_mode = extruder_duplication_enabled;
  340. active_extruder = DXC_ext;
  341. extruder_duplication_enabled = false;
  342. #endif
  343. if (unload_length) // Unload the filament
  344. unload_filament(unload_length, show_lcd, PAUSE_MODE_CHANGE_FILAMENT);
  345. #if ENABLED(DUAL_X_CARRIAGE)
  346. active_extruder = saved_ext;
  347. extruder_duplication_enabled = saved_ext_dup_mode;
  348. stepper.set_directions();
  349. #endif
  350. return true;
  351. }
  352. /**
  353. * For Paused Print:
  354. * - Show "Press button (or M108) to resume"
  355. *
  356. * For Filament Change:
  357. * - Show "Insert filament and press button to continue"
  358. *
  359. * - Wait for a click before returning
  360. * - Heaters can time out and must reheat before continuing
  361. *
  362. * Used by M125 and M600
  363. */
  364. void show_continue_prompt(const bool is_reload) {
  365. TERN_(HAS_LCD_MENU, lcd_pause_show_message(is_reload ? PAUSE_MESSAGE_INSERT : PAUSE_MESSAGE_WAITING));
  366. SERIAL_ECHO_START();
  367. serialprintPGM(is_reload ? PSTR(_PMSG(STR_FILAMENT_CHANGE_INSERT) "\n") : PSTR(_PMSG(STR_FILAMENT_CHANGE_WAIT) "\n"));
  368. }
  369. void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep_count/*=0*/ DXC_ARGS) {
  370. bool nozzle_timed_out = false;
  371. show_continue_prompt(is_reload);
  372. #if HAS_BUZZER
  373. filament_change_beep(max_beep_count, true);
  374. #else
  375. UNUSED(max_beep_count);
  376. #endif
  377. // Start the heater idle timers
  378. const millis_t nozzle_timeout = SEC_TO_MS(PAUSE_PARK_NOZZLE_TIMEOUT);
  379. HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
  380. #if ENABLED(DUAL_X_CARRIAGE)
  381. const int8_t saved_ext = active_extruder;
  382. const bool saved_ext_dup_mode = extruder_duplication_enabled;
  383. active_extruder = DXC_ext;
  384. extruder_duplication_enabled = false;
  385. #endif
  386. // Wait for filament insert by user and press button
  387. KEEPALIVE_STATE(PAUSED_FOR_USER);
  388. TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, GET_TEXT(MSG_NOZZLE_PARKED), CONTINUE_STR));
  389. TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(GET_TEXT(MSG_NOZZLE_PARKED)));
  390. wait_for_user = true; // LCD click or M108 will clear this
  391. while (wait_for_user) {
  392. TERN_(HAS_BUZZER, filament_change_beep(max_beep_count));
  393. // If the nozzle has timed out...
  394. if (!nozzle_timed_out)
  395. HOTEND_LOOP() nozzle_timed_out |= thermalManager.hotend_idle[e].timed_out;
  396. // Wait for the user to press the button to re-heat the nozzle, then
  397. // re-heat the nozzle, re-show the continue prompt, restart idle timers, start over
  398. if (nozzle_timed_out) {
  399. TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_HEAT));
  400. SERIAL_ECHO_MSG(_PMSG(STR_FILAMENT_CHANGE_HEAT));
  401. TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, GET_TEXT(MSG_HEATER_TIMEOUT), GET_TEXT(MSG_REHEAT)));
  402. TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(GET_TEXT(MSG_HEATER_TIMEOUT)));
  403. wait_for_user_response(0, true); // Wait for LCD click or M108
  404. TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_INFO, GET_TEXT(MSG_REHEATING)));
  405. TERN_(EXTENSIBLE_UI, ExtUI::onStatusChanged_P(GET_TEXT(MSG_REHEATING)));
  406. // Re-enable the heaters if they timed out
  407. HOTEND_LOOP() thermalManager.reset_hotend_idle_timer(e);
  408. // Wait for the heaters to reach the target temperatures
  409. ensure_safe_temperature();
  410. // Show the prompt to continue
  411. show_continue_prompt(is_reload);
  412. // Start the heater idle timers
  413. const millis_t nozzle_timeout = SEC_TO_MS(PAUSE_PARK_NOZZLE_TIMEOUT);
  414. HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
  415. TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Reheat Done"), CONTINUE_STR));
  416. TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("Reheat finished.")));
  417. wait_for_user = true;
  418. nozzle_timed_out = false;
  419. TERN_(HAS_BUZZER, filament_change_beep(max_beep_count, true));
  420. }
  421. idle_no_sleep();
  422. }
  423. #if ENABLED(DUAL_X_CARRIAGE)
  424. active_extruder = saved_ext;
  425. extruder_duplication_enabled = saved_ext_dup_mode;
  426. stepper.set_directions();
  427. #endif
  428. }
  429. /**
  430. * Resume or Start print procedure
  431. *
  432. * - If not paused, do nothing and return
  433. * - Reset heater idle timers
  434. * - Load filament if specified, but only if:
  435. * - a nozzle timed out, or
  436. * - the nozzle is already heated.
  437. * - Display "wait for print to resume"
  438. * - Retract to prevent oozing
  439. * - Move the nozzle back to resume_position
  440. * - Unretract
  441. * - Re-prime the nozzle...
  442. * - FWRETRACT: Recover/prime from the prior G10.
  443. * - !FWRETRACT: Retract by resume_position.e, if negative.
  444. * Not sure how this logic comes into use.
  445. * - Sync the planner E to resume_position.e
  446. * - Send host action for resume, if configured
  447. * - Resume the current SD print job, if any
  448. */
  449. void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_length/*=0*/, const float &purge_length/*=ADVANCED_PAUSE_PURGE_LENGTH*/, const int8_t max_beep_count/*=0*/ DXC_ARGS) {
  450. /*
  451. SERIAL_ECHOLNPAIR(
  452. "start of resume_print()\ndual_x_carriage_mode:", dual_x_carriage_mode,
  453. "\nextruder_duplication_enabled:", extruder_duplication_enabled,
  454. "\nactive_extruder:", active_extruder,
  455. "\n"
  456. );
  457. //*/
  458. if (!did_pause_print) return;
  459. // Re-enable the heaters if they timed out
  460. bool nozzle_timed_out = false;
  461. HOTEND_LOOP() {
  462. nozzle_timed_out |= thermalManager.hotend_idle[e].timed_out;
  463. thermalManager.reset_hotend_idle_timer(e);
  464. }
  465. if (nozzle_timed_out || thermalManager.hotEnoughToExtrude(active_extruder)) // Load the new filament
  466. load_filament(slow_load_length, fast_load_length, purge_length, max_beep_count, true, nozzle_timed_out, PAUSE_MODE_SAME DXC_PASS);
  467. TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_RESUME));
  468. // Retract to prevent oozing
  469. unscaled_e_move(-(PAUSE_PARK_RETRACT_LENGTH), feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE));
  470. // Move XY to starting position, then Z
  471. do_blocking_move_to_xy(resume_position, feedRate_t(NOZZLE_PARK_XY_FEEDRATE));
  472. // Move Z_AXIS to saved position
  473. do_blocking_move_to_z(resume_position.z, feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  474. // Unretract
  475. unscaled_e_move(PAUSE_PARK_RETRACT_LENGTH, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE));
  476. // Intelligent resuming
  477. #if ENABLED(FWRETRACT)
  478. // If retracted before goto pause
  479. if (fwretract.retracted[active_extruder])
  480. unscaled_e_move(-fwretract.settings.retract_length, fwretract.settings.retract_feedrate_mm_s);
  481. #endif
  482. // If resume_position is negative
  483. if (resume_position.e < 0) unscaled_e_move(resume_position.e, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE));
  484. #if ADVANCED_PAUSE_RESUME_PRIME != 0
  485. unscaled_e_move(ADVANCED_PAUSE_RESUME_PRIME, feedRate_t(ADVANCED_PAUSE_PURGE_FEEDRATE));
  486. #endif
  487. // Now all extrusion positions are resumed and ready to be confirmed
  488. // Set extruder to saved position
  489. planner.set_e_position_mm((destination.e = current_position.e = resume_position.e));
  490. TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_STATUS));
  491. #ifdef ACTION_ON_RESUMED
  492. host_action_resumed();
  493. #elif defined(ACTION_ON_RESUME)
  494. host_action_resume();
  495. #endif
  496. --did_pause_print;
  497. TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("Resuming"), DISMISS_STR));
  498. #if ENABLED(SDSUPPORT)
  499. if (did_pause_print) { card.startFileprint(); --did_pause_print; }
  500. #endif
  501. #if ENABLED(ADVANCED_PAUSE_FANS_PAUSE) && HAS_FAN
  502. thermalManager.set_fans_paused(false);
  503. #endif
  504. TERN_(HAS_FILAMENT_SENSOR, runout.reset());
  505. // Resume the print job timer if it was running
  506. if (print_job_timer.isPaused()) print_job_timer.start();
  507. TERN_(HAS_DISPLAY, ui.reset_status());
  508. TERN_(HAS_LCD_MENU, ui.return_to_status());
  509. }
  510. #endif // ADVANCED_PAUSE_FEATURE