Explorar el Código

Add HAS_FILAMENT_RUNOUT_DISTANCE

Scott Lahteine hace 4 años
padre
commit
cfd31ff70e

+ 4
- 5
Marlin/src/feature/runout.cpp Ver fichero

@@ -51,13 +51,12 @@ void FilamentSensorBase::filament_present(const uint8_t extruder) {
51 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 55
   float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
60 56
   volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS];
57
+  #if ENABLED(FILAMENT_MOTION_SENSOR)
58
+    uint8_t FilamentSensorEncoder::motion_detected;
59
+  #endif
61 60
 #else
62 61
   int8_t RunoutResponseDebounced::runout_count; // = 0
63 62
 #endif

+ 9
- 17
Marlin/src/feature/runout.h Ver fichero

@@ -84,7 +84,7 @@ class TFilamentMonitor : public FilamentMonitorBase {
84 84
       response.filament_present(extruder);
85 85
     }
86 86
 
87
-    #ifdef FILAMENT_RUNOUT_DISTANCE_MM
87
+    #if HAS_FILAMENT_RUNOUT_DISTANCE
88 88
       static inline float& runout_distance() { return response.runout_distance_mm; }
89 89
       static inline void set_runout_distance(const float &mm) { response.runout_distance_mm = mm; }
90 90
     #endif
@@ -103,15 +103,11 @@ class TFilamentMonitor : public FilamentMonitorBase {
103 103
       if ( enabled && !filament_ran_out
104 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 107
         response.run();
110 108
         sensor.run();
111 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 111
         if (ran_out) {
116 112
           filament_ran_out = true;
117 113
           event_filament_runout();
@@ -242,7 +238,7 @@ class FilamentSensorBase {
242 238
 
243 239
 /********************************* RESPONSE TYPE *********************************/
244 240
 
245
-#ifdef FILAMENT_RUNOUT_DISTANCE_MM
241
+#if HAS_FILAMENT_RUNOUT_DISTANCE
246 242
 
247 243
   // RunoutResponseDelayed triggers a runout event only if the length
248 244
   // of filament specified by FILAMENT_RUNOUT_DISTANCE_MM has been fed
@@ -293,7 +289,7 @@ class FilamentSensorBase {
293 289
       }
294 290
   };
295 291
 
296
-#else // !FILAMENT_RUNOUT_DISTANCE_MM
292
+#else // !HAS_FILAMENT_RUNOUT_DISTANCE
297 293
 
298 294
   // RunoutResponseDebounced triggers a runout event after a runout
299 295
   // condition has been detected runout_threshold times in a row.
@@ -310,17 +306,13 @@ class FilamentSensorBase {
310 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 311
 /********************************* TEMPLATE SPECIALIZATION *********************************/
316 312
 
317 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 318
 extern FilamentMonitor runout;

+ 4
- 8
Marlin/src/gcode/feature/runout/M412.cpp Ver fichero

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

+ 3
- 0
Marlin/src/inc/Conditionals_adv.h Ver fichero

@@ -70,6 +70,9 @@
70 70
 
71 71
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
72 72
   #define HAS_FILAMENT_SENSOR 1
73
+  #ifdef FILAMENT_RUNOUT_DISTANCE_MM
74
+    #define HAS_FILAMENT_RUNOUT_DISTANCE 1
75
+  #endif
73 76
 #endif
74 77
 
75 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 Ver fichero

@@ -35,7 +35,7 @@ void FilamentRunoutScreen::onRedraw(draw_mode_t what) {
35 35
   w.heading(   GET_TEXT_F(MSG_FILAMENT));
36 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 39
     extern const char NUL_STR[];
40 40
     w.heading(GET_TEXT_F(MSG_RUNOUT_DISTANCE_MM));
41 41
     w.units(GET_TEXT_F(MSG_UNITS_MM));
@@ -51,7 +51,7 @@ bool FilamentRunoutScreen::onTouchHeld(uint8_t tag) {
51 51
   const float increment = getIncrement();
52 52
   switch (tag) {
53 53
     case 2: setFilamentRunoutEnabled(!getFilamentRunoutEnabled()); break;
54
-    #ifdef FILAMENT_RUNOUT_DISTANCE_MM
54
+    #if HAS_FILAMENT_RUNOUT_DISTANCE
55 55
       case  10: UI_DECREMENT(FilamentRunoutDistance_mm); break;
56 56
       case  11: UI_INCREMENT(FilamentRunoutDistance_mm); break;
57 57
     #endif

+ 1
- 1
Marlin/src/lcd/extui/ui_api.cpp Ver fichero

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

+ 1
- 1
Marlin/src/lcd/extui/ui_api.h Ver fichero

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

+ 2
- 2
Marlin/src/lcd/menu/menu_advanced.cpp Ver fichero

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

+ 4
- 6
Marlin/src/module/configuration_store.cpp Ver fichero

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

+ 2
- 4
Marlin/src/module/stepper.cpp Ver fichero

@@ -118,7 +118,7 @@ Stepper stepper; // Singleton
118 118
   #include "../feature/mixing.h"
119 119
 #endif
120 120
 
121
-#ifdef FILAMENT_RUNOUT_DISTANCE_MM
121
+#if HAS_FILAMENT_RUNOUT_DISTANCE
122 122
   #include "../feature/runout.h"
123 123
 #endif
124 124
 
@@ -1808,9 +1808,7 @@ uint32_t Stepper::block_phase_isr() {
1808 1808
           PAGE_SEGMENT_UPDATE_POS(E);
1809 1809
         }
1810 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 1812
       discard_current_block();
1815 1813
     }
1816 1814
     else {

Loading…
Cancelar
Guardar