Skip to content

Commit 62696d8

Browse files
ellenspTracy Spiva
authored and
Tracy Spiva
committed
✨ Persistent AUTOTEMP settings (MarlinFirmware#25093)
1 parent 806a76f commit 62696d8

File tree

7 files changed

+109
-47
lines changed

7 files changed

+109
-47
lines changed

Marlin/Configuration_adv.h

+3
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@
459459
#define AUTOTEMP
460460
#if ENABLED(AUTOTEMP)
461461
#define AUTOTEMP_OLDWEIGHT 0.98 // Factor used to weight previous readings (0.0 < value < 1.0)
462+
#define AUTOTEMP_MIN 210
463+
#define AUTOTEMP_MAX 250
464+
#define AUTOTEMP_FACTOR 0.1f
462465
// Turn on AUTOTEMP on M104/M109 by default using proportions set here
463466
//#define AUTOTEMP_PROPORTIONAL
464467
#if ENABLED(AUTOTEMP_PROPORTIONAL)

Marlin/src/inc/SanityCheck.h

+15
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

+3-4
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,9 @@ void menu_backlash();
295295
// Autotemp, Min, Max, Fact
296296
//
297297
#if BOTH(AUTOTEMP, HAS_TEMP_HOTEND)
298-
EDIT_ITEM(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
299-
EDIT_ITEM(int3, MSG_MIN, &planner.autotemp_min, 0, thermalManager.hotend_max_target(0));
300-
EDIT_ITEM(int3, MSG_MAX, &planner.autotemp_max, 0, thermalManager.hotend_max_target(0));
301-
EDIT_ITEM(float42_52, MSG_FACTOR, &planner.autotemp_factor, 0, 10);
298+
EDIT_ITEM(int3, MSG_MIN, &planner.autotemp.min, 0, thermalManager.hotend_max_target(0));
299+
EDIT_ITEM(int3, MSG_MAX, &planner.autotemp.max, 0, thermalManager.hotend_max_target(0));
300+
EDIT_ITEM(float42_52, MSG_FACTOR, &planner.autotemp.factor, 0, 10);
302301
#endif
303302

304303
//

Marlin/src/module/planner.cpp

+16-17
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,12 @@ float Planner::mm_per_step[DISTINCT_AXES]; // (mm) Millimeters per step
198198
constexpr bool Planner::leveling_active;
199199
#endif
200200

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

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

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

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

14531452
/**
@@ -1457,13 +1456,13 @@ void Planner::check_axes_activity() {
14571456
void Planner::autotemp_M104_M109() {
14581457
_autotemp_update_from_hotend();
14591458

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

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

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

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

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

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

Marlin/src/module/planner.h

+25-21
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 {
@@ -326,25 +334,21 @@ typedef struct {
326334
};
327335
#endif
328336

329-
#if DISABLED(SKEW_CORRECTION)
330-
#define XY_SKEW_FACTOR 0
331-
#define XZ_SKEW_FACTOR 0
332-
#define YZ_SKEW_FACTOR 0
333-
#endif
334-
335-
typedef struct {
336-
#if ENABLED(SKEW_CORRECTION_GCODE)
337-
float xy;
338-
#if ENABLED(SKEW_CORRECTION_FOR_Z)
339-
float xz, yz;
337+
#if ENABLED(SKEW_CORRECTION)
338+
typedef struct {
339+
#if ENABLED(SKEW_CORRECTION_GCODE)
340+
float xy;
341+
#if ENABLED(SKEW_CORRECTION_FOR_Z)
342+
float xz, yz;
343+
#else
344+
const float xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR;
345+
#endif
340346
#else
341-
const float xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR;
347+
const float xy = XY_SKEW_FACTOR,
348+
xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR;
342349
#endif
343-
#else
344-
const float xy = XY_SKEW_FACTOR,
345-
xz = XZ_SKEW_FACTOR, yz = YZ_SKEW_FACTOR;
346-
#endif
347-
} skew_factor_t;
350+
} skew_factor_t;
351+
#endif
348352

349353
#if ENABLED(DISABLE_INACTIVE_EXTRUDER)
350354
typedef IF<(BLOCK_BUFFER_SIZE > 64), uint16_t, uint8_t>::type last_move_t;
@@ -476,7 +480,9 @@ class Planner {
476480
static xyze_pos_t position_cart;
477481
#endif
478482

479-
static skew_factor_t skew_factor;
483+
#if ENABLED(SKEW_CORRECTION)
484+
static skew_factor_t skew_factor;
485+
#endif
480486

481487
#if ENABLED(SD_ABORT_ON_ENDSTOP_HIT)
482488
static bool abort_on_endstop_hit;
@@ -972,9 +978,7 @@ class Planner {
972978
#endif
973979

974980
#if ENABLED(AUTOTEMP)
975-
static celsius_t autotemp_min, autotemp_max;
976-
static float autotemp_factor;
977-
static bool autotemp_enabled;
981+
static autotemp_t autotemp;
978982
static void autotemp_update();
979983
static void autotemp_M104_M109();
980984
static void autotemp_task();

Marlin/src/module/settings.cpp

+45-3
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ typedef struct SettingsDataStruct {
245245
//
246246
float planner_z_fade_height; // M420 Zn planner.z_fade_height
247247

248+
//
249+
// AUTOTEMP
250+
//
251+
#if ENABLED(AUTOTEMP)
252+
celsius_t planner_autotemp_max, planner_autotemp_min;
253+
float planner_autotemp_factor;
254+
#endif
255+
248256
//
249257
// MESH_BED_LEVELING
250258
//
@@ -472,7 +480,9 @@ typedef struct SettingsDataStruct {
472480
//
473481
// SKEW_CORRECTION
474482
//
475-
skew_factor_t planner_skew_factor; // M852 I J K
483+
#if ENABLED(SKEW_CORRECTION)
484+
skew_factor_t planner_skew_factor; // M852 I J K
485+
#endif
476486

477487
//
478488
// ADVANCED_PAUSE_FEATURE
@@ -855,6 +865,16 @@ void MarlinSettings::postprocess() {
855865
EEPROM_WRITE(zfh);
856866
}
857867

868+
//
869+
// AUTOTEMP
870+
//
871+
#if ENABLED(AUTOTEMP)
872+
_FIELD_TEST(planner_autotemp_max);
873+
EEPROM_WRITE(planner.autotemp.max);
874+
EEPROM_WRITE(planner.autotemp.min);
875+
EEPROM_WRITE(planner.autotemp.factor);
876+
#endif
877+
858878
//
859879
// Mesh Bed Leveling
860880
//
@@ -1453,8 +1473,10 @@ void MarlinSettings::postprocess() {
14531473
//
14541474
// Skew correction factors
14551475
//
1456-
_FIELD_TEST(planner_skew_factor);
1457-
EEPROM_WRITE(planner.skew_factor);
1476+
#if ENABLED(SKEW_CORRECTION)
1477+
_FIELD_TEST(planner_skew_factor);
1478+
EEPROM_WRITE(planner.skew_factor);
1479+
#endif
14581480

14591481
//
14601482
// Advanced Pause filament load & unload lengths
@@ -1803,6 +1825,15 @@ void MarlinSettings::postprocess() {
18031825
//
18041826
EEPROM_READ(TERN(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height, dummyf));
18051827

1828+
//
1829+
// AUTOTEMP
1830+
//
1831+
#if ENABLED(AUTOTEMP)
1832+
EEPROM_READ(planner.autotemp.max);
1833+
EEPROM_READ(planner.autotemp.min);
1834+
EEPROM_READ(planner.autotemp.factor);
1835+
#endif
1836+
18061837
//
18071838
// Mesh (Manual) Bed Leveling
18081839
//
@@ -2423,6 +2454,7 @@ void MarlinSettings::postprocess() {
24232454
//
24242455
// Skew correction factors
24252456
//
2457+
#if ENABLED(SKEW_CORRECTION)
24262458
{
24272459
skew_factor_t skew_factor;
24282460
_FIELD_TEST(planner_skew_factor);
@@ -2437,6 +2469,7 @@ void MarlinSettings::postprocess() {
24372469
}
24382470
#endif
24392471
}
2472+
#endif
24402473

24412474
//
24422475
// Advanced Pause filament load & unload lengths
@@ -2999,6 +3032,15 @@ void MarlinSettings::reset() {
29993032
TERN_(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height = (DEFAULT_LEVELING_FADE_HEIGHT));
30003033
TERN_(HAS_LEVELING, reset_bed_level());
30013034

3035+
//
3036+
// AUTOTEMP
3037+
//
3038+
#if ENABLED(AUTOTEMP)
3039+
planner.autotemp.max = AUTOTEMP_MAX;
3040+
planner.autotemp.min = AUTOTEMP_MIN;
3041+
planner.autotemp.factor = AUTOTEMP_FACTOR;
3042+
#endif
3043+
30023044
//
30033045
// X Axis Twist Compensation
30043046
//

Marlin/src/module/temperature.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2930,7 +2930,7 @@ void Temperature::init() {
29302930
void Temperature::disable_all_heaters() {
29312931

29322932
// Disable autotemp, unpause and reset everything
2933-
TERN_(AUTOTEMP, planner.autotemp_enabled = false);
2933+
TERN_(AUTOTEMP, planner.autotemp.enabled = false);
29342934
TERN_(PROBING_HEATERS_OFF, pause_heaters(false));
29352935

29362936
#if HAS_HOTEND
@@ -4005,7 +4005,7 @@ void Temperature::isr() {
40054005
OPTARG(G26_CLICK_CAN_CANCEL, const bool click_to_cancel/*=false*/)
40064006
) {
40074007
#if ENABLED(AUTOTEMP)
4008-
REMEMBER(1, planner.autotemp_enabled, false);
4008+
REMEMBER(1, planner.autotemp.enabled, false);
40094009
#endif
40104010

40114011
#if TEMP_RESIDENCY_TIME > 0

0 commit comments

Comments
 (0)