Skip to content

Commit 1d46e67

Browse files
✨ PLR_BED_THRESHOLD (MarlinFirmware#26649)
Co-authored-by: Scott Lahteine <[email protected]>
1 parent 85ded0b commit 1d46e67

File tree

9 files changed

+63
-15
lines changed

9 files changed

+63
-15
lines changed

Marlin/Configuration_adv.h

+10-9
Original file line numberDiff line numberDiff line change
@@ -1743,19 +1743,20 @@
17431743
*/
17441744
//#define POWER_LOSS_RECOVERY
17451745
#if ENABLED(POWER_LOSS_RECOVERY)
1746-
#define PLR_ENABLED_DEFAULT false // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500)
1747-
//#define BACKUP_POWER_SUPPLY // Backup power / UPS to move the steppers on power loss
1748-
//#define POWER_LOSS_ZRAISE 2 // (mm) Z axis raise on resume (on power loss with UPS)
1749-
//#define POWER_LOSS_PIN 44 // Pin to detect power loss. Set to -1 to disable default pin on boards without module.
1750-
//#define POWER_LOSS_STATE HIGH // State of pin indicating power loss
1751-
//#define POWER_LOSS_PULLUP // Set pullup / pulldown as appropriate for your sensor
1746+
#define PLR_ENABLED_DEFAULT false // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500)
1747+
//#define PLR_BED_THRESHOLD BED_MAXTEMP // (°C) Skip user confirmation at or above this bed temperature (0 to disable)
1748+
//#define BACKUP_POWER_SUPPLY // Backup power / UPS to move the steppers on power loss
1749+
//#define POWER_LOSS_ZRAISE 2 // (mm) Z axis raise on resume (on power loss with UPS)
1750+
//#define POWER_LOSS_PIN 44 // Pin to detect power loss. Set to -1 to disable default pin on boards without module.
1751+
//#define POWER_LOSS_STATE HIGH // State of pin indicating power loss
1752+
//#define POWER_LOSS_PULLUP // Set pullup / pulldown as appropriate for your sensor
17521753
//#define POWER_LOSS_PULLDOWN
1753-
//#define POWER_LOSS_PURGE_LEN 20 // (mm) Length of filament to purge on resume
1754-
//#define POWER_LOSS_RETRACT_LEN 10 // (mm) Length of filament to retract on fail. Requires backup power.
1754+
//#define POWER_LOSS_PURGE_LEN 20 // (mm) Length of filament to purge on resume
1755+
//#define POWER_LOSS_RETRACT_LEN 10 // (mm) Length of filament to retract on fail. Requires backup power.
17551756

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

17601761
// Enable if Z homing is needed for proper recovery. 99.9% of the time this should be disabled!
17611762
//#define POWER_LOSS_RECOVER_ZHOME

Marlin/src/feature/powerloss.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737

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

40+
#if HAS_PLR_BED_THRESHOLD
41+
celsius_t PrintJobRecovery::bed_temp_threshold; // Initialized by settings.load()
42+
#endif
43+
4044
MediaFile PrintJobRecovery::file;
4145
job_recovery_info_t PrintJobRecovery::info;
4246
const char PrintJobRecovery::filename[5] = "/PLR";

Marlin/src/feature/powerloss.h

+4
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ class PrintJobRecovery {
175175
static void enable(const bool onoff);
176176
static void changed();
177177

178+
#if HAS_PLR_BED_THRESHOLD
179+
static celsius_t bed_temp_threshold;
180+
#endif
181+
178182
static bool exists() { return card.jobRecoverFileExists(); }
179183
static void open(const bool read) { card.openJobRecoveryFile(read); }
180184
static void close() { file.close(); }

Marlin/src/gcode/feature/powerloss/M1000.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include "../../../feature/powerloss.h"
2929
#include "../../../module/motion.h"
3030

31+
#if HAS_PLR_BED_THRESHOLD
32+
#include "../../../module/temperature.h" // for degBed
33+
#endif
34+
3135
#include "../../../lcd/marlinui.h"
3236
#if ENABLED(EXTENSIBLE_UI)
3337
#include "../../../lcd/extui/ui_api.h"
@@ -60,12 +64,15 @@ inline void plr_error(FSTR_P const prefix) {
6064
/**
6165
* M1000: Resume from power-loss (undocumented)
6266
* - With 'S' go to the Resume/Cancel menu
67+
* ...unless the bed temperature is already above a configured minimum temperature.
6368
* - With no parameters, run recovery commands
6469
*/
6570
void GcodeSuite::M1000() {
6671

6772
if (recovery.valid()) {
68-
if (parser.seen_test('S')) {
73+
const bool force_resume = TERN0(HAS_PLR_BED_THRESHOLD, recovery.bed_temp_threshold && (thermalManager.degBed() >= recovery.bed_temp_threshold));
74+
75+
if (!force_resume && parser.seen_test('S')) {
6976
#if HAS_MARLINUI_MENU
7077
ui.goto_screen(menu_job_recovery);
7178
#elif HAS_DWIN_E3V2_BASIC

Marlin/src/gcode/feature/powerloss/M413.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
* Parameters
3636
* S[bool] - Flag to enable / disable.
3737
* If omitted, report current state.
38+
*
39+
* With PLR_BED_THRESHOLD:
40+
* B Bed Temperature above which recovery will proceed without asking permission.
3841
*/
3942
void GcodeSuite::M413() {
4043

@@ -43,6 +46,11 @@ void GcodeSuite::M413() {
4346
else
4447
M413_report();
4548

49+
#if HAS_PLR_BED_THRESHOLD
50+
if (parser.seenval('B'))
51+
recovery.bed_temp_threshold = parser.value_celsius();
52+
#endif
53+
4654
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
4755
if (parser.seen("RL")) recovery.load();
4856
if (parser.seen_test('W')) recovery.save(true);
@@ -57,7 +65,11 @@ void GcodeSuite::M413() {
5765

5866
void GcodeSuite::M413_report(const bool forReplay/*=true*/) {
5967
report_heading_etc(forReplay, F(STR_POWER_LOSS_RECOVERY));
60-
SERIAL_ECHOPGM(" M413 S", AS_DIGIT(recovery.enabled), " ; ");
68+
SERIAL_ECHOPGM(" M413 S", AS_DIGIT(recovery.enabled)
69+
#if HAS_PLR_BED_THRESHOLD
70+
, " B", recovery.bed_temp_threshold
71+
#endif
72+
);
6173
serialprintln_onoff(recovery.enabled);
6274
}
6375

Marlin/src/inc/Conditionals_adv.h

+5
Original file line numberDiff line numberDiff line change
@@ -1355,3 +1355,8 @@
13551355
#if DISABLED(INCH_MODE_SUPPORT)
13561356
#undef MANUAL_MOVE_DISTANCE_IN
13571357
#endif
1358+
1359+
// Power-Loss Recovery
1360+
#if ENABLED(POWER_LOSS_RECOVERY) && defined(PLR_BED_THRESHOLD)
1361+
#define HAS_PLR_BED_THRESHOLD 1
1362+
#endif

Marlin/src/lcd/language/language_en.h

+1
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ namespace LanguageNarrow_en {
501501
LSTR MSG_RESUME_PRINT = _UxGT("Resume Print");
502502
LSTR MSG_STOP_PRINT = _UxGT("Stop Print");
503503
LSTR MSG_OUTAGE_RECOVERY = _UxGT("Power Outage");
504+
LSTR MSG_RESUME_BED_TEMP = _UxGT("Resume Bed Temp");
504505
LSTR MSG_HOST_START_PRINT = _UxGT("Host Start");
505506
LSTR MSG_PRINTING_OBJECT = _UxGT("Print Obj");
506507
LSTR MSG_CANCEL_OBJECT = _UxGT("Cancel Obj");

Marlin/src/lcd/menu/menu_configuration.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ void menu_configuration() {
640640

641641
#if ENABLED(POWER_LOSS_RECOVERY)
642642
EDIT_ITEM(bool, MSG_OUTAGE_RECOVERY, &recovery.enabled, recovery.changed);
643+
#if HAS_PLR_BED_THRESHOLD
644+
EDIT_ITEM(int3, MSG_RESUME_BED_TEMP, &recovery.bed_temp_threshold, 0, BED_MAX_TARGET);
645+
#endif
643646
#endif
644647

645648
// Preheat configurations

Marlin/src/module/settings.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ typedef struct SettingsDataStruct {
444444
// POWER_LOSS_RECOVERY
445445
//
446446
bool recovery_enabled; // M413 S
447+
celsius_t bed_temp_threshold; // M413 B
447448

448449
//
449450
// FWRETRACT
@@ -1268,8 +1269,10 @@ void MarlinSettings::postprocess() {
12681269
//
12691270
{
12701271
_FIELD_TEST(recovery_enabled);
1271-
const bool recovery_enabled = TERN(POWER_LOSS_RECOVERY, recovery.enabled, ENABLED(PLR_ENABLED_DEFAULT));
1272+
const bool recovery_enabled = TERN0(POWER_LOSS_RECOVERY, recovery.enabled);
1273+
const celsius_t bed_temp_threshold = TERN0(HAS_PLR_BED_THRESHOLD, recovery.bed_temp_threshold);
12721274
EEPROM_WRITE(recovery_enabled);
1275+
EEPROM_WRITE(bed_temp_threshold);
12731276
}
12741277

12751278
//
@@ -2310,10 +2313,15 @@ void MarlinSettings::postprocess() {
23102313
// Power-Loss Recovery
23112314
//
23122315
{
2313-
bool recovery_enabled;
23142316
_FIELD_TEST(recovery_enabled);
2317+
bool recovery_enabled;
2318+
celsius_t bed_temp_threshold;
23152319
EEPROM_READ(recovery_enabled);
2316-
TERN_(POWER_LOSS_RECOVERY, if (!validating) recovery.enabled = recovery_enabled);
2320+
EEPROM_READ(bed_temp_threshold);
2321+
if (!validating) {
2322+
TERN_(POWER_LOSS_RECOVERY, recovery.enabled = recovery_enabled);
2323+
TERN_(HAS_PLR_BED_THRESHOLD, recovery.bed_temp_threshold = bed_temp_threshold);
2324+
}
23172325
}
23182326

23192327
//
@@ -3460,7 +3468,10 @@ void MarlinSettings::reset() {
34603468
//
34613469
// Power-Loss Recovery
34623470
//
3463-
TERN_(POWER_LOSS_RECOVERY, recovery.enable(ENABLED(PLR_ENABLED_DEFAULT)));
3471+
#if ENABLED(POWER_LOSS_RECOVERY)
3472+
recovery.enable(ENABLED(PLR_ENABLED_DEFAULT));
3473+
TERN_(HAS_PLR_BED_THRESHOLD, recovery.bed_temp_threshold = PLR_BED_THRESHOLD);
3474+
#endif
34643475

34653476
//
34663477
// Firmware Retraction

0 commit comments

Comments
 (0)