|
@@ -34,13 +34,15 @@
|
34
|
34
|
|
35
|
35
|
#include "../inc/MarlinConfig.h"
|
36
|
36
|
|
|
37
|
+#define FIL_RUNOUT_THRESHOLD 5
|
|
38
|
+
|
37
|
39
|
class FilamentRunoutSensor {
|
38
|
40
|
public:
|
39
|
41
|
FilamentRunoutSensor() {}
|
40
|
42
|
|
41
|
43
|
static void setup();
|
42
|
44
|
|
43
|
|
- FORCE_INLINE static void reset() { filament_ran_out = false; }
|
|
45
|
+ FORCE_INLINE static void reset() { runout_count = 0; filament_ran_out = false; }
|
44
|
46
|
|
45
|
47
|
FORCE_INLINE static void run() {
|
46
|
48
|
if ((IS_SD_PRINTING || print_job_timer.isRunning()) && check() && !filament_ran_out) {
|
|
@@ -51,28 +53,30 @@ class FilamentRunoutSensor {
|
51
|
53
|
}
|
52
|
54
|
private:
|
53
|
55
|
static bool filament_ran_out;
|
|
56
|
+ static uint8_t runout_count;
|
54
|
57
|
|
55
|
58
|
FORCE_INLINE static bool check() {
|
56
|
59
|
#if NUM_RUNOUT_SENSORS < 2
|
57
|
60
|
// A single sensor applying to all extruders
|
58
|
|
- return READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
|
|
61
|
+ const bool is_out = READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
|
59
|
62
|
#else
|
60
|
63
|
// Read the sensor for the active extruder
|
|
64
|
+ bool is_out;
|
61
|
65
|
switch (active_extruder) {
|
62
|
|
- case 0: return READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
|
63
|
|
- case 1: return READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_INVERTING;
|
|
66
|
+ case 0: is_out = READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING; break;
|
|
67
|
+ case 1: is_out = READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_INVERTING; break;
|
64
|
68
|
#if NUM_RUNOUT_SENSORS > 2
|
65
|
|
- case 2: return READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT_INVERTING;
|
|
69
|
+ case 2: is_out = READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT_INVERTING; break;
|
66
|
70
|
#if NUM_RUNOUT_SENSORS > 3
|
67
|
|
- case 3: return READ(FIL_RUNOUT4_PIN) == FIL_RUNOUT_INVERTING;
|
|
71
|
+ case 3: is_out = READ(FIL_RUNOUT4_PIN) == FIL_RUNOUT_INVERTING; break;
|
68
|
72
|
#if NUM_RUNOUT_SENSORS > 4
|
69
|
|
- case 4: return READ(FIL_RUNOUT5_PIN) == FIL_RUNOUT_INVERTING;
|
|
73
|
+ case 4: is_out = READ(FIL_RUNOUT5_PIN) == FIL_RUNOUT_INVERTING; break;
|
70
|
74
|
#endif
|
71
|
75
|
#endif
|
72
|
76
|
#endif
|
73
|
77
|
}
|
74
|
78
|
#endif
|
75
|
|
- return false;
|
|
79
|
+ return (is_out ? ++runout_count : (runout_count = 0)) > FIL_RUNOUT_THRESHOLD;
|
76
|
80
|
}
|
77
|
81
|
};
|
78
|
82
|
|