Browse Source

Add HAS_FILAMENT_RUNOUT_DISTANCE

Scott Lahteine 5 years ago
parent
commit
cfd31ff70e

+ 4
- 5
Marlin/src/feature/runout.cpp View File

51
   runout.filament_present(extruder); // calls response.filament_present(extruder)
51
   runout.filament_present(extruder); // calls response.filament_present(extruder)
52
 }
52
 }
53
 
53
 
54
-#if ENABLED(FILAMENT_MOTION_SENSOR)
55
-  uint8_t FilamentSensorEncoder::motion_detected;
56
-#endif
57
-
58
-#ifdef FILAMENT_RUNOUT_DISTANCE_MM
54
+#if HAS_FILAMENT_RUNOUT_DISTANCE
59
   float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
55
   float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
60
   volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS];
56
   volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS];
57
+  #if ENABLED(FILAMENT_MOTION_SENSOR)
58
+    uint8_t FilamentSensorEncoder::motion_detected;
59
+  #endif
61
 #else
60
 #else
62
   int8_t RunoutResponseDebounced::runout_count; // = 0
61
   int8_t RunoutResponseDebounced::runout_count; // = 0
63
 #endif
62
 #endif

+ 9
- 17
Marlin/src/feature/runout.h View File

84
       response.filament_present(extruder);
84
       response.filament_present(extruder);
85
     }
85
     }
86
 
86
 
87
-    #ifdef FILAMENT_RUNOUT_DISTANCE_MM
87
+    #if HAS_FILAMENT_RUNOUT_DISTANCE
88
       static inline float& runout_distance() { return response.runout_distance_mm; }
88
       static inline float& runout_distance() { return response.runout_distance_mm; }
89
       static inline void set_runout_distance(const float &mm) { response.runout_distance_mm = mm; }
89
       static inline void set_runout_distance(const float &mm) { response.runout_distance_mm = mm; }
90
     #endif
90
     #endif
103
       if ( enabled && !filament_ran_out
103
       if ( enabled && !filament_ran_out
104
         && (printingIsActive() || TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print))
104
         && (printingIsActive() || TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print))
105
       ) {
105
       ) {
106
-        #ifdef FILAMENT_RUNOUT_DISTANCE_MM
107
-          cli(); // Prevent RunoutResponseDelayed::block_completed from accumulating here
108
-        #endif
106
+        TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, cli()); // Prevent RunoutResponseDelayed::block_completed from accumulating here
109
         response.run();
107
         response.run();
110
         sensor.run();
108
         sensor.run();
111
         const bool ran_out = response.has_run_out();
109
         const bool ran_out = response.has_run_out();
112
-        #ifdef FILAMENT_RUNOUT_DISTANCE_MM
113
-          sei();
114
-        #endif
110
+        TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, sei());
115
         if (ran_out) {
111
         if (ran_out) {
116
           filament_ran_out = true;
112
           filament_ran_out = true;
117
           event_filament_runout();
113
           event_filament_runout();
242
 
238
 
243
 /********************************* RESPONSE TYPE *********************************/
239
 /********************************* RESPONSE TYPE *********************************/
244
 
240
 
245
-#ifdef FILAMENT_RUNOUT_DISTANCE_MM
241
+#if HAS_FILAMENT_RUNOUT_DISTANCE
246
 
242
 
247
   // RunoutResponseDelayed triggers a runout event only if the length
243
   // RunoutResponseDelayed triggers a runout event only if the length
248
   // of filament specified by FILAMENT_RUNOUT_DISTANCE_MM has been fed
244
   // of filament specified by FILAMENT_RUNOUT_DISTANCE_MM has been fed
293
       }
289
       }
294
   };
290
   };
295
 
291
 
296
-#else // !FILAMENT_RUNOUT_DISTANCE_MM
292
+#else // !HAS_FILAMENT_RUNOUT_DISTANCE
297
 
293
 
298
   // RunoutResponseDebounced triggers a runout event after a runout
294
   // RunoutResponseDebounced triggers a runout event after a runout
299
   // condition has been detected runout_threshold times in a row.
295
   // condition has been detected runout_threshold times in a row.
310
       static inline void filament_present(const uint8_t)          { runout_count = runout_threshold; }
306
       static inline void filament_present(const uint8_t)          { runout_count = runout_threshold; }
311
   };
307
   };
312
 
308
 
