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

@ -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);
}