Skip to content

Commit

Permalink
🩹 Fix some temp constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jan 10, 2024
1 parent 25caae1 commit cb291e8
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/gcode/bedlevel/G26.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/e3v2/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 11 additions & 7 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class DGUSScreenHandler {
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;
Expand Down
20 changes: 13 additions & 7 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/lcd/menu/menu_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cb291e8

Please sign in to comment.