🩹 Fix some temp constraints

This commit is contained in:
Scott Lahteine 2024-01-09 22:41:00 -06:00
parent 25caae1e8c
commit cb291e8d00
14 changed files with 52 additions and 43 deletions

View file

@ -615,7 +615,7 @@ void GcodeSuite::G26() {
// If any preset or temperature was specified // If any preset or temperature was specified
if (noztemp) { 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."); SERIAL_ECHOLNPGM("?Specified nozzle temperature not plausible.");
return; return;
} }

View file

@ -2458,7 +2458,7 @@
#ifndef BED_OVERSHOOT #ifndef BED_OVERSHOOT
#define BED_OVERSHOOT 10 #define BED_OVERSHOOT 10
#endif #endif
#define BED_MAX_TARGET (BED_MAXTEMP - (BED_OVERSHOOT)) #define BED_MAX_TARGET ((BED_MAXTEMP) - (BED_OVERSHOOT))
#else #else
#undef PIDTEMPBED #undef PIDTEMPBED
#undef PREHEAT_BEFORE_LEVELING #undef PREHEAT_BEFORE_LEVELING
@ -2469,8 +2469,8 @@
#ifndef COOLER_OVERSHOOT #ifndef COOLER_OVERSHOOT
#define COOLER_OVERSHOOT 2 #define COOLER_OVERSHOOT 2
#endif #endif
#define COOLER_MIN_TARGET (COOLER_MINTEMP + (COOLER_OVERSHOOT)) #define COOLER_MIN_TARGET ((COOLER_MINTEMP) + (COOLER_OVERSHOOT))
#define COOLER_MAX_TARGET (COOLER_MAXTEMP - (COOLER_OVERSHOOT)) #define COOLER_MAX_TARGET ((COOLER_MAXTEMP) - (COOLER_OVERSHOOT))
#endif #endif
#if HAS_TEMP_HOTEND || HAS_HEATED_BED || HAS_TEMP_CHAMBER || HAS_TEMP_PROBE || HAS_TEMP_COOLER || HAS_TEMP_BOARD || HAS_TEMP_SOC #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 #ifndef CHAMBER_OVERSHOOT
#define CHAMBER_OVERSHOOT 10 #define CHAMBER_OVERSHOOT 10
#endif #endif
#define CHAMBER_MAX_TARGET (CHAMBER_MAXTEMP - (CHAMBER_OVERSHOOT)) #define CHAMBER_MAX_TARGET ((CHAMBER_MAXTEMP) - (CHAMBER_OVERSHOOT))
#else #else
#undef PIDTEMPCHAMBER #undef PIDTEMPCHAMBER
#endif #endif

View file

@ -114,7 +114,7 @@
#define MAX_FLOW_RATE 299 #define MAX_FLOW_RATE 299
#define MIN_FLOW_RATE 10 #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 #define MIN_E_TEMP 0
#endif #endif

View file

@ -155,7 +155,7 @@
// Editable temperature limits // Editable temperature limits
#define MIN_ETEMP 0 #define MIN_ETEMP 0
#define MAX_ETEMP (thermalManager.hotend_maxtemp[0] - (HOTEND_OVERSHOOT)) #define MAX_ETEMP thermalManager.hotend_max_target(0)
#define MIN_BEDTEMP 0 #define MIN_BEDTEMP 0
#define MAX_BEDTEMP BED_MAX_TARGET #define MAX_BEDTEMP BED_MAX_TARGET

View file

