浏览代码

Support for multiple filament runout sensors

Studiodyne 7 年前
父节点
当前提交
d3ca82d8c2

+ 6
- 5
Marlin/Configuration.h 查看文件

852
 #endif
852
 #endif
853
 
853
 
854
 /**
854
 /**
855
- * Filament Runout Sensor
856
- * A mechanical or opto endstop is used to check for the presence of filament.
855
+ * Filament Runout Sensors
856
+ * Mechanical or opto endstops are used to check for the presence of filament.
857
  *
857
  *
858
- * RAMPS-based boards use SERVO3_PIN.
859
- * For other boards you may need to define FIL_RUNOUT_PIN.
860
- * By default the firmware assumes HIGH = has filament, LOW = ran out
858
+ * RAMPS-based boards use SERVO3_PIN for the first runout sensor.
859
+ * For other boards you may need to define FIL_RUNOUT_PIN, FIL_RUNOUT2_PIN, etc.
860
+ * By default the firmware assumes HIGH=FILAMENT PRESENT.
861
  */
861
  */
862
 //#define FILAMENT_RUNOUT_SENSOR
862
 //#define FILAMENT_RUNOUT_SENSOR
863
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
863
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
864
+  #define NUM_RUNOUT_SENSORS   1     // Number of sensors, up to one per extruder. Define a FIL_RUNOUT#_PIN for each.
864
   #define FIL_RUNOUT_INVERTING false // set to true to invert the logic of the sensor.
865
   #define FIL_RUNOUT_INVERTING false // set to true to invert the logic of the sensor.
865
   #define FIL_RUNOUT_PULLUP          // Use internal pullup for filament runout pins.
866
   #define FIL_RUNOUT_PULLUP          // Use internal pullup for filament runout pins.
866
   //#define FIL_RUNOUT_PULLDOWN      // Use internal pulldown for filament runout pins.
867
   //#define FIL_RUNOUT_PULLDOWN      // Use internal pulldown for filament runout pins.

+ 2
- 20
Marlin/src/Marlin.cpp 查看文件

216
   #endif
216
   #endif
217
 }
217
 }
218
 
218
 
