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 d3d306a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 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
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dogm/status_screen_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 20 additions & 22 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 Expand Up @@ -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
Expand Down
20 changes: 7 additions & 13 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
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,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 };
Expand Down

0 comments on commit d3d306a

Please sign in to comment.