mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-26 21:36:21 +00:00
🧑💻 Add Temperature::is_above_target
This commit is contained in:
parent
984a758621
commit
0e72c90f49
@ -1213,7 +1213,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
|
||||
Popup_Handler(ETemp);
|
||||
else {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(2)) {
|
||||
Popup_Handler(Heating);
|
||||
thermalManager.wait_for_hotend(0);
|
||||
}
|
||||
@ -1356,7 +1356,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
Popup_Handler(ETemp);
|
||||
}
|
||||
else {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(2)) {
|
||||
Popup_Handler(Heating);
|
||||
thermalManager.wait_for_hotend(0);
|
||||
Redraw_Menu();
|
||||
@ -1743,7 +1743,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
|
||||
Popup_Handler(ETemp);
|
||||
else {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(2)) {
|
||||
Popup_Handler(Heating);
|
||||
thermalManager.wait_for_hotend(0);
|
||||
}
|
||||
@ -1762,7 +1762,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
Popup_Handler(ETemp);
|
||||
}
|
||||
else {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(2)) {
|
||||
Popup_Handler(Heating);
|
||||
thermalManager.wait_for_hotend(0);
|
||||
}
|
||||
@ -1780,7 +1780,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
|
||||
Popup_Handler(ETemp);
|
||||
else {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(2)) {
|
||||
Popup_Handler(Heating);
|
||||
thermalManager.wait_for_hotend(0);
|
||||
}
|
||||
@ -4505,7 +4505,7 @@ void CrealityDWINClass::Popup_Control() {
|
||||
if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
|
||||
Popup_Handler(ETemp);
|
||||
else {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(-2)) {
|
||||
if (thermalManager.temp_hotend[0].is_below_target(2)) {
|
||||
Popup_Handler(Heating);
|
||||
thermalManager.wait_for_hotend(0);
|
||||
}
|
||||
|
@ -1599,22 +1599,25 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
|
||||
#endif
|
||||
|
||||
#if HEATER_IDLE_HANDLER
|
||||
if (heater_idle[IDLE_INDEX_BED].timed_out) {
|
||||
const bool bed_timed_out = heater_idle[IDLE_INDEX_BED].timed_out;
|
||||
if (bed_timed_out) {
|
||||
temp_bed.soft_pwm_amount = 0;
|
||||
if (DISABLED(PIDTEMPBED)) WRITE_HEATER_BED(LOW);
|
||||
}
|
||||
else
|
||||
#else
|
||||
constexpr bool bed_timed_out = false;
|
||||
#endif
|
||||
{
|
||||
|
||||
if (!bed_timed_out) {
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
temp_bed.soft_pwm_amount = WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP) ? (int)get_pid_output_bed() >> 1 : 0;
|
||||
#else
|
||||
// Check if temperature is within the correct band
|
||||
if (WITHIN(temp_bed.celsius, BED_MINTEMP, BED_MAXTEMP)) {
|
||||
#if ENABLED(BED_LIMIT_SWITCHING)
|
||||
if (temp_bed.celsius >= temp_bed.target + BED_HYSTERESIS)
|
||||
if (temp_bed.is_above_target((BED_HYSTERESIS) - 1))
|
||||
temp_bed.soft_pwm_amount = 0;
|
||||
else if (temp_bed.is_below_target(-(BED_HYSTERESIS) + 1))
|
||||
else if (temp_bed.is_below_target((BED_HYSTERESIS) - 1))
|
||||
temp_bed.soft_pwm_amount = MAX_BED_POWER >> 1;
|
||||
#else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
|
||||
temp_bed.soft_pwm_amount = temp_bed.is_below_target() ? MAX_BED_POWER >> 1 : 0;
|
||||
@ -1641,7 +1644,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
|
||||
#endif
|
||||
|
||||
#if ENABLED(THERMAL_PROTECTION_CHAMBER)
|
||||
if (degChamber() > CHAMBER_MAXTEMP) maxtemp_error(H_CHAMBER);
|
||||
if (degChamber() > (CHAMBER_MAXTEMP)) maxtemp_error(H_CHAMBER);
|
||||
#endif
|
||||
|
||||
#if WATCH_CHAMBER
|
||||
@ -1669,13 +1672,12 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
|
||||
#if CHAMBER_FAN_MODE == 0
|
||||
fan_chamber_pwm = CHAMBER_FAN_BASE;
|
||||
#elif CHAMBER_FAN_MODE == 1
|
||||
fan_chamber_pwm = (temp_chamber.celsius > temp_chamber.target) ? (CHAMBER_FAN_BASE) + (CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target) : 0;
|
||||
fan_chamber_pwm = temp_chamber.is_above_target() ? (CHAMBER_FAN_BASE) + (CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target) : 0;
|
||||
#elif CHAMBER_FAN_MODE == 2
|
||||
fan_chamber_pwm = (CHAMBER_FAN_BASE) + (CHAMBER_FAN_FACTOR) * ABS(temp_chamber.celsius - temp_chamber.target);
|
||||
if (temp_chamber.soft_pwm_amount)
|
||||
fan_chamber_pwm += (CHAMBER_FAN_FACTOR) * 2;
|
||||
if (temp_chamber.soft_pwm_amount) fan_chamber_pwm += (CHAMBER_FAN_FACTOR) * 2;
|
||||
#elif CHAMBER_FAN_MODE == 3
|
||||
fan_chamber_pwm = CHAMBER_FAN_BASE + _MAX((CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target), 0);
|
||||
fan_chamber_pwm = (CHAMBER_FAN_BASE) + _MAX((CHAMBER_FAN_FACTOR) * (temp_chamber.celsius - temp_chamber.target), 0);
|
||||
#endif
|
||||
NOMORE(fan_chamber_pwm, 255);
|
||||
set_fan_speed(CHAMBER_FAN_INDEX, fan_chamber_pwm);
|
||||
@ -1688,7 +1690,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
|
||||
#ifndef MIN_COOLING_SLOPE_DEG_CHAMBER_VENT
|
||||
#define MIN_COOLING_SLOPE_DEG_CHAMBER_VENT 1.5
|
||||
#endif
|
||||
if (!flag_chamber_excess_heat && temp_chamber.celsius - temp_chamber.target >= HIGH_EXCESS_HEAT_LIMIT) {
|
||||
if (!flag_chamber_excess_heat && temp_chamber.is_above_target((HIGH_EXCESS_HEAT_LIMIT) - 1)) {
|
||||
// Open vent after MIN_COOLING_SLOPE_TIME_CHAMBER_VENT seconds if the
|
||||
// temperature didn't drop at least MIN_COOLING_SLOPE_DEG_CHAMBER_VENT
|
||||
if (next_cool_check_ms_2 == 0 || ELAPSED(ms, next_cool_check_ms_2)) {
|
||||
@ -1702,7 +1704,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
|
||||
next_cool_check_ms_2 = 0;
|
||||
old_temp = 9999;
|
||||
}
|
||||
if (flag_chamber_excess_heat && (temp_chamber.target - temp_chamber.celsius >= LOW_EXCESS_HEAT_LIMIT))
|
||||
if (flag_chamber_excess_heat && temp_chamber.is_above_target((LOW_EXCESS_HEAT_LIMIT) - 1))
|
||||
flag_chamber_excess_heat = false;
|
||||
#endif
|
||||
}
|
||||
@ -1734,9 +1736,9 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
|
||||
}
|
||||
else {
|
||||
#if ENABLED(CHAMBER_LIMIT_SWITCHING)
|
||||
if (temp_chamber.celsius >= temp_chamber.target + TEMP_CHAMBER_HYSTERESIS)
|
||||
if (temp_chamber.is_above_target((TEMP_CHAMBER_HYSTERESIS) - 1))
|
||||
temp_chamber.soft_pwm_amount = 0;
|
||||
else if (temp_chamber.is_below_target(-(TEMP_CHAMBER_HYSTERESIS) + 1))
|
||||
else if (temp_chamber.is_below_target((TEMP_CHAMBER_HYSTERESIS) - 1))
|
||||
temp_chamber.soft_pwm_amount = (MAX_CHAMBER_POWER) >> 1;
|
||||
#else
|
||||
temp_chamber.soft_pwm_amount = temp_chamber.is_below_target() ? (MAX_CHAMBER_POWER) >> 1 : 0;
|
||||
@ -1788,20 +1790,18 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
|
||||
if (temp_cooler.target == 0) temp_cooler.target = COOLER_MIN_TARGET;
|
||||
if (ELAPSED(ms, next_cooler_check_ms)) {
|
||||
next_cooler_check_ms = ms + COOLER_CHECK_INTERVAL;
|
||||
if (temp_cooler.celsius > temp_cooler.target) {
|
||||
temp_cooler.soft_pwm_amount = temp_cooler.celsius > temp_cooler.target ? MAX_COOLER_POWER : 0;
|
||||
flag_cooler_state = temp_cooler.soft_pwm_amount > 0 ? true : false; // used to allow M106 fan control when cooler is disabled
|
||||
if (temp_cooler.is_above_target()) { // too warm?
|
||||
temp_cooler.soft_pwm_amount = MAX_COOLER_POWER;
|
||||
#if ENABLED(COOLER_FAN)
|
||||
int16_t fan_cooler_pwm = (COOLER_FAN_BASE) + (COOLER_FAN_FACTOR) * ABS(temp_cooler.celsius - temp_cooler.target);
|
||||
NOMORE(fan_cooler_pwm, 255);
|
||||
set_fan_speed(COOLER_FAN_INDEX, fan_cooler_pwm); // Set cooler fan pwm
|
||||
const int16_t fan_cooler_pwm = (COOLER_FAN_BASE) + (COOLER_FAN_FACTOR) * ABS(temp_cooler.celsius - temp_cooler.target);
|
||||
set_fan_speed(COOLER_FAN_INDEX, _MIN(fan_cooler_pwm, 255)); // Set cooler fan pwm
|
||||
cooler_fan_flush_ms = ms + 5000;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
temp_cooler.soft_pwm_amount = 0;
|
||||
#if ENABLED(COOLER_FAN)
|
||||
set_fan_speed(COOLER_FAN_INDEX, temp_cooler.celsius > temp_cooler.target - 2 ? COOLER_FAN_BASE : 0);
|
||||
set_fan_speed(COOLER_FAN_INDEX, temp_cooler.is_above_target(-2) ? COOLER_FAN_BASE : 0);
|
||||
#endif
|
||||
WRITE_HEATER_COOLER(LOW);
|
||||
}
|
||||
|
@ -421,7 +421,8 @@ public:
|
||||
typedef struct HeaterInfo : public TempInfo {
|
||||
celsius_t target;
|
||||
uint8_t soft_pwm_amount;
|
||||
bool is_below_target(const celsius_t offs=0) const { return (celsius < (target + offs)); }
|
||||
bool is_below_target(const celsius_t offs=0) const { return (target - celsius > offs); } // celsius < target - offs
|
||||
bool is_above_target(const celsius_t offs=0) const { return (celsius - target > offs); } // celsius > target + offs
|
||||
} heater_info_t;
|
||||
|
||||
// A heater with PID stabilization
|
||||
|
Loading…
Reference in New Issue
Block a user