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

Auto power loss print resume with temperature limitation #26649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1743,19 +1743,20 @@
*/
//#define POWER_LOSS_RECOVERY
#if ENABLED(POWER_LOSS_RECOVERY)
#define PLR_ENABLED_DEFAULT false // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500)
//#define BACKUP_POWER_SUPPLY // Backup power / UPS to move the steppers on power loss
//#define POWER_LOSS_ZRAISE 2 // (mm) Z axis raise on resume (on power loss with UPS)
//#define POWER_LOSS_PIN 44 // Pin to detect power loss. Set to -1 to disable default pin on boards without module.
//#define POWER_LOSS_STATE HIGH // State of pin indicating power loss
//#define POWER_LOSS_PULLUP // Set pullup / pulldown as appropriate for your sensor
#define PLR_ENABLED_DEFAULT false // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500)
//#define PLR_BED_THRESHOLD BED_MAXTEMP // (°C) Skip user confirmation at or above this bed temperature (0 to disable)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thinkyhead
Actually BED_MAXTEMP also disables the feature. Was it intention?

//#define BACKUP_POWER_SUPPLY // Backup power / UPS to move the steppers on power loss
//#define POWER_LOSS_ZRAISE 2 // (mm) Z axis raise on resume (on power loss with UPS)
//#define POWER_LOSS_PIN 44 // Pin to detect power loss. Set to -1 to disable default pin on boards without module.
//#define POWER_LOSS_STATE HIGH // State of pin indicating power loss
//#define POWER_LOSS_PULLUP // Set pullup / pulldown as appropriate for your sensor
//#define POWER_LOSS_PULLDOWN
//#define POWER_LOSS_PURGE_LEN 20 // (mm) Length of filament to purge on resume
//#define POWER_LOSS_RETRACT_LEN 10 // (mm) Length of filament to retract on fail. Requires backup power.
//#define POWER_LOSS_PURGE_LEN 20 // (mm) Length of filament to purge on resume
//#define POWER_LOSS_RETRACT_LEN 10 // (mm) Length of filament to retract on fail. Requires backup power.

// Without a POWER_LOSS_PIN the following option helps reduce wear on the SD card,
// especially with "vase mode" printing. Set too high and vases cannot be continued.
#define POWER_LOSS_MIN_Z_CHANGE 0.05 // (mm) Minimum Z change before saving power-loss data
#define POWER_LOSS_MIN_Z_CHANGE 0.05 // (mm) Minimum Z change before saving power-loss data

// Enable if Z homing is needed for proper recovery. 99.9% of the time this should be disabled!
//#define POWER_LOSS_RECOVER_ZHOME
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/feature/powerloss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

bool PrintJobRecovery::enabled; // Initialized by settings.load()

#if HAS_PLR_BED_THRESHOLD
celsius_t PrintJobRecovery::bed_temp_threshold; // Initialized by settings.load()
#endif

