Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix, Improve Power-Loss Recovery #22828

Merged
merged 13 commits into from
Feb 9, 2022
16 changes: 13 additions & 3 deletions Marlin/src/feature/powerloss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW

#endif

#endif // POWER_LOSS_PIN

#if PIN_EXISTS(POWER_LOSS) || ENABLED(DEBUG_POWER_LOSS_RECOVERY)

/**
* An outage was detected by a sensor pin.
* - If not SD printing, let the machine turn off on its own with no "KILL" screen
Expand All @@ -273,7 +277,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
* - If backup power is available Retract E and Raise Z
* - Go to the KILL screen
*/
void PrintJobRecovery::_outage() {
void PrintJobRecovery::_outage(TERN_(DEBUG_POWER_LOSS_RECOVERY, const bool simulated/*=false*/)) {
#if ENABLED(BACKUP_POWER_SUPPLY)
static bool lock = false;
if (lock) return; // No re-entrance from idle() during retract_and_lift()
Expand Down Expand Up @@ -301,10 +305,16 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
retract_and_lift(zraise);
#endif

kill(GET_TEXT(MSG_OUTAGE_RECOVERY));
if (TERN0(DEBUG_POWER_LOSS_RECOVERY, simulated)) {
card.fileHasFinished();
current_position.reset();
sync_plan_position();
}
else
kill(GET_TEXT(MSG_OUTAGE_RECOVERY));
}

#endif
#endif // POWER_LOSS_PIN || DEBUG_POWER_LOSS_RECOVERY

/**
* Save the recovery info the recovery file
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/powerloss.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ class PrintJobRecovery {
static void retract_and_lift(const_float_t zraise);
#endif

#if PIN_EXISTS(POWER_LOSS)
#if PIN_EXISTS(POWER_LOSS) || ENABLED(DEBUG_POWER_LOSS_RECOVERY)
friend class GcodeSuite;
static void _outage();
static void _outage(TERN_(DEBUG_POWER_LOSS_RECOVERY, const bool simulated=false));
#endif
};

Expand Down
5 changes: 2 additions & 3 deletions Marlin/src/gcode/feature/powerloss/M413.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ void GcodeSuite::M413() {
if (parser.seen_test('W')) recovery.save(true);
if (parser.seen_test('P')) recovery.purge();
if (parser.seen_test('D')) recovery.debug(PSTR("M413"));
#if PIN_EXISTS(POWER_LOSS)
if (parser.seen_test('O')) recovery._outage();
#endif
if (parser.seen_test('O')) recovery._outage();
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
if (parser.seen_test('C')) recovery.check();
if (parser.seen_test('E')) SERIAL_ECHOPGM_P(recovery.exists() ? PSTR("PLR Exists\n") : PSTR("No PLR\n"));
if (parser.seen_test('V')) SERIAL_ECHOPGM_P(recovery.valid() ? PSTR("Valid\n") : PSTR("Invalid\n"));
#endif
Expand Down