|
@@ -111,7 +111,7 @@ class FilamentSensorBase {
|
111
|
111
|
static void filament_present(const uint8_t extruder);
|
112
|
112
|
|
113
|
113
|
public:
|
114
|
|
- static void setup() {
|
|
114
|
+ static inline void setup() {
|
115
|
115
|
#if ENABLED(FIL_RUNOUT_PULLUP)
|
116
|
116
|
#define INIT_RUNOUT_PIN(P) SET_INPUT_PULLUP(P)
|
117
|
117
|
#elif ENABLED(FIL_RUNOUT_PULLDOWN)
|
|
@@ -138,14 +138,8 @@ class FilamentSensorBase {
|
138
|
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
|
143
|
return (
|
150
|
144
|
(READ(FIL_RUNOUT_PIN ) ? _BV(0) : 0)
|
151
|
145
|
#if NUM_RUNOUT_SENSORS > 1
|
|
@@ -163,7 +157,18 @@ class FilamentSensorBase {
|
163
|
157
|
#endif
|
164
|
158
|
#endif
|
165
|
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,22 +224,22 @@ class FilamentSensorBase {
|
219
|
224
|
*/
|
220
|
225
|
class FilamentSensorSwitch : public FilamentSensorBase {
|
221
|
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
|
229
|
#if NUM_RUNOUT_SENSORS == 1
|
225
|
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
|
232
|
#else
|
228
|
233
|
#if ENABLED(DUAL_X_CARRIAGE)
|
229
|
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
|
236
|
else
|
232
|
237
|
#elif ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
|
233
|
238
|
if (extruder_duplication_enabled)
|
234
|
|
- return runout_bits; // Any extruder
|
|
239
|
+ return runout_states; // Any extruder
|
235
|
240
|
else
|
236
|
241
|
#endif
|
237
|
|
- return TEST(runout_bits, extruder); // Specific extruder
|
|
242
|
+ return TEST(runout_states, extruder); // Specific extruder
|
238
|
243
|
#endif
|
239
|
244
|
}
|
240
|
245
|
|
|
@@ -242,7 +247,7 @@ class FilamentSensorBase {
|
242
|
247
|
static inline void block_completed(const block_t* const b) { UNUSED(b); }
|
243
|
248
|
|
244
|
249
|
static inline void run() {
|
245
|
|
- const bool out = poll_runout_pin(active_extruder);
|
|
250
|
+ const bool out = poll_runout_state(active_extruder);
|
246
|
251
|
if (!out) filament_present(active_extruder);
|
247
|
252
|
#ifdef FILAMENT_RUNOUT_SENSOR_DEBUG
|
248
|
253
|
static bool was_out = false;
|
|
@@ -272,7 +277,7 @@ class FilamentSensorBase {
|
272
|
277
|
public:
|
273
|
278
|
static float runout_distance_mm;
|
274
|
279
|
|
275
|
|
- static void reset() {
|
|
280
|
+ static inline void reset() {
|
276
|
281
|
LOOP_L_N(i, EXTRUDERS) filament_present(i);
|
277
|
282
|
}
|
278
|
283
|
|