313
-#endif // !FILAMENT_RUNOUT_DISTANCE_MM
309
+#endif // !HAS_FILAMENT_RUNOUT_DISTANCE
314
 
310
 
315
 /********************************* TEMPLATE SPECIALIZATION *********************************/
311
 /********************************* TEMPLATE SPECIALIZATION *********************************/
316
 
312
 
317
 typedef TFilamentMonitor<
313
 typedef TFilamentMonitor<
318
-  #ifdef FILAMENT_RUNOUT_DISTANCE_MM
319
-    RunoutResponseDelayed,
320
-    TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch)
321
-  #else
322
-    RunoutResponseDebounced, FilamentSensorSwitch
323
-  #endif
324
-> FilamentMonitor;
314
+          TERN(HAS_FILAMENT_RUNOUT_DISTANCE, RunoutResponseDelayed, RunoutResponseDebounced),
315
+          TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch)
316
+        > FilamentMonitor;
325
 
317
 
326
 extern FilamentMonitor runout;
318
 extern FilamentMonitor runout;

+ 4
- 8
Marlin/src/gcode/feature/runout/M412.cpp View File

32
  */
32
  */
33
 void GcodeSuite::M412() {
33
 void GcodeSuite::M412() {
34
   if (parser.seen("RS"
34
   if (parser.seen("RS"
35
-    #ifdef FILAMENT_RUNOUT_DISTANCE_MM
36
-      "D"
37
-    #endif
38
-    #if ENABLED(HOST_ACTION_COMMANDS)
39
-      "H"
40
-    #endif
35
+    TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, "D")
36
+    TERN_(HOST_ACTION_COMMANDS, "H")
41
   )) {
37
   )) {
42
     #if ENABLED(HOST_ACTION_COMMANDS)
38
     #if ENABLED(HOST_ACTION_COMMANDS)
43
       if (parser.seen('H')) runout.host_handling = parser.value_bool();
39
       if (parser.seen('H')) runout.host_handling = parser.value_bool();
45
     const bool seenR = parser.seen('R'), seenS = parser.seen('S');
41
     const bool seenR = parser.seen('R'), seenS = parser.seen('S');
46
     if (seenR || seenS) runout.reset();
42
     if (seenR || seenS) runout.reset();
47
     if (seenS) runout.enabled = parser.value_bool();
43
     if (seenS) runout.enabled = parser.value_bool();
48
-    #ifdef FILAMENT_RUNOUT_DISTANCE_MM
44
+    #if HAS_FILAMENT_RUNOUT_DISTANCE
49
       if (parser.seen('D')) runout.set_runout_distance(parser.value_linear_units());
45
       if (parser.seen('D')) runout.set_runout_distance(parser.value_linear_units());
50
     #endif
46
     #endif
51
   }
47
   }
53
     SERIAL_ECHO_START();
49
     SERIAL_ECHO_START();
54
     SERIAL_ECHOPGM("Filament runout ");
50
     SERIAL_ECHOPGM("Filament runout ");
55
     serialprintln_onoff(runout.enabled);
51
     serialprintln_onoff(runout.enabled);
56
-    #ifdef FILAMENT_RUNOUT_DISTANCE_MM
52
+    #if HAS_FILAMENT_RUNOUT_DISTANCE
57
       SERIAL_ECHOLNPAIR("Filament runout distance (mm): ", runout.runout_distance());
53
       SERIAL_ECHOLNPAIR("Filament runout distance (mm): ", runout.runout_distance());
58
     #endif
54
     #endif
59
   }
55
   }

+ 3
- 0
Marlin/src/inc/Conditionals_adv.h View File

70
 
70
 
71
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
71
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
72
   #define HAS_FILAMENT_SENSOR 1
72
   #define HAS_FILAMENT_SENSOR 1
73
+  #ifdef FILAMENT_RUNOUT_DISTANCE_MM
74
+    #define HAS_FILAMENT_RUNOUT_DISTANCE 1
75
+  #endif
73
 #endif
76
 #endif
74
 
77
 
75
 // Let SD_FINISHED_RELEASECOMMAND stand in for SD_FINISHED_STEPPERRELEASE
78
 // Let SD_FINISHED_RELEASECOMMAND stand in for SD_FINISHED_STEPPERRELEASE

+ 2
- 2
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/filament_runout_screen.cpp View File

35
   w.heading(   GET_TEXT_F(MSG_FILAMENT));
