Browse Source

Add poll_runout_states, which returns 1 for runouts (#12547)

Scott Lahteine 5 years ago
parent
commit
929a513a6b
No account linked to committer's email address
1 changed files with 23 additions and 18 deletions
  1. 23
    18
      Marlin/src/feature/runout.h

+ 23
- 18
Marlin/src/feature/runout.h View File

111
     static void filament_present(const uint8_t extruder);
111
     static void filament_present(const uint8_t extruder);
112
 
112
 
113
   public:
113
   public:
114
-    static void setup() {
114
+    static inline void setup() {
115
       #if ENABLED(FIL_RUNOUT_PULLUP)
115
       #if ENABLED(FIL_RUNOUT_PULLUP)
116
         #define INIT_RUNOUT_PIN(P) SET_INPUT_PULLUP(P)
116
         #define INIT_RUNOUT_PIN(P) SET_INPUT_PULLUP(P)
117
       #elif ENABLED(FIL_RUNOUT_PULLDOWN)
117
       #elif ENABLED(FIL_RUNOUT_PULLDOWN)
138
       #endif
138
       #endif
139
     }
139
     }
140
 
140
 
141
-    #if FIL_RUNOUT_INVERTING
142
-      #define FIL_RUNOUT_INVERT_MASK (_BV(NUM_RUNOUT_SENSORS) - 1)
143
-    #else
144
-      #define FIL_RUNOUT_INVERT_MASK 0
145
-    #endif
146
-
147
-    // Return a bitmask of all runout sensor states
148
-    static uint8_t poll_runout_pins() {
141
+    // Return a bitmask of runout pin states
142
+    static inline uint8_t poll_runout_pins() {
149
       return (
143
       return (
150
         (READ(FIL_RUNOUT_PIN ) ? _BV(0) : 0)
144
         (READ(FIL_RUNOUT_PIN ) ? _BV(0) : 0)
151
         #if NUM_RUNOUT_SENSORS > 1
145
         #if NUM_RUNOUT_SENSORS > 1
163
             #endif
157
             #endif
164
           #endif
158
           #endif
165
         #endif
159
         #endif
166
-      ) ^ FIL_RUNOUT_INVERT_MASK;
160
+      );
161
+    }
162
+
163
+    // Return a bitmask of runout flag states (1 bits always indicates runout)
164
+    static inline uint8_t poll_runout_states() {
165
+      return poll_runout_pins() ^ uint8_t(
166
+        #if DISABLED(FIL_RUNOUT_INVERTING)
167
+          _BV(NUM_RUNOUT_SENSORS) - 1
168
+        #else
169
+          0
170
+        #endif
171
+      );
167
     }
172
     }
168
 };
173
 };
169
 
174
 
219
    */
224
    */
220
   class FilamentSensorSwitch : public FilamentSensorBase {
225
   class FilamentSensorSwitch : public FilamentSensorBase {
221
     private:
226
     private:
222
-      static bool poll_runout_pin(const uint8_t extruder) {
223
-        const uint8_t runout_bits = poll_runout_pins();
227
+      static inline bool poll_runout_state(const uint8_t extruder) {
228
+        const uint8_t runout_states = poll_runout_states();
224
         #if NUM_RUNOUT_SENSORS == 1
229
         #if NUM_RUNOUT_SENSORS == 1
225
           UNUSED(extruder);
230
           UNUSED(extruder);
226
-          return runout_bits;                     // A single sensor applying to all extruders
231
+          return runout_states;                     // A single sensor applying to all extruders
227
         #else
232
         #else
228
           #if ENABLED(DUAL_X_CARRIAGE)
233
           #if ENABLED(DUAL_X_CARRIAGE)
229
             if (dual_x_carriage_mode == DXC_DUPLICATION_MODE || dual_x_carriage_mode == DXC_SCALED_DUPLICATION_MODE)
234
             if (dual_x_carriage_mode == DXC_DUPLICATION_MODE || dual_x_carriage_mode == DXC_SCALED_DUPLICATION_MODE)
230
-              return runout_bits;                 // Any extruder
235
+              return runout_states;                 // Any extruder
231
             else
236
             else
232
           #elif ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
237
           #elif ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
233
             if (extruder_duplication_enabled)
238
             if (extruder_duplication_enabled)
234
-              return runout_bits;                 // Any extruder
239
+              return runout_states;                 // Any extruder
235
             else
240
             else
236
           #endif
241
           #endif
237
-              return TEST(runout_bits, extruder); // Specific extruder
242
+              return TEST(runout_states, extruder); // Specific extruder
238
         #endif
243
         #endif
239
       }
244
       }
240
 
245
 
242
       static inline void block_completed(const block_t* const b) { UNUSED(b); }
247
       static inline void block_completed(const block_t* const b) { UNUSED(b); }
243
 
248
 
244
       static inline void run() {
249
       static inline void run() {
245
-        const bool out = poll_runout_pin(active_extruder);
250
+        const bool out = poll_runout_state(active_extruder);
246
         if (!out) filament_present(active_extruder);
251
         if (!out) filament_present(active_extruder);
247
         #ifdef FILAMENT_RUNOUT_SENSOR_DEBUG
252
         #ifdef FILAMENT_RUNOUT_SENSOR_DEBUG
248
           static bool was_out = false;
253
           static bool was_out = false;
272
     public:
277
     public:
273
       static float runout_distance_mm;
278
       static float runout_distance_mm;
274
 
279
 
275
-      static void reset() {
280
+      static inline void reset() {
276
         LOOP_L_N(i, EXTRUDERS) filament_present(i);
281
         LOOP_L_N(i, EXTRUDERS) filament_present(i);
277
       }
282
       }
278
 
283
 

Loading…
Cancel
Save