소스 검색

Support for multiple filament runout sensors

Studiodyne 7 년 전
부모
커밋
d3ca82d8c2
7개의 변경된 파일98개의 추가작업 그리고 41개의 파일을 삭제
  1. 6
    5
      Marlin/Configuration.h
  2. 2
    20
      Marlin/src/Marlin.cpp
  3. 1
    1
      Marlin/src/feature/pause.cpp
  4. 28
    10
      Marlin/src/feature/runout.cpp
  5. 49
    2
      Marlin/src/feature/runout.h
  6. 0
    1
      Marlin/src/inc/Conditionals_post.h
  7. 12
    2
      Marlin/src/inc/SanityCheck.h

+ 6
- 5
Marlin/Configuration.h 파일 보기

@@ -852,15 +852,16 @@
852 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 862
 //#define FILAMENT_RUNOUT_SENSOR
863 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 865
   #define FIL_RUNOUT_INVERTING false // set to true to invert the logic of the sensor.
865 866
   #define FIL_RUNOUT_PULLUP          // Use internal pullup for filament runout pins.
866 867
   //#define FIL_RUNOUT_PULLDOWN      // Use internal pulldown for filament runout pins.

+ 2
- 20
Marlin/src/Marlin.cpp 파일 보기

@@ -216,20 +216,6 @@ void setup_killpin() {
216 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 219
 void setup_powerhold() {
234 220
   #if HAS_SUICIDE
235 221
     OUT_WRITE(SUICIDE_PIN, HIGH);
@@ -336,11 +322,7 @@ void disable_all_steppers() {
336 322
 void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
337 323
 
338 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 326
   #endif
345 327
 
346 328
   if (commands_in_queue < BUFSIZE) get_available_commands();
@@ -661,7 +643,7 @@ void setup() {
661 643
   #endif
662 644
 
663 645
   #if ENABLED(FILAMENT_RUNOUT_SENSOR)
664
-    setup_filrunoutpin();
646
+    runout.setup();
665 647
   #endif
666 648
 
667 649
   setup_killpin();

+ 1
- 1
Marlin/src/feature/pause.cpp 파일 보기

@@ -500,7 +500,7 @@ void resume_print(const float &load_length/*=0*/, const float &purge_length/*=AD
500 500
   planner.set_e_position_mm(destination[E_AXIS] = current_position[E_AXIS] = resume_position[E_AXIS]);
501 501
 
502 502
   #if ENABLED(FILAMENT_RUNOUT_SENSOR)
503
-    filament_ran_out = false;
503
+    runout.reset();
504 504
   #endif
505 505
 
506 506
   #if ENABLED(ULTIPANEL)

+ 28
- 10
Marlin/src/feature/runout.cpp 파일 보기

@@ -24,21 +24,39 @@
24 24
  * feature/runout.cpp - Runout sensor support
25 25
  */
26 26
 
27
-#include "../inc/MarlinConfig.h"
27
+#include "../inc/MarlinConfigPre.h"
28 28
 
29 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 62
 #endif // FILAMENT_RUNOUT_SENSOR

+ 49
- 2
Marlin/src/feature/runout.h 파일 보기

@@ -27,8 +27,55 @@
27 27
 #ifndef _RUNOUT_H_
28 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 81
 #endif // _RUNOUT_H_

+ 0
- 1
Marlin/src/inc/Conditionals_post.h 파일 보기

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

+ 12
- 2
Marlin/src/inc/SanityCheck.h 파일 보기

@@ -429,11 +429,21 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
429 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 434
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
435
-  #if !HAS_FIL_RUNOUT
435
+  #if !PIN_EXISTS(FIL_RUNOUT)
436 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 447
   #elif DISABLED(SDSUPPORT) && DISABLED(PRINTJOB_TIMER_AUTOSTART)
438 448
     #error "FILAMENT_RUNOUT_SENSOR requires SDSUPPORT or PRINTJOB_TIMER_AUTOSTART."
439 449
   #elif DISABLED(ADVANCED_PAUSE_FEATURE)

Loading…
취소
저장