219
-#if ENABLED(FILAMENT_RUNOUT_SENSOR)
220
-
221
-  void setup_filrunoutpin() {
222
-    #if ENABLED(FIL_RUNOUT_PULLUP)
223
-      SET_INPUT_PULLUP(FIL_RUNOUT_PIN);
224
-    #elif ENABLED(FIL_RUNOUT_PULLDOWN)
225
-      SET_INPUT_PULLDOWN(FIL_RUNOUT_PIN);
226
-    #else
227
-      SET_INPUT(FIL_RUNOUT_PIN);
228
-    #endif
229
-  }
230
-
231
-#endif
232
-
233
 void setup_powerhold() {
219
 void setup_powerhold() {
234
   #if HAS_SUICIDE
220
   #if HAS_SUICIDE
235
     OUT_WRITE(SUICIDE_PIN, HIGH);
221
     OUT_WRITE(SUICIDE_PIN, HIGH);
336
 void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
322
 void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
337
 
323
 
338
   #if ENABLED(FILAMENT_RUNOUT_SENSOR)
324
   #if ENABLED(FILAMENT_RUNOUT_SENSOR)
339
-    if ((IS_SD_PRINTING || print_job_timer.isRunning())
340
-      && READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING
341
-      && thermalManager.targetHotEnoughToExtrude(active_extruder)
342
-    )
343
-      handle_filament_runout();
325
+    runout.run();
344
   #endif
326
   #endif
345
 
327
 
346
   if (commands_in_queue < BUFSIZE) get_available_commands();
328
   if (commands_in_queue < BUFSIZE) get_available_commands();
661
   #endif
643
   #endif
662
 
644
 
663
   #if ENABLED(FILAMENT_RUNOUT_SENSOR)
645
   #if ENABLED(FILAMENT_RUNOUT_SENSOR)
664
-    setup_filrunoutpin();
646
+    runout.setup();
665
   #endif
647
   #endif
666
 
648
 
667
   setup_killpin();
649
   setup_killpin();

+ 1
- 1
Marlin/src/feature/pause.cpp 查看文件

500
   planner.set_e_position_mm(destination[E_AXIS] = current_position[E_AXIS] = resume_position[E_AXIS]);
500
   planner.set_e_position_mm(destination[E_AXIS] = current_position[E_AXIS] = resume_position[E_AXIS]);
501
 
501
 
502
   #if ENABLED(FILAMENT_RUNOUT_SENSOR)
502
   #if ENABLED(FILAMENT_RUNOUT_SENSOR)
503
-    filament_ran_out = false;
503
+    runout.reset();
504
   #endif
504
   #endif
505
 
505
 
506
   #if ENABLED(ULTIPANEL)
506
   #if ENABLED(ULTIPANEL)

+ 28
- 10
Marlin/src/feature/runout.cpp 查看文件

24
  * feature/runout.cpp - Runout sensor support
24
  * feature/runout.cpp - Runout sensor support
25
  */
25
  */
26
 
26
 
27
-#include "../inc/MarlinConfig.h"
27
+#include "../inc/MarlinConfigPre.h"
28
 
28
 
29
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
29
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
30
 
30
 
31
-#include "../module/stepper.h"
32
-#include "../gcode/queue.h"
31
+#include "runout.h"
33
 
32
 
34
-bool filament_ran_out = false;
33
+FilamentRunoutSensor runout;
35
 
34
 
36
-void handle_filament_runout() {
37
-  if (!filament_ran_out) {
38
-    filament_ran_out = true;
39
-    enqueue_and_echo_commands_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
40
-    stepper.synchronize();
41
-  }
35
+bool FilamentRunoutSensor::filament_ran_out; // = false;
36
+
37
+void FilamentRunoutSensor::setup() {
38
+
39
+  #if ENABLED(FIL_RUNOUT_PULLUP)
40
+    #define INIT_RUNOUT_PIN(P) SET_INPUT_PULLUP(P)
41
+  #elif ENABLED(FIL_RUNOUT_PULLDOWN)
42
+    #define INIT_RUNOUT_PIN(P) SET_INPUT_PULLDOWN(P)
43
+  #else
44
+    #define INIT_RUNOUT_PIN(P) SET_INPUT(P)
45
+  #endif
46
+
47
+  INIT_RUNOUT_PIN(FIL_RUNOUT_PIN);
48
+  #if NUM_RUNOUT_SENSORS > 1
49
+    INIT_RUNOUT_PIN(FIL_RUNOUT2_PIN);
50
+    #if NUM_RUNOUT_SENSORS > 2
51
+      INIT_RUNOUT_PIN(FIL_RUNOUT3_PIN);
52
+      #if NUM_RUNOUT_SENSORS > 3
53
+        INIT_RUNOUT_PIN(FIL_RUNOUT4_PIN);
54
+        #if NUM_RUNOUT_SENSORS > 4
55
+          INIT_RUNOUT_PIN(FIL_RUNOUT5_PIN);
56
+        #endif
57
+      #endif
58
+    #endif
59
+  #endif
42
 }
60
 }
43
 
61
 
44
 #endif // FILAMENT_RUNOUT_SENSOR
62
 #endif // FILAMENT_RUNOUT_SENSOR

+ 49
- 2
Marlin/src/feature/runout.h 查看文件

27
 #ifndef _RUNOUT_H_
27
 #ifndef _RUNOUT_H_
28
 #define _RUNOUT_H_
28
 #define _RUNOUT_H_
29
 
29
 
30
-extern bool filament_ran_out;
30
+#include "../sd/cardreader.h"
31
+#include "../module/printcounter.h"
32
+#include "../module/stepper.h"
33
+#include "../gcode/queue.h"
31
 
34
 
32
-void handle_filament_runout();
35
+#include "../inc/MarlinConfig.h"
36
+
37
+class FilamentRunoutSensor {
38
+
39
+  FilamentRunoutSensor() {}
40
+
41
+  static bool filament_ran_out;
42
+  static void setup();
43
+
44
+  FORCE_INLINE static reset() { filament_ran_out = false; }
45
+
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;
61
+            #endif
62
+          #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();
74
+    }
75
+  }
76
+
77
+};
78
+
79
+extern FilamentRunoutSensor runout;
33
 
