Skip to content

Commit cb291e8

Browse files
committed
🩹 Fix some temp constraints
1 parent 25caae1 commit cb291e8

File tree

14 files changed

+52
-43
lines changed

14 files changed

+52
-43
lines changed

Marlin/src/gcode/bedlevel/G26.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ void GcodeSuite::G26() {
615615

616616
// If any preset or temperature was specified
617617
if (noztemp) {
618-
if (!WITHIN(noztemp, 165, (HEATER_0_MAXTEMP) - (HOTEND_OVERSHOOT))) {
618+
if (!WITHIN(noztemp, 165, thermalManager.hotend_max_target(active_extruder))) {
619619
SERIAL_ECHOLNPGM("?Specified nozzle temperature not plausible.");
620620
return;
621621
}

Marlin/src/inc/Conditionals_post.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,7 @@
24582458
#ifndef BED_OVERSHOOT
24592459
#define BED_OVERSHOOT 10
24602460
#endif
2461-
#define BED_MAX_TARGET (BED_MAXTEMP - (BED_OVERSHOOT))
2461+
#define BED_MAX_TARGET ((BED_MAXTEMP) - (BED_OVERSHOOT))
24622462
#else
24632463
#undef PIDTEMPBED
24642464
#undef PREHEAT_BEFORE_LEVELING
@@ -2469,8 +2469,8 @@
24692469
#ifndef COOLER_OVERSHOOT
24702470
#define COOLER_OVERSHOOT 2
24712471
#endif
2472-
#define COOLER_MIN_TARGET (COOLER_MINTEMP + (COOLER_OVERSHOOT))
2473-
#define COOLER_MAX_TARGET (COOLER_MAXTEMP - (COOLER_OVERSHOOT))
2472+
#define COOLER_MIN_TARGET ((COOLER_MINTEMP) + (COOLER_OVERSHOOT))
2473+
#define COOLER_MAX_TARGET ((COOLER_MAXTEMP) - (COOLER_OVERSHOOT))
24742474
#endif
24752475

24762476
#if HAS_TEMP_HOTEND || HAS_HEATED_BED || HAS_TEMP_CHAMBER || HAS_TEMP_PROBE || HAS_TEMP_COOLER || HAS_TEMP_BOARD || HAS_TEMP_SOC
@@ -2482,7 +2482,7 @@
24822482
#ifndef CHAMBER_OVERSHOOT
24832483
#define CHAMBER_OVERSHOOT 10
24842484
#endif
2485-
#define CHAMBER_MAX_TARGET (CHAMBER_MAXTEMP - (CHAMBER_OVERSHOOT))
2485+
#define CHAMBER_MAX_TARGET ((CHAMBER_MAXTEMP) - (CHAMBER_OVERSHOOT))
24862486
#else
24872487
#undef PIDTEMPCHAMBER
24882488
#endif

Marlin/src/lcd/e3v2/jyersui/dwin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
#define MAX_FLOW_RATE 299
115115
#define MIN_FLOW_RATE 10
116116

117-
#define MAX_E_TEMP (HEATER_0_MAXTEMP - HOTEND_OVERSHOOT)
117+
#define MAX_E_TEMP thermalManager.hotend_max_target(0)
118118
#define MIN_E_TEMP 0
119119
#endif
120120

Marlin/src/lcd/e3v2/proui/dwin.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@
154154
#endif
155155

156156
// Editable temperature limits
157-
#define MIN_ETEMP 0
158-
#define MAX_ETEMP (thermalManager.hotend_maxtemp[0] - (HOTEND_OVERSHOOT))
157+
#define MIN_ETEMP 0
158+
#define MAX_ETEMP thermalManager.hotend_max_target(0)
159159
#define MIN_BEDTEMP 0
160160
#define MAX_BEDTEMP BED_MAX_TARGET
161161

Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,7 @@ void AnycubicTFT::getCommandFromTFT() {
697697
case 18: { // A18 set fan speed
698698
float fanPercent;
699699
if (codeSeen('S')) {
700-
fanPercent = codeValue();
701-
fanPercent = constrain(fanPercent, 0, 100);
700+
fanPercent = constrain(codeValue(), 0, 100);
702701
setTargetFan_percent(fanPercent, FAN0);
703702
}
704703
else

Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ namespace Anycubic {
10111011
#if HAS_HOTEND
10121012
else if (control_index == TXT_HOTEND_TARGET || control_index == TXT_ADJUST_HOTEND) { // hotend target temp
10131013
control_value = (uint16_t(data_buf[4]) << 8) | uint16_t(data_buf[5]);
1014-
temp = constrain(uint16_t(control_value), 0, HEATER_0_MAXTEMP);
1014+
temp = constrain(uint16_t(control_value), 0, thermalManager.hotend_max_target(0));
10151015
setTargetTemp_celsius(temp, E0);
10161016
//sprintf(str_buf,"%u/%u", (uint16_t)thermalManager.degHotend(0), uint16_t(control_value));
10171017
//sendTxtToTFT(str_buf, TXT_PRINT_HOTEND);
@@ -1021,7 +1021,7 @@ namespace Anycubic {
10211021
#if HAS_HEATED_BED
10221022
else if (control_index == TXT_BED_TARGET || control_index == TXT_ADJUST_BED) {// bed target temp
10231023
control_value = (uint16_t(data_buf[4]) << 8) | uint16_t(data_buf[5]);
1024-
temp = constrain(uint16_t(control_value), 0, BED_MAXTEMP);
1024+
temp = constrain(uint16_t(control_value), 0, BED_MAX_TARGET);
10251025
setTargetTemp_celsius(temp, BED);
10261026
//sprintf(str_buf,"%u/%u", uint16_t(thermalManager.degBed()), uint16_t(control_value));
10271027
//sendTxtToTFT(str_buf, TXT_PRINT_BED);

Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -379,21 +379,21 @@ void DGUSScreenHandler::handleTemperatureChanged(DGUS_VP_Variable &var, void *va
379379
default: return;
380380
#if HAS_HOTEND
381381
case VP_T_E0_Set:
382-
NOMORE(newvalue, HEATER_0_MAXTEMP);
382+
NOMORE(newvalue, thermalManager.hotend_max_target(0));
383383
thermalManager.setTargetHotend(newvalue, 0);
384384
acceptedvalue = thermalManager.degTargetHotend(0);
385385
break;
386386
#endif
387387
#if HAS_MULTI_HOTEND
388388
case VP_T_E1_Set:
389-
NOMORE(newvalue, HEATER_1_MAXTEMP);
389+
NOMORE(newvalue, thermalManager.hotend_max_target(1));
390390
thermalManager.setTargetHotend(newvalue, 1);
391391
acceptedvalue = thermalManager.degTargetHotend(1);
392392
break;
393393
#endif
394394
#if HAS_HEATED_BED
395395
case VP_T_Bed_Set:
396-
NOMORE(newvalue, BED_MAXTEMP);
396+
NOMORE(newvalue, BED_MAX_TARGET);
397397
thermalManager.setTargetBed(newvalue);
398398
acceptedvalue = thermalManager.degTargetBed();
399399
break;

Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -809,15 +809,19 @@ void DGUSRxHandler::pidSetTemp(DGUS_VP &vp, void *data_ptr) {
809809

810810
switch (screen.pid_heater) {
811811
default: return;
812-
case DGUS_Data::Heater::BED:
813-
temp = constrain(temp, BED_MINTEMP, BED_MAX_TARGET);
814-
break;
815-
case DGUS_Data::Heater::H0:
816-
temp = constrain(temp, HEATER_0_MINTEMP, (HEATER_0_MAXTEMP - HOTEND_OVERSHOOT));
817-
break;
812+
#if HAS_HEATED_BED
813+
case DGUS_Data::Heater::BED:
814+
LIMIT(temp, BED_MINTEMP, BED_MAX_TARGET);
815+
break;
816+
#endif
817+
#if HAS_HOTEND
818+
case DGUS_Data::Heater::H0:
819+
LIMIT(temp, celsius_t(HEATER_0_MINTEMP), thermalManager.hotend_max_target(0));
820+
break;
821+
#endif
818822
#if HAS_MULTI_HOTEND
819823
case DGUS_Data::Heater::H1:
820-
temp = constrain(temp, HEATER_1_MINTEMP, (HEATER_1_MAXTEMP - HOTEND_OVERSHOOT));
824+
LIMIT(temp, celsius_t(HEATER_1_MINTEMP), thermalManager.hotend_max_target(0));
821825
break;
822826
#endif
823827
}

Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ uint16_t DGUSScreenHandler::filament_length = DGUS_DEFAULT_FILAMENT_LEN;
5151
char DGUSScreenHandler::gcode[] = "";
5252

5353
DGUS_Data::Heater DGUSScreenHandler::pid_heater = DGUS_Data::Heater::H0;
54-
uint16_t DGUSScreenHandler::pid_temp = DGUS_PLA_TEMP_HOTEND;
54+
celsius_t DGUSScreenHandler::pid_temp = DGUS_PLA_TEMP_HOTEND;
5555
uint8_t DGUSScreenHandler::pid_cycles = 5;
5656

5757
bool DGUSScreenHandler::settings_ready = false;

Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class DGUSScreenHandler {
106106
static char gcode[DGUS_GCODE_LEN + 1];
107107

108108
static DGUS_Data::Heater pid_heater;
109-
static uint16_t pid_temp;
109+
static celsius_t pid_temp;
110110
static uint8_t pid_cycles;
111111

112112
static bool wait_continue;

Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
#include "../ui_api.h"
3333
#include "../../../module/stepper.h"
34+
#include "../../../module/temperature.h"
3435
#include "../../../module/printcounter.h"
36+
3537
#if ENABLED(ADVANCED_PAUSE_FEATURE)
3638
#include "../../../feature/pause.h"
3739
#endif
@@ -266,15 +268,19 @@ void DGUSTxHandler::tempMax(DGUS_VP &vp) {
266268

267269
switch (vp.addr) {
268270
default: return;
269-
case DGUS_Addr::TEMP_Max_Bed:
270-
temp = BED_MAX_TARGET;
271-
break;
272-
case DGUS_Addr::TEMP_Max_H0:
273-
temp = HEATER_0_MAXTEMP - HOTEND_OVERSHOOT;
274-
break;
271+
#if HAS_HEATED_BED
272+
case DGUS_Addr::TEMP_Max_Bed:
273+
temp = BED_MAX_TARGET;
274+
break;
275+
#endif
276+
#if HAS_HOTEND
277+
case DGUS_Addr::TEMP_Max_H0:
278+
temp = thermalManager.hotend_max_target(0);
279+
break;
280+
#endif
275281
#if HAS_MULTI_HOTEND
276282
case DGUS_Addr::TEMP_Max_H1:
277-
temp = HEATER_1_MAXTEMP - HOTEND_OVERSHOOT;
283+
temp = thermalManager.hotend_max_target(1);
278284
break;
279285
#endif
280286
}

Marlin/src/lcd/menu/menu_configuration.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ void menu_advanced_settings();
262262

263263
if (c.timeout) GCODES_ITEM(MSG_HOTEND_IDLE_DISABLE, F("M87"));
264264
EDIT_ITEM(int3, MSG_TIMEOUT, &c.timeout, 0, 999);
265-
EDIT_ITEM(int3, MSG_TEMPERATURE, &c.trigger, 0, HEATER_0_MAXTEMP);
266-
EDIT_ITEM(int3, MSG_HOTEND_IDLE_NOZZLE_TARGET, &c.nozzle_target, 0, HEATER_0_MAXTEMP);
267-
EDIT_ITEM(int3, MSG_HOTEND_IDLE_BED_TARGET, &c.bed_target, 0, BED_MAXTEMP);
265+
EDIT_ITEM(int3, MSG_TEMPERATURE, &c.trigger, 0, thermalManager.hotend_max_target(0));
266+
EDIT_ITEM(int3, MSG_HOTEND_IDLE_NOZZLE_TARGET, &c.nozzle_target, 0, thermalManager.hotend_max_target(0));
267+
EDIT_ITEM(int3, MSG_HOTEND_IDLE_BED_TARGET, &c.bed_target, 0, BED_MAX_TARGET);
268268

269269
END_MENU();
270270
}
@@ -397,10 +397,10 @@ void menu_advanced_settings();
397397
#if HAS_PREHEAT && DISABLED(SLIM_LCD_MENUS)
398398

399399
void _menu_configuration_preheat_settings() {
400-
#define _MINTEMP_ITEM(N) HEATER_##N##_MINTEMP,
401-
#define _MAXTEMP_ITEM(N) HEATER_##N##_MAXTEMP,
402-
#define MINTEMP_ALL _MIN(REPEAT(HOTENDS, _MINTEMP_ITEM) 999)
403-
#define MAXTEMP_ALL _MAX(REPEAT(HOTENDS, _MAXTEMP_ITEM) 0)
400+
#define _MIN_ITEM(N) HEATER_##N##_MINTEMP,
401+
#define _MAX_ITEM(N) thermalManager.hotend_max_target(0),
402+
#define MINTARGET_ALL _MIN(REPEAT(HOTENDS, _MIN_ITEM) 999)
403+
#define MAXTARGET_ALL _MAX(REPEAT(HOTENDS, _MAX_ITEM) 0)
404404
const uint8_t m = MenuItemBase::itemIndex;
405405
START_MENU();
406406
STATIC_ITEM_F(ui.get_preheat_label(m), SS_DEFAULT|SS_INVERT);
@@ -410,7 +410,7 @@ void menu_advanced_settings();
410410
EDIT_ITEM_N(percent, m, MSG_FAN_SPEED, &editable.uint8, 0, 255, []{ ui.material_preset[MenuItemBase::itemIndex].fan_speed = editable.uint8; });
411411
#endif
412412
#if HAS_TEMP_HOTEND
413-
EDIT_ITEM(int3, MSG_NOZZLE, &ui.material_preset[m].hotend_temp, MINTEMP_ALL, MAXTEMP_ALL - (HOTEND_OVERSHOOT));
413+
EDIT_ITEM(int3, MSG_NOZZLE, &ui.material_preset[m].hotend_temp, MINTARGET_ALL, MAXTARGET_ALL);
414414
#endif
415415
#if HAS_HEATED_BED
416416
EDIT_ITEM(int3, MSG_BED, &ui.material_preset[m].bed_temp, BED_MINTEMP, BED_MAX_TARGET);

Marlin/src/module/temperature.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,13 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
301301

302302
// Sanity-check max readable temperatures
303303
#define CHECK_MAXTEMP_(N,M,S) static_assert( \
304-
S >= 998 || M <= _MAX(TT_NAME(S)[0].celsius, TT_NAME(S)[COUNT(TT_NAME(S)) - 1].celsius) - HOTEND_OVERSHOOT, \
304+
S >= 998 || M <= _MAX(TT_NAME(S)[0].celsius, TT_NAME(S)[COUNT(TT_NAME(S)) - 1].celsius) - (HOTEND_OVERSHOOT), \
305305
"HEATER_" STRINGIFY(N) "_MAXTEMP (" STRINGIFY(M) ") is too high for thermistor_" STRINGIFY(S) ".h with HOTEND_OVERSHOOT=" STRINGIFY(HOTEND_OVERSHOOT) ".");
306306
#define CHECK_MAXTEMP(N) TERN(TEMP_SENSOR_##N##_IS_THERMISTOR, CHECK_MAXTEMP_, CODE_0)(N, HEATER_##N##_MAXTEMP, TEMP_SENSOR_##N)
307307
REPEAT(HOTENDS, CHECK_MAXTEMP)
308308

309309
#if HAS_PREHEAT
310-
#define CHECK_PREHEAT__(N,P,T,M) static_assert(T <= M - HOTEND_OVERSHOOT, "PREHEAT_" STRINGIFY(P) "_TEMP_HOTEND (" STRINGIFY(T) ") must be less than HEATER_" STRINGIFY(N) "_MAXTEMP (" STRINGIFY(M) ") - " STRINGIFY(HOTEND_OVERSHOOT) ".");
310+
#define CHECK_PREHEAT__(N,P,T,M) static_assert(T <= (M) - (HOTEND_OVERSHOOT), "PREHEAT_" STRINGIFY(P) "_TEMP_HOTEND (" STRINGIFY(T) ") must be less than HEATER_" STRINGIFY(N) "_MAXTEMP (" STRINGIFY(M) ") - " STRINGIFY(HOTEND_OVERSHOOT) ".");
311311
#define CHECK_PREHEAT_(N,P) CHECK_PREHEAT__(N, P, PREHEAT_##P##_TEMP_HOTEND, HEATER_##N##_MAXTEMP)
312312
#define CHECK_PREHEAT(P) REPEAT2(HOTENDS, CHECK_PREHEAT_, P)
313313
#if PREHEAT_COUNT >= 1
@@ -1694,7 +1694,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id OPTARG(ERR_INCLUDE_T
16941694
}
16951695

16961696
float pid_output = power * 254.0f / mpc.heater_power + 1.0f; // Ensure correct quantization into a range of 0 to 127
1697-
pid_output = constrain(pid_output, 0, MPC_MAX);
1697+
LIMIT(pid_output, 0, MPC_MAX);
16981698

16991699
/* <-- add a slash to enable
17001700
static uint32_t nexttime = millis() + 1000;

Marlin/src/module/temperature.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ class Temperature {
597597
#if HAS_HOTEND
598598
static hotend_info_t temp_hotend[HOTENDS];
599599
static constexpr celsius_t hotend_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP, HEATER_5_MAXTEMP, HEATER_6_MAXTEMP, HEATER_7_MAXTEMP);
600-
static celsius_t hotend_max_target(const uint8_t e) { return hotend_maxtemp[e] - (HOTEND_OVERSHOOT); }
600+
static constexpr celsius_t hotend_max_target(const uint8_t e) { return hotend_maxtemp[e] - (HOTEND_OVERSHOOT); }
601601
#endif
602602

603603
#if HAS_HEATED_BED

0 commit comments

Comments
 (0)