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

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