From 9de9e37539a7c0f489ebc4ef19934f94e0239ef8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 1 Jan 2018 18:03:18 -0600 Subject: [PATCH] Some temperature code cleanup --- Marlin/Marlin_main.cpp | 2 +- Marlin/temperature.cpp | 54 ++++++++++++++++++------------------------ Marlin/temperature.h | 10 ++++---- 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 7502147f8..40c7c19ee 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -6737,7 +6737,7 @@ inline void gcode_M17() { HOTEND_LOOP() thermalManager.start_heater_idle_timer(e, nozzle_timeout); - wait_for_user = true; /* Wait for user to load filament */ + wait_for_user = true; // Wait for user to load filament nozzle_timed_out = false; #if HAS_BUZZER diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 750f08467..6add38795 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -830,10 +830,8 @@ void Temperature::manage_heater() { #endif #if HEATER_IDLE_HANDLER - if (bed_idle_timeout_exceeded) - { + if (bed_idle_timeout_exceeded) { soft_pwm_amount_bed = 0; - #if DISABLED(PIDTEMPBED) WRITE_HEATER_BED(LOW); #endif @@ -843,23 +841,17 @@ void Temperature::manage_heater() { { #if ENABLED(PIDTEMPBED) soft_pwm_amount_bed = WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP) ? (int)get_pid_output_bed() >> 1 : 0; - - #elif ENABLED(BED_LIMIT_SWITCHING) + #else // Check if temperature is within the correct band if (WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP)) { - if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS) - soft_pwm_amount_bed = 0; - else if (current_temperature_bed <= target_temperature_bed - (BED_HYSTERESIS)) - soft_pwm_amount_bed = MAX_BED_POWER >> 1; - } - else { - soft_pwm_amount_bed = 0; - WRITE_HEATER_BED(LOW); - } - #else // !PIDTEMPBED && !BED_LIMIT_SWITCHING - // Check if temperature is within the correct range - if (WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP)) { - soft_pwm_amount_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0; + #if ENABLED(BED_LIMIT_SWITCHING) + if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS) + soft_pwm_amount_bed = 0; + else if (current_temperature_bed <= target_temperature_bed - (BED_HYSTERESIS)) + soft_pwm_amount_bed = MAX_BED_POWER >> 1; + #else // !PIDTEMPBED && !BED_LIMIT_SWITCHING + soft_pwm_amount_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0; + #endif } else { soft_pwm_amount_bed = 0; @@ -1257,7 +1249,7 @@ void Temperature::init() { #endif } #endif // BED_MAXTEMP - #endif //HAS_TEMP_BED + #endif // HAS_TEMP_BED #if ENABLED(PROBING_HEATERS_OFF) paused = false; @@ -1311,7 +1303,7 @@ void Temperature::init() { millis_t Temperature::thermal_runaway_bed_timer; #endif - void Temperature::thermal_runaway_protection(Temperature::TRState * const state, millis_t * const timer, const float current, const float target, const int8_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc) { + void Temperature::thermal_runaway_protection(Temperature::TRState * const state, millis_t * const timer, const float ¤t, const float &target, const int8_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc) { static float tr_target_temperature[HOTENDS + 1] = { 0.0 }; @@ -1334,22 +1326,22 @@ void Temperature::init() { #if HEATER_IDLE_HANDLER // If the heater idle timeout expires, restart - if (heater_id >= 0 && heater_idle_timeout_exceeded[heater_id]) { + if ((heater_id >= 0 && heater_idle_timeout_exceeded[heater_id]) + #if HAS_TEMP_BED + || (heater_id < 0 && bed_idle_timeout_exceeded) + #endif + ) { *state = TRInactive; tr_target_temperature[heater_index] = 0; } - #if HAS_TEMP_BED - else if (heater_id < 0 && bed_idle_timeout_exceeded) { - *state = TRInactive; - tr_target_temperature[heater_index] = 0; - } - #endif else #endif - // If the target temperature changes, restart - if (tr_target_temperature[heater_index] != target) { - tr_target_temperature[heater_index] = target; - *state = target > 0 ? TRFirstHeating : TRInactive; + { + // If the target temperature changes, restart + if (tr_target_temperature[heater_index] != target) { + tr_target_temperature[heater_index] = target; + *state = target > 0 ? TRFirstHeating : TRInactive; + } } switch (*state) { diff --git a/Marlin/temperature.h b/Marlin/temperature.h index da05b1ce2..037fa2d0f 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -508,7 +508,8 @@ class Temperature { #endif #if HEATER_IDLE_HANDLER - static void start_heater_idle_timer(uint8_t e, millis_t timeout_ms) { + + static void start_heater_idle_timer(const uint8_t e, const millis_t timeout_ms) { #if HOTENDS == 1 UNUSED(e); #endif @@ -535,7 +536,7 @@ class Temperature { } #if HAS_TEMP_BED - static void start_bed_idle_timer(millis_t timeout_ms) { + static void start_bed_idle_timer(const millis_t timeout_ms) { bed_idle_timeout_ms = millis() + timeout_ms; bed_idle_timeout_exceeded = false; } @@ -550,7 +551,8 @@ class Temperature { FORCE_INLINE static bool is_bed_idle() { return bed_idle_timeout_exceeded; } #endif - #endif + + #endif // HEATER_IDLE_HANDLER #if HAS_TEMP_HOTEND || HAS_TEMP_BED static void print_heaterstates(); @@ -592,7 +594,7 @@ class Temperature { typedef enum TRState { TRInactive, TRFirstHeating, TRStable, TRRunaway } TRstate; - static void thermal_runaway_protection(TRState * const state, millis_t * const timer, const float current, const float target, const int8_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc); + static void thermal_runaway_protection(TRState * const state, millis_t * const timer, const float ¤t, const float &target, const int8_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc); #if ENABLED(THERMAL_PROTECTION_HOTENDS) static TRState thermal_runaway_state_machine[HOTENDS];