|
@@ -0,0 +1,89 @@
|
|
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 <http://www.gnu.org/licenses/>.
|
|
20
|
+ *
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+/**
|
|
24
|
+ * Hotend Idle Timeout
|
|
25
|
+ * Prevent filament in the nozzle from charring and causing a critical jam.
|
|
26
|
+ */
|
|
27
|
+
|
|
28
|
+#include "../inc/MarlinConfig.h"
|
|
29
|
+
|
|
30
|
+#if ENABLED(HOTEND_IDLE_TIMEOUT)
|
|
31
|
+
|
|
32
|
+#include "hotend_idle.h"
|
|
33
|
+#include "../gcode/gcode.h"
|
|
34
|
+
|
|
35
|
+#include "../module/temperature.h"
|
|
36
|
+#include "../module/motion.h"
|
|
37
|
+#include "../lcd/ultralcd.h"
|
|
38
|
+
|
|
39
|
+extern HotendIdleProtection hotend_idle;
|
|
40
|
+
|
|
41
|
+millis_t HotendIdleProtection::next_protect_ms = 0;
|
|
42
|
+
|
|
43
|
+void HotendIdleProtection::check_hotends(const millis_t &ms) {
|
|
44
|
+ bool do_prot = false;
|
|
45
|
+ HOTEND_LOOP() {
|
|
46
|
+ if (thermalManager.degHotendNear(e, HOTEND_IDLE_MIN_TRIGGER)) {
|
|
47
|
+ do_prot = true; break;
|
|
48
|
+ }
|
|
49
|
+ }
|
|
50
|
+ if (bool(next_protect_ms) != do_prot)
|
|
51
|
+ next_protect_ms = do_prot ? ms + hp_interval : 0;
|
|
52
|
+}
|
|
53
|
+
|
|
54
|
+void HotendIdleProtection::check_e_motion(const millis_t &ms) {
|
|
55
|
+ static float old_e_position = 0;
|
|
56
|
+ if (old_e_position != current_position.e) {
|
|
57
|
+ old_e_position = current_position.e; // Track filament motion
|
|
58
|
+ if (next_protect_ms) // If some heater is on then...
|
|
59
|
+ next_protect_ms = ms + hp_interval; // ...delay the timeout till later
|
|
60
|
+ }
|
|
61
|
+}
|
|
62
|
+
|
|
63
|
+void HotendIdleProtection::check() {
|
|
64
|
+ const millis_t ms = millis(); // Shared millis
|
|
65
|
+
|
|
66
|
+ check_hotends(ms); // Any hotends need protection?
|
|
67
|
+ check_e_motion(ms); // Motion will protect them
|
|
68
|
+
|
|
69
|
+ // Hot and not moving for too long...
|
|
70
|
+ if (next_protect_ms && ELAPSED(ms, next_protect_ms))
|
|
71
|
+ timed_out();
|
|
72
|
+}
|
|
73
|
+
|
|
74
|
+// Lower (but don't raise) hotend / bed temperatures
|
|
75
|
+void HotendIdleProtection::timed_out() {
|
|
76
|
+ next_protect_ms = 0;
|
|
77
|
+ SERIAL_ECHOLNPGM("Hotend Idle Timeout");
|
|
78
|
+ LCD_MESSAGEPGM(MSG_HOTEND_IDLE_TIMEOUT);
|
|
79
|
+ HOTEND_LOOP() {
|
|
80
|
+ if ((HOTEND_IDLE_NOZZLE_TARGET) < thermalManager.degTargetHotend(e))
|
|
81
|
+ thermalManager.setTargetHotend(HOTEND_IDLE_NOZZLE_TARGET, e);
|
|
82
|
+ }
|
|
83
|
+ #if HAS_HEATED_BED
|
|
84
|
+ if ((HOTEND_IDLE_BED_TARGET) < thermalManager.degTargetBed())
|
|
85
|
+ thermalManager.setTargetBed(HOTEND_IDLE_BED_TARGET);
|
|
86
|
+ #endif
|
|
87
|
+}
|
|
88
|
+
|
|
89
|
+#endif // HOTEND_IDLE_TIMEOUT
|