MediaFile PrintJobRecovery::file;
job_recovery_info_t PrintJobRecovery::info;
const char PrintJobRecovery::filename[5] = "/PLR";
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/feature/powerloss.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ class PrintJobRecovery {
static void enable(const bool onoff);
static void changed();

#if HAS_PLR_BED_THRESHOLD
static celsius_t bed_temp_threshold;
#endif

static bool exists() { return card.jobRecoverFileExists(); }
static void open(const bool read) { card.openJobRecoveryFile(read); }
static void close() { file.close(); }
Expand Down
9 changes: 8 additions & 1 deletion Marlin/src/gcode/feature/powerloss/M1000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include "../../../feature/powerloss.h"
#include "../../../module/motion.h"

#if HAS_PLR_BED_THRESHOLD
#include "../../../module/temperature.h" // for degBed
#endif

#include "../../../lcd/marlinui.h"
#if ENABLED(EXTENSIBLE_UI)
#include "../../../lcd/extui/ui_api.h"
Expand Down Expand Up @@ -60,12 +64,15 @@ inline void plr_error(FSTR_P const prefix) {
/**
* M1000: Resume from power-loss (undocumented)
* - With 'S' go to the Resume/Cancel menu
* ...unless the bed temperature is already above a configured minimum temperature.
* - With no parameters, run recovery commands
*/
void GcodeSuite::M1000() {

if (recovery.valid()) {
if (parser.seen_test('S')) {
const bool force_resume = TERN0(HAS_PLR_BED_THRESHOLD, recovery.bed_temp_threshold && (thermalManager.degBed() >= recovery.bed_temp_threshold));

if (!force_resume && parser.seen_test('S')) {
#if HAS_MARLINUI_MENU
ui.goto_screen(menu_job_recovery);
#elif HAS_DWIN_E3V2_BASIC
Expand Down
14 changes: 13 additions & 1 deletion Marlin/src/gcode/feature/powerloss/M413.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
* Parameters
* S[bool] - Flag to enable / disable.
* If omitted, report current state.
*
* With PLR_BED_THRESHOLD:
* B Bed Temperature above which recovery will proceed without asking permission.
*/
void GcodeSuite::M413() {

Expand All @@ -43,6 +46,11 @@ void GcodeSuite::M413() {
else
M413_report();

#if HAS_PLR_BED_THRESHOLD
if (parser.seenval('B'))
recovery.bed_temp_threshold = parser.value_celsius();
#endif

#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
if (parser.seen("RL")) recovery.load();
if (parser.seen_test('W')) recovery.save(true);
Expand All @@ -57,7 +65,11 @@ void GcodeSuite::M413() {

void GcodeSuite::M413_report(const bool forReplay/*=true*/) {
report_heading_etc(forReplay, F(STR_POWER_LOSS_RECOVERY));
SERIAL_ECHOPGM(" M413 S", AS_DIGIT(recovery.enabled), " ; ");
SERIAL_ECHOPGM(" M413 S", AS_DIGIT(recovery.enabled)
#if HAS_PLR_BED_THRESHOLD
, " B", recovery.bed_temp_threshold
#endif
);
serialprintln_onoff(recovery.enabled);
}

Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1355,3 +1355,8 @@
#if DISABLED(INCH_MODE_SUPPORT)
#undef MANUAL_MOVE_DISTANCE_IN
#endif

// Power-Loss Recovery
#if ENABLED(POWER_LOSS_RECOVERY) && defined(PLR_BED_THRESHOLD)
#define HAS_PLR_BED_THRESHOLD 1
#endif
1 change: 1 addition & 0 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ namespace LanguageNarrow_en {
LSTR MSG_RESUME_PRINT = _UxGT("Resume Print");
LSTR MSG_STOP_PRINT = _UxGT("Stop Print");
LSTR MSG_OUTAGE_RECOVERY = _UxGT("Power Outage");
LSTR MSG_RESUME_BED_TEMP = _UxGT("Resume Bed Temp");
LSTR MSG_HOST_START_PRINT = _UxGT("Host Start");
LSTR MSG_PRINTING_OBJECT = _UxGT("Print Obj");
LSTR MSG_CANCEL_OBJECT = _UxGT("Cancel Obj");
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/lcd/menu/menu_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@ void menu_configuration() {

#if ENABLED(POWER_LOSS_RECOVERY)
EDIT_ITEM(bool, MSG_OUTAGE_RECOVERY, &recovery.enabled, recovery.changed);
#if HAS_PLR_BED_THRESHOLD
EDIT_ITEM(int3, MSG_RESUME_BED_TEMP, &recovery.bed_temp_threshold, 0, BED_MAX_TARGET);
#endif
#endif

// Preheat configurations
Expand Down
19 changes: 15 additions & 4 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ typedef struct SettingsDataStruct {
// POWER_LOSS_RECOVERY
//
bool recovery_enabled; // M413 S
celsius_t bed_temp_threshold; // M413 B

//
// FWRETRACT
Expand Down Expand Up @@ -1268,8 +1269,10 @@ void MarlinSettings::postprocess() {
//
{
_FIELD_TEST(recovery_enabled);
const bool recovery_enabled = TERN(POWER_LOSS_RECOVERY, recovery.enabled, ENABLED(PLR_ENABLED_DEFAULT));
const bool recovery_enabled = TERN0(POWER_LOSS_RECOVERY, recovery.enabled);
const celsius_t bed_temp_threshold = TERN0(HAS_PLR_BED_THRESHOLD, recovery.bed_temp_threshold);
EEPROM_WRITE(recovery_enabled);
EEPROM_WRITE(bed_temp_threshold);
}

//
Expand Down Expand Up @@ -2310,10 +2313,15 @@ void MarlinSettings::postprocess() {
// Power-Loss Recovery
//
{
bool recovery_enabled;
_FIELD_TEST(recovery_enabled);
bool recovery_enabled;
celsius_t bed_temp_threshold;
EEPROM_READ(recovery_enabled);
TERN_(POWER_LOSS_RECOVERY, if (!validating) recovery.enabled = recovery_enabled);
EEPROM_READ(bed_temp_threshold);
if (!validating) {
TERN_(POWER_LOSS_RECOVERY, recovery.enabled = recovery_enabled);
TERN_(HAS_PLR_BED_THRESHOLD, recovery.bed_temp_threshold = bed_temp_threshold);
}
}

//
Expand Down Expand Up @@ -3460,7 +3468,10 @@ void MarlinSettings::reset() {
//
// Power-Loss Recovery
//
TERN_(POWER_LOSS_RECOVERY, recovery.enable(ENABLED(PLR_ENABLED_DEFAULT)));
#if ENABLED(POWER_LOSS_RECOVERY)
recovery.enable(ENABLED(PLR_ENABLED_DEFAULT));
TERN_(HAS_PLR_BED_THRESHOLD, recovery.bed_temp_threshold = PLR_BED_THRESHOLD);
#endif

//
// Firmware Retraction
Expand Down
Loading