35
   w.heading(   GET_TEXT_F(MSG_FILAMENT));
36
   w.toggle( 2, GET_TEXT_F(MSG_RUNOUT_SENSOR), getFilamentRunoutEnabled());
36
   w.toggle( 2, GET_TEXT_F(MSG_RUNOUT_SENSOR), getFilamentRunoutEnabled());
37
 
37
 
38
-  #ifdef FILAMENT_RUNOUT_DISTANCE_MM
38
+  #if HAS_FILAMENT_RUNOUT_DISTANCE
39
     extern const char NUL_STR[];
39
     extern const char NUL_STR[];
40
     w.heading(GET_TEXT_F(MSG_RUNOUT_DISTANCE_MM));
40
     w.heading(GET_TEXT_F(MSG_RUNOUT_DISTANCE_MM));
41
     w.units(GET_TEXT_F(MSG_UNITS_MM));
41
     w.units(GET_TEXT_F(MSG_UNITS_MM));
51
   const float increment = getIncrement();
51
   const float increment = getIncrement();
52
   switch (tag) {
52
   switch (tag) {
53
     case 2: setFilamentRunoutEnabled(!getFilamentRunoutEnabled()); break;
53
     case 2: setFilamentRunoutEnabled(!getFilamentRunoutEnabled()); break;
54
-    #ifdef FILAMENT_RUNOUT_DISTANCE_MM
54
+    #if HAS_FILAMENT_RUNOUT_DISTANCE
55
       case  10: UI_DECREMENT(FilamentRunoutDistance_mm); break;
55
       case  10: UI_DECREMENT(FilamentRunoutDistance_mm); break;
56
       case  11: UI_INCREMENT(FilamentRunoutDistance_mm); break;
56
       case  11: UI_INCREMENT(FilamentRunoutDistance_mm); break;
57
     #endif
57
     #endif

+ 1
- 1
Marlin/src/lcd/extui/ui_api.cpp View File

591
     bool getFilamentRunoutEnabled()                 { return runout.enabled; }
591
     bool getFilamentRunoutEnabled()                 { return runout.enabled; }
592
     void setFilamentRunoutEnabled(const bool value) { runout.enabled = value; }
592
     void setFilamentRunoutEnabled(const bool value) { runout.enabled = value; }
593
 
593
 
594
-    #ifdef FILAMENT_RUNOUT_DISTANCE_MM
594
+    #if HAS_FILAMENT_RUNOUT_DISTANCE
595
       float getFilamentRunoutDistance_mm()                 { return runout.runout_distance(); }
595
       float getFilamentRunoutDistance_mm()                 { return runout.runout_distance(); }
596
       void setFilamentRunoutDistance_mm(const float value) { runout.set_runout_distance(constrain(value, 0, 999)); }
596
       void setFilamentRunoutDistance_mm(const float value) { runout.set_runout_distance(constrain(value, 0, 999)); }
597
     #endif
597
     #endif

+ 1
- 1
Marlin/src/lcd/extui/ui_api.h View File

237
     bool getFilamentRunoutEnabled();
237
     bool getFilamentRunoutEnabled();
238
     void setFilamentRunoutEnabled(const bool);
238
     void setFilamentRunoutEnabled(const bool);
239
 
239
 
240
-    #ifdef FILAMENT_RUNOUT_DISTANCE_MM
240
+    #if HAS_FILAMENT_RUNOUT_DISTANCE
241
       float getFilamentRunoutDistance_mm();
241
       float getFilamentRunoutDistance_mm();
242
       void setFilamentRunoutDistance_mm(const float);
242
       void setFilamentRunoutDistance_mm(const float);
243
     #endif
243
     #endif

+ 2
- 2
Marlin/src/lcd/menu/menu_advanced.cpp View File

43
   #include "../../module/temperature.h"
43
   #include "../../module/temperature.h"
44
 #endif
44
 #endif
45
 
45
 
46
-#if ENABLED(FILAMENT_RUNOUT_SENSOR) && FILAMENT_RUNOUT_DISTANCE_MM
46
+#if HAS_FILAMENT_RUNOUT_DISTANCE
47
   #include "../../feature/runout.h"
47
   #include "../../feature/runout.h"
48
 #endif
48
 #endif
49
 
49
 
142
       #endif
142
       #endif
143
     #endif
143
     #endif
144
 
144
 
145
-    #if ENABLED(FILAMENT_RUNOUT_SENSOR) && FILAMENT_RUNOUT_DISTANCE_MM
145
+    #if HAS_FILAMENT_RUNOUT_DISTANCE
146
       editable.decimal = runout.runout_distance();
146
       editable.decimal = runout.runout_distance();
147
       EDIT_ITEM(float3, MSG_RUNOUT_DISTANCE_MM, &editable.decimal, 1, 30,
147
       EDIT_ITEM(float3, MSG_RUNOUT_DISTANCE_MM, &editable.decimal, 1, 30,
148
         []{ runout.set_runout_distance(editable.decimal); }, true
148
         []{ runout.set_runout_distance(editable.decimal); }, true

+ 4
- 6
Marlin/src/module/configuration_store.cpp View File

604
       #else
604
       #else
605
         constexpr bool runout_sensor_enabled = true;
605
         constexpr bool runout_sensor_enabled = true;
606
       #endif
606
       #endif
607
-      #if HAS_FILAMENT_SENSOR && defined(FILAMENT_RUNOUT_DISTANCE_MM)
607
+      #if HAS_FILAMENT_RUNOUT_DISTANCE
608
         const float &runout_distance_mm = runout.runout_distance();
608
         const float &runout_distance_mm = runout.runout_distance();
609
       #else
609
       #else
610
         constexpr float runout_distance_mm = 0;
610
         constexpr float runout_distance_mm = 0;
1460
 
1460
 
1461
         float runout_distance_mm;
1461
         float runout_distance_mm;
1462
         EEPROM_READ(runout_distance_mm);
1462
         EEPROM_READ(runout_distance_mm);
1463
-        #if HAS_FILAMENT_SENSOR && defined(FILAMENT_RUNOUT_DISTANCE_MM)
1463
+        #if HAS_FILAMENT_RUNOUT_DISTANCE
1464
           if (!validating) runout.set_runout_distance(runout_distance_mm);
1464
           if (!validating) runout.set_runout_distance(runout_distance_mm);
1465
         #endif
1465
         #endif
1466
       }
1466
       }
2384
   #if HAS_FILAMENT_SENSOR
2384
   #if HAS_FILAMENT_SENSOR
2385
     runout.enabled = true;
2385
     runout.enabled = true;
2386
     runout.reset();
2386
     runout.reset();
2387
-    #ifdef FILAMENT_RUNOUT_DISTANCE_MM
2388
-      runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM);
2389
-    #endif
2387
+    TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM));
2390
   #endif
