2017-09-06 11:28:31 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-09-16 07:13:07 +00:00
|
|
|
* feature/pause.cpp - Pause feature support functions
|
|
|
|
* This may be combined with related G-codes if features are consolidated.
|
2017-09-06 11:28:31 +00:00
|
|
|
*/
|
|
|
|
|
2017-09-16 07:13:07 +00:00
|
|
|
#include "../inc/MarlinConfig.h"
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2017-09-16 07:13:07 +00:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE) || ENABLED(PARK_HEAD_ON_PAUSE)
|
|
|
|
|
|
|
|
#include "../Marlin.h"
|
|
|
|
#include "../gcode/gcode.h"
|
|
|
|
#include "../module/motion.h"
|
|
|
|
#include "../module/planner.h"
|
|
|
|
#include "../module/stepper.h"
|
|
|
|
#include "../module/printcounter.h"
|
|
|
|
#include "../module/temperature.h"
|
|
|
|
|
2017-10-10 07:35:20 +00:00
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
|
|
|
|
#include "../feature/runout.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-16 07:13:07 +00:00
|
|
|
#if ENABLED(ULTIPANEL)
|
|
|
|
#include "../lcd/ultralcd.h"
|
2017-09-06 11:28:31 +00:00
|
|
|
#endif
|
|
|
|
|
2017-09-16 07:13:07 +00:00
|
|
|
#include "../libs/buzzer.h"
|
2017-12-25 07:38:06 +00:00
|
|
|
#include "../libs/nozzle.h"
|
2017-09-16 07:13:07 +00:00
|
|
|
|
|
|
|
// private:
|
|
|
|
|
2017-09-06 11:28:31 +00:00
|
|
|
static float resume_position[XYZE];
|
2017-09-16 07:13:07 +00:00
|
|
|
|
2017-09-06 11:28:31 +00:00
|
|
|
#if ENABLED(SDSUPPORT)
|
2017-09-16 07:13:07 +00:00
|
|
|
#include "../sd/cardreader.h"
|
2017-09-06 11:28:31 +00:00
|
|
|
static bool sd_print_paused = false;
|
|
|
|
#endif
|
|
|
|
|
2017-09-30 21:06:43 +00:00
|
|
|
#if HAS_BUZZER
|
|
|
|
static void filament_change_beep(const int8_t max_beep_count, const bool init=false) {
|
|
|
|
static millis_t next_buzz = 0;
|
|
|
|
static int8_t runout_beep = 0;
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2017-09-30 21:06:43 +00:00
|
|
|
if (init) next_buzz = runout_beep = 0;
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2017-09-30 21:06:43 +00:00
|
|
|
const millis_t ms = millis();
|
|
|
|
if (ELAPSED(ms, next_buzz)) {
|
|
|
|
if (max_beep_count < 0 || runout_beep < max_beep_count + 5) { // Only beep as long as we're supposed to
|
|
|
|
next_buzz = ms + ((max_beep_count < 0 || runout_beep < max_beep_count) ? 2500 : 400);
|
|
|
|
BUZZ(300, 2000);
|
|
|
|
runout_beep++;
|
|
|
|
}
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-30 21:06:43 +00:00
|
|
|
#endif
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
static void ensure_safe_temperature() {
|
|
|
|
bool heaters_heating = true;
|
|
|
|
|
|
|
|
wait_for_heatup = true; // M108 will clear this
|
|
|
|
while (wait_for_heatup && heaters_heating) {
|
|
|
|
idle();
|
|
|
|
heaters_heating = false;
|
|
|
|
HOTEND_LOOP() {
|
|
|
|
if (thermalManager.degTargetHotend(e) && abs(thermalManager.degHotend(e) - thermalManager.degTargetHotend(e)) > TEMP_HYSTERESIS) {
|
|
|
|
heaters_heating = true;
|
|
|
|
#if ENABLED(ULTIPANEL)
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 14:34:16 +00:00
|
|
|
void do_pause_e_move(const float &length, const float fr) {
|
2017-11-10 08:26:49 +00:00
|
|
|
current_position[E_AXIS] += length / planner.e_factor[active_extruder];
|
2017-10-23 14:34:16 +00:00
|
|
|
set_destination_from_current();
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
planner.buffer_line_kinematic(destination, fr, active_extruder);
|
|
|
|
#else
|
2017-11-09 04:13:33 +00:00
|
|
|
buffer_line_to_destination(fr);
|
2017-10-23 14:34:16 +00:00
|
|
|
#endif
|
|
|
|
stepper.synchronize();
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:13:07 +00:00
|
|
|
// public:
|
|
|
|
|
|
|
|
bool move_away_flag = false;
|
|
|
|
|
2017-12-25 07:38:06 +00:00
|
|
|
bool pause_print(const float &retract, const point_t &park_point, const float &unload_length/*=0*/,
|
|
|
|
const int8_t max_beep_count/*=0*/, const bool show_lcd/*=false*/
|
2017-09-06 11:28:31 +00:00
|
|
|
) {
|
|
|
|
if (move_away_flag) return false; // already paused
|
|
|
|
|
2017-12-25 07:36:42 +00:00
|
|
|
#ifdef ACTION_ON_PAUSE
|
|
|
|
SERIAL_ECHOLNPGM("//action:" ACTION_ON_PAUSE);
|
|
|
|
#endif
|
|
|
|
|
2017-12-25 07:38:06 +00:00
|
|
|
if (!DEBUGGING(DRYRUN) && unload_length != 0) {
|
2017-09-06 11:28:31 +00:00
|
|
|
#if ENABLED(PREVENT_COLD_EXTRUSION)
|
|
|
|
if (!thermalManager.allow_cold_extrude &&
|
|
|
|
thermalManager.degTargetHotend(active_extruder) < thermalManager.extrude_min_temp) {
|
|
|
|
SERIAL_ERROR_START();
|
|
|
|
SERIAL_ERRORLNPGM(MSG_TOO_COLD_FOR_M600);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ensure_safe_temperature(); // wait for extruder to heat up before unloading
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indicate that the printer is paused
|
|
|
|
move_away_flag = true;
|
|
|
|
|
|
|
|
// Pause the print job and timer
|
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
if (IS_SD_PRINTING) {
|
|
|
|
card.pauseSDPrint();
|
|
|
|
sd_print_paused = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
print_job_timer.pause();
|
|
|
|
|
|
|
|
// Show initial message and wait for synchronize steppers
|
|
|
|
if (show_lcd) {
|
|
|
|
#if ENABLED(ULTIPANEL)
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INIT);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
stepper.synchronize();
|
2017-10-23 14:34:16 +00:00
|
|
|
COPY(resume_position, current_position); // Save current position for later
|
|
|
|
|
|
|
|
// Initial retract before move to filament change position
|
2017-12-25 07:38:06 +00:00
|
|
|
if (retract && !thermalManager.tooColdToExtrude(active_extruder))
|
|
|
|
do_pause_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2017-12-25 07:38:06 +00:00
|
|
|
// Park the nozzle by moving up by z_lift and then moving to (x_pos, y_pos)
|
|
|
|
Nozzle::park(2, park_point);
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
if (unload_length != 0) {
|
|
|
|
if (show_lcd) {
|
|
|
|
#if ENABLED(ULTIPANEL)
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_UNLOAD);
|
|
|
|
idle();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unload filament
|
2017-10-23 14:34:16 +00:00
|
|
|
do_pause_e_move(unload_length, FILAMENT_CHANGE_UNLOAD_FEEDRATE);
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (show_lcd) {
|
|
|
|
#if ENABLED(ULTIPANEL)
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAS_BUZZER
|
|
|
|
filament_change_beep(max_beep_count, true);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
idle();
|
|
|
|
|
|
|
|
// Disable extruders steppers for manual filament changing (only on boards that have separate ENABLE_PINS)
|
|
|
|
#if E0_ENABLE_PIN != X_ENABLE_PIN && E1_ENABLE_PIN != Y_ENABLE_PIN
|
|
|
|
disable_e_steppers();
|
|
|
|
safe_delay(100);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Start the heater idle timers
|
|
|
|
const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
|
|
|
|
|
|
|
|
HOTEND_LOOP()
|
|
|
|
thermalManager.start_heater_idle_timer(e, nozzle_timeout);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:13:07 +00:00
|
|
|
void wait_for_filament_reload(const int8_t max_beep_count/*=0*/) {
|
2017-09-06 11:28:31 +00:00
|
|
|
bool nozzle_timed_out = false;
|
|
|
|
|
|
|
|
// Wait for filament insert by user and press button
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
wait_for_user = true; // LCD click or M108 will clear this
|
|
|
|
while (wait_for_user) {
|
|
|
|
#if HAS_BUZZER
|
|
|
|
filament_change_beep(max_beep_count);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If the nozzle has timed out, wait for the user to press the button to re-heat the nozzle, then
|
|
|
|
// re-heat the nozzle, re-show the insert screen, restart the idle timers, and start over
|
|
|
|
if (!nozzle_timed_out)
|
|
|
|
HOTEND_LOOP()
|
|
|
|
nozzle_timed_out |= thermalManager.is_heater_idle(e);
|
|
|
|
|
|
|
|
if (nozzle_timed_out) {
|
|
|
|
#if ENABLED(ULTIPANEL)
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Wait for LCD click or M108
|
|
|
|
while (wait_for_user) idle(true);
|
|
|
|
|
|
|
|
// Re-enable the heaters if they timed out
|
|
|
|
HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e);
|
|
|
|
|
|
|
|
// Wait for the heaters to reach the target temperatures
|
|
|
|
ensure_safe_temperature();
|
|
|
|
|
|
|
|
#if ENABLED(ULTIPANEL)
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Start the heater idle timers
|
|
|
|
const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
|
|
|
|
|
|
|
|
HOTEND_LOOP()
|
|
|
|
thermalManager.start_heater_idle_timer(e, nozzle_timeout);
|
|
|
|
|
|
|
|
wait_for_user = true; /* Wait for user to load filament */
|
|
|
|
nozzle_timed_out = false;
|
|
|
|
|
|
|
|
#if HAS_BUZZER
|
|
|
|
filament_change_beep(max_beep_count, true);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
idle(true);
|
|
|
|
}
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:13:07 +00:00
|
|
|
void resume_print(const float &load_length/*=0*/, const float &initial_extrude_length/*=0*/, const int8_t max_beep_count/*=0*/) {
|
2017-09-06 11:28:31 +00:00
|
|
|
bool nozzle_timed_out = false;
|
|
|
|
|
|
|
|
if (!move_away_flag) return;
|
|
|
|
|
|
|
|
// Re-enable the heaters if they timed out
|
|
|
|
HOTEND_LOOP() {
|
|
|
|
nozzle_timed_out |= thermalManager.is_heater_idle(e);
|
|
|
|
thermalManager.reset_heater_idle_timer(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nozzle_timed_out) ensure_safe_temperature();
|
|
|
|
|
|
|
|
#if HAS_BUZZER
|
|
|
|
filament_change_beep(max_beep_count, true);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (load_length != 0) {
|
|
|
|
#if ENABLED(ULTIPANEL)
|
|
|
|
// Show "insert filament"
|
|
|
|
if (nozzle_timed_out)
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
wait_for_user = true; // LCD click or M108 will clear this
|
|
|
|
while (wait_for_user && nozzle_timed_out) {
|
|
|
|
#if HAS_BUZZER
|
|
|
|
filament_change_beep(max_beep_count);
|
|
|
|
#endif
|
|
|
|
idle(true);
|
|
|
|
}
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
|
|
|
|
#if ENABLED(ULTIPANEL)
|
|
|
|
// Show "load" message
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_LOAD);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Load filament
|
2017-10-23 14:34:16 +00:00
|
|
|
do_pause_e_move(load_length, FILAMENT_CHANGE_LOAD_FEEDRATE);
|
2017-09-06 11:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(ULTIPANEL) && ADVANCED_PAUSE_EXTRUDE_LENGTH > 0
|
|
|
|
|
2017-12-25 07:38:06 +00:00
|
|
|
if (!thermalManager.tooColdToExtrude(active_extruder)) {
|
|
|
|
float extrude_length = initial_extrude_length;
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2017-12-25 07:38:06 +00:00
|
|
|
do {
|
|
|
|
if (extrude_length > 0) {
|
|
|
|
// "Wait for filament extrude"
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_EXTRUDE);
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2017-12-25 07:38:06 +00:00
|
|
|
// Extrude filament to get into hotend
|
|
|
|
do_pause_e_move(extrude_length, ADVANCED_PAUSE_EXTRUDE_FEEDRATE);
|
|
|
|
}
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2017-12-25 07:38:06 +00:00
|
|
|
// Show "Extrude More" / "Resume" menu and wait for reply
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
wait_for_user = false;
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_OPTION);
|
|
|
|
while (advanced_pause_menu_response == ADVANCED_PAUSE_RESPONSE_WAIT_FOR) idle(true);
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2017-12-25 07:38:06 +00:00
|
|
|
extrude_length = ADVANCED_PAUSE_EXTRUDE_LENGTH;
|
2017-09-06 11:28:31 +00:00
|
|
|
|
2017-12-25 07:38:06 +00:00
|
|
|
// Keep looping if "Extrude More" was selected
|
|
|
|
} while (advanced_pause_menu_response == ADVANCED_PAUSE_RESPONSE_EXTRUDE_MORE);
|
|
|
|
}
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(ULTIPANEL)
|
|
|
|
// "Wait for print to resume"
|
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_RESUME);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Set extruder to saved position
|
2017-10-23 14:34:16 +00:00
|
|
|
planner.set_e_position_mm((current_position[E_AXIS] = resume_position[E_AXIS]));
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
// Move XY to starting position, then Z
|
2017-12-25 07:38:06 +00:00
|
|
|
do_blocking_move_to_xy(resume_position[X_AXIS], resume_position[Y_AXIS], NOZZLE_PARK_XY_FEEDRATE);
|
|
|
|
do_blocking_move_to_z(resume_position[Z_AXIS], NOZZLE_PARK_Z_FEEDRATE);
|
2017-09-06 11:28:31 +00:00
|
|
|
|
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
|
|
|
|
filament_ran_out = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(ULTIPANEL)
|
2017-10-23 14:34:16 +00:00
|
|
|
// Show pause status screen
|
2017-09-06 11:28:31 +00:00
|
|
|
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_STATUS);
|
|
|
|
#endif
|
|
|
|
|
2017-12-25 07:36:42 +00:00
|
|
|
#ifdef ACTION_ON_RESUME
|
|
|
|
SERIAL_ECHOLNPGM("//action:" ACTION_ON_RESUME);
|
|
|
|
#endif
|
|
|
|
|
2017-09-06 11:28:31 +00:00
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
if (sd_print_paused) {
|
|
|
|
card.startFileprint();
|
|
|
|
sd_print_paused = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
move_away_flag = false;
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:13:07 +00:00
|
|
|
#endif // ADVANCED_PAUSE_FEATURE || PARK_HEAD_ON_PAUSE
|