From 7659844012dd51b589ca4e910313fda345b80550 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 24 May 2022 21:16:03 +0200 Subject: [PATCH] Reimplement disable_heater to take immediate effect Split off setIsrTargetTemperatures and temp_mgr_pid() so that we can propagate the target temperatures instantaneously down the pid/pwm chain during emergencies. This reduces the amount of code in disable_heater() itself, making it a bit more maintenable. The bed still isn't disabled on-the-spot yet, due to the heatbed_pwm automaton. To be improved later. --- Firmware/temperature.cpp | 139 ++++++++++++++++++++++----------------- Firmware/temperature.h | 2 +- 2 files changed, 79 insertions(+), 62 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 338fb8261..d41217de8 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -909,45 +909,6 @@ void temp_runaway_stop(bool isPreheat, bool isBed) } #endif - -void disable_heater() -{ - setAllTargetHotends(0); - setTargetBed(0); - #if defined(TEMP_0_PIN) && TEMP_0_PIN > -1 - target_temperature[0]=0; - soft_pwm[0]=0; - #if defined(HEATER_0_PIN) && HEATER_0_PIN > -1 - WRITE(HEATER_0_PIN,LOW); - #endif - #endif - - #if defined(TEMP_1_PIN) && TEMP_1_PIN > -1 && EXTRUDERS > 1 - target_temperature[1]=0; - soft_pwm[1]=0; - #if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 - WRITE(HEATER_1_PIN,LOW); - #endif - #endif - - #if defined(TEMP_2_PIN) && TEMP_2_PIN > -1 && EXTRUDERS > 2 - target_temperature[2]=0; - soft_pwm[2]=0; - #if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 - WRITE(HEATER_2_PIN,LOW); - #endif - #endif - - #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 - target_temperature_bed=0; - soft_pwm_bed=0; - timer02_set_pwm0(soft_pwm_bed << 1); - bedPWMDisabled = 0; - #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 - //WRITE(HEATER_BED_PIN,LOW); - #endif - #endif -} //! codes of alert messages for the LCD - it is shorter to compare an uin8_t //! than raw const char * of the messages themselves. //! Could be used for MAXTEMP situations too - after reaching MAXTEMP and turning off the heater automagically @@ -1786,6 +1747,25 @@ bool has_temperature_compensation() #define ENABLE_TEMP_MGR_INTERRUPT() TIMSK5 |= (1< -1 && EXTRUDERS > 0 + WRITE(HEATER_0_PIN,LOW); +#endif +#if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 && EXTRUDERS > 1 + WRITE(HEATER_1_PIN,LOW); +#endif +#if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 && EXTRUDERS > 2 + WRITE(HEATER_2_PIN,LOW); +#endif +#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 + // TODO: this doesn't take immediate effect! + timer02_set_pwm0(0); + bedPWMDisabled = 0; +#endif + + CRITICAL_SECTION_END; +} diff --git a/Firmware/temperature.h b/Firmware/temperature.h index fe479e023..08de851f3 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -210,7 +210,7 @@ FORCE_INLINE bool isCoolingBed() { #define CHECK_ALL_HEATERS (checkAllHotends()||(target_temperature_bed!=0)) int getHeaterPower(int heater); -void disable_heater(); // Disable all heaters +void disable_heater(); // Disable all heaters *instantaneously* void updatePID();