2388
   #endif
2391
 
2389
 
2392
   //
2390
   //
3551
       CONFIG_ECHO_START();
3549
       CONFIG_ECHO_START();
3552
       SERIAL_ECHOLNPAIR(
3550
       SERIAL_ECHOLNPAIR(
3553
         "  M412 S", int(runout.enabled)
3551
         "  M412 S", int(runout.enabled)
3554
-        #ifdef FILAMENT_RUNOUT_DISTANCE_MM
3552
+        #if HAS_FILAMENT_RUNOUT_DISTANCE
3555
           , " D", LINEAR_UNIT(runout.runout_distance())
3553
           , " D", LINEAR_UNIT(runout.runout_distance())
3556
         #endif
3554
         #endif
3557
       );
3555
       );

+ 2
- 4
Marlin/src/module/stepper.cpp View File

118
   #include "../feature/mixing.h"
118
   #include "../feature/mixing.h"
119
 #endif
119
 #endif
120
 
120
 
121
-#ifdef FILAMENT_RUNOUT_DISTANCE_MM
121
+#if HAS_FILAMENT_RUNOUT_DISTANCE
122
   #include "../feature/runout.h"
122
   #include "../feature/runout.h"
123
 #endif
123
 #endif
124
 
124
 
1808
           PAGE_SEGMENT_UPDATE_POS(E);
1808
           PAGE_SEGMENT_UPDATE_POS(E);
1809
         }
1809
         }
1810
       #endif
1810
       #endif
1811
-      #ifdef FILAMENT_RUNOUT_DISTANCE_MM
1812
-        runout.block_completed(current_block);
1813
-      #endif
1811
+      TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.block_completed(current_block));
1814
       discard_current_block();
1812
       discard_current_block();
1815
     }
1813
     }
1816
     else {
1814
     else {

Loading…
Cancel
Save