My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

temperature.h 34KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * temperature.h - temperature controller
  25. */
  26. #include "thermistor/thermistors.h"
  27. #include "../inc/MarlinConfig.h"
  28. #if ENABLED(AUTO_POWER_CONTROL)
  29. #include "../feature/power.h"
  30. #endif
  31. #if ENABLED(AUTO_REPORT_TEMPERATURES)
  32. #include "../libs/autoreport.h"
  33. #endif
  34. #if HAS_FANCHECK
  35. #include "../feature/fancheck.h"
  36. #endif
  37. #ifndef SOFT_PWM_SCALE
  38. #define SOFT_PWM_SCALE 0
  39. #endif
  40. #define HOTEND_INDEX TERN(HAS_MULTI_HOTEND, e, 0)
  41. #define E_NAME TERN_(HAS_MULTI_HOTEND, e)
  42. // Element identifiers. Positive values are hotends. Negative values are other heaters or coolers.
  43. typedef enum : int8_t {
  44. H_REDUNDANT = HID_REDUNDANT,
  45. H_COOLER = HID_COOLER,
  46. H_PROBE = HID_PROBE,
  47. H_BOARD = HID_BOARD,
  48. H_CHAMBER = HID_CHAMBER,
  49. H_BED = HID_BED,
  50. H_E0 = HID_E0, H_E1, H_E2, H_E3, H_E4, H_E5, H_E6, H_E7,
  51. H_NONE = -128
  52. } heater_id_t;
  53. // PID storage
  54. typedef struct { float Kp, Ki, Kd; } PID_t;
  55. typedef struct { float Kp, Ki, Kd, Kc; } PIDC_t;
  56. typedef struct { float Kp, Ki, Kd, Kf; } PIDF_t;
  57. typedef struct { float Kp, Ki, Kd, Kc, Kf; } PIDCF_t;
  58. typedef
  59. #if BOTH(PID_EXTRUSION_SCALING, PID_FAN_SCALING)
  60. PIDCF_t
  61. #elif ENABLED(PID_EXTRUSION_SCALING)
  62. PIDC_t
  63. #elif ENABLED(PID_FAN_SCALING)
  64. PIDF_t
  65. #else
  66. PID_t
  67. #endif
  68. hotend_pid_t;
  69. #if ENABLED(PID_EXTRUSION_SCALING)
  70. typedef IF<(LPQ_MAX_LEN > 255), uint16_t, uint8_t>::type lpq_ptr_t;
  71. #endif
  72. #define PID_PARAM(F,H) _PID_##F(TERN(PID_PARAMS_PER_HOTEND, H, 0 & H)) // Always use 'H' to suppress warning
  73. #define _PID_Kp(H) TERN(PIDTEMP, Temperature::temp_hotend[H].pid.Kp, NAN)
  74. #define _PID_Ki(H) TERN(PIDTEMP, Temperature::temp_hotend[H].pid.Ki, NAN)
  75. #define _PID_Kd(H) TERN(PIDTEMP, Temperature::temp_hotend[H].pid.Kd, NAN)
  76. #if ENABLED(PIDTEMP)
  77. #define _PID_Kc(H) TERN(PID_EXTRUSION_SCALING, Temperature::temp_hotend[H].pid.Kc, 1)
  78. #define _PID_Kf(H) TERN(PID_FAN_SCALING, Temperature::temp_hotend[H].pid.Kf, 0)
  79. #else
  80. #define _PID_Kc(H) 1
  81. #define _PID_Kf(H) 0
  82. #endif
  83. /**
  84. * States for ADC reading in the ISR
  85. */
  86. enum ADCSensorState : char {
  87. StartSampling,
  88. #if HAS_TEMP_ADC_0
  89. PrepareTemp_0, MeasureTemp_0,
  90. #endif
  91. #if HAS_TEMP_ADC_BED
  92. PrepareTemp_BED, MeasureTemp_BED,
  93. #endif
  94. #if HAS_TEMP_ADC_CHAMBER
  95. PrepareTemp_CHAMBER, MeasureTemp_CHAMBER,
  96. #endif
  97. #if HAS_TEMP_ADC_COOLER
  98. PrepareTemp_COOLER, MeasureTemp_COOLER,
  99. #endif
  100. #if HAS_TEMP_ADC_PROBE
  101. PrepareTemp_PROBE, MeasureTemp_PROBE,
  102. #endif
  103. #if HAS_TEMP_ADC_BOARD
  104. PrepareTemp_BOARD, MeasureTemp_BOARD,
  105. #endif
  106. #if HAS_TEMP_ADC_REDUNDANT
  107. PrepareTemp_REDUNDANT, MeasureTemp_REDUNDANT,
  108. #endif
  109. #if HAS_TEMP_ADC_1
  110. PrepareTemp_1, MeasureTemp_1,
  111. #endif
  112. #if HAS_TEMP_ADC_2
  113. PrepareTemp_2, MeasureTemp_2,
  114. #endif
  115. #if HAS_TEMP_ADC_3
  116. PrepareTemp_3, MeasureTemp_3,
  117. #endif
  118. #if HAS_TEMP_ADC_4
  119. PrepareTemp_4, MeasureTemp_4,
  120. #endif
  121. #if HAS_TEMP_ADC_5
  122. PrepareTemp_5, MeasureTemp_5,
  123. #endif
  124. #if HAS_TEMP_ADC_6
  125. PrepareTemp_6, MeasureTemp_6,
  126. #endif
  127. #if HAS_TEMP_ADC_7
  128. PrepareTemp_7, MeasureTemp_7,
  129. #endif
  130. #if HAS_JOY_ADC_X
  131. PrepareJoy_X, MeasureJoy_X,
  132. #endif
  133. #if HAS_JOY_ADC_Y
  134. PrepareJoy_Y, MeasureJoy_Y,
  135. #endif
  136. #if HAS_JOY_ADC_Z
  137. PrepareJoy_Z, MeasureJoy_Z,
  138. #endif
  139. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  140. Prepare_FILWIDTH, Measure_FILWIDTH,
  141. #endif
  142. #if ENABLED(POWER_MONITOR_CURRENT)
  143. Prepare_POWER_MONITOR_CURRENT,
  144. Measure_POWER_MONITOR_CURRENT,
  145. #endif
  146. #if ENABLED(POWER_MONITOR_VOLTAGE)
  147. Prepare_POWER_MONITOR_VOLTAGE,
  148. Measure_POWER_MONITOR_VOLTAGE,
  149. #endif
  150. #if HAS_ADC_BUTTONS
  151. Prepare_ADC_KEY, Measure_ADC_KEY,
  152. #endif
  153. SensorsReady, // Temperatures ready. Delay the next round of readings to let ADC pins settle.
  154. StartupDelay // Startup, delay initial temp reading a tiny bit so the hardware can settle
  155. };
  156. // Minimum number of Temperature::ISR loops between sensor readings.
  157. // Multiplied by 16 (OVERSAMPLENR) to obtain the total time to
  158. // get all oversampled sensor readings
  159. #define MIN_ADC_ISR_LOOPS 10
  160. #define ACTUAL_ADC_SAMPLES _MAX(int(MIN_ADC_ISR_LOOPS), int(SensorsReady))
  161. #if HAS_PID_HEATING
  162. #define PID_K2 (1-float(PID_K1))
  163. #define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / TEMP_TIMER_FREQUENCY)
  164. // Apply the scale factors to the PID values
  165. #define scalePID_i(i) ( float(i) * PID_dT )
  166. #define unscalePID_i(i) ( float(i) / PID_dT )
  167. #define scalePID_d(d) ( float(d) / PID_dT )
  168. #define unscalePID_d(d) ( float(d) * PID_dT )
  169. #endif
  170. #if ENABLED(G26_MESH_VALIDATION) && EITHER(HAS_MARLINUI_MENU, EXTENSIBLE_UI)
  171. #define G26_CLICK_CAN_CANCEL 1
  172. #endif
  173. // A temperature sensor
  174. typedef struct TempInfo {
  175. uint16_t acc;
  176. int16_t raw;
  177. celsius_float_t celsius;
  178. inline void reset() { acc = 0; }
  179. inline void sample(const uint16_t s) { acc += s; }
  180. inline void update() { raw = acc; }
  181. } temp_info_t;
  182. #if HAS_TEMP_REDUNDANT
  183. // A redundant temperature sensor
  184. typedef struct RedundantTempInfo : public TempInfo {
  185. temp_info_t* target;
  186. } redundant_info_t;
  187. #endif
  188. // A PWM heater with temperature sensor
  189. typedef struct HeaterInfo : public TempInfo {
  190. celsius_t target;
  191. uint8_t soft_pwm_amount;
  192. } heater_info_t;
  193. // A heater with PID stabilization
  194. template<typename T>
  195. struct PIDHeaterInfo : public HeaterInfo {
  196. T pid; // Initialized by settings.load()
  197. };
  198. #if ENABLED(PIDTEMP)
  199. typedef struct PIDHeaterInfo<hotend_pid_t> hotend_info_t;
  200. #else
  201. typedef heater_info_t hotend_info_t;
  202. #endif
  203. #if HAS_HEATED_BED
  204. #if ENABLED(PIDTEMPBED)
  205. typedef struct PIDHeaterInfo<PID_t> bed_info_t;
  206. #else
  207. typedef heater_info_t bed_info_t;
  208. #endif
  209. #endif
  210. #if HAS_HEATED_CHAMBER
  211. #if ENABLED(PIDTEMPCHAMBER)
  212. typedef struct PIDHeaterInfo<PID_t> chamber_info_t;
  213. #else
  214. typedef heater_info_t chamber_info_t;
  215. #endif
  216. #elif HAS_TEMP_CHAMBER
  217. typedef temp_info_t chamber_info_t;
  218. #endif
  219. #if HAS_TEMP_PROBE
  220. typedef temp_info_t probe_info_t;
  221. #endif
  222. #if EITHER(HAS_COOLER, HAS_TEMP_COOLER)
  223. typedef heater_info_t cooler_info_t;
  224. #endif
  225. #if HAS_TEMP_BOARD
  226. typedef temp_info_t board_info_t;
  227. #endif
  228. // Heater watch handling
  229. template <int INCREASE, int HYSTERESIS, millis_t PERIOD>
  230. struct HeaterWatch {
  231. celsius_t target;
  232. millis_t next_ms;
  233. inline bool elapsed(const millis_t &ms) { return next_ms && ELAPSED(ms, next_ms); }
  234. inline bool elapsed() { return elapsed(millis()); }
  235. inline bool check(const celsius_t curr) { return curr >= target; }
  236. inline void restart(const celsius_t curr, const celsius_t tgt) {
  237. if (tgt) {
  238. const celsius_t newtarget = curr + INCREASE;
  239. if (newtarget < tgt - HYSTERESIS - 1) {
  240. target = newtarget;
  241. next_ms = millis() + SEC_TO_MS(PERIOD);
  242. return;
  243. }
  244. }
  245. next_ms = 0;
  246. }
  247. };
  248. #if WATCH_HOTENDS
  249. typedef struct HeaterWatch<WATCH_TEMP_INCREASE, TEMP_HYSTERESIS, WATCH_TEMP_PERIOD> hotend_watch_t;
  250. #endif
  251. #if WATCH_BED
  252. typedef struct HeaterWatch<WATCH_BED_TEMP_INCREASE, TEMP_BED_HYSTERESIS, WATCH_BED_TEMP_PERIOD> bed_watch_t;
  253. #endif
  254. #if WATCH_CHAMBER
  255. typedef struct HeaterWatch<WATCH_CHAMBER_TEMP_INCREASE, TEMP_CHAMBER_HYSTERESIS, WATCH_CHAMBER_TEMP_PERIOD> chamber_watch_t;
  256. #endif
  257. #if WATCH_COOLER
  258. typedef struct HeaterWatch<WATCH_COOLER_TEMP_INCREASE, TEMP_COOLER_HYSTERESIS, WATCH_COOLER_TEMP_PERIOD> cooler_watch_t;
  259. #endif
  260. // Temperature sensor read value ranges
  261. typedef struct { int16_t raw_min, raw_max; } raw_range_t;
  262. typedef struct { celsius_t mintemp, maxtemp; } celsius_range_t;
  263. typedef struct { int16_t raw_min, raw_max; celsius_t mintemp, maxtemp; } temp_range_t;
  264. #define THERMISTOR_ABS_ZERO_C -273.15f // bbbbrrrrr cold !
  265. #define THERMISTOR_RESISTANCE_NOMINAL_C 25.0f // mmmmm comfortable
  266. #if HAS_USER_THERMISTORS
  267. enum CustomThermistorIndex : uint8_t {
  268. #if TEMP_SENSOR_0_IS_CUSTOM
  269. CTI_HOTEND_0,
  270. #endif
  271. #if TEMP_SENSOR_1_IS_CUSTOM
  272. CTI_HOTEND_1,
  273. #endif
  274. #if TEMP_SENSOR_2_IS_CUSTOM
  275. CTI_HOTEND_2,
  276. #endif
  277. #if TEMP_SENSOR_3_IS_CUSTOM
  278. CTI_HOTEND_3,
  279. #endif
  280. #if TEMP_SENSOR_4_IS_CUSTOM
  281. CTI_HOTEND_4,
  282. #endif
  283. #if TEMP_SENSOR_5_IS_CUSTOM
  284. CTI_HOTEND_5,
  285. #endif
  286. #if TEMP_SENSOR_BED_IS_CUSTOM
  287. CTI_BED,
  288. #endif
  289. #if TEMP_SENSOR_CHAMBER_IS_CUSTOM
  290. CTI_CHAMBER,
  291. #endif
  292. #if TEMP_SENSOR_PROBE_IS_CUSTOM
  293. CTI_PROBE,
  294. #endif
  295. #if TEMP_SENSOR_COOLER_IS_CUSTOM
  296. CTI_COOLER,
  297. #endif
  298. #if TEMP_SENSOR_BOARD_IS_CUSTOM
  299. CTI_BOARD,
  300. #endif
  301. #if TEMP_SENSOR_REDUNDANT_IS_CUSTOM
  302. CTI_REDUNDANT,
  303. #endif
  304. USER_THERMISTORS
  305. };
  306. // User-defined thermistor
  307. typedef struct {
  308. bool pre_calc; // true if pre-calculations update needed
  309. float sh_c_coeff, // Steinhart-Hart C coefficient .. defaults to '0.0'
  310. sh_alpha,
  311. series_res,
  312. res_25, res_25_recip,
  313. res_25_log,
  314. beta, beta_recip;
  315. } user_thermistor_t;
  316. #endif
  317. #if HAS_AUTO_FAN || HAS_FANCHECK
  318. #define HAS_FAN_LOGIC 1
  319. #endif
  320. class Temperature {
  321. public:
  322. #if HAS_HOTEND
  323. static hotend_info_t temp_hotend[HOTENDS];
  324. static const celsius_t hotend_maxtemp[HOTENDS];
  325. static celsius_t hotend_max_target(const uint8_t e) { return hotend_maxtemp[e] - (HOTEND_OVERSHOOT); }
  326. #endif
  327. #if HAS_HEATED_BED
  328. static bed_info_t temp_bed;
  329. #endif
  330. #if HAS_TEMP_PROBE
  331. static probe_info_t temp_probe;
  332. #endif
  333. #if HAS_TEMP_CHAMBER
  334. static chamber_info_t temp_chamber;
  335. #endif
  336. #if HAS_TEMP_COOLER
  337. static cooler_info_t temp_cooler;
  338. #endif
  339. #if HAS_TEMP_BOARD
  340. static board_info_t temp_board;
  341. #endif
  342. #if HAS_TEMP_REDUNDANT
  343. static redundant_info_t temp_redundant;
  344. #endif
  345. #if EITHER(AUTO_POWER_E_FANS, HAS_FANCHECK)
  346. static uint8_t autofan_speed[HOTENDS];
  347. #endif
  348. #if ENABLED(AUTO_POWER_CHAMBER_FAN)
  349. static uint8_t chamberfan_speed;
  350. #endif
  351. #if ENABLED(AUTO_POWER_COOLER_FAN)
  352. static uint8_t coolerfan_speed;
  353. #endif
  354. #if ENABLED(FAN_SOFT_PWM)
  355. static uint8_t soft_pwm_amount_fan[FAN_COUNT],
  356. soft_pwm_count_fan[FAN_COUNT];
  357. #endif
  358. #if BOTH(FAN_SOFT_PWM, USE_CONTROLLER_FAN)
  359. static uint8_t soft_pwm_controller_speed;
  360. #endif
  361. #if ENABLED(PREVENT_COLD_EXTRUSION)
  362. static bool allow_cold_extrude;
  363. static celsius_t extrude_min_temp;
  364. static bool tooCold(const celsius_t temp) { return allow_cold_extrude ? false : temp < extrude_min_temp - (TEMP_WINDOW); }
  365. static bool tooColdToExtrude(const uint8_t E_NAME) { return tooCold(wholeDegHotend(HOTEND_INDEX)); }
  366. static bool targetTooColdToExtrude(const uint8_t E_NAME) { return tooCold(degTargetHotend(HOTEND_INDEX)); }
  367. #else
  368. static bool tooColdToExtrude(const uint8_t) { return false; }
  369. static bool targetTooColdToExtrude(const uint8_t) { return false; }
  370. #endif
  371. static bool hotEnoughToExtrude(const uint8_t e) { return !tooColdToExtrude(e); }
  372. static bool targetHotEnoughToExtrude(const uint8_t e) { return !targetTooColdToExtrude(e); }
  373. #if EITHER(SINGLENOZZLE_STANDBY_TEMP, SINGLENOZZLE_STANDBY_FAN)
  374. #if ENABLED(SINGLENOZZLE_STANDBY_TEMP)
  375. static celsius_t singlenozzle_temp[EXTRUDERS];
  376. #endif
  377. #if ENABLED(SINGLENOZZLE_STANDBY_FAN)
  378. static uint8_t singlenozzle_fan_speed[EXTRUDERS];
  379. #endif
  380. static void singlenozzle_change(const uint8_t old_tool, const uint8_t new_tool);
  381. #endif
  382. #if HEATER_IDLE_HANDLER
  383. // Heater idle handling. Marlin creates one per hotend and one for the heated bed.
  384. typedef struct {
  385. millis_t timeout_ms;
  386. bool timed_out;
  387. inline void update(const millis_t &ms) { if (!timed_out && timeout_ms && ELAPSED(ms, timeout_ms)) timed_out = true; }
  388. inline void start(const millis_t &ms) { timeout_ms = millis() + ms; timed_out = false; }
  389. inline void reset() { timeout_ms = 0; timed_out = false; }
  390. inline void expire() { start(0); }
  391. } heater_idle_t;
  392. // Indices and size for the heater_idle array
  393. enum IdleIndex : int8_t {
  394. _II = -1
  395. #define _IDLE_INDEX_E(N) ,IDLE_INDEX_E##N
  396. REPEAT(HOTENDS, _IDLE_INDEX_E)
  397. #undef _IDLE_INDEX_E
  398. OPTARG(HAS_HEATED_BED, IDLE_INDEX_BED)
  399. , NR_HEATER_IDLE
  400. };
  401. // Convert the given heater_id_t to idle array index
  402. static IdleIndex idle_index_for_id(const int8_t heater_id) {
  403. TERN_(HAS_HEATED_BED, if (heater_id == H_BED) return IDLE_INDEX_BED);
  404. return (IdleIndex)_MAX(heater_id, 0);
  405. }
  406. static heater_idle_t heater_idle[NR_HEATER_IDLE];
  407. #endif // HEATER_IDLE_TIMER
  408. #if HAS_ADC_BUTTONS
  409. static uint32_t current_ADCKey_raw;
  410. static uint16_t ADCKey_count;
  411. #endif
  412. #if ENABLED(PID_EXTRUSION_SCALING)
  413. static int16_t lpq_len;
  414. #endif
  415. #if HAS_FAN_LOGIC
  416. static constexpr millis_t fan_update_interval_ms = TERN(HAS_PWMFANCHECK, 5000, TERN(HAS_FANCHECK, 1000, 2500));
  417. #endif
  418. private:
  419. #if ENABLED(WATCH_HOTENDS)
  420. static hotend_watch_t watch_hotend[HOTENDS];
  421. #endif
  422. #if ENABLED(PID_EXTRUSION_SCALING)
  423. static int32_t last_e_position, lpq[LPQ_MAX_LEN];
  424. static lpq_ptr_t lpq_ptr;
  425. #endif
  426. #if HAS_HOTEND
  427. static temp_range_t temp_range[HOTENDS];
  428. #endif
  429. #if HAS_HEATED_BED
  430. #if ENABLED(WATCH_BED)
  431. static bed_watch_t watch_bed;
  432. #endif
  433. IF_DISABLED(PIDTEMPBED, static millis_t next_bed_check_ms);
  434. static int16_t mintemp_raw_BED, maxtemp_raw_BED;
  435. #endif
  436. #if HAS_HEATED_CHAMBER
  437. #if ENABLED(WATCH_CHAMBER)
  438. static chamber_watch_t watch_chamber;
  439. #endif
  440. TERN(PIDTEMPCHAMBER,,static millis_t next_chamber_check_ms);
  441. static int16_t mintemp_raw_CHAMBER, maxtemp_raw_CHAMBER;
  442. #endif
  443. #if HAS_COOLER
  444. #if ENABLED(WATCH_COOLER)
  445. static cooler_watch_t watch_cooler;
  446. #endif
  447. static millis_t next_cooler_check_ms, cooler_fan_flush_ms;
  448. static int16_t mintemp_raw_COOLER, maxtemp_raw_COOLER;
  449. #endif
  450. #if HAS_TEMP_BOARD && ENABLED(THERMAL_PROTECTION_BOARD)
  451. static int16_t mintemp_raw_BOARD, maxtemp_raw_BOARD;
  452. #endif
  453. #if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1
  454. static uint8_t consecutive_low_temperature_error[HOTENDS];
  455. #endif
  456. #if MILLISECONDS_PREHEAT_TIME > 0
  457. static millis_t preheat_end_time[HOTENDS];
  458. #endif
  459. #if HAS_FAN_LOGIC
  460. static millis_t fan_update_ms;
  461. static void manage_extruder_fans(millis_t ms) {
  462. if (ELAPSED(ms, fan_update_ms)) { // only need to check fan state very infrequently
  463. const millis_t next_ms = ms + fan_update_interval_ms;
  464. #if HAS_PWMFANCHECK
  465. #define FAN_CHECK_DURATION 100
  466. if (fan_check.is_measuring()) {
  467. fan_check.compute_speed(ms + FAN_CHECK_DURATION - fan_update_ms);
  468. fan_update_ms = next_ms;
  469. }
  470. else
  471. fan_update_ms = ms + FAN_CHECK_DURATION;
  472. fan_check.toggle_measuring();
  473. #else
  474. TERN_(HAS_FANCHECK, fan_check.compute_speed(next_ms - fan_update_ms));
  475. fan_update_ms = next_ms;
  476. #endif
  477. TERN_(HAS_AUTO_FAN, update_autofans()); // Needed as last when HAS_PWMFANCHECK to properly force fan speed
  478. }
  479. }
  480. #endif
  481. #if ENABLED(PROBING_HEATERS_OFF)
  482. static bool paused_for_probing;
  483. #endif
  484. public:
  485. /**
  486. * Instance Methods
  487. */
  488. void init();
  489. /**
  490. * Static (class) methods
  491. */
  492. #if HAS_USER_THERMISTORS
  493. static user_thermistor_t user_thermistor[USER_THERMISTORS];
  494. static void M305_report(const uint8_t t_index, const bool forReplay=true);
  495. static void reset_user_thermistors();
  496. static celsius_float_t user_thermistor_to_deg_c(const uint8_t t_index, const int16_t raw);
  497. static bool set_pull_up_res(int8_t t_index, float value) {
  498. //if (!WITHIN(t_index, 0, USER_THERMISTORS - 1)) return false;
  499. if (!WITHIN(value, 1, 1000000)) return false;
  500. user_thermistor[t_index].series_res = value;
  501. return true;
  502. }
  503. static bool set_res25(int8_t t_index, float value) {
  504. if (!WITHIN(value, 1, 10000000)) return false;
  505. user_thermistor[t_index].res_25 = value;
  506. user_thermistor[t_index].pre_calc = true;
  507. return true;
  508. }
  509. static bool set_beta(int8_t t_index, float value) {
  510. if (!WITHIN(value, 1, 1000000)) return false;
  511. user_thermistor[t_index].beta = value;
  512. user_thermistor[t_index].pre_calc = true;
  513. return true;
  514. }
  515. static bool set_sh_coeff(int8_t t_index, float value) {
  516. if (!WITHIN(value, -0.01f, 0.01f)) return false;
  517. user_thermistor[t_index].sh_c_coeff = value;
  518. user_thermistor[t_index].pre_calc = true;
  519. return true;
  520. }
  521. #endif
  522. #if HAS_HOTEND
  523. static celsius_float_t analog_to_celsius_hotend(const int16_t raw, const uint8_t e);
  524. #endif
  525. #if HAS_HEATED_BED
  526. static celsius_float_t analog_to_celsius_bed(const int16_t raw);
  527. #endif
  528. #if HAS_TEMP_CHAMBER
  529. static celsius_float_t analog_to_celsius_chamber(const int16_t raw);
  530. #endif
  531. #if HAS_TEMP_PROBE
  532. static celsius_float_t analog_to_celsius_probe(const int16_t raw);
  533. #endif
  534. #if HAS_TEMP_COOLER
  535. static celsius_float_t analog_to_celsius_cooler(const int16_t raw);
  536. #endif
  537. #if HAS_TEMP_BOARD
  538. static celsius_float_t analog_to_celsius_board(const int16_t raw);
  539. #endif
  540. #if HAS_TEMP_REDUNDANT
  541. static celsius_float_t analog_to_celsius_redundant(const int16_t raw);
  542. #endif
  543. #if HAS_FAN
  544. static uint8_t fan_speed[FAN_COUNT];
  545. #define FANS_LOOP(I) LOOP_L_N(I, FAN_COUNT)
  546. static void set_fan_speed(const uint8_t fan, const uint16_t speed);
  547. #if ENABLED(REPORT_FAN_CHANGE)
  548. static void report_fan_speed(const uint8_t fan);
  549. #endif
  550. #if EITHER(PROBING_FANS_OFF, ADVANCED_PAUSE_FANS_PAUSE)
  551. static bool fans_paused;
  552. static uint8_t saved_fan_speed[FAN_COUNT];
  553. #endif
  554. #if ENABLED(ADAPTIVE_FAN_SLOWING)
  555. static uint8_t fan_speed_scaler[FAN_COUNT];
  556. #endif
  557. static uint8_t scaledFanSpeed(const uint8_t fan, const uint8_t fs) {
  558. UNUSED(fan); // Potentially unused!
  559. return (fs * uint16_t(TERN(ADAPTIVE_FAN_SLOWING, fan_speed_scaler[fan], 128))) >> 7;
  560. }
  561. static uint8_t scaledFanSpeed(const uint8_t fan) {
  562. return scaledFanSpeed(fan, fan_speed[fan]);
  563. }
  564. static constexpr inline uint8_t pwmToPercent(const uint8_t speed) { return ui8_to_percent(speed); }
  565. static uint8_t fanSpeedPercent(const uint8_t fan) { return ui8_to_percent(fan_speed[fan]); }
  566. static uint8_t scaledFanSpeedPercent(const uint8_t fan) { return ui8_to_percent(scaledFanSpeed(fan)); }
  567. #if ENABLED(EXTRA_FAN_SPEED)
  568. typedef struct { uint8_t saved, speed; } extra_fan_t;
  569. static extra_fan_t extra_fan_speed[FAN_COUNT];
  570. static void set_temp_fan_speed(const uint8_t fan, const uint16_t command_or_speed);
  571. #endif
  572. #if EITHER(PROBING_FANS_OFF, ADVANCED_PAUSE_FANS_PAUSE)
  573. void set_fans_paused(const bool p);
  574. #endif
  575. #endif // HAS_FAN
  576. static void zero_fan_speeds() {
  577. #if HAS_FAN
  578. FANS_LOOP(i) set_fan_speed(i, 0);
  579. #endif
  580. }
  581. /**
  582. * Called from the Temperature ISR
  583. */
  584. static void isr();
  585. static void readings_ready();
  586. /**
  587. * Call periodically to manage heaters
  588. */
  589. static void manage_heater() _O2; // Added _O2 to work around a compiler error
  590. /**
  591. * Preheating hotends
  592. */
  593. #if MILLISECONDS_PREHEAT_TIME > 0
  594. static bool is_preheating(const uint8_t E_NAME) {
  595. return preheat_end_time[HOTEND_INDEX] && PENDING(millis(), preheat_end_time[HOTEND_INDEX]);
  596. }
  597. static void start_preheat_time(const uint8_t E_NAME) {
  598. preheat_end_time[HOTEND_INDEX] = millis() + MILLISECONDS_PREHEAT_TIME;
  599. }
  600. static void reset_preheat_time(const uint8_t E_NAME) {
  601. preheat_end_time[HOTEND_INDEX] = 0;
  602. }
  603. #else
  604. #define is_preheating(n) (false)
  605. #endif
  606. //high level conversion routines, for use outside of temperature.cpp
  607. //inline so that there is no performance decrease.
  608. //deg=degreeCelsius
  609. static celsius_float_t degHotend(const uint8_t E_NAME) {
  610. return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].celsius);
  611. }
  612. static celsius_t wholeDegHotend(const uint8_t E_NAME) {
  613. return TERN0(HAS_HOTEND, static_cast<celsius_t>(temp_hotend[HOTEND_INDEX].celsius + 0.5f));
  614. }
  615. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  616. static int16_t rawHotendTemp(const uint8_t E_NAME) {
  617. return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].raw);
  618. }
  619. #endif
  620. static celsius_t degTargetHotend(const uint8_t E_NAME) {
  621. return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].target);
  622. }
  623. #if HAS_HOTEND
  624. static void setTargetHotend(const celsius_t celsius, const uint8_t E_NAME) {
  625. const uint8_t ee = HOTEND_INDEX;
  626. #if MILLISECONDS_PREHEAT_TIME > 0
  627. if (celsius == 0)
  628. reset_preheat_time(ee);
  629. else if (temp_hotend[ee].target == 0)
  630. start_preheat_time(ee);
  631. #endif
  632. TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on());
  633. temp_hotend[ee].target = _MIN(celsius, hotend_max_target(ee));
  634. start_watching_hotend(ee);
  635. }
  636. static bool isHeatingHotend(const uint8_t E_NAME) {
  637. return temp_hotend[HOTEND_INDEX].target > temp_hotend[HOTEND_INDEX].celsius;
  638. }
  639. static bool isCoolingHotend(const uint8_t E_NAME) {
  640. return temp_hotend[HOTEND_INDEX].target < temp_hotend[HOTEND_INDEX].celsius;
  641. }
  642. #if HAS_TEMP_HOTEND
  643. static bool wait_for_hotend(const uint8_t target_extruder, const bool no_wait_for_cooling=true
  644. OPTARG(G26_CLICK_CAN_CANCEL, const bool click_to_cancel=false)
  645. );
  646. #if ENABLED(WAIT_FOR_HOTEND)
  647. static void wait_for_hotend_heating(const uint8_t target_extruder);
  648. #endif
  649. #endif
  650. static bool still_heating(const uint8_t e) {
  651. return degTargetHotend(e) > TEMP_HYSTERESIS && ABS(wholeDegHotend(e) - degTargetHotend(e)) > TEMP_HYSTERESIS;
  652. }
  653. static bool degHotendNear(const uint8_t e, const celsius_t temp) {
  654. return ABS(wholeDegHotend(e) - temp) < (TEMP_HYSTERESIS);
  655. }
  656. // Start watching a Hotend to make sure it's really heating up
  657. static void start_watching_hotend(const uint8_t E_NAME) {
  658. UNUSED(HOTEND_INDEX);
  659. #if WATCH_HOTENDS
  660. watch_hotend[HOTEND_INDEX].restart(degHotend(HOTEND_INDEX), degTargetHotend(HOTEND_INDEX));
  661. #endif
  662. }
  663. #endif // HAS_HOTEND
  664. #if HAS_HEATED_BED
  665. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  666. static int16_t rawBedTemp() { return temp_bed.raw; }
  667. #endif
  668. static celsius_float_t degBed() { return temp_bed.celsius; }
  669. static celsius_t wholeDegBed() { return static_cast<celsius_t>(degBed() + 0.5f); }
  670. static celsius_t degTargetBed() { return temp_bed.target; }
  671. static bool isHeatingBed() { return temp_bed.target > temp_bed.celsius; }
  672. static bool isCoolingBed() { return temp_bed.target < temp_bed.celsius; }
  673. // Start watching the Bed to make sure it's really heating up
  674. static void start_watching_bed() { TERN_(WATCH_BED, watch_bed.restart(degBed(), degTargetBed())); }
  675. static void setTargetBed(const celsius_t celsius) {
  676. TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on());
  677. temp_bed.target = _MIN(celsius, BED_MAX_TARGET);
  678. start_watching_bed();
  679. }
  680. static bool wait_for_bed(const bool no_wait_for_cooling=true
  681. OPTARG(G26_CLICK_CAN_CANCEL, const bool click_to_cancel=false)
  682. );
  683. static void wait_for_bed_heating();
  684. static bool degBedNear(const celsius_t temp) {
  685. return ABS(wholeDegBed() - temp) < (TEMP_BED_HYSTERESIS);
  686. }
  687. #endif // HAS_HEATED_BED
  688. #if HAS_TEMP_PROBE
  689. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  690. static int16_t rawProbeTemp() { return temp_probe.raw; }
  691. #endif
  692. static celsius_float_t degProbe() { return temp_probe.celsius; }
  693. static celsius_t wholeDegProbe() { return static_cast<celsius_t>(degProbe() + 0.5f); }
  694. static bool isProbeBelowTemp(const celsius_t target_temp) { return wholeDegProbe() < target_temp; }
  695. static bool isProbeAboveTemp(const celsius_t target_temp) { return wholeDegProbe() > target_temp; }
  696. static bool wait_for_probe(const celsius_t target_temp, bool no_wait_for_cooling=true);
  697. #endif
  698. #if HAS_TEMP_CHAMBER
  699. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  700. static int16_t rawChamberTemp() { return temp_chamber.raw; }
  701. #endif
  702. static celsius_float_t degChamber() { return temp_chamber.celsius; }
  703. static celsius_t wholeDegChamber() { return static_cast<celsius_t>(degChamber() + 0.5f); }
  704. #if HAS_HEATED_CHAMBER
  705. static celsius_t degTargetChamber() { return temp_chamber.target; }
  706. static bool isHeatingChamber() { return temp_chamber.target > temp_chamber.celsius; }
  707. static bool isCoolingChamber() { return temp_chamber.target < temp_chamber.celsius; }
  708. static bool wait_for_chamber(const bool no_wait_for_cooling=true);
  709. #endif
  710. #endif
  711. #if HAS_HEATED_CHAMBER
  712. static void setTargetChamber(const celsius_t celsius) {
  713. temp_chamber.target = _MIN(celsius, CHAMBER_MAX_TARGET);
  714. start_watching_chamber();
  715. }
  716. // Start watching the Chamber to make sure it's really heating up
  717. static void start_watching_chamber() { TERN_(WATCH_CHAMBER, watch_chamber.restart(degChamber(), degTargetChamber())); }
  718. #endif
  719. #if HAS_TEMP_COOLER
  720. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  721. static int16_t rawCoolerTemp() { return temp_cooler.raw; }
  722. #endif
  723. static celsius_float_t degCooler() { return temp_cooler.celsius; }
  724. static celsius_t wholeDegCooler() { return static_cast<celsius_t>(temp_cooler.celsius + 0.5f); }
  725. #if HAS_COOLER
  726. static celsius_t degTargetCooler() { return temp_cooler.target; }
  727. static bool isLaserHeating() { return temp_cooler.target > temp_cooler.celsius; }
  728. static bool isLaserCooling() { return temp_cooler.target < temp_cooler.celsius; }
  729. static bool wait_for_cooler(const bool no_wait_for_cooling=true);
  730. #endif
  731. #endif
  732. #if HAS_TEMP_BOARD
  733. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  734. static int16_t rawBoardTemp() { return temp_board.raw; }
  735. #endif
  736. static celsius_float_t degBoard() { return temp_board.celsius; }
  737. static celsius_t wholeDegBoard() { return static_cast<celsius_t>(temp_board.celsius + 0.5f); }
  738. #endif
  739. #if HAS_TEMP_REDUNDANT
  740. #if ENABLED(SHOW_TEMP_ADC_VALUES)
  741. static int16_t rawRedundantTemp() { return temp_redundant.raw; }
  742. static int16_t rawRedundanTargetTemp() { return (*temp_redundant.target).raw; }
  743. #endif
  744. static celsius_float_t degRedundant() { return temp_redundant.celsius; }
  745. static celsius_float_t degRedundantTarget() { return (*temp_redundant.target).celsius; }
  746. static celsius_t wholeDegRedundant() { return static_cast<celsius_t>(temp_redundant.celsius + 0.5f); }
  747. static celsius_t wholeDegRedundantTarget() { return static_cast<celsius_t>((*temp_redundant.target).celsius + 0.5f); }
  748. #endif
  749. #if HAS_COOLER
  750. static void setTargetCooler(const celsius_t celsius) {
  751. temp_cooler.target = constrain(celsius, COOLER_MIN_TARGET, COOLER_MAX_TARGET);
  752. start_watching_cooler();
  753. }
  754. // Start watching the Cooler to make sure it's really cooling down
  755. static void start_watching_cooler() { TERN_(WATCH_COOLER, watch_cooler.restart(degCooler(), degTargetCooler())); }
  756. #endif
  757. /**
  758. * The software PWM power for a heater
  759. */
  760. static int16_t getHeaterPower(const heater_id_t heater_id);
  761. /**
  762. * Switch off all heaters, set all target temperatures to 0
  763. */
  764. static void disable_all_heaters();
  765. /**
  766. * Cooldown, as from the LCD. Disables all heaters and fans.
  767. */
  768. static void cooldown() {
  769. zero_fan_speeds();
  770. disable_all_heaters();
  771. }
  772. #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
  773. /**
  774. * Methods to check if heaters are enabled, indicating an active job
  775. */
  776. static bool auto_job_over_threshold();
  777. static void auto_job_check_timer(const bool can_start, const bool can_stop);
  778. #endif
  779. /**
  780. * Perform auto-tuning for hotend or bed in response to M303
  781. */
  782. #if HAS_PID_HEATING
  783. #if ANY(PID_DEBUG, PID_BED_DEBUG, PID_CHAMBER_DEBUG)
  784. static bool pid_debug_flag;
  785. #endif
  786. static void PID_autotune(const celsius_t target, const heater_id_t heater_id, const int8_t ncycles, const bool set_result=false);
  787. #if ENABLED(NO_FAN_SLOWING_IN_PID_TUNING)
  788. static bool adaptive_fan_slowing;
  789. #elif ENABLED(ADAPTIVE_FAN_SLOWING)
  790. static constexpr bool adaptive_fan_slowing = true;
  791. #endif
  792. /**
  793. * Update the temp manager when PID values change
  794. */
  795. #if ENABLED(PIDTEMP)
  796. static void updatePID() {
  797. TERN_(PID_EXTRUSION_SCALING, last_e_position = 0);
  798. }
  799. #endif
  800. #endif
  801. #if ENABLED(PROBING_HEATERS_OFF)
  802. static void pause_heaters(const bool p);
  803. #endif
  804. #if HEATER_IDLE_HANDLER
  805. static void reset_hotend_idle_timer(const uint8_t E_NAME) {
  806. heater_idle[HOTEND_INDEX].reset();
  807. start_watching_hotend(HOTEND_INDEX);
  808. }
  809. #if HAS_HEATED_BED
  810. static void reset_bed_idle_timer() {
  811. heater_idle[IDLE_INDEX_BED].reset();
  812. start_watching_bed();
  813. }
  814. #endif
  815. #endif // HEATER_IDLE_HANDLER
  816. #if HAS_TEMP_SENSOR
  817. static void print_heater_states(const uint8_t target_extruder
  818. OPTARG(HAS_TEMP_REDUNDANT, const bool include_r=false)
  819. );
  820. #if ENABLED(AUTO_REPORT_TEMPERATURES)
  821. struct AutoReportTemp { static void report(); };
  822. static AutoReporter<AutoReportTemp> auto_reporter;
  823. #endif
  824. #endif
  825. #if HAS_HOTEND && HAS_STATUS_MESSAGE
  826. static void set_heating_message(const uint8_t e);
  827. #else
  828. static void set_heating_message(const uint8_t) {}
  829. #endif
  830. #if HAS_MARLINUI_MENU && HAS_TEMPERATURE
  831. static void lcd_preheat(const uint8_t e, const int8_t indh, const int8_t indb);
  832. #endif
  833. private:
  834. // Reading raw temperatures and converting to Celsius when ready
  835. static volatile bool raw_temps_ready;
  836. static void update_raw_temperatures();
  837. static void updateTemperaturesFromRawValues();
  838. static bool updateTemperaturesIfReady() {
  839. if (!raw_temps_ready) return false;
  840. updateTemperaturesFromRawValues();
  841. raw_temps_ready = false;
  842. return true;
  843. }
  844. // MAX Thermocouples
  845. #if HAS_MAX_TC
  846. #define MAX_TC_COUNT COUNT_ENABLED(TEMP_SENSOR_0_IS_MAX_TC, TEMP_SENSOR_1_IS_MAX_TC, TEMP_SENSOR_REDUNDANT_IS_MAX_TC)
  847. #if MAX_TC_COUNT > 1
  848. #define HAS_MULTI_MAX_TC 1
  849. #define READ_MAX_TC(N) read_max_tc(N)
  850. #else
  851. #define READ_MAX_TC(N) read_max_tc()
  852. #endif
  853. static int16_t read_max_tc(TERN_(HAS_MULTI_MAX_TC, const uint8_t hindex=0));
  854. #endif
  855. #if HAS_AUTO_FAN
  856. #if ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
  857. static bool autofans_on;
  858. #endif
  859. static void update_autofans();
  860. #endif
  861. #if HAS_HOTEND
  862. static float get_pid_output_hotend(const uint8_t e);
  863. #endif
  864. #if ENABLED(PIDTEMPBED)
  865. static float get_pid_output_bed();
  866. #endif
  867. #if ENABLED(PIDTEMPCHAMBER)
  868. static float get_pid_output_chamber();
  869. #endif
  870. static void _temp_error(const heater_id_t e, FSTR_P const serial_msg, FSTR_P const lcd_msg);
  871. static void min_temp_error(const heater_id_t e);
  872. static void max_temp_error(const heater_id_t e);
  873. #define HAS_THERMAL_PROTECTION ANY(THERMAL_PROTECTION_HOTENDS, THERMAL_PROTECTION_CHAMBER, THERMAL_PROTECTION_BED, THERMAL_PROTECTION_COOLER)
  874. #if HAS_THERMAL_PROTECTION
  875. // Indices and size for the tr_state_machine array. One for each protected heater.
  876. enum RunawayIndex : int8_t {
  877. _RI = -1
  878. #if ENABLED(THERMAL_PROTECTION_HOTENDS)
  879. #define _RUNAWAY_IND_E(N) ,RUNAWAY_IND_E##N
  880. REPEAT(HOTENDS, _RUNAWAY_IND_E)
  881. #undef _RUNAWAY_IND_E
  882. #endif
  883. OPTARG(THERMAL_PROTECTION_BED, RUNAWAY_IND_BED)
  884. OPTARG(THERMAL_PROTECTION_CHAMBER, RUNAWAY_IND_CHAMBER)
  885. OPTARG(THERMAL_PROTECTION_COOLER, RUNAWAY_IND_COOLER)
  886. , NR_HEATER_RUNAWAY
  887. };
  888. // Convert the given heater_id_t to runaway state array index
  889. static RunawayIndex runaway_index_for_id(const int8_t heater_id) {
  890. TERN_(THERMAL_PROTECTION_CHAMBER, if (heater_id == H_CHAMBER) return RUNAWAY_IND_CHAMBER);
  891. TERN_(THERMAL_PROTECTION_COOLER, if (heater_id == H_COOLER) return RUNAWAY_IND_COOLER);
  892. TERN_(THERMAL_PROTECTION_BED, if (heater_id == H_BED) return RUNAWAY_IND_BED);
  893. return (RunawayIndex)_MAX(heater_id, 0);
  894. }
  895. enum TRState : char { TRInactive, TRFirstHeating, TRStable, TRRunaway
  896. OPTARG(THERMAL_PROTECTION_VARIANCE_MONITOR, TRMalfunction)
  897. };
  898. typedef struct {
  899. millis_t timer = 0;
  900. TRState state = TRInactive;
  901. float running_temp;
  902. #if ENABLED(THERMAL_PROTECTION_VARIANCE_MONITOR)
  903. millis_t variance_timer = 0;
  904. celsius_float_t last_temp = 0.0, variance = 0.0;
  905. #endif
  906. void run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc);
  907. } tr_state_machine_t;
  908. static tr_state_machine_t tr_state_machine[NR_HEATER_RUNAWAY];
  909. #endif // HAS_THERMAL_PROTECTION
  910. };
  911. extern Temperature thermalManager;