Skip to content

Commit afe5ecb

Browse files
ellenspAndy-Big
authored andcommitted
✨ Persistent AUTOTEMP settings (MarlinFirmware#25093)
1 parent bff8d6a commit afe5ecb

File tree

7 files changed

+109
-47
lines changed

7 files changed

+109
-47
lines changed

Marlin/Configuration_adv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,9 @@
450450
#define AUTOTEMP
451451
#if ENABLED(AUTOTEMP)
452452
#define AUTOTEMP_OLDWEIGHT 0.98 // Factor used to weight previous readings (0.0 < value < 1.0)
453+
#define AUTOTEMP_MIN 210
454+
#define AUTOTEMP_MAX 250
455+
#define AUTOTEMP_FACTOR 0.1f
453456
// Turn on AUTOTEMP on M104/M109 by default using proportions set here
454457
//#define AUTOTEMP_PROPORTIONAL
455458
#if ENABLED(AUTOTEMP_PROPORTIONAL)

Marlin/src/inc/SanityCheck.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,21 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
15491549
#error "To use CHAMBER_LIMIT_SWITCHING you must disable PIDTEMPCHAMBER."
15501550
#endif
15511551

1552+
/**
1553+
* AUTOTEMP
1554+
*/
1555+
#if ENABLED(AUTOTEMP)
1556+
#ifndef AUTOTEMP_MIN
1557+
#error "AUTOTEMP requires AUTOTEMP_MIN."
1558+
#elif !defined(AUTOTEMP_MAX)
1559+
#error "AUTOTEMP requires AUTOTEMP_MAX."
1560+
#elif !defined(AUTOTEMP_FACTOR)
1561+
#error "AUTOTEMP requires AUTOTEMP_FACTOR."
1562+
#elif AUTOTEMP_MAX < AUTOTEMP_MIN
1563+
#error "AUTOTEMP_MAX must be greater than or equal to AUTOTEMP_MIN."
1564+
#endif
1565+
#endif
1566+
15521567
/**
15531568
* Features that require a min/max/specific NUM_AXES
15541569
*/

Marlin/src/lcd/menu/menu_advanced.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,9 @@ void menu_bedlevel_points();
406406
// Autotemp, Min, Max, Fact
407407
//
408408
#if BOTH(AUTOTEMP, HAS_TEMP_HOTEND)
409-
EDIT_ITEM(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
410-
EDIT_ITEM(int3, MSG_MIN, &planner.autotemp_min, 0, thermalManager.hotend_max_target(0));
411-
EDIT_ITEM(int3, MSG_MAX, &planner.autotemp_max, 0, thermalManager.hotend_max_target(0));
412-
EDIT_ITEM(float42_52, MSG_FACTOR, &planner.autotemp_factor, 0, 10);
409+
EDIT_ITEM(int3, MSG_MIN, &planner.autotemp.min, 0, thermalManager.hotend_max_target(0));
410+
EDIT_ITEM(int3, MSG_MAX, &planner.autotemp.max, 0, thermalManager.hotend_max_target(0));
411+
EDIT_ITEM(float42_52, MSG_FACTOR, &planner.autotemp.factor, 0, 10);
413412
#endif
414413

415414
//

Marlin/src/module/planner.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,12 @@ float Planner::mm_per_step[DISTINCT_AXES]; // (mm) Millimeters per step
199199
constexpr bool Planner::leveling_active;
200200
#endif
201201

202-
skew_factor_t Planner::skew_factor; // Initialized by settings.load()
202+
#if ENABLED(SKEW_CORRECTION)
203+
skew_factor_t Planner::skew_factor; // Initialized by settings.load()
204+
#endif
203205

204206
#if ENABLED(AUTOTEMP)
205-
celsius_t Planner::autotemp_max = 250,
206-
Planner::autotemp_min = 210;
207-
float Planner::autotemp_factor = 0.1f;
208-
bool Planner::autotemp_enabled = false;
207+
autotemp_t Planner::autotemp = { AUTOTEMP_MIN, AUTOTEMP_MAX, AUTOTEMP_FACTOR, false };
209208
#endif
210209

211210
// private:
@@ -1433,8 +1432,8 @@ void Planner::check_axes_activity() {
14331432
#if ENABLED(AUTOTEMP_PROPORTIONAL)
14341433
void Planner::_autotemp_update_from_hotend() {
14351434
const celsius_t target = thermalManager.degTargetHotend(active_extruder);
1436-
autotemp_min = target + AUTOTEMP_MIN_P;
1437-
autotemp_max = target + AUTOTEMP_MAX_P;
1435+
autotemp.min = target + AUTOTEMP_MIN_P;
1436+
autotemp.max = target + AUTOTEMP_MAX_P;
14381437
}
14391438
#endif
14401439

@@ -1445,8 +1444,8 @@ void Planner::check_axes_activity() {
14451444
*/
14461445
void Planner::autotemp_update() {
14471446
_autotemp_update_from_hotend();
1448-
autotemp_factor = TERN(AUTOTEMP_PROPORTIONAL, AUTOTEMP_FACTOR_P, 0);
1449-
autotemp_enabled = autotemp_factor != 0;
1447+
autotemp.factor = TERN(AUTOTEMP_PROPORTIONAL, AUTOTEMP_FACTOR_P, 0);
1448+
autotemp.enabled = autotemp.factor != 0;
14501449
}
14511450

14521451
/**
@@ -1456,13 +1455,13 @@ void Planner::check_axes_activity() {
14561455
void Planner::autotemp_M104_M109() {
14571456
_autotemp_update_from_hotend();
14581457

1459-
if (parser.seenval('S')) autotemp_min = parser.value_celsius();
1460-
if (parser.seenval('B')) autotemp_max = parser.value_celsius();
1458+
if (parser.seenval('S')) autotemp.min = parser.value_celsius();
1459+
if (parser.seenval('B')) autotemp.max = parser.value_celsius();
14611460

14621461
// When AUTOTEMP_PROPORTIONAL is enabled, F0 disables autotemp.
14631462
// Normally, leaving off F also disables autotemp.
1464-
autotemp_factor = parser.seen('F') ? parser.value_float() : TERN(AUTOTEMP_PROPORTIONAL, AUTOTEMP_FACTOR_P, 0);
1465-
autotemp_enabled = autotemp_factor != 0;
1463+
autotemp.factor = parser.seen('F') ? parser.value_float() : TERN(AUTOTEMP_PROPORTIONAL, AUTOTEMP_FACTOR_P, 0);
1464+
autotemp.enabled = autotemp.factor != 0;
14661465
}
14671466

14681467
/**
@@ -1473,8 +1472,8 @@ void Planner::check_axes_activity() {
14731472
void Planner::autotemp_task() {
14741473
static float oldt = 0.0f;
14751474

1476-
if (!autotemp_enabled) return;
1477-
if (thermalManager.degTargetHotend(active_extruder) < autotemp_min - 2) return; // Below the min?
1475+
if (!autotemp.enabled) return;
1476+
if (thermalManager.degTargetHotend(active_extruder) < autotemp.min - 2) return; // Below the min?
14781477

14791478
float high = 0.0f;
14801479
for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
@@ -1485,8 +1484,8 @@ void Planner::check_axes_activity() {
14851484
}
14861485
}
14871486

1488-
float t = autotemp_min + high * autotemp_factor;
1489-
LIMIT(t, autotemp_min, autotemp_max);
1487+
float t = autotemp.min + high * autotemp.factor;
1488+
LIMIT(t, autotemp.min, autotemp.max);
14901489
if (t < oldt) t = t * (1.0f - (AUTOTEMP_OLDWEIGHT)) + oldt * (AUTOTEMP_OLDWEIGHT);
14911490
oldt = t;
14921491
thermalManager.setTargetHotend(t, active_extruder);

Marlin/src/module/planner.h

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ typedef struct {
156156

157157
} block_flags_t;
158158

159+
#if ENABLED(AUTOTEMP)
160+
typedef struct {
161+
celsius_t min, max;
162+
float factor;
163+
bool enabled;
164+
} autotemp_t;
165+
#endif
166+
159167
#if ENABLED(LASER_FEATURE)
160168

161169
typedef struct {
@@ -337,25 +345,21 @@ typedef struct {
337345
};
338346
#endif
339347

340-
#if DISABLED(SKEW_CORRECTION)
341-
#define XY_SKEW_FACTOR 0
342-
#define XZ_SKEW_FACTOR 0
343-
#define YZ_SKEW_FACTOR 0
344-
#endif
345-
346-
typedef struct {
347-
#if ENABLED(SKEW_CORRECTION_GCODE)
348-
float xy;
349-
#if ENABLED(SKEW_CORRECTION_FOR_Z)
350-
float xz, yz;
348+
#if ENABLED(SKEW_CORRECTION)
349+
typedef struct {
350+
#if ENABLED(SKEW_CORRECTION_GCODE)
351+
float xy;
352+
#if ENABLED(SKEW_CORRECTION_FOR_Z)
353+
float xz, yz;
354+
#else
355+
const float xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR;
356+
#endif
351357
#else
352-
const float xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR;
358+
const float xy = XY_SKEW_FACTOR,
359+
xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR;
353360
#endif
354-
#else
355-
const float xy = XY_SKEW_FACTOR,
356-
xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR;
357-
#endif
358-
} skew_factor_t;
361+
} skew_factor_t;
362+
#endif
359363

360364
#if ENABLED(DISABLE_INACTIVE_EXTRUDER)
361365
typedef IF<(BLOCK_BUFFER_SIZE > 64), uint16_t, uint8_t>::type last_move_t;
@@ -489,7 +493,9 @@ class Planner {
489493
static xyze_pos_t position_cart;
490494
#endif
491495

492-
static skew_factor_t skew_factor;
496+
#if ENABLED(SKEW_CORRECTION)
497+
static skew_factor_t skew_factor;
498+
#endif
493499

494500
#if ENABLED(SD_ABORT_ON_ENDSTOP_HIT)
495501
static bool abort_on_endstop_hit;
@@ -985,9 +991,7 @@ class Planner {
985991
#endif
986992

987993
#if ENABLED(AUTOTEMP)
988-
static celsius_t autotemp_min, autotemp_max;
989-
static float autotemp_factor;
990-
static bool autotemp_enabled;
994+
static autotemp_t autotemp;
991995
static void autotemp_update();
992996
static void autotemp_M104_M109();
993997
static void autotemp_task();

Marlin/src/module/settings.cpp

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ typedef struct SettingsDataStruct {
250250
//
251251
float planner_z_fade_height; // M420 Zn planner.z_fade_height
252252

253+
//
254+
// AUTOTEMP
255+
//
256+
#if ENABLED(AUTOTEMP)
257+
celsius_t planner_autotemp_max, planner_autotemp_min;
258+
float planner_autotemp_factor;
259+
#endif
260+
253261
//
254262
// MESH_BED_LEVELING
255263
//
@@ -477,7 +485,9 @@ typedef struct SettingsDataStruct {
477485
//
478486
// SKEW_CORRECTION
479487
//
480-
skew_factor_t planner_skew_factor; // M852 I J K
488+
#if ENABLED(SKEW_CORRECTION)
489+
skew_factor_t planner_skew_factor; // M852 I J K
490+
#endif
481491

482492
//
483493
// ADVANCED_PAUSE_FEATURE
@@ -872,6 +882,16 @@ void MarlinSettings::postprocess() {
872882
EEPROM_WRITE(zfh);
873883
}
874884

885+
//
886+
// AUTOTEMP
887+
//
888+
#if ENABLED(AUTOTEMP)
889+
_FIELD_TEST(planner_autotemp_max);
890+
EEPROM_WRITE(planner.autotemp.max);
891+
EEPROM_WRITE(planner.autotemp.min);
892+
EEPROM_WRITE(planner.autotemp.factor);
893+
#endif
894+
875895
//
876896
// Mesh Bed Leveling
877897
//
@@ -1470,8 +1490,10 @@ void MarlinSettings::postprocess() {
14701490
//
14711491
// Skew correction factors
14721492
//
1473-
_FIELD_TEST(planner_skew_factor);
1474-
EEPROM_WRITE(planner.skew_factor);
1493+
#if ENABLED(SKEW_CORRECTION)
1494+
_FIELD_TEST(planner_skew_factor);
1495+
EEPROM_WRITE(planner.skew_factor);
1496+
#endif
14751497

14761498
//
14771499
// Advanced Pause filament load & unload lengths
@@ -1844,6 +1866,15 @@ void MarlinSettings::postprocess() {
18441866
//
18451867
EEPROM_READ(TERN(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height, dummyf));
18461868

1869+
//
1870+
// AUTOTEMP
1871+
//
1872+
#if ENABLED(AUTOTEMP)
1873+
EEPROM_READ(planner.autotemp.max);
1874+
EEPROM_READ(planner.autotemp.min);
1875+
EEPROM_READ(planner.autotemp.factor);
1876+
#endif
1877+
18471878
//
18481879
// Mesh (Manual) Bed Leveling
18491880
//
@@ -2466,6 +2497,7 @@ void MarlinSettings::postprocess() {
24662497
//
24672498
// Skew correction factors
24682499
//
2500+
#if ENABLED(SKEW_CORRECTION)
24692501
{
24702502
skew_factor_t skew_factor;
24712503
_FIELD_TEST(planner_skew_factor);
@@ -2480,6 +2512,7 @@ void MarlinSettings::postprocess() {
24802512
}
24812513
#endif
24822514
}
2515+
#endif
24832516

24842517
//
24852518
// Advanced Pause filament load & unload lengths
@@ -3176,6 +3209,15 @@ void MarlinSettings::reset() {
31763209
TERN_(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height = (DEFAULT_LEVELING_FADE_HEIGHT));
31773210
TERN_(HAS_LEVELING, reset_bed_level());
31783211

3212+
//
3213+
// AUTOTEMP
3214+
//
3215+
#if ENABLED(AUTOTEMP)
3216+
planner.autotemp.max = AUTOTEMP_MAX;
3217+
planner.autotemp.min = AUTOTEMP_MIN;
3218+
planner.autotemp.factor = AUTOTEMP_FACTOR;
3219+
#endif
3220+
31793221
//
31803222
// X Axis Twist Compensation
31813223
//

Marlin/src/module/temperature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,7 +2943,7 @@ void Temperature::init() {
29432943
void Temperature::disable_all_heaters() {
29442944

29452945
// Disable autotemp, unpause and reset everything
2946-
TERN_(AUTOTEMP, planner.autotemp_enabled = false);
2946+
TERN_(AUTOTEMP, planner.autotemp.enabled = false);
29472947
TERN_(PROBING_HEATERS_OFF, pause_heaters(false));
29482948

29492949
#if HAS_HOTEND
@@ -4018,7 +4018,7 @@ void Temperature::isr() {
40184018
OPTARG(G26_CLICK_CAN_CANCEL, const bool click_to_cancel/*=false*/)
40194019
) {
40204020
#if ENABLED(AUTOTEMP)
4021-
REMEMBER(1, planner.autotemp_enabled, false);
4021+
REMEMBER(1, planner.autotemp.enabled, false);
40224022
#endif
40234023

40244024
#if TEMP_RESIDENCY_TIME > 0

0 commit comments

Comments
 (0)