|
@@ -35,45 +35,45 @@
|
35
|
35
|
#include "../inc/MarlinConfig.h"
|
36
|
36
|
|
37
|
37
|
class FilamentRunoutSensor {
|
|
38
|
+ public:
|
|
39
|
+ FilamentRunoutSensor() {}
|
38
|
40
|
|
39
|
|
- FilamentRunoutSensor() {}
|
|
41
|
+ static void setup();
|
40
|
42
|
|
41
|
|
- static bool filament_ran_out;
|
42
|
|
- static void setup();
|
|
43
|
+ FORCE_INLINE static void reset() { filament_ran_out = false; }
|
43
|
44
|
|
44
|
|
- FORCE_INLINE static reset() { filament_ran_out = false; }
|
|
45
|
+ FORCE_INLINE static void run() {
|
|
46
|
+ if ((IS_SD_PRINTING || print_job_timer.isRunning()) && check() && !filament_ran_out) {
|
|
47
|
+ filament_ran_out = true;
|
|
48
|
+ enqueue_and_echo_commands_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
|
|
49
|
+ stepper.synchronize();
|
|
50
|
+ }
|
|
51
|
+ }
|
|
52
|
+ private:
|
|
53
|
+ static bool filament_ran_out;
|
45
|
54
|
|
46
|
|
- FORCE_INLINE static bool check() {
|
47
|
|
- #if NUM_RUNOUT_SENSORS < 2
|
48
|
|
- // A single sensor applying to all extruders
|
49
|
|
- return READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
|
50
|
|
- #else
|
51
|
|
- // Read the sensor for the active extruder
|
52
|
|
- switch (active_extruder) {
|
53
|
|
- case 0: return READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
|
54
|
|
- case 1: return READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_INVERTING;
|
55
|
|
- #if NUM_RUNOUT_SENSORS > 2
|
56
|
|
- case 2: return READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT_INVERTING;
|
57
|
|
- #if NUM_RUNOUT_SENSORS > 3
|
58
|
|
- case 3: return READ(FIL_RUNOUT4_PIN) == FIL_RUNOUT_INVERTING;
|
59
|
|
- #if NUM_RUNOUT_SENSORS > 4
|
60
|
|
- case 4: return READ(FIL_RUNOUT5_PIN) == FIL_RUNOUT_INVERTING;
|
|
55
|
+ FORCE_INLINE static bool check() {
|
|
56
|
+ #if NUM_RUNOUT_SENSORS < 2
|
|
57
|
+ // A single sensor applying to all extruders
|
|
58
|
+ return READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
|
|
59
|
+ #else
|
|
60
|
+ // Read the sensor for the active extruder
|
|
61
|
+ 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;
|
|
64
|
+ #if NUM_RUNOUT_SENSORS > 2
|
|
65
|
+ case 2: return READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT_INVERTING;
|
|
66
|
+ #if NUM_RUNOUT_SENSORS > 3
|
|
67
|
+ case 3: return READ(FIL_RUNOUT4_PIN) == FIL_RUNOUT_INVERTING;
|
|
68
|
+ #if NUM_RUNOUT_SENSORS > 4
|
|
69
|
+ case 4: return READ(FIL_RUNOUT5_PIN) == FIL_RUNOUT_INVERTING;
|
|
70
|
+ #endif
|
61
|
71
|
#endif
|
62
|
72
|
#endif
|
63
|
|
- #endif
|
64
|
|
- }
|
65
|
|
- #endif
|
66
|
|
- return false;
|
67
|
|
- }
|
68
|
|
-
|
69
|
|
- FORCE_INLINE static void run() {
|
70
|
|
- if ((IS_SD_PRINTING || print_job_timer.isRunning()) && check() && !filament_ran_out) {
|
71
|
|
- filament_ran_out = true;
|
72
|
|
- enqueue_and_echo_commands_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
|
73
|
|
- stepper.synchronize();
|
|
73
|
+ }
|
|
74
|
+ #endif
|
|
75
|
+ return false;
|
74
|
76
|
}
|
75
|
|
- }
|
76
|
|
-
|
77
|
77
|
};
|
78
|
78
|
|
79
|
79
|
extern FilamentRunoutSensor runout;
|