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.

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