Refactor heater watch, job timer auto-start (#16725)

This commit is contained in:
Scott Lahteine
2020-01-30 03:24:43 -06:00
committed by GitHub
parent 50889c0f94
commit 9caf5c05e7
7 changed files with 113 additions and 57 deletions

View File

@ -220,10 +220,10 @@ Temperature thermalManager;
#endif // FAN_COUNT > 0
#if WATCH_HOTENDS
heater_watch_t Temperature::watch_hotend[HOTENDS]; // = { { 0 } }
hotend_watch_t Temperature::watch_hotend[HOTENDS]; // = { { 0 } }
#endif
#if HEATER_IDLE_HANDLER
heater_idle_t Temperature::hotend_idle[HOTENDS]; // = { { 0 } }
hotend_idle_t Temperature::hotend_idle[HOTENDS]; // = { { 0 } }
#endif
#if HAS_HEATED_BED
@ -236,13 +236,13 @@ Temperature thermalManager;
int16_t Temperature::maxtemp_raw_BED = HEATER_BED_RAW_HI_TEMP;
#endif
#if WATCH_BED
heater_watch_t Temperature::watch_bed; // = { 0 }
bed_watch_t Temperature::watch_bed; // = { 0 }
#endif
#if DISABLED(PIDTEMPBED)
millis_t Temperature::next_bed_check_ms;
#endif
#if HEATER_IDLE_HANDLER
heater_idle_t Temperature::bed_idle; // = { 0 }
hotend_idle_t Temperature::bed_idle; // = { 0 }
#endif
#endif // HAS_HEATED_BED
@ -256,7 +256,7 @@ Temperature thermalManager;
int16_t Temperature::maxtemp_raw_CHAMBER = HEATER_CHAMBER_RAW_HI_TEMP;
#endif
#if WATCH_CHAMBER
heater_watch_t Temperature::watch_chamber{0};
chamber_watch_t Temperature::watch_chamber{0};
#endif
millis_t Temperature::next_chamber_check_ms;
#endif // HAS_HEATED_CHAMBER
@ -1974,12 +1974,7 @@ void Temperature::init() {
*/
void Temperature::start_watching_hotend(const uint8_t E_NAME) {
const uint8_t ee = HOTEND_INDEX;
if (degTargetHotend(ee) && degHotend(ee) < degTargetHotend(ee) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
watch_hotend[ee].target = degHotend(ee) + WATCH_TEMP_INCREASE;
watch_hotend[ee].next_ms = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
}
else
watch_hotend[ee].next_ms = 0;
watch_hotend[ee].restart(degHotend(ee), degTargetHotend(ee));
}
#endif
@ -1990,12 +1985,7 @@ void Temperature::init() {
* This is called when the temperature is set. (M140, M190)
*/
void Temperature::start_watching_bed() {
if (degTargetBed() && degBed() < degTargetBed() - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) {
watch_bed.target = degBed() + WATCH_BED_TEMP_INCREASE;
watch_bed.next_ms = millis() + (WATCH_BED_TEMP_PERIOD) * 1000UL;
}
else
watch_bed.next_ms = 0;
watch_bed.restart(degBed(), degTargetBed());
}
#endif
@ -2006,12 +1996,7 @@ void Temperature::init() {
* This is called when the temperature is set. (M141, M191)
*/
void Temperature::start_watching_chamber() {
if (degChamber() < degTargetChamber() - (WATCH_CHAMBER_TEMP_INCREASE + TEMP_CHAMBER_HYSTERESIS + 1)) {
watch_chamber.target = degChamber() + WATCH_CHAMBER_TEMP_INCREASE;
watch_chamber.next_ms = millis() + (WATCH_CHAMBER_TEMP_PERIOD) * 1000UL;
}
else
watch_chamber.next_ms = 0;
watch_chamber.restart(degChamber(), degTargetChamber());
}
#endif
@ -2154,6 +2139,34 @@ void Temperature::disable_all_heaters() {
#endif
}
#if ENABLED(PRINTJOB_TIMER_AUTOSTART)
bool Temperature::over_autostart_threshold() {
#if HOTENDS
HOTEND_LOOP() if (degTargetHotend(e) < (EXTRUDE_MINTEMP) / 2) return true;
#endif
#if HAS_HEATED_BED
if (degTargetBed() > BED_MINTEMP) return true;
#endif
#if HAS_HEATED_CHAMBER
if (degTargetChamber() > CHAMBER_MINTEMP) return true;
#endif
return false;
}
void Temperature::check_timer_autostart(const bool can_start, const bool can_stop) {
if (over_autostart_threshold()) {
if (can_start) startOrResumeJob();
}
else if (can_stop) {
print_job_timer.stop();
ui.reset_status();
}
}
#endif
#if ENABLED(PROBING_HEATERS_OFF)
void Temperature::pause(const bool p) {
@ -2166,7 +2179,7 @@ void Temperature::disable_all_heaters() {
#endif
}
else {
HOTEND_LOOP() reset_heater_idle_timer(e);
HOTEND_LOOP() reset_hotend_idle_timer(e);
#if HAS_HEATED_BED
reset_bed_idle_timer();
#endif

View File

@ -228,15 +228,38 @@ typedef struct {
inline void start(const millis_t &ms) { timeout_ms = millis() + ms; timed_out = false; }
inline void reset() { timeout_ms = 0; timed_out = false; }
inline void expire() { start(0); }
} heater_idle_t;
} hotend_idle_t;
// Heater watch handling
typedef struct {
template <int INCREASE, int HYSTERESIS, millis_t PERIOD>
struct HeaterWatch {
uint16_t target;
millis_t next_ms;
inline bool elapsed(const millis_t &ms) { return next_ms && ELAPSED(ms, next_ms); }
inline bool elapsed() { return elapsed(millis()); }
} heater_watch_t;
inline void restart(const int16_t curr, const int16_t tgt) {
if (tgt) {
const int16_t newtarget = curr + INCREASE;
if (newtarget < tgt - HYSTERESIS - 1) {
target = newtarget;
next_ms = millis() + PERIOD * 1000UL;
return;
}
}
next_ms = 0;
}
};
#if WATCH_HOTENDS
typedef struct HeaterWatch<WATCH_TEMP_INCREASE, TEMP_HYSTERESIS, WATCH_TEMP_PERIOD> hotend_watch_t;
#endif
#if WATCH_BED
typedef struct HeaterWatch<WATCH_BED_TEMP_INCREASE, TEMP_BED_HYSTERESIS, WATCH_BED_TEMP_PERIOD> bed_watch_t;
#endif
#if WATCH_CHAMBER
typedef struct HeaterWatch<WATCH_CHAMBER_TEMP_INCREASE, TEMP_CHAMBER_HYSTERESIS, WATCH_CHAMBER_TEMP_PERIOD> chamber_watch_t;
#endif
// Temperature sensor read value ranges
typedef struct { int16_t raw_min, raw_max; } raw_range_t;
@ -345,12 +368,12 @@ class Temperature {
FORCE_INLINE static bool targetHotEnoughToExtrude(const uint8_t e) { return !targetTooColdToExtrude(e); }
#if HEATER_IDLE_HANDLER
static heater_idle_t hotend_idle[HOTENDS];
static hotend_idle_t hotend_idle[HOTENDS];
#if HAS_HEATED_BED
static heater_idle_t bed_idle;
static hotend_idle_t bed_idle;
#endif
#if HAS_HEATED_CHAMBER
static heater_idle_t chamber_idle;
static hotend_idle_t chamber_idle;
#endif
#endif
@ -363,7 +386,7 @@ class Temperature {
static volatile bool raw_temps_ready;
#if WATCH_HOTENDS
static heater_watch_t watch_hotend[HOTENDS];
static hotend_watch_t watch_hotend[HOTENDS];
#endif
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
@ -382,7 +405,7 @@ class Temperature {
#if HAS_HEATED_BED
#if WATCH_BED
static heater_watch_t watch_bed;
static bed_watch_t watch_bed;
#endif
#if DISABLED(PIDTEMPBED)
static millis_t next_bed_check_ms;
@ -397,7 +420,7 @@ class Temperature {
#if HAS_HEATED_CHAMBER
#if WATCH_CHAMBER
static heater_watch_t watch_chamber;
static chamber_watch_t watch_chamber;
#endif
static millis_t next_chamber_check_ms;
#ifdef CHAMBER_MINTEMP
@ -736,6 +759,14 @@ class Temperature {
*/
static void disable_all_heaters();
#if ENABLED(PRINTJOB_TIMER_AUTOSTART)
/**
* Methods to check if heaters are enabled, indicating an active job
*/
static bool over_autostart_threshold();
static void check_timer_autostart(const bool can_start, const bool can_stop);
#endif
/**
* Perform auto-tuning for hotend or bed in response to M303
*/
@ -768,7 +799,7 @@ class Temperature {
#if HEATER_IDLE_HANDLER
static void reset_heater_idle_timer(const uint8_t E_NAME) {
static void reset_hotend_idle_timer(const uint8_t E_NAME) {
hotend_idle[HOTEND_INDEX].reset();
start_watching_hotend(HOTEND_INDEX);
}