Power Loss Recovery with a UPS (#15943)

This commit is contained in:
BigTreeTech
2019-11-21 07:40:21 +08:00
committed by Scott Lahteine
parent ab9f0f2c4f
commit ab8b24fdba
111 changed files with 290 additions and 31 deletions

View File

@ -65,6 +65,9 @@ PrintJobRecovery recovery;
#ifndef POWER_LOSS_RETRACT_LEN
#define POWER_LOSS_RETRACT_LEN 0
#endif
#ifndef POWER_LOSS_ZRAISE
#define POWER_LOSS_ZRAISE 2
#endif
/**
* Clear the recovery info
@ -235,10 +238,34 @@ void PrintJobRecovery::save(const bool force/*=false*/, const bool save_queue/*=
}
#if PIN_EXISTS(POWER_LOSS)
void PrintJobRecovery::_outage() {
save(true);
#if ENABLED(BACKUP_POWER_SUPPLY)
static bool lock = false;
if (lock) return; // No re-entrance from idle() during raise_z()
lock = true;
#endif
if (IS_SD_PRINTING()) save(true);
#if ENABLED(BACKUP_POWER_SUPPLY)
raise_z();
#endif
kill(GET_TEXT(MSG_OUTAGE_RECOVERY));
}
#if ENABLED(BACKUP_POWER_SUPPLY)
void PrintJobRecovery::raise_z() {
// Disable all heaters to reduce power loss
thermalManager.disable_all_heaters();
quickstop_stepper();
// Raise Z axis
gcode.process_subcommands_now_P(PSTR("G91\nG0 Z" STRINGIFY(POWER_LOSS_ZRAISE)));
planner.synchronize();
}
#endif
#endif
/**
@ -260,8 +287,6 @@ void PrintJobRecovery::write() {
*/
void PrintJobRecovery::resume() {
#define RECOVERY_ZRAISE 2
const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
#if HAS_LEVELING
@ -272,15 +297,27 @@ void PrintJobRecovery::resume() {
// Reset E, raise Z, home XY...
gcode.process_subcommands_now_P(PSTR("G92.9 E0"
#if Z_HOME_DIR > 0
// If Z homing goes to max, reset E and home all
"\nG28R0"
// If Z homing goes to max, just reset E and home all
"\n"
"G28R0"
#if ENABLED(MARLIN_DEV_MODE)
"S"
#endif
#else
#else // "G92.9 E0 ..."
// Set Z to 0, raise Z by RECOVERY_ZRAISE, and Home (XY only for Cartesian)
// with no raise. (Only do simulated homing in Marlin Dev Mode.)
"Z0\nG1Z" STRINGIFY(RECOVERY_ZRAISE) "\nG28R0"
#if ENABLED(BACKUP_POWER_SUPPLY)
"Z" STRINGIFY(POWER_LOSS_ZRAISE) // Z-axis was already raised at outage
#else
"Z0\n" // Set Z=0
"G1Z" STRINGIFY(POWER_LOSS_ZRAISE) // Raise Z
#endif
"\n"
"G28R0"
#if ENABLED(MARLIN_DEV_MODE)
"S"
#elif !IS_KINEMATIC

View File

@ -168,7 +168,7 @@ class PrintJobRecovery {
#if PIN_EXISTS(POWER_LOSS)
static inline void outage() {
if (enabled && IS_SD_PRINTING() && READ(POWER_LOSS_PIN) == POWER_LOSS_STATE)
if (enabled && READ(POWER_LOSS_PIN) == POWER_LOSS_STATE)
_outage();
}
#endif
@ -184,6 +184,10 @@ class PrintJobRecovery {
private:
static void write();
#if ENABLED(BACKUP_POWER_SUPPLY)
static void raise_z();
#endif
#if PIN_EXISTS(POWER_LOSS)
static void _outage();
#endif