diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index 5c7f9e1f6d..7fae11783e 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -615,7 +615,7 @@ void GcodeSuite::G26() { // If any preset or temperature was specified if (noztemp) { - if (!WITHIN(noztemp, 165, (HEATER_0_MAXTEMP) - (HOTEND_OVERSHOOT))) { + if (!WITHIN(noztemp, 165, thermalManager.hotend_max_target(active_extruder))) { SERIAL_ECHOLNPGM("?Specified nozzle temperature not plausible."); return; } diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index eabb011300..076b1301d5 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -2458,7 +2458,7 @@ #ifndef BED_OVERSHOOT #define BED_OVERSHOOT 10 #endif - #define BED_MAX_TARGET (BED_MAXTEMP - (BED_OVERSHOOT)) + #define BED_MAX_TARGET ((BED_MAXTEMP) - (BED_OVERSHOOT)) #else #undef PIDTEMPBED #undef PREHEAT_BEFORE_LEVELING @@ -2469,8 +2469,8 @@ #ifndef COOLER_OVERSHOOT #define COOLER_OVERSHOOT 2 #endif - #define COOLER_MIN_TARGET (COOLER_MINTEMP + (COOLER_OVERSHOOT)) - #define COOLER_MAX_TARGET (COOLER_MAXTEMP - (COOLER_OVERSHOOT)) + #define COOLER_MIN_TARGET ((COOLER_MINTEMP) + (COOLER_OVERSHOOT)) + #define COOLER_MAX_TARGET ((COOLER_MAXTEMP) - (COOLER_OVERSHOOT)) #endif #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 @@ #ifndef CHAMBER_OVERSHOOT #define CHAMBER_OVERSHOOT 10 #endif - #define CHAMBER_MAX_TARGET (CHAMBER_MAXTEMP - (CHAMBER_OVERSHOOT)) + #define CHAMBER_MAX_TARGET ((CHAMBER_MAXTEMP) - (CHAMBER_OVERSHOOT)) #else #undef PIDTEMPCHAMBER #endif diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index 296f46f68a..8d0482f410 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp @@ -114,7 +114,7 @@ #define MAX_FLOW_RATE 299 #define MIN_FLOW_RATE 10 - #define MAX_E_TEMP (HEATER_0_MAXTEMP - HOTEND_OVERSHOOT) + #define MAX_E_TEMP thermalManager.hotend_max_target(0) #define MIN_E_TEMP 0 #endif diff --git a/Marlin/src/lcd/e3v2/proui/dwin.cpp b/Marlin/src/lcd/e3v2/proui/dwin.cpp index 7520b46b60..b42a9a263b 100644 --- a/Marlin/src/lcd/e3v2/proui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/proui/dwin.cpp @@ -154,8 +154,8 @@ #endif // Editable temperature limits -#define MIN_ETEMP 0 -#define MAX_ETEMP (thermalManager.hotend_maxtemp[0] - (HOTEND_OVERSHOOT)) +#define MIN_ETEMP 0 +#define MAX_ETEMP thermalManager.hotend_max_target(0) #define MIN_BEDTEMP 0 #define MAX_BEDTEMP BED_MAX_TARGET diff --git a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp index 8b073652b0..f8cba15676 100644 --- a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp +++ b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp @@ -697,8 +697,7 @@ void AnycubicTFT::getCommandFromTFT() { case 18: { // A18 set fan speed float fanPercent; if (codeSeen('S')) { - fanPercent = codeValue(); - fanPercent = constrain(fanPercent, 0, 100); + fanPercent = constrain(codeValue(), 0, 100); setTargetFan_percent(fanPercent, FAN0); } else diff --git a/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp b/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp index 3209aa76f2..ed4f8c7367 100644 --- a/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp +++ b/Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp @@ -1011,7 +1011,7 @@ namespace Anycubic { #if HAS_HOTEND else if (control_index == TXT_HOTEND_TARGET || control_index == TXT_ADJUST_HOTEND) { // hotend target temp control_value = (uint16_t(data_buf[4]) << 8) | uint16_t(data_buf[5]); - temp = constrain(uint16_t(control_value), 0, HEATER_0_MAXTEMP); + temp = constrain(uint16_t(control_value), 0, thermalManager.hotend_max_target(0)); setTargetTemp_celsius(temp, E0); //sprintf(str_buf,"%u/%u", (uint16_t)thermalManager.degHotend(0), uint16_t(control_value)); //sendTxtToTFT(str_buf, TXT_PRINT_HOTEND); @@ -1021,7 +1021,7 @@ namespace Anycubic { #if HAS_HEATED_BED else if (control_index == TXT_BED_TARGET || control_index == TXT_ADJUST_BED) {// bed target temp control_value = (uint16_t(data_buf[4]) << 8) | uint16_t(data_buf[5]); - temp = constrain(uint16_t(control_value), 0, BED_MAXTEMP); + temp = constrain(uint16_t(control_value), 0, BED_MAX_TARGET); setTargetTemp_celsius(temp, BED); //sprintf(str_buf,"%u/%u", uint16_t(thermalManager.degBed()), uint16_t(control_value)); //sendTxtToTFT(str_buf, TXT_PRINT_BED); diff --git a/Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp index d440ea5375..dc2156a0e2 100644 --- a/Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp @@ -379,21 +379,21 @@ void DGUSScreenHandler::handleTemperatureChanged(DGUS_VP_Variable &var, void *va default: return; #if HAS_HOTEND case VP_T_E0_Set: - NOMORE(newvalue, HEATER_0_MAXTEMP); + NOMORE(newvalue, thermalManager.hotend_max_target(0)); thermalManager.setTargetHotend(newvalue, 0); acceptedvalue = thermalManager.degTargetHotend(0); break; #endif #if HAS_MULTI_HOTEND case VP_T_E1_Set: - NOMORE(newvalue, HEATER_1_MAXTEMP); + NOMORE(newvalue, thermalManager.hotend_max_target(1)); thermalManager.setTargetHotend(newvalue, 1); acceptedvalue = thermalManager.degTargetHotend(1); break; #endif #if HAS_HEATED_BED case VP_T_Bed_Set: - NOMORE(newvalue, BED_MAXTEMP); + NOMORE(newvalue, BED_MAX_TARGET); thermalManager.setTargetBed(newvalue); acceptedvalue = thermalManager.degTargetBed(); break; diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp index aa58e85692..c953b417a5 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp @@ -809,15 +809,19 @@ void DGUSRxHandler::pidSetTemp(DGUS_VP &vp, void *data_ptr) { switch (screen.pid_heater) { default: return; - case DGUS_Data::Heater::BED: - temp = constrain(temp, BED_MINTEMP, BED_MAX_TARGET); - break; - case DGUS_Data::Heater::H0: - temp = constrain(temp, HEATER_0_MINTEMP, (HEATER_0_MAXTEMP - HOTEND_OVERSHOOT)); - break; + #if HAS_HEATED_BED + case DGUS_Data::Heater::BED: + LIMIT(temp, BED_MINTEMP, BED_MAX_TARGET); + break; + #endif + #if HAS_HOTEND + case DGUS_Data::Heater::H0: + LIMIT(temp, celsius_t(HEATER_0_MINTEMP), thermalManager.hotend_max_target(0)); + break; + #endif #if HAS_MULTI_HOTEND case DGUS_Data::Heater::H1: - temp = constrain(temp, HEATER_1_MINTEMP, (HEATER_1_MAXTEMP - HOTEND_OVERSHOOT)); + LIMIT(temp, celsius_t(HEATER_1_MINTEMP), thermalManager.hotend_max_target(0)); break; #endif } diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp index 76aa3de872..703c56d1e1 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp @@ -51,7 +51,7 @@ uint16_t DGUSScreenHandler::filament_length = DGUS_DEFAULT_FILAMENT_LEN; char DGUSScreenHandler::gcode[] = ""; DGUS_Data::Heater DGUSScreenHandler::pid_heater = DGUS_Data::Heater::H0; -uint16_t DGUSScreenHandler::pid_temp = DGUS_PLA_TEMP_HOTEND; +celsius_t DGUSScreenHandler::pid_temp = DGUS_PLA_TEMP_HOTEND; uint8_t DGUSScreenHandler::pid_cycles = 5; bool DGUSScreenHandler::settings_ready = false; diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h index 27f7f92517..e5942ad44d 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h @@ -106,7 +106,7 @@ public: static char gcode[DGUS_GCODE_LEN + 1]; static DGUS_Data::Heater pid_heater; - static uint16_t pid_temp; + static celsius_t pid_temp; static uint8_t pid_cycles; static bool wait_continue; diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp index 037eafcc94..1212f715c0 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp @@ -31,7 +31,9 @@ #include "../ui_api.h" #include "../../../module/stepper.h" +#include "../../../module/temperature.h" #include "../../../module/printcounter.h" + #if ENABLED(ADVANCED_PAUSE_FEATURE) #include "../../../feature/pause.h" #endif @@ -266,15 +268,19 @@ void DGUSTxHandler::tempMax(DGUS_VP &vp) { switch (vp.addr) { default: return; - case DGUS_Addr::TEMP_Max_Bed: - temp = BED_MAX_TARGET; - break; - case DGUS_Addr::TEMP_Max_H0: - temp = HEATER_0_MAXTEMP - HOTEND_OVERSHOOT; - break; + #if HAS_HEATED_BED + case DGUS_Addr::TEMP_Max_Bed: + temp = BED_MAX_TARGET; + break; + #endif + #if HAS_HOTEND + case DGUS_Addr::TEMP_Max_H0: + temp = thermalManager.hotend_max_target(0); + break; + #endif #if HAS_MULTI_HOTEND case DGUS_Addr::TEMP_Max_H1: - temp = HEATER_1_MAXTEMP - HOTEND_OVERSHOOT; + temp = thermalManager.hotend_max_target(1); break; #endif } diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 7347f219e0..3280b23e5b 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -262,9 +262,9 @@ void menu_advanced_settings(); if (c.timeout) GCODES_ITEM(MSG_HOTEND_IDLE_DISABLE, F("M87")); EDIT_ITEM(int3, MSG_TIMEOUT, &c.timeout, 0, 999); - EDIT_ITEM(int3, MSG_TEMPERATURE, &c.trigger, 0, HEATER_0_MAXTEMP); - EDIT_ITEM(int3, MSG_HOTEND_IDLE_NOZZLE_TARGET, &c.nozzle_target, 0, HEATER_0_MAXTEMP); - EDIT_ITEM(int3, MSG_HOTEND_IDLE_BED_TARGET, &c.bed_target, 0, BED_MAXTEMP); + EDIT_ITEM(int3, MSG_TEMPERATURE, &c.trigger, 0, thermalManager.hotend_max_target(0)); + EDIT_ITEM(int3, MSG_HOTEND_IDLE_NOZZLE_TARGET, &c.nozzle_target, 0, thermalManager.hotend_max_target(0)); + EDIT_ITEM(int3, MSG_HOTEND_IDLE_BED_TARGET, &c.bed_target, 0, BED_MAX_TARGET); END_MENU(); } @@ -397,10 +397,10 @@ void menu_advanced_settings(); #if HAS_PREHEAT && DISABLED(SLIM_LCD_MENUS) void _menu_configuration_preheat_settings() { - #define _MINTEMP_ITEM(N) HEATER_##N##_MINTEMP, - #define _MAXTEMP_ITEM(N) HEATER_##N##_MAXTEMP, - #define MINTEMP_ALL _MIN(REPEAT(HOTENDS, _MINTEMP_ITEM) 999) - #define MAXTEMP_ALL _MAX(REPEAT(HOTENDS, _MAXTEMP_ITEM) 0) + #define _MIN_ITEM(N) HEATER_##N##_MINTEMP, + #define _MAX_ITEM(N) thermalManager.hotend_max_target(0), + #define MINTARGET_ALL _MIN(REPEAT(HOTENDS, _MIN_ITEM) 999) + #define MAXTARGET_ALL _MAX(REPEAT(HOTENDS, _MAX_ITEM) 0) const uint8_t m = MenuItemBase::itemIndex; START_MENU(); STATIC_ITEM_F(ui.get_preheat_label(m), SS_DEFAULT|SS_INVERT); @@ -410,7 +410,7 @@ void menu_advanced_settings(); EDIT_ITEM_N(percent, m, MSG_FAN_SPEED, &editable.uint8, 0, 255, []{ ui.material_preset[MenuItemBase::itemIndex].fan_speed = editable.uint8; }); #endif #if HAS_TEMP_HOTEND - EDIT_ITEM(int3, MSG_NOZZLE, &ui.material_preset[m].hotend_temp, MINTEMP_ALL, MAXTEMP_ALL - (HOTEND_OVERSHOOT)); + EDIT_ITEM(int3, MSG_NOZZLE, &ui.material_preset[m].hotend_temp, MINTARGET_ALL, MAXTARGET_ALL); #endif #if HAS_HEATED_BED EDIT_ITEM(int3, MSG_BED, &ui.material_preset[m].bed_temp, BED_MINTEMP, BED_MAX_TARGET); diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index c4920c2100..ad1daae762 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -301,13 +301,13 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED); // Sanity-check max readable temperatures #define CHECK_MAXTEMP_(N,M,S) static_assert( \ - S >= 998 || M <= _MAX(TT_NAME(S)[0].celsius, TT_NAME(S)[COUNT(TT_NAME(S)) - 1].celsius) - HOTEND_OVERSHOOT, \ + S >= 998 || M <= _MAX(TT_NAME(S)[0].celsius, TT_NAME(S)[COUNT(TT_NAME(S)) - 1].celsius) - (HOTEND_OVERSHOOT), \ "HEATER_" STRINGIFY(N) "_MAXTEMP (" STRINGIFY(M) ") is too high for thermistor_" STRINGIFY(S) ".h with HOTEND_OVERSHOOT=" STRINGIFY(HOTEND_OVERSHOOT) "."); #define CHECK_MAXTEMP(N) TERN(TEMP_SENSOR_##N##_IS_THERMISTOR, CHECK_MAXTEMP_, CODE_0)(N, HEATER_##N##_MAXTEMP, TEMP_SENSOR_##N) REPEAT(HOTENDS, CHECK_MAXTEMP) #if HAS_PREHEAT - #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) "."); + #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) "."); #define CHECK_PREHEAT_(N,P) CHECK_PREHEAT__(N, P, PREHEAT_##P##_TEMP_HOTEND, HEATER_##N##_MAXTEMP) #define CHECK_PREHEAT(P) REPEAT2(HOTENDS, CHECK_PREHEAT_, P) #if PREHEAT_COUNT >= 1 @@ -1694,7 +1694,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id OPTARG(ERR_INCLUDE_T } float pid_output = power * 254.0f / mpc.heater_power + 1.0f; // Ensure correct quantization into a range of 0 to 127 - pid_output = constrain(pid_output, 0, MPC_MAX); + LIMIT(pid_output, 0, MPC_MAX); /* <-- add a slash to enable static uint32_t nexttime = millis() + 1000; diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index c69a272adf..088a17ec1b 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -597,7 +597,7 @@ class Temperature { #if HAS_HOTEND static hotend_info_t temp_hotend[HOTENDS]; 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); - static celsius_t hotend_max_target(const uint8_t e) { return hotend_maxtemp[e] - (HOTEND_OVERSHOOT); } + static constexpr celsius_t hotend_max_target(const uint8_t e) { return hotend_maxtemp[e] - (HOTEND_OVERSHOOT); } #endif #if HAS_HEATED_BED