Browse Source

Default Filament Runout Sensor enabled state (#19013)

Steven Haigh 5 years ago
parent
commit
a62ae2aa2d
No account linked to committer's email address

+ 5
- 4
Marlin/Configuration.h View File

1178
  */
1178
  */
1179
 //#define FILAMENT_RUNOUT_SENSOR
1179
 //#define FILAMENT_RUNOUT_SENSOR
1180
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
1180
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
1181
-  #define NUM_RUNOUT_SENSORS   1     // Number of sensors, up to one per extruder. Define a FIL_RUNOUT#_PIN for each.
1182
-  #define FIL_RUNOUT_STATE     LOW   // Pin state indicating that filament is NOT present.
1183
-  #define FIL_RUNOUT_PULLUP          // Use internal pullup for filament runout pins.
1184
-  //#define FIL_RUNOUT_PULLDOWN      // Use internal pulldown for filament runout pins.
1181
+  #define FIL_RUNOUT_ENABLED_DEFAULT true // Enable the sensor on startup. Override with M412 followed by M500.
1182
+  #define NUM_RUNOUT_SENSORS   1          // Number of sensors, up to one per extruder. Define a FIL_RUNOUT#_PIN for each.
1183
+  #define FIL_RUNOUT_STATE     LOW        // Pin state indicating that filament is NOT present.
1184
+  #define FIL_RUNOUT_PULLUP               // Use internal pullup for filament runout pins.
1185
+  //#define FIL_RUNOUT_PULLDOWN           // Use internal pulldown for filament runout pins.
1185
 
1186
 
1186
   // Set one or more commands to execute on filament runout.
1187
   // Set one or more commands to execute on filament runout.
1187
   // (After 'M412 H' Marlin will ask the host to handle the process.)
1188
   // (After 'M412 H' Marlin will ask the host to handle the process.)

+ 0
- 8
Marlin/src/feature/runout.cpp View File

44
   #include "../module/tool_change.h"
44
   #include "../module/tool_change.h"
45
 #endif
45
 #endif
46
 
46
 
47
-/**
48
- * Called by FilamentSensorSwitch::run when filament is detected.
49
- * Called by FilamentSensorEncoder::block_completed when motion is detected.
50
- */
51
-void FilamentSensorBase::filament_present(const uint8_t extruder) {
52
-  runout.filament_present(extruder); // calls response.filament_present(extruder)
53
-}
54
-
55
 #if HAS_FILAMENT_RUNOUT_DISTANCE
47
 #if HAS_FILAMENT_RUNOUT_DISTANCE
56
   float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
48
   float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
57
   volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS];
49
   volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS];

+ 25
- 10
Marlin/src/feature/runout.h View File

48
 
48
 
49
 void event_filament_runout();
49
 void event_filament_runout();
50
 
50
 