80
 
34
 #endif // _RUNOUT_H_
81
 #endif // _RUNOUT_H_

+ 0
- 1
Marlin/src/inc/Conditionals_post.h 查看文件

792
 
792
 
793
 // Sensors
793
 // Sensors
794
 #define HAS_FILAMENT_WIDTH_SENSOR (PIN_EXISTS(FILWIDTH))
794
 #define HAS_FILAMENT_WIDTH_SENSOR (PIN_EXISTS(FILWIDTH))
795
-#define HAS_FIL_RUNOUT (PIN_EXISTS(FIL_RUNOUT))
796
 
795
 
797
 // User Interface
796
 // User Interface
798
 #define HAS_HOME (PIN_EXISTS(HOME))
797
 #define HAS_HOME (PIN_EXISTS(HOME))

+ 12
- 2
Marlin/src/inc/SanityCheck.h 查看文件

429
 #endif
429
 #endif
430
 
430
 
431
 /**
431
 /**
432
- * Filament Runout needs a pin and either SD Support or Auto print start detection
432
+ * Filament Runout needs one or more pins and either SD Support or Auto print start detection
433
  */
433
  */
434
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
434
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
435
-  #if !HAS_FIL_RUNOUT
435
+  #if !PIN_EXISTS(FIL_RUNOUT)
436
     #error "FILAMENT_RUNOUT_SENSOR requires FIL_RUNOUT_PIN."
436
     #error "FILAMENT_RUNOUT_SENSOR requires FIL_RUNOUT_PIN."
437
+  #elif NUM_RUNOUT_SENSORS > E_STEPPERS
438
+    #error "NUM_RUNOUT_SENSORS cannot exceed the number of E steppers."
439
+  #elif NUM_RUNOUT_SENSORS > 1 && !PIN_EXISTS(FIL_RUNOUT2)
440
+    #error "FILAMENT_RUNOUT_SENSOR with NUM_RUNOUT_SENSORS > 1 requires FIL_RUNOUT2_PIN."
441
+  #elif NUM_RUNOUT_SENSORS > 2 && !PIN_EXISTS(FIL_RUNOUT3)
442
+    #error "FILAMENT_RUNOUT_SENSOR with NUM_RUNOUT_SENSORS > 2 requires FIL_RUNOUT3_PIN."
443
+  #elif NUM_RUNOUT_SENSORS > 3 && !PIN_EXISTS(FIL_RUNOUT4)
444
+    #error "FILAMENT_RUNOUT_SENSOR with NUM_RUNOUT_SENSORS > 3 requires FIL_RUNOUT4_PIN."
445
+  #elif NUM_RUNOUT_SENSORS > 4 && !PIN_EXISTS(FIL_RUNOUT5)
446
+    #error "FILAMENT_RUNOUT_SENSOR with NUM_RUNOUT_SENSORS > 4 requires FIL_RUNOUT5_PIN."
437
   #elif DISABLED(SDSUPPORT) && DISABLED(PRINTJOB_TIMER_AUTOSTART)
447
   #elif DISABLED(SDSUPPORT) && DISABLED(PRINTJOB_TIMER_AUTOSTART)
438
     #error "FILAMENT_RUNOUT_SENSOR requires SDSUPPORT or PRINTJOB_TIMER_AUTOSTART."
448
     #error "FILAMENT_RUNOUT_SENSOR requires SDSUPPORT or PRINTJOB_TIMER_AUTOSTART."
439
   #elif DISABLED(ADVANCED_PAUSE_FEATURE)
449
   #elif DISABLED(ADVANCED_PAUSE_FEATURE)

正在加载...
取消
保存