Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 14, 2020
1 parent bfcf7dc commit dfde61a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
Expand Down
38 changes: 19 additions & 19 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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
Expand All @@ -1974,53 +1974,53 @@ 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:

#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));
Expand Down
16 changes: 5 additions & 11 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,18 +354,12 @@ 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
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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand All @@ -861,7 +855,7 @@ 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) {
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
Expand Down

0 comments on commit dfde61a

Please sign in to comment.