2018-04-22 02:41:26 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-04-22 02:41:26 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2018-04-22 02:41:26 +02:00
|
|
|
*
|
|
|
|
* 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
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-04-22 02:41:26 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-08-09 01:21:44 +02:00
|
|
|
* feature/powerloss.cpp - Resume an SD print after power-loss
|
2018-04-22 02:41:26 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfigPre.h"
|
|
|
|
|
|
|
|
#if ENABLED(POWER_LOSS_RECOVERY)
|
|
|
|
|
2020-03-13 22:29:29 +01:00
|
|
|
#include "powerloss.h"
|
2018-11-17 03:47:07 +01:00
|
|
|
#include "../core/macros.h"
|
2018-04-22 02:41:26 +02:00
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
bool PrintJobRecovery::enabled; // Initialized by settings.load()
|
|
|
|
|
|
|
|
SdFile PrintJobRecovery::file;
|
|
|
|
job_recovery_info_t PrintJobRecovery::info;
|
2019-08-02 12:21:44 +02:00
|
|
|
const char PrintJobRecovery::filename[5] = "/PLR";
|
2019-09-11 01:52:41 +02:00
|
|
|
uint8_t PrintJobRecovery::queue_index_r;
|
|
|
|
uint32_t PrintJobRecovery::cmd_sdpos, // = 0
|
|
|
|
PrintJobRecovery::sdpos[BUFSIZE];
|
2018-11-17 03:47:07 +01:00
|
|
|
|
2020-06-16 08:45:27 +02:00
|
|
|
#if ENABLED(DWIN_CREALITY_LCD)
|
|
|
|
bool PrintJobRecovery::dwin_flag; // = false
|
|
|
|
#endif
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
#include "../sd/cardreader.h"
|
2018-04-22 02:41:26 +02:00
|
|
|
#include "../lcd/ultralcd.h"
|
|
|
|
#include "../gcode/queue.h"
|
2018-11-17 03:47:07 +01:00
|
|
|
#include "../gcode/gcode.h"
|
2018-09-11 06:09:26 +02:00
|
|
|
#include "../module/motion.h"
|
2018-04-22 02:41:26 +02:00
|
|
|
#include "../module/planner.h"
|
|
|
|
#include "../module/printcounter.h"
|
|
|
|
#include "../module/temperature.h"
|
|
|
|
#include "../core/serial.h"
|
|
|
|
|
2018-09-17 04:24:15 +02:00
|
|
|
#if ENABLED(FWRETRACT)
|
|
|
|
#include "fwretract.h"
|
|
|
|
#endif
|
|
|
|
|
2019-04-06 03:02:46 +02:00
|
|
|
#define DEBUG_OUT ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
|
|
|
#include "../core/debug_out.h"
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
PrintJobRecovery recovery;
|
2018-07-03 06:21:28 +02:00
|
|
|
|
2019-05-08 03:38:40 +02:00
|
|
|
#ifndef POWER_LOSS_PURGE_LEN
|
|
|
|
#define POWER_LOSS_PURGE_LEN 0
|
|
|
|
#endif
|
2020-07-15 08:14:03 +02:00
|
|
|
#ifndef POWER_LOSS_ZRAISE
|
|
|
|
#define POWER_LOSS_ZRAISE 2 // Move on loss with backup power, or on resume without it
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DISABLED(BACKUP_POWER_SUPPLY)
|
|
|
|
#undef POWER_LOSS_RETRACT_LEN // No retract at outage without backup power
|
|
|
|
#endif
|
2019-05-08 03:38:40 +02:00
|
|
|
#ifndef POWER_LOSS_RETRACT_LEN
|
|
|
|
#define POWER_LOSS_RETRACT_LEN 0
|
|
|
|
#endif
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
/**
|
|
|
|
* Clear the recovery info
|
|
|
|
*/
|
|
|
|
void PrintJobRecovery::init() { memset(&info, 0, sizeof(info)); }
|
2018-07-02 23:42:13 +02:00
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
/**
|
|
|
|
* Enable or disable then call changed()
|
|
|
|
*/
|
|
|
|
void PrintJobRecovery::enable(const bool onoff) {
|
|
|
|
enabled = onoff;
|
|
|
|
changed();
|
|
|
|
}
|
2018-07-02 23:42:13 +02:00
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
/**
|
|
|
|
* The enabled state was changed:
|
|
|
|
* - Enabled: Purge the job recovery file
|
|
|
|
* - Disabled: Write the job recovery file
|
|
|
|
*/
|
|
|
|
void PrintJobRecovery::changed() {
|
|
|
|
if (!enabled)
|
|
|
|
purge();
|
|
|
|
else if (IS_SD_PRINTING())
|
|
|
|
save(true);
|
|
|
|
}
|
2018-04-22 02:41:26 +02:00
|
|
|
|
|
|
|
/**
|
2018-07-03 06:21:28 +02:00
|
|
|
* Check for Print Job Recovery during setup()
|
|
|
|
*
|
2018-11-17 03:47:07 +01:00
|
|
|
* If a saved state exists send 'M1000 S' to initiate job recovery.
|
2018-04-22 02:41:26 +02:00
|
|
|
*/
|
2018-11-17 03:47:07 +01:00
|
|
|
void PrintJobRecovery::check() {
|
2020-04-19 08:11:56 +02:00
|
|
|
//if (!card.isMounted()) card.mount();
|
2020-03-10 01:00:11 +01:00
|
|
|
if (card.isMounted()) {
|
|
|
|
load();
|
2020-04-19 08:11:56 +02:00
|
|
|
if (!valid()) return cancel();
|
2020-03-10 01:00:11 +01:00
|
|
|
queue.inject_P(PSTR("M1000 S"));
|
2020-06-16 08:45:27 +02:00
|
|
|
TERN_(DWIN_CREALITY_LCD, dwin_flag = true);
|
2018-11-17 03:47:07 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-03 06:21:28 +02:00
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
/**
|
|
|
|
* Delete the recovery file and clear the recovery data
|
|
|
|
*/
|
|
|
|
void PrintJobRecovery::purge() {
|
|
|
|
init();
|
|
|
|
card.removeJobRecoveryFile();
|
|
|
|
}
|
2018-04-22 02:41:26 +02:00
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
/**
|
|
|
|
* Load the recovery data, if it exists
|
|
|
|
*/
|
|
|
|
void PrintJobRecovery::load() {
|
|
|
|
if (exists()) {
|
|
|
|
open(true);
|
|
|
|
(void)file.read(&info, sizeof(info));
|
|
|
|
close();
|
2018-04-22 02:41:26 +02:00
|
|
|
}
|
2019-04-06 03:02:46 +02:00
|
|
|
debug(PSTR("Load"));
|
2018-04-22 02:41:26 +02:00
|
|
|
}
|
|
|
|
|
2019-09-11 01:52:41 +02:00
|
|
|
/**
|
|
|
|
* Set info fields that won't change
|
|
|
|
*/
|
|
|
|
void PrintJobRecovery::prepare() {
|
|
|
|
card.getAbsFilename(info.sd_filename); // SD filename
|
|
|
|
cmd_sdpos = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-22 02:41:26 +02:00
|
|
|
/**
|
2018-07-02 23:42:13 +02:00
|
|
|
* Save the current machine state to the power-loss recovery file
|
2018-04-22 02:41:26 +02:00
|
|
|
*/
|
2020-07-15 08:14:03 +02:00
|
|
|
void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/) {
|
2018-11-17 03:47:07 +01:00
|
|
|
|
2018-04-22 02:41:26 +02:00
|
|
|
#if SAVE_INFO_INTERVAL_MS > 0
|
2018-11-17 03:47:07 +01:00
|
|
|
static millis_t next_save_ms; // = 0
|
2018-04-22 02:41:26 +02:00
|
|
|
millis_t ms = millis();
|
|
|
|
#endif
|
2018-11-17 03:47:07 +01:00
|
|
|
|
2019-05-03 05:29:05 +02:00
|
|
|
#ifndef POWER_LOSS_MIN_Z_CHANGE
|
|
|
|
#define POWER_LOSS_MIN_Z_CHANGE 0.05 // Vase-mode-friendly out of the box
|
|
|
|
#endif
|
|
|
|
|
2019-04-02 00:52:45 +02:00
|
|
|
// Did Z change since the last call?
|
2018-11-17 03:47:07 +01:00
|
|
|
if (force
|
|
|
|
#if DISABLED(SAVE_EACH_CMD_MODE) // Always save state when enabled
|
|
|
|
#if SAVE_INFO_INTERVAL_MS > 0 // Save if interval is elapsed
|
|
|
|
|| ELAPSED(ms, next_save_ms)
|
2018-07-19 02:50:42 +02:00
|
|
|
#endif
|
2019-05-03 05:29:05 +02:00
|
|
|
// Save if Z is above the last-saved position by some minimum height
|
2019-09-29 11:25:39 +02:00
|
|
|
|| current_position.z > info.current_position.z + POWER_LOSS_MIN_Z_CHANGE
|
2018-04-22 02:41:26 +02:00
|
|
|
#endif
|
|
|
|
) {
|
2018-11-17 03:47:07 +01:00
|
|
|
|
2018-04-22 02:41:26 +02:00
|
|
|
#if SAVE_INFO_INTERVAL_MS > 0
|
|
|
|
next_save_ms = ms + SAVE_INFO_INTERVAL_MS;
|
|
|
|
#endif
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
// Set Head and Foot to matching non-zero values
|
|
|
|
if (!++info.valid_head) ++info.valid_head; // non-zero in sequence
|
|
|
|
//if (!IS_SD_PRINTING()) info.valid_head = 0;
|
|
|
|
info.valid_foot = info.valid_head;
|
2018-04-22 02:41:26 +02:00
|
|
|
|
|
|
|
// Machine state
|
2019-09-29 11:25:39 +02:00
|
|
|
info.current_position = current_position;
|
2020-07-15 08:14:03 +02:00
|
|
|
info.zraise = zraise;
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset);
|
|
|
|
TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift);
|
2018-11-17 03:47:07 +01:00
|
|
|
info.feedrate = uint16_t(feedrate_mm_s * 60.0f);
|
2018-07-03 06:21:28 +02:00
|
|
|
|
2019-05-18 01:47:15 +02:00
|
|
|
#if EXTRUDERS > 1
|
|
|
|
info.active_extruder = active_extruder;
|
2018-07-03 06:21:28 +02:00
|
|
|
#endif
|
|
|
|
|
2019-10-31 20:09:37 +01:00
|
|
|
#if DISABLED(NO_VOLUMETRICS)
|
|
|
|
info.volumetric_enabled = parser.volumetric_enabled;
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
for (int8_t e = 0; e < EXTRUDERS; e++) info.filament_size[e] = planner.filament_size[e];
|
|
|
|
#else
|
2020-05-04 23:37:20 +02:00
|
|
|
if (parser.volumetric_enabled) info.filament_size[0] = planner.filament_size[active_extruder];
|
2019-11-02 05:51:25 +01:00
|
|
|
#endif
|
2019-10-31 20:09:37 +01:00
|
|
|
#endif
|
|
|
|
|
2019-09-10 09:20:49 +02:00
|
|
|
#if EXTRUDERS
|
|
|
|
HOTEND_LOOP() info.target_temperature[e] = thermalManager.temp_hotend[e].target;
|
|
|
|
#endif
|
2018-07-02 23:42:13 +02:00
|
|
|
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(HAS_HEATED_BED, info.target_temperature_bed = thermalManager.temp_bed.target);
|
2018-07-02 23:42:13 +02:00
|
|
|
|
2020-04-27 11:41:18 +02:00
|
|
|
#if HAS_FAN
|
2019-01-12 07:41:48 +01:00
|
|
|
COPY(info.fan_speed, thermalManager.fan_speed);
|
2018-07-02 23:42:13 +02:00
|
|
|
#endif
|
2018-04-22 02:41:26 +02:00
|
|
|
|
|
|
|
#if HAS_LEVELING
|
2018-11-17 03:47:07 +01:00
|
|
|
info.leveling = planner.leveling_active;
|
2020-04-22 23:35:03 +02:00
|
|
|
info.fade = TERN0(ENABLE_LEVELING_FADE_HEIGHT, planner.z_fade_height);
|
2018-04-22 02:41:26 +02:00
|
|
|
#endif
|
|
|
|
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(GRADIENT_MIX, memcpy(&info.gradient, &mixer.gradient, sizeof(info.gradient)));
|
2019-02-10 11:54:23 +01:00
|
|
|
|
2018-09-17 04:24:15 +02:00
|
|
|
#if ENABLED(FWRETRACT)
|
2018-11-17 03:47:07 +01:00
|
|
|
COPY(info.retract, fwretract.current_retract);
|
|
|
|
info.retract_hop = fwretract.current_hop;
|
2018-09-17 04:24:15 +02:00
|
|
|
#endif
|
|
|
|
|
2019-09-11 08:29:33 +02:00
|
|
|
// Relative axis modes
|
|
|
|
info.axis_relative = gcode.axis_relative;
|
2019-03-29 19:40:42 +01:00
|
|
|
|
2018-04-22 02:41:26 +02:00
|
|
|
// Elapsed print job time
|
2018-11-17 03:47:07 +01:00
|
|
|
info.print_job_elapsed = print_job_timer.duration();
|
2018-04-22 02:41:26 +02:00
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
write();
|
|
|
|
}
|
|
|
|
}
|
2018-04-22 02:41:26 +02:00
|
|
|
|
2019-09-11 01:52:41 +02:00
|
|
|
#if PIN_EXISTS(POWER_LOSS)
|
2019-11-21 00:40:21 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY)
|
|
|
|
|
|
|
|
void PrintJobRecovery::retract_and_lift(const float &zraise) {
|
|
|
|
#if POWER_LOSS_RETRACT_LEN || POWER_LOSS_ZRAISE
|
|
|
|
|
|
|
|
gcode.set_relative_mode(true); // Use relative coordinates
|
|
|
|
|
|
|
|
#if POWER_LOSS_RETRACT_LEN
|
|
|
|
// Retract filament now
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G1 F3000 E-" STRINGIFY(POWER_LOSS_RETRACT_LEN)));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if POWER_LOSS_ZRAISE
|
|
|
|
// Raise the Z axis now
|
|
|
|
if (zraise) {
|
|
|
|
char cmd[20], str_1[16];
|
|
|
|
sprintf_P(cmd, PSTR("G0 Z%s"), dtostrf(zraise, 1, 3, str_1));
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
UNUSED(zraise);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//gcode.axis_relative = info.axis_relative;
|
|
|
|
planner.synchronize();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An outage was detected by a sensor pin.
|
|
|
|
* - If not SD printing, let the machine turn off on its own with no "KILL" screen
|
|
|
|
* - Disable all heaters first to save energy
|
|
|
|
* - Save the recovery data for the current instant
|
|
|
|
* - If backup power is available Retract E and Raise Z
|
|
|
|
* - Go to the KILL screen
|
|
|
|
*/
|
2019-09-11 01:52:41 +02:00
|
|
|
void PrintJobRecovery::_outage() {
|
2019-11-21 00:40:21 +01:00
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY)
|
|
|
|
static bool lock = false;
|
2020-07-15 08:14:03 +02:00
|
|
|
if (lock) return; // No re-entrance from idle() during retract_and_lift()
|
2019-11-21 00:40:21 +01:00
|
|
|
lock = true;
|
|
|
|
#endif
|
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
#if POWER_LOSS_ZRAISE
|
|
|
|
// Get the limited Z-raise to do now or on resume
|
|
|
|
const float zraise = _MAX(0, _MIN(current_position.z + POWER_LOSS_ZRAISE, Z_MAX_POS - 1) - current_position.z);
|
|
|
|
#else
|
|
|
|
constexpr float zraise = 0;
|
|
|
|
#endif
|
2019-11-21 00:40:21 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
// Save, including the limited Z raise
|
|
|
|
if (IS_SD_PRINTING()) save(true, zraise);
|
2019-11-21 00:40:21 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
// Disable all heaters to reduce power loss
|
|
|
|
thermalManager.disable_all_heaters();
|
|
|
|
|
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY)
|
|
|
|
// Do a hard-stop of the steppers (with possibly a loud thud)
|
2019-11-21 00:40:21 +01:00
|
|
|
quickstop_stepper();
|
2020-07-15 08:14:03 +02:00
|
|
|
// With backup power a retract and raise can be done now
|
|
|
|
retract_and_lift(zraise);
|
|
|
|
#endif
|
2019-11-21 00:40:21 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
kill(GET_TEXT(MSG_OUTAGE_RECOVERY));
|
|
|
|
}
|
2019-11-21 00:40:21 +01:00
|
|
|
|
2019-09-11 01:52:41 +02:00
|
|
|
#endif
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
/**
|
|
|
|
* Save the recovery info the recovery file
|
|
|
|
*/
|
|
|
|
void PrintJobRecovery::write() {
|
2018-07-19 02:50:42 +02:00
|
|
|
|
2019-04-06 03:02:46 +02:00
|
|
|
debug(PSTR("Write"));
|
2018-11-17 03:47:07 +01:00
|
|
|
|
|
|
|
open(false);
|
|
|
|
file.seekSet(0);
|
|
|
|
const int16_t ret = file.write(&info, sizeof(info));
|
2019-04-06 03:02:46 +02:00
|
|
|
if (ret == -1) DEBUG_ECHOLNPGM("Power-loss file write failed.");
|
2019-05-03 05:29:05 +02:00
|
|
|
if (!file.close()) DEBUG_ECHOLNPGM("Power-loss file close failed.");
|
2018-11-17 03:47:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume the saved print job
|
|
|
|
*/
|
|
|
|
void PrintJobRecovery::resume() {
|
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16];
|
|
|
|
|
2019-09-11 01:52:41 +02:00
|
|
|
const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
#if HAS_LEVELING
|
|
|
|
// Make sure leveling is off before any G92 and G28
|
|
|
|
gcode.process_subcommands_now_P(PSTR("M420 S0 Z0"));
|
|
|
|
#endif
|
|
|
|
|
2019-04-16 07:17:27 +02:00
|
|
|
// Reset E, raise Z, home XY...
|
2020-07-15 08:14:03 +02:00
|
|
|
#if Z_HOME_DIR > 0
|
2019-11-21 00:40:21 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
// If Z homing goes to max, just reset E and home all
|
|
|
|
gcode.process_subcommands_now_P(PSTR(
|
|
|
|
"G92.9 E0\n"
|
|
|
|
"G28R0" TERN_(MARLIN_DEV_MODE, "S")
|
|
|
|
));
|
2019-11-21 00:40:21 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
#else // "G92.9 E0 ..."
|
2019-11-21 00:40:21 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
// Set Z to 0, raise Z by info.zraise, and Home (XY only for Cartesian)
|
|
|
|
// with no raise. (Only do simulated homing in Marlin Dev Mode.)
|
2018-11-17 03:47:07 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
sprintf_P(cmd, PSTR("G92.9 E0 "
|
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY)
|
|
|
|
"Z%s" // Z was already raised at outage
|
|
|
|
#else
|
|
|
|
"Z0\nG1Z%s" // Set Z=0 and Raise Z now
|
|
|
|
#endif
|
|
|
|
),
|
|
|
|
dtostrf(info.zraise, 1, 3, str_1)
|
|
|
|
);
|
|
|
|
gcode.process_subcommands_now(cmd);
|
2018-11-17 03:47:07 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
gcode.process_subcommands_now_P(PSTR(
|
|
|
|
"G28R0" // No raise during G28
|
|
|
|
TERN_(MARLIN_DEV_MODE, "S") // Simulated Homing
|
|
|
|
TERN_(IS_CARTESIAN, "XY") // Don't home Z on Cartesian
|
|
|
|
));
|
2018-11-17 03:47:07 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
// Pretend that all axes are homed
|
2020-08-27 23:38:02 +02:00
|
|
|
set_all_homed();
|
2020-07-15 08:14:03 +02:00
|
|
|
|
2019-10-31 20:09:37 +01:00
|
|
|
// Recover volumetric extrusion state
|
2019-11-02 05:51:25 +01:00
|
|
|
#if DISABLED(NO_VOLUMETRICS)
|
2019-10-31 20:09:37 +01:00
|
|
|
#if EXTRUDERS > 1
|
|
|
|
for (int8_t e = 0; e < EXTRUDERS; e++) {
|
2020-07-15 08:14:03 +02:00
|
|
|
sprintf_P(cmd, PSTR("M200 T%i D%s"), e, dtostrf(info.filament_size[e], 1, 3, str_1));
|
2019-10-31 20:09:37 +01:00
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
}
|
|
|
|
if (!info.volumetric_enabled) {
|
|
|
|
sprintf_P(cmd, PSTR("M200 T%i D0"), info.active_extruder);
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (info.volumetric_enabled) {
|
2020-07-15 08:14:03 +02:00
|
|
|
sprintf_P(cmd, PSTR("M200 D%s"), dtostrf(info.filament_size[0], 1, 3, str_1));
|
2019-10-31 20:09:37 +01:00
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
#if HAS_HEATED_BED
|
|
|
|
const int16_t bt = info.target_temperature_bed;
|
|
|
|
if (bt) {
|
|
|
|
// Restore the bed temperature
|
|
|
|
sprintf_P(cmd, PSTR("M190 S%i"), bt);
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Restore all hotend temperatures
|
2020-04-20 06:56:55 +02:00
|
|
|
#if HAS_HOTEND
|
2019-09-10 09:20:49 +02:00
|
|
|
HOTEND_LOOP() {
|
|
|
|
const int16_t et = info.target_temperature[e];
|
|
|
|
if (et) {
|
2020-04-20 06:56:55 +02:00
|
|
|
#if HAS_MULTI_HOTEND
|
2020-07-15 08:14:03 +02:00
|
|
|
sprintf_P(cmd, PSTR("T%i S"), e);
|
2019-09-10 09:20:49 +02:00
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
#endif
|
|
|
|
sprintf_P(cmd, PSTR("M109 S%i"), et);
|
2018-11-17 03:47:07 +01:00
|
|
|
gcode.process_subcommands_now(cmd);
|
2019-09-10 09:20:49 +02:00
|
|
|
}
|
2018-11-17 03:47:07 +01:00
|
|
|
}
|
2019-09-10 09:20:49 +02:00
|
|
|
#endif
|
2018-11-17 03:47:07 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
// Select the previously active tool (with no_move)
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
sprintf_P(cmd, PSTR("T%i S"), info.active_extruder);
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
#endif
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
// Restore print cooling fan speeds
|
2018-11-28 22:35:18 +01:00
|
|
|
FANS_LOOP(i) {
|
2018-11-17 03:47:07 +01:00
|
|
|
uint8_t f = info.fan_speed[i];
|
|
|
|
if (f) {
|
|
|
|
sprintf_P(cmd, PSTR("M106 P%i S%i"), i, f);
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore retract and hop state
|
|
|
|
#if ENABLED(FWRETRACT)
|
2020-03-14 05:18:16 +01:00
|
|
|
LOOP_L_N(e, EXTRUDERS) {
|
2019-10-22 22:58:07 +02:00
|
|
|
if (info.retract[e] != 0.0) {
|
2018-11-17 03:47:07 +01:00
|
|
|
fwretract.current_retract[e] = info.retract[e];
|
|
|
|
fwretract.retracted[e] = true;
|
2019-10-22 22:58:07 +02:00
|
|
|
}
|
2018-11-17 03:47:07 +01:00
|
|
|
}
|
|
|
|
fwretract.current_hop = info.retract_hop;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_LEVELING
|
|
|
|
// Restore leveling state before 'G92 Z' to ensure
|
|
|
|
// the Z stepper count corresponds to the native Z.
|
|
|
|
if (info.fade || info.leveling) {
|
2019-08-08 08:51:37 +02:00
|
|
|
sprintf_P(cmd, PSTR("M420 S%i Z%s"), int(info.leveling), dtostrf(info.fade, 1, 1, str_1));
|
2018-11-17 03:47:07 +01:00
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-02-10 11:54:23 +01:00
|
|
|
#if ENABLED(GRADIENT_MIX)
|
|
|
|
memcpy(&mixer.gradient, &info.gradient, sizeof(info.gradient));
|
|
|
|
#endif
|
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
// Un-retract if there was a retract at outage
|
|
|
|
#if POWER_LOSS_RETRACT_LEN
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_RETRACT_LEN) " F3000"));
|
2019-04-16 01:53:39 +02:00
|
|
|
#endif
|
2019-05-08 03:38:40 +02:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
// Additional purge if configured
|
|
|
|
#if POWER_LOSS_PURGE_LEN
|
|
|
|
sprintf_P(cmd, PSTR("G1 E%d F200"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
|
2019-04-16 01:53:39 +02:00
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
#endif
|
2018-11-17 03:47:07 +01:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_FEATURE)
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G12"));
|
|
|
|
#endif
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
// Move back to the saved XY
|
2019-08-08 08:51:37 +02:00
|
|
|
sprintf_P(cmd, PSTR("G1 X%s Y%s F3000"),
|
2019-09-29 11:25:39 +02:00
|
|
|
dtostrf(info.current_position.x, 1, 3, str_1),
|
|
|
|
dtostrf(info.current_position.y, 1, 3, str_2)
|
2019-08-08 08:51:37 +02:00
|
|
|
);
|
2018-11-17 03:47:07 +01:00
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
|
|
|
|
// Move back to the saved Z
|
2019-09-29 11:25:39 +02:00
|
|
|
dtostrf(info.current_position.z, 1, 3, str_1);
|
2019-06-08 12:27:59 +02:00
|
|
|
#if Z_HOME_DIR > 0
|
|
|
|
sprintf_P(cmd, PSTR("G1 Z%s F200"), str_1);
|
|
|
|
#else
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G1 Z0 F200"));
|
|
|
|
sprintf_P(cmd, PSTR("G92.9 Z%s"), str_1);
|
|
|
|
#endif
|
2018-11-17 03:47:07 +01:00
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
|
|
|
|
// Restore the feedrate
|
|
|
|
sprintf_P(cmd, PSTR("G1 F%d"), info.feedrate);
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
|
2019-04-16 01:53:39 +02:00
|
|
|
// Restore E position with G92.9
|
2019-09-29 11:25:39 +02:00
|
|
|
sprintf_P(cmd, PSTR("G92.9 E%s"), dtostrf(info.current_position.e, 1, 3, str_1));
|
2019-04-16 01:53:39 +02:00
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
|
2019-09-11 08:29:33 +02:00
|
|
|
// Relative axis modes
|
|
|
|
gcode.axis_relative = info.axis_relative;
|
2019-04-16 01:53:39 +02:00
|
|
|
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset);
|
|
|
|
TERN_(HAS_POSITION_SHIFT, position_shift = info.position_shift);
|
2019-04-16 01:53:39 +02:00
|
|
|
#if HAS_HOME_OFFSET || HAS_POSITION_SHIFT
|
2019-09-29 11:25:39 +02:00
|
|
|
LOOP_XYZ(i) update_workspace_offset((AxisEnum)i);
|
2019-04-16 01:53:39 +02:00
|
|
|
#endif
|
2019-03-29 19:40:42 +01:00
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
// Resume the SD file from the last position
|
|
|
|
char *fn = info.sd_filename;
|
2019-11-02 05:51:25 +01:00
|
|
|
extern const char M23_STR[];
|
|
|
|
sprintf_P(cmd, M23_STR, fn);
|
2018-11-17 03:47:07 +01:00
|
|
|
gcode.process_subcommands_now(cmd);
|
2019-09-11 01:52:41 +02:00
|
|
|
sprintf_P(cmd, PSTR("M24 S%ld T%ld"), resume_sdpos, info.print_job_elapsed);
|
2018-11-17 03:47:07 +01:00
|
|
|
gcode.process_subcommands_now(cmd);
|
2018-04-22 02:41:26 +02:00
|
|
|
}
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
|
|
|
|
|
|
|
void PrintJobRecovery::debug(PGM_P const prefix) {
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_PRINT_P(prefix);
|
|
|
|
DEBUG_ECHOLNPAIR(" Job Recovery Info...\nvalid_head:", int(info.valid_head), " valid_foot:", int(info.valid_foot));
|
2018-11-17 03:47:07 +01:00
|
|
|
if (info.valid_head) {
|
|
|
|
if (info.valid_head == info.valid_foot) {
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_ECHOPGM("current_position: ");
|
2018-11-17 03:47:07 +01:00
|
|
|
LOOP_XYZE(i) {
|
2019-04-06 03:02:46 +02:00
|
|
|
if (i) DEBUG_CHAR(',');
|
2020-06-23 04:12:45 +02:00
|
|
|
DEBUG_DECIMAL(info.current_position[i]);
|
2018-11-17 03:47:07 +01:00
|
|
|
}
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_EOL();
|
2019-04-16 01:53:39 +02:00
|
|
|
|
2020-07-15 08:14:03 +02:00
|
|
|
DEBUG_ECHOLNPAIR("zraise: ", info.zraise);
|
|
|
|
|
2019-04-16 01:53:39 +02:00
|
|
|
#if HAS_HOME_OFFSET
|
|
|
|
DEBUG_ECHOPGM("home_offset: ");
|
|
|
|
LOOP_XYZ(i) {
|
|
|
|
if (i) DEBUG_CHAR(',');
|
2020-06-23 04:12:45 +02:00
|
|
|
DEBUG_DECIMAL(info.home_offset[i]);
|
2019-04-16 01:53:39 +02:00
|
|
|
}
|
|
|
|
DEBUG_EOL();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_POSITION_SHIFT
|
|
|
|
DEBUG_ECHOPGM("position_shift: ");
|
|
|
|
LOOP_XYZ(i) {
|
|
|
|
if (i) DEBUG_CHAR(',');
|
2020-06-23 04:12:45 +02:00
|
|
|
DEBUG_DECIMAL(info.position_shift[i]);
|
2019-04-16 01:53:39 +02:00
|
|
|
}
|
|
|
|
DEBUG_EOL();
|
|
|
|
#endif
|
|
|
|
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_ECHOLNPAIR("feedrate: ", info.feedrate);
|
2018-11-17 03:47:07 +01:00
|
|
|
|
2019-05-18 01:47:15 +02:00
|
|
|
#if EXTRUDERS > 1
|
|
|
|
DEBUG_ECHOLNPAIR("active_extruder: ", int(info.active_extruder));
|
2018-11-17 03:47:07 +01:00
|
|
|
#endif
|
|
|
|
|
2020-04-20 06:56:55 +02:00
|
|
|
#if HAS_HOTEND
|
2019-09-10 09:20:49 +02:00
|
|
|
DEBUG_ECHOPGM("target_temperature: ");
|
|
|
|
HOTEND_LOOP() {
|
|
|
|
DEBUG_ECHO(info.target_temperature[e]);
|
|
|
|
if (e < HOTENDS - 1) DEBUG_CHAR(',');
|
|
|
|
}
|
|
|
|
DEBUG_EOL();
|
|
|
|
#endif
|
2018-11-17 03:47:07 +01:00
|
|
|
|
|
|
|
#if HAS_HEATED_BED
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_ECHOLNPAIR("target_temperature_bed: ", info.target_temperature_bed);
|
2018-11-17 03:47:07 +01:00
|
|
|
#endif
|
|
|
|
|
2020-04-27 11:41:18 +02:00
|
|
|
#if HAS_FAN
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_ECHOPGM("fan_speed: ");
|
2019-03-07 09:09:39 +01:00
|
|
|
FANS_LOOP(i) {
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_ECHO(int(info.fan_speed[i]));
|
|
|
|
if (i < FAN_COUNT - 1) DEBUG_CHAR(',');
|
2018-11-17 03:47:07 +01:00
|
|
|
}
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_EOL();
|
2018-11-17 03:47:07 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_LEVELING
|
2020-07-07 02:14:15 +02:00
|
|
|
DEBUG_ECHOLNPAIR("leveling: ", int(info.leveling), " fade: ", info.fade);
|
2018-11-17 03:47:07 +01:00
|
|
|
#endif
|
|
|
|
#if ENABLED(FWRETRACT)
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_ECHOPGM("retract: ");
|
2018-11-17 03:47:07 +01:00
|
|
|
for (int8_t e = 0; e < EXTRUDERS; e++) {
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_ECHO(info.retract[e]);
|
|
|
|
if (e < EXTRUDERS - 1) DEBUG_CHAR(',');
|
2018-11-17 03:47:07 +01:00
|
|
|
}
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_EOL();
|
|
|
|
DEBUG_ECHOLNPAIR("retract_hop: ", info.retract_hop);
|
2018-11-17 03:47:07 +01:00
|
|
|
#endif
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_ECHOLNPAIR("sd_filename: ", info.sd_filename);
|
|
|
|
DEBUG_ECHOLNPAIR("sdpos: ", info.sdpos);
|
|
|
|
DEBUG_ECHOLNPAIR("print_job_elapsed: ", info.print_job_elapsed);
|
2018-11-17 03:47:07 +01:00
|
|
|
}
|
|
|
|
else
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_ECHOLNPGM("INVALID DATA");
|
2018-11-17 03:47:07 +01:00
|
|
|
}
|
2019-04-06 03:02:46 +02:00
|
|
|
DEBUG_ECHOLNPGM("---");
|
2018-11-17 03:47:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG_POWER_LOSS_RECOVERY
|
|
|
|
|
2018-04-22 02:41:26 +02:00
|
|
|
#endif // POWER_LOSS_RECOVERY
|