From d3d306a341d967ed1781d141eb1d8aefca11d2f9 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 13 Sep 2020 19:06:29 -0500 Subject: [PATCH] clean --- Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp | 2 +- Marlin/src/lcd/dogm/status_screen_DOGM.cpp | 2 +- Marlin/src/lcd/extui/ui_api.cpp | 2 +- Marlin/src/module/temperature.cpp | 42 ++++++++++----------- Marlin/src/module/temperature.h | 20 ++++------ 5 files changed, 30 insertions(+), 38 deletions(-) diff --git a/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp b/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp index 468c71f88b754..0a1177d63ee95 100644 --- a/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp @@ -536,7 +536,7 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char pr #if !HEATER_IDLE_HANDLER UNUSED(blink); #else - if (!blink && thermalManager.heater_idle[idle_index_for_id(heater_id)].timed_out) { + if (!blink && thermalManager.heater_idle[thermalManager.idle_index_for_id(heater_id)].timed_out) { lcd_put_wchar(' '); if (t2 >= 10) lcd_put_wchar(' '); if (t2 >= 100) lcd_put_wchar(' '); diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index 61bfd15e0e68f..4b51c2949b231 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -327,7 +327,7 @@ FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, cons if (PAGE_UNDER(7)) { #if HEATER_IDLE_HANDLER - const bool dodraw = (blink || !thermalManager.heater_idle[IDLE_INDEX_BED].timed_out); + const bool dodraw = (blink || !thermalManager.heater_idle[thermalManager.IDLE_INDEX_BED].timed_out); #else constexpr bool dodraw = true; #endif diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index a5e1630d3774d..4d65429bf1d24 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -233,7 +233,7 @@ namespace ExtUI { bool isHeaterIdle(const heater_t heater) { #if HEATER_IDLE_HANDLER switch (heater) { - TERN_(HAS_HEATED_BED, case BED: return thermalManager.heater_idle[IDLE_INDEX_BED].timed_out); + TERN_(HAS_HEATED_BED, case BED: return thermalManager.heater_idle[thermalManager.IDLE_INDEX_BED].timed_out); TERN_(HAS_HEATED_CHAMBER, case CHAMBER: return false); // Chamber has no idle timer default: return TERN0(HAS_HOTEND, thermalManager.heater_idle[heater - H0].timed_out); diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index b96b39e3d167c..e0fa6fa98f53e 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -1951,7 +1951,7 @@ void Temperature::init() { #if HEATER_IDLE_HANDLER // Convert the given heater_id_t to an idle array index - const uint8_t idle_index = idle_index_for_id(heater_id); + const IdleIndex idle_index = idle_index_for_id(heater_id); #endif /** @@ -1963,8 +1963,8 @@ void Temperature::init() { default: SERIAL_ECHO(heater_id); } SERIAL_ECHOLNPAIR( - " ; sizeof(this->running_temp):", sizeof(this->running_temp), - " ; State:", this->state, " ; Timer:", this->timer, " ; Temperature:", current, " ; Target Temp:", target + " ; sizeof(running_temp):", sizeof(running_temp), + " ; State:", state, " ; Timer:", timer, " ; Temperature:", current, " ; Target Temp:", target #if HEATER_IDLE_HANDLER , " ; Idle Timeout:", heater_idle[idle_index].timed_out #endif @@ -1974,27 +1974,27 @@ void Temperature::init() { #if HEATER_IDLE_HANDLER // If the heater idle timeout expires, restart if (heater_idle[idle_index].timed_out) { - this->state = TRInactive; - this->running_temp = 0; + state = TRInactive; + running_temp = 0; } else #endif { // If the target temperature changes, restart - if (this->running_temp != target) { - this->running_temp = target; - this->state = target > 0 ? TRFirstHeating : TRInactive; + if (running_temp != target) { + running_temp = target; + state = target > 0 ? TRFirstHeating : TRInactive; } } - switch (this->state) { + switch (state) { // Inactive state waits for a target temperature to be set case TRInactive: break; // When first heating, wait for the temperature to be reached then go to Stable state case TRFirstHeating: - if (current < this->running_temp) break; - this->state = TRStable; + if (current < running_temp) break; + state = TRStable; // While the temperature is stable watch for a bad temperature case TRStable: @@ -2002,25 +2002,25 @@ void Temperature::init() { #if ENABLED(ADAPTIVE_FAN_SLOWING) if (adaptive_fan_slowing && heater_id >= 0) { const int fan_index = _MIN(heater_id, FAN_COUNT - 1); - if (fan_speed[fan_index] == 0 || current >= this->running_temp - (hysteresis_degc * 0.25f)) + if (fan_speed[fan_index] == 0 || current >= running_temp - (hysteresis_degc * 0.25f)) fan_speed_scaler[fan_index] = 128; - else if (current >= this->running_temp - (hysteresis_degc * 0.3335f)) + else if (current >= running_temp - (hysteresis_degc * 0.3335f)) fan_speed_scaler[fan_index] = 96; - else if (current >= this->running_temp - (hysteresis_degc * 0.5f)) + else if (current >= running_temp - (hysteresis_degc * 0.5f)) fan_speed_scaler[fan_index] = 64; - else if (current >= this->running_temp - (hysteresis_degc * 0.8f)) + else if (current >= running_temp - (hysteresis_degc * 0.8f)) fan_speed_scaler[fan_index] = 32; else fan_speed_scaler[fan_index] = 0; } #endif - if (current >= this->running_temp - hysteresis_degc) { - this->timer = millis() + SEC_TO_MS(period_seconds); + if (current >= running_temp - hysteresis_degc) { + timer = millis() + SEC_TO_MS(period_seconds); break; } - else if (PENDING(millis(), this->timer)) break; - this->state = TRRunaway; + else if (PENDING(millis(), timer)) break; + state = TRRunaway; case TRRunaway: TERN_(DWIN_CREALITY_LCD, Popup_Window_Temperature(0)); @@ -2338,9 +2338,7 @@ void Temperature::readings_ready() { #else #define BEDCMP(A,B) ((A)>(B)) #endif - const bool bed_on = temp_bed.target > 0 - || TERN0(PIDTEMPBED, temp_bed.soft_pwm_amount) > 0 - ; + const bool bed_on = (temp_bed.target > 0) || TERN0(PIDTEMPBED, temp_bed.soft_pwm_amount > 0); if (BEDCMP(temp_bed.raw, maxtemp_raw_BED)) max_temp_error(H_BED); if (bed_on && BEDCMP(mintemp_raw_BED, temp_bed.raw)) min_temp_error(H_BED); #endif diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index cc2fc59fa39c3..50378993ea540 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -354,22 +354,16 @@ class Temperature { #if ENABLED(HAS_HEATED_BED) IDLE_INDEX_BED, #endif - #if ENABLED(HAS_HEATED_CHAMBER) - IDLE_INDEX_CHAMBER, - #endif NR_HEATER_IDLE }; #undef _ENUM_FOR_E // Convert the given heater_id_t to idle array index - inline uint8_t idle_index_for_id(const int8_t heater_id) { - #if HAS_HEATED_CHAMBER - if (heater_id == H_CHAMBER) return IDLE_INDEX_CHAMBER; - #endif + static inline IdleIndex idle_index_for_id(const int8_t heater_id) { #if HAS_HEATED_BED if (heater_id == H_BED) return IDLE_INDEX_BED; #endif - return _MAX(heater_id, 0); + return (IdleIndex)_MAX(heater_id, 0); } static heater_idle_t heater_idle[NR_HEATER_IDLE]; @@ -772,7 +766,7 @@ class Temperature { #if HEATER_IDLE_HANDLER static void reset_hotend_idle_timer(const uint8_t E_NAME) { - hotend_idle[HOTEND_INDEX].reset(); + heater_idle[HOTEND_INDEX].reset(); start_watching_hotend(HOTEND_INDEX); } @@ -844,9 +838,9 @@ class Temperature { #if HAS_THERMAL_PROTECTION - // Indices and size for the heater_idle array + // Indices and size for the tr_state_machine array #define _ENUM_FOR_E(N) RUNAWAY_IND_E##N, - enum IdleIndex : uint8_t { + enum RunawayIndex : uint8_t { #if ENABLED(THERMAL_PROTECTION_HOTENDS) REPEAT(HOTENDS, _ENUM_FOR_E) #endif @@ -861,14 +855,14 @@ class Temperature { #undef _ENUM_FOR_E // Convert the given heater_id_t to runaway state array index - inline uint8_t runaway_index_for_id(const int8_t heater_id) { + static inline RunawayIndex runaway_index_for_id(const int8_t heater_id) { #if HAS_THERMALLY_PROTECTED_CHAMBER if (heater_id == H_CHAMBER) return RUNAWAY_IND_CHAMBER; #endif #if HAS_THERMALLY_PROTECTED_BED if (heater_id == H_BED) return RUNAWAY_IND_BED; #endif - return _MAX(heater_id, 0); + return (RunawayIndex)_MAX(heater_id, 0); } enum TRState : char { TRInactive, TRFirstHeating, TRStable, TRRunaway };