@ -112,11 +112,9 @@ Temperature thermalManager;
bool Temperature : : adaptive_fan_slowing = true ;
# endif
hotend_info_t Temperature : : temp_hotend [ HOTENDS
# if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
+ 1
# if HOTENDS
hotend_info_t Temperature : : temp_hotend [ HOTEND_TEMPS ] ; // = { 0 }
# endif
] ; // = { 0 }
# if ENABLED(AUTO_POWER_E_FANS)
uint8_t Temperature : : autofan_speed [ HOTENDS ] ; // = { 0 }
@ -283,6 +281,7 @@ volatile bool Temperature::temp_meas_ready = false;
# define TEMPDIR(N) ((HEATER_##N##_RAW_LO_TEMP) < (HEATER_##N##_RAW_HI_TEMP) ? 1 : -1)
# if HOTENDS
// Init mintemp and maxtemp with extreme values to prevent false errors during startup
constexpr temp_range_t sensor_heater_0 { HEATER_0_RAW_LO_TEMP , HEATER_0_RAW_HI_TEMP , 0 , 16383 } ,
sensor_heater_1 { HEATER_1_RAW_LO_TEMP , HEATER_1_RAW_HI_TEMP , 0 , 16383 } ,
@ -292,6 +291,7 @@ constexpr temp_range_t sensor_heater_0 { HEATER_0_RAW_LO_TEMP, HEATER_0_RAW_HI_T
sensor_heater_5 { HEATER_5_RAW_LO_TEMP , HEATER_5_RAW_HI_TEMP , 0 , 16383 } ;
temp_range_t Temperature : : temp_range [ HOTENDS ] = ARRAY_BY_HOTENDS ( sensor_heater_0 , sensor_heater_1 , sensor_heater_2 , sensor_heater_3 , sensor_heater_4 , sensor_heater_5 ) ;
# endif
# ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
uint8_t Temperature : : consecutive_low_temperature_error [ HOTENDS ] = { 0 } ;
@ -627,17 +627,20 @@ temp_range_t Temperature::temp_range[HOTENDS] = ARRAY_BY_HOTENDS(sensor_heater_0
* Class and Instance Methods
*/
Temperature : : Temperature ( ) { }
int16_t Temperature : : getHeaterPower ( const heater_ind_t heater_id ) {
switch ( heater_id ) {
default : return temp_hotend [ heater_id ] . soft_pwm_amount ;
# if HAS_HEATED_BED
case H_BED : return temp_bed . soft_pwm_amount ;
# endif
# if HAS_HEATED_CHAMBER
case H_CHAMBER : return temp_chamber . soft_pwm_amount ;
# endif
default :
# if HOTENDS
return temp_hotend [ heater_id ] . soft_pwm_amount ;
# else
return 0 ;
# endif
}
}
@ -816,6 +819,8 @@ void Temperature::min_temp_error(const heater_ind_t heater) {
_temp_error ( heater , PSTR ( MSG_T_MINTEMP ) , TEMP_ERR_PSTR ( MSG_ERR_MINTEMP , heater ) ) ;
}
# if HOTENDS
float Temperature : : get_pid_output_hotend ( const uint8_t e ) {
# if HOTENDS == 1
# define _HOTEND_TEST true
@ -925,6 +930,8 @@ float Temperature::get_pid_output_hotend(const uint8_t e) {
return pid_output ;
}
# endif // HOTENDS
# if ENABLED(PIDTEMPBED)
float Temperature : : get_pid_output_bed ( ) {
@ -1025,9 +1032,9 @@ void Temperature::manage_heater() {
if ( temp_hotend [ 1 ] . celsius < _MAX ( HEATER_1_MINTEMP , HEATER_1_MAX6675_TMIN + .01 ) ) min_temp_error ( H_E1 ) ;
# endif
# if HAS_THERMAL_PROTECTION || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN || HEATER_IDLE_HANDLER
millis_t ms = millis ( ) ;
# endif
# if HOTENDS
HOTEND_LOOP ( ) {
# if ENABLED(THERMAL_PROTECTION_HOTENDS)
@ -1064,6 +1071,8 @@ void Temperature::manage_heater() {
} // HOTEND_LOOP
# endif // HOTENDS
# if HAS_AUTO_FAN
if ( ELAPSED ( ms , next_auto_fan_check_ms ) ) { // only need to check fan state very infrequently
checkExtruderAutoFans ( ) ;
@ -1206,6 +1215,8 @@ void Temperature::manage_heater() {
//temp_bed.soft_pwm_amount = WITHIN(temp_chamber.celsius, CHAMBER_MINTEMP, CHAMBER_MAXTEMP) ? (int)get_pid_output_chamber() >> 1 : 0;
# endif // HAS_HEATED_CHAMBER
UNUSED ( ms ) ;
}
# define TEMP_AD595(RAW) ((RAW) * 5.0 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET)
@ -1358,6 +1369,7 @@ void Temperature::manage_heater() {
}
# endif
# if HOTENDS
// Derived from RepRap FiveD extruder::getTemperature()
// For hot end temperature measurement.
float Temperature : : analog_to_celsius_hotend ( const int raw , const uint8_t e ) {
@ -1450,6 +1462,7 @@ float Temperature::analog_to_celsius_hotend(const int raw, const uint8_t e) {
return 0 ;
}
# endif // HOTENDS
# if HAS_HEATED_BED
// Derived from RepRap FiveD extruder::getTemperature()
@ -1500,7 +1513,9 @@ void Temperature::updateTemperaturesFromRawValues() {
# if ENABLED(HEATER_1_USES_MAX6675)
temp_hotend [ 1 ] . raw = READ_MAX6675 ( 1 ) ;
# endif
# if HOTENDS
HOTEND_LOOP ( ) temp_hotend [ e ] . celsius = analog_to_celsius_hotend ( temp_hotend [ e ] . raw , e ) ;
# endif
# if HAS_HEATED_BED
temp_bed . celsius = analog_to_celsius_bed ( temp_bed . raw ) ;
# endif
@ -1802,7 +1817,7 @@ void Temperature::init() {
# endif // HOTENDS > 2
# endif // HOTENDS > 1
# endif // HOTENDS > 1
# endif // HOTENDS
# if HAS_HEATED_BED
# ifdef BED_MINTEMP
@ -1976,7 +1991,9 @@ void Temperature::disable_all_heaters() {
planner . autotemp_enabled = false ;
# endif
# if HOTENDS
HOTEND_LOOP ( ) setTargetHotend ( 0 , e ) ;
# endif
# if HAS_HEATED_BED
setTargetBed ( 0 ) ;
@ -2238,10 +2255,12 @@ void Temperature::readings_ready() {
current_raw_filwidth = raw_filwidth_value > > 10 ; // Divide to get to 0-16384 range since we used 1/128 IIR filter approach
# endif
# if HOTENDS
HOTEND_LOOP ( ) temp_hotend [ e ] . reset ( ) ;
# if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
temp_hotend [ 1 ] . reset ( ) ;
# endif
# endif
# if HAS_HEATED_BED
temp_bed . reset ( ) ;
@ -2261,6 +2280,8 @@ void Temperature::readings_ready() {
joystick . z . reset ( ) ;
# endif
# if HOTENDS
static constexpr int8_t temp_dir [ ] = {
# if ENABLED(HEATER_0_USES_MAX6675)
0
@ -2311,6 +2332,8 @@ void Temperature::readings_ready() {
}
}
# endif // HOTENDS
# if HAS_HEATED_BED
# if TEMPDIR(BED) < 0
# define BEDCMP(A,B) ((A)<=(B))
@ -2399,11 +2422,9 @@ void Temperature::isr() {
static bool ADCKey_pressed = false ;
# endif
# if ENABLED(SLOW_PWM_HEATERS)
static uint8_t slow_pwm_count = 0 ;
# endif
# if HOTENDS
static SoftPWM soft_pwm_hotend [ HOTENDS ] ;
# endif
# if HAS_HEATED_BED
static SoftPWM soft_pwm_bed ;
@ -2414,6 +2435,8 @@ void Temperature::isr() {
# endif
# if DISABLED(SLOW_PWM_HEATERS)
# if HOTENDS || HAS_HEATED_BED || HAS_HEATED_CHAMBER
constexpr uint8_t pwm_mask =
# if ENABLED(SOFT_PWM_DITHER)
_BV ( SOFT_PWM_SCALE ) - 1
@ -2421,16 +2444,19 @@ void Temperature::isr() {
0
# endif
;
# define _PWM_MOD(N,S,T) do{ \
const bool on = S . add ( pwm_mask , T . soft_pwm_amount ) ; \
WRITE_HEATER_ # # N ( on ) ; \
} while ( 0 )
# endif
/**
* Standard heater PWM modulation
*/
if ( pwm_count_tmp > = 127 ) {
pwm_count_tmp - = 127 ;
# define _PWM_MOD(N,S,T) do{ \
const bool on = S . add ( pwm_mask , T . soft_pwm_amount ) ; \
WRITE_HEATER_ # # N ( on ) ; \
} while ( 0 )
# if HOTENDS
# define _PWM_MOD_E(N) _PWM_MOD(N,soft_pwm_hotend[N],temp_hotend[N])
_PWM_MOD_E ( 0 ) ;
# if HOTENDS > 1
@ -2448,6 +2474,7 @@ void Temperature::isr() {
# endif // HOTENDS > 3
# endif // HOTENDS > 2
# endif // HOTENDS > 1
# endif // HOTENDS
# if HAS_HEATED_BED
_PWM_MOD ( BED , soft_pwm_bed , temp_bed ) ;
@ -2538,6 +2565,8 @@ void Temperature::isr() {
# define _SLOW_PWM(NR,PWM,SRC) do{ PWM.count = SRC.soft_pwm_amount; _SLOW_SET(NR,PWM,(PWM.count > 0)); }while(0)
# define _PWM_OFF(NR,PWM) do{ if (PWM.count < slow_pwm_count) _SLOW_SET(NR,PWM,0); }while(0)
static uint8_t slow_pwm_count = 0 ;
if ( slow_pwm_count = = 0 ) {
# if HOTENDS
@ -2634,6 +2663,7 @@ void Temperature::isr() {
slow_pwm_count + + ;
slow_pwm_count & = 0x7F ;
# if HOTENDS
soft_pwm_hotend [ 0 ] . dec ( ) ;
# if HOTENDS > 1
soft_pwm_hotend [ 1 ] . dec ( ) ;
@ -2650,6 +2680,7 @@ void Temperature::isr() {
# endif // HOTENDS > 3
# endif // HOTENDS > 2
# endif // HOTENDS > 1
# endif // HOTENDS
# if HAS_HEATED_BED
soft_pwm_bed . dec ( ) ;
# endif
@ -2940,7 +2971,7 @@ void Temperature::isr() {
# endif // AUTO_REPORT_TEMPERATURES
# if H AS_DISPLAY
# if H OTENDS && H AS_DISPLAY
void Temperature : : set_heating_message ( const uint8_t e ) {
const bool heating = isHeatingHotend ( e ) ;
# if HOTENDS > 1