51
+template<class RESPONSE_T, class SENSOR_T>
52
+class TFilamentMonitor;
53
+class FilamentSensorEncoder;
54
+class FilamentSensorSwitch;
55
+class RunoutResponseDelayed;
56
+class RunoutResponseDebounced;
57
+
58
+/********************************* TEMPLATE SPECIALIZATION *********************************/
59
+
60
+typedef TFilamentMonitor<
61
+          TERN(HAS_FILAMENT_RUNOUT_DISTANCE, RunoutResponseDelayed, RunoutResponseDebounced),
62
+          TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch)
63
+        > FilamentMonitor;
64
+
65
+extern FilamentMonitor runout;
66
+
67
+/*******************************************************************************************/
68
+
51
 class FilamentMonitorBase {
69
 class FilamentMonitorBase {
52
   public:
70
   public:
53
     static bool enabled, filament_ran_out;
71
     static bool enabled, filament_ran_out;
121
 
139
 
122
 class FilamentSensorBase {
140
 class FilamentSensorBase {
123
   protected:
141
   protected:
124
-    static void filament_present(const uint8_t extruder);
142
+    /**
143
+     * Called by FilamentSensorSwitch::run when filament is detected.
144
+     * Called by FilamentSensorEncoder::block_completed when motion is detected.
145
+     */
146
+    static inline void filament_present(const uint8_t extruder) {
147
+      runout.filament_present(extruder); // ...which calls response.filament_present(extruder)
148
+    }
125
 
149
 
126
   public:
150
   public:
127
     static inline void setup() {
151
     static inline void setup() {
311
   };
335
   };
312
 
336
 
313
 #endif // !HAS_FILAMENT_RUNOUT_DISTANCE
337
 #endif // !HAS_FILAMENT_RUNOUT_DISTANCE
314
-
315
-/********************************* TEMPLATE SPECIALIZATION *********************************/
316
-
317
-typedef TFilamentMonitor<
318
-          TERN(HAS_FILAMENT_RUNOUT_DISTANCE, RunoutResponseDelayed, RunoutResponseDebounced),
319
-          TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch)
320
-        > FilamentMonitor;
321
-
322
-extern FilamentMonitor runout;

+ 12
- 9
Marlin/src/module/settings.cpp View File

106
 
106
 
107
 #if HAS_FILAMENT_SENSOR
107
 #if HAS_FILAMENT_SENSOR
108
   #include "../feature/runout.h"
108
   #include "../feature/runout.h"
109
+  #ifndef FIL_RUNOUT_ENABLED_DEFAULT
110
+    #define FIL_RUNOUT_ENABLED_DEFAULT true
111
+  #endif
109
 #endif
112
 #endif
110
 
113
 
111
 #if ENABLED(EXTRA_LIN_ADVANCE_K)
114
 #if ENABLED(EXTRA_LIN_ADVANCE_K)
646
       #if HAS_FILAMENT_SENSOR
649
       #if HAS_FILAMENT_SENSOR
647
         const bool &runout_sensor_enabled = runout.enabled;
650
         const bool &runout_sensor_enabled = runout.enabled;
648
       #else
651
       #else
649
-        constexpr bool runout_sensor_enabled = true;
652
+        constexpr int8_t runout_sensor_enabled = -1;
650
       #endif
653
       #endif
654
+      _FIELD_TEST(runout_sensor_enabled);
655
+      EEPROM_WRITE(runout_sensor_enabled);
656
+
651
       #if HAS_FILAMENT_RUNOUT_DISTANCE
657
       #if HAS_FILAMENT_RUNOUT_DISTANCE
652
         const float &runout_distance_mm = runout.runout_distance();
658
         const float &runout_distance_mm = runout.runout_distance();
653
       #else
659
       #else
654
         constexpr float runout_distance_mm = 0;
660
         constexpr float runout_distance_mm = 0;
655
       #endif
661
       #endif
656
-      _FIELD_TEST(runout_sensor_enabled);
657
-      EEPROM_WRITE(runout_sensor_enabled);
658
       EEPROM_WRITE(runout_distance_mm);
662
       EEPROM_WRITE(runout_distance_mm);
659
     }
663
     }
660
 
664
 
1518
       // Filament Runout Sensor
1522
       // Filament Runout Sensor
1519
       //
1523
       //
1520
       {
1524
       {
1521
-        #if HAS_FILAMENT_SENSOR
1522
-          const bool &runout_sensor_enabled = runout.enabled;
1523
-        #else
1524
-          bool runout_sensor_enabled;
1525
-        #endif
1525
+        int8_t runout_sensor_enabled;
1526
         _FIELD_TEST(runout_sensor_enabled);
1526
         _FIELD_TEST(runout_sensor_enabled);
1527
         EEPROM_READ(runout_sensor_enabled);
1527
         EEPROM_READ(runout_sensor_enabled);
1528
+        #if HAS_FILAMENT_SENSOR
1529
+          runout.enabled = runout_sensor_enabled < 0 ? FIL_RUNOUT_ENABLED_DEFAULT : runout_sensor_enabled;
1530
+        #endif
1528
 
1531
 
1529
         TERN_(HAS_FILAMENT_SENSOR, if (runout.enabled) runout.reset());
1532
         TERN_(HAS_FILAMENT_SENSOR, if (runout.enabled) runout.reset());
1530
 
1533
 
2476
   //
2479
   //
2477
 
2480
 
2478
   #if HAS_FILAMENT_SENSOR
2481
   #if HAS_FILAMENT_SENSOR
2479
-    runout.enabled = true;
2482
+    runout.enabled = FIL_RUNOUT_ENABLED_DEFAULT;
2480
     runout.reset();
2483
     runout.reset();
2481
     TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM));
2484
     TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM));
2482
   #endif
2485
   #endif

Loading…
Cancel
Save