@ -697,8 +697,7 @@ void AnycubicTFT::getCommandFromTFT() {
case 18: { // A18 set fan speed case 18: { // A18 set fan speed
float fanPercent; float fanPercent;
if (codeSeen('S')) { if (codeSeen('S')) {
fanPercent = codeValue(); fanPercent = constrain(codeValue(), 0, 100);
fanPercent = constrain(fanPercent, 0, 100);
setTargetFan_percent(fanPercent, FAN0); setTargetFan_percent(fanPercent, FAN0);
} }
else else

View file

@ -1011,7 +1011,7 @@ namespace Anycubic {
#if HAS_HOTEND #if HAS_HOTEND
else if (control_index == TXT_HOTEND_TARGET || control_index == TXT_ADJUST_HOTEND) { // hotend target temp 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]); 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); setTargetTemp_celsius(temp, E0);
//sprintf(str_buf,"%u/%u", (uint16_t)thermalManager.degHotend(0), uint16_t(control_value)); //sprintf(str_buf,"%u/%u", (uint16_t)thermalManager.degHotend(0), uint16_t(control_value));
//sendTxtToTFT(str_buf, TXT_PRINT_HOTEND); //sendTxtToTFT(str_buf, TXT_PRINT_HOTEND);
@ -1021,7 +1021,7 @@ namespace Anycubic {
#if HAS_HEATED_BED #if HAS_HEATED_BED
else if (control_index == TXT_BED_TARGET || control_index == TXT_ADJUST_BED) {// bed target temp 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]); 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); setTargetTemp_celsius(temp, BED);
//sprintf(str_buf,"%u/%u", uint16_t(thermalManager.degBed()), uint16_t(control_value)); //sprintf(str_buf,"%u/%u", uint16_t(thermalManager.degBed()), uint16_t(control_value));
//sendTxtToTFT(str_buf, TXT_PRINT_BED); //sendTxtToTFT(str_buf, TXT_PRINT_BED);

View file

@ -379,21 +379,21 @@ void DGUSScreenHandler::handleTemperatureChanged(DGUS_VP_Variable &var, void *va
default: return; default: return;
#if HAS_HOTEND #if HAS_HOTEND
case VP_T_E0_Set: case VP_T_E0_Set:
NOMORE(newvalue, HEATER_0_MAXTEMP); NOMORE(newvalue, thermalManager.hotend_max_target(0));
thermalManager.setTargetHotend(newvalue, 0); thermalManager.setTargetHotend(newvalue, 0);
acceptedvalue = thermalManager.degTargetHotend(0); acceptedvalue = thermalManager.degTargetHotend(0);
break; break;
#endif #endif
#if HAS_MULTI_HOTEND #if HAS_MULTI_HOTEND
case VP_T_E1_Set: case VP_T_E1_Set:
NOMORE(newvalue, HEATER_1_MAXTEMP); NOMORE(newvalue, thermalManager.hotend_max_target(1));
thermalManager.setTargetHotend(newvalue, 1); thermalManager.setTargetHotend(newvalue, 1);
acceptedvalue = thermalManager.degTargetHotend(1); acceptedvalue = thermalManager.degTargetHotend(1);
break; break;
#endif #endif
#if HAS_HEATED_BED #if HAS_HEATED_BED
case VP_T_Bed_Set: case VP_T_Bed_Set:
NOMORE(newvalue, BED_MAXTEMP); NOMORE(newvalue, BED_MAX_TARGET);
thermalManager.setTargetBed(newvalue); thermalManager.setTargetBed(newvalue);
acceptedvalue = thermalManager.degTargetBed(); acceptedvalue = thermalManager.degTargetBed();
break; break;

View file

@ -809,15 +809,19 @@ void DGUSRxHandler::pidSetTemp(DGUS_VP &vp, void *data_ptr) {
switch (screen.pid_heater) { switch (screen.pid_heater) {
default: return; default: return;
#if HAS_HEATED_BED
case DGUS_Data::Heater::BED: case DGUS_Data::Heater::BED:
temp = constrain(temp, BED_MINTEMP, BED_MAX_TARGET); LIMIT(temp, BED_MINTEMP, BED_MAX_TARGET);
break; break;
#endif
#if HAS_HOTEND
case DGUS_Data::Heater::H0: case DGUS_Data::Heater::H0:
temp = constrain(temp, HEATER_0_MINTEMP, (HEATER_0_MAXTEMP - HOTEND_OVERSHOOT)); LIMIT(temp, celsius_t(HEATER_0_MINTEMP), thermalManager.hotend_max_target(0));
break; break;
#endif
#if HAS_MULTI_HOTEND #if HAS_MULTI_HOTEND
case DGUS_Data::Heater::H1: 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; break;
#endif #endif
} }

View file

@ -51,7 +51,7 @@ uint16_t DGUSScreenHandler::filament_length = DGUS_DEFAULT_FILAMENT_LEN;
char DGUSScreenHandler::gcode[] = ""; char DGUSScreenHandler::gcode[] = "";
DGUS_Data::Heater DGUSScreenHandler::pid_heater = DGUS_Data::Heater::H0; 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; uint8_t DGUSScreenHandler::pid_cycles = 5;
bool DGUSScreenHandler::settings_ready = false; bool DGUSScreenHandler::settings_ready = false;

View file

@ -106,7 +106,7 @@ public:
static char gcode[DGUS_GCODE_LEN + 1]; static char gcode[DGUS_GCODE_LEN + 1];
static DGUS_Data::Heater pid_heater; static DGUS_Data::Heater pid_heater;
static uint16_t pid_temp; static celsius_t pid_temp;
static uint8_t pid_cycles; static uint8_t pid_cycles;
static bool wait_continue; static bool wait_continue;

View file

@ -31,7 +31,9 @@
#include "../ui_api.h" #include "../ui_api.h"
#include "../../../module/stepper.h" #include "../../../module/stepper.h"
#include "../../../module/temperature.h"
#include "../../../module/printcounter.h" #include "../../../module/printcounter.h"
#if ENABLED(ADVANCED_PAUSE_FEATURE) #if ENABLED(ADVANCED_PAUSE_FEATURE)
#include "../../../feature/pause.h" #include "../../../feature/pause.h"
#endif #endif
@ -266,15 +268,19 @@ void DGUSTxHandler::tempMax(DGUS_VP &vp) {
switch (vp.addr) { switch (vp.addr) {
default: return; default: return;
#if HAS_HEATED_BED
case DGUS_Addr::TEMP_Max_Bed: case DGUS_Addr::TEMP_Max_Bed:
temp = BED_MAX_TARGET; temp = BED_MAX_TARGET;
break; break;
#endif
#if HAS_HOTEND
case DGUS_Addr::TEMP_Max_H0: case DGUS_Addr::TEMP_Max_H0:
temp = HEATER_0_MAXTEMP - HOTEND_OVERSHOOT; temp = thermalManager.hotend_max_target(0);
break; break;
#endif
#if HAS_MULTI_HOTEND #if HAS_MULTI_HOTEND
case DGUS_Addr::TEMP_Max_H1: case DGUS_Addr::TEMP_Max_H1:
temp = HEATER_1_MAXTEMP - HOTEND_OVERSHOOT; temp = thermalManager.hotend_max_target(1);
break; break;
#endif #endif
} }

View file

@ -262,9 +262,9 @@ void menu_advanced_settings();
if (c.timeout) GCODES_ITEM(MSG_HOTEND_IDLE_DISABLE, F("M87")); if (c.timeout) GCODES_ITEM(MSG_HOTEND_IDLE_DISABLE, F("M87"));
EDIT_ITEM(int3, MSG_TIMEOUT, &c.timeout, 0, 999); EDIT_ITEM(int3, MSG_TIMEOUT, &c.timeout, 0, 999);
EDIT_ITEM(int3, MSG_TEMPERATURE, &c.trigger, 0, HEATER_0_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, HEATER_0_MAXTEMP); 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_MAXTEMP); EDIT_ITEM(int3, MSG_HOTEND_IDLE_BED_TARGET, &c.bed_target, 0, BED_MAX_TARGET);
END_MENU(); END_MENU();
} }
@ -397,10 +397,10 @@ void menu_advanced_settings();
#if HAS_PREHEAT && DISABLED(SLIM_LCD_MENUS) #if HAS_PREHEAT && DISABLED(SLIM_LCD_MENUS)
void _menu_configuration_preheat_settings() { void _menu_configuration_preheat_settings() {
#define _MINTEMP_ITEM(N) HEATER_##N##_MINTEMP, #define _MIN_ITEM(N) HEATER_##N##_MINTEMP,
#define _MAXTEMP_ITEM(N) HEATER_##N##_MAXTEMP, #define _MAX_ITEM(N) thermalManager.hotend_max_target(0),
#define MINTEMP_ALL _MIN(REPEAT(HOTENDS, _MINTEMP_ITEM) 999) #define MINTARGET_ALL _MIN(REPEAT(HOTENDS, _MIN_ITEM) 999)
#define MAXTEMP_ALL _MAX(REPEAT(HOTENDS, _MAXTEMP_ITEM) 0) #define MAXTARGET_ALL _MAX(REPEAT(HOTENDS, _MAX_ITEM) 0)
const uint8_t m = MenuItemBase::itemIndex; const uint8_t m = MenuItemBase::itemIndex;
START_MENU(); START_MENU();
STATIC_ITEM_F(ui.get_preheat_label(m), SS_DEFAULT|SS_INVERT); 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; }); EDIT_ITEM_N(percent, m, MSG_FAN_SPEED, &editable.uint8, 0, 255, []{ ui.material_preset[MenuItemBase::itemIndex].fan_speed = editable.uint8; });
#endif #endif
#if HAS_TEMP_HOTEND #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 #endif
#if HAS_HEATED_BED #if HAS_HEATED_BED
EDIT_ITEM(int3, MSG_BED, &ui.material_preset[m].bed_temp, BED_MINTEMP, BED_MAX_TARGET); EDIT_ITEM(int3, MSG_BED, &ui.material_preset[m].bed_temp, BED_MINTEMP, BED_MAX_TARGET);

View file

@ -301,13 +301,13 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
// Sanity-check max readable temperatures // Sanity-check max readable temperatures
#define CHECK_MAXTEMP_(N,M,S) static_assert( \ #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) "."); "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) #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) REPEAT(HOTENDS, CHECK_MAXTEMP)
#if HAS_PREHEAT #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_(N,P) CHECK_PREHEAT__(N, P, PREHEAT_##P##_TEMP_HOTEND, HEATER_##N##_MAXTEMP)
#define CHECK_PREHEAT(P) REPEAT2(HOTENDS, CHECK_PREHEAT_, P) #define CHECK_PREHEAT(P) REPEAT2(HOTENDS, CHECK_PREHEAT_, P)
#if PREHEAT_COUNT >= 1 #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 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 /* <-- add a slash to enable
static uint32_t nexttime = millis() + 1000; static uint32_t nexttime = millis() + 1000;

View file

@ -597,7 +597,7 @@ class Temperature {
#if HAS_HOTEND #if HAS_HOTEND
static hotend_info_t temp_hotend[HOTENDS]; 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 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 #endif
#if HAS_HEATED_BED #if HAS_HEATED_BED