|
@@ -43,7 +43,7 @@
|
43
|
43
|
#define FILAMENT_RUNOUT_THRESHOLD 5
|
44
|
44
|
#endif
|
45
|
45
|
|
46
|
|
-void event_filament_runout();
|
|
46
|
+void event_filament_runout(const uint8_t extruder);
|
47
|
47
|
|
48
|
48
|
template<class RESPONSE_T, class SENSOR_T>
|
49
|
49
|
class TFilamentMonitor;
|
|
@@ -119,11 +119,41 @@ class TFilamentMonitor : public FilamentMonitorBase {
|
119
|
119
|
TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, cli()); // Prevent RunoutResponseDelayed::block_completed from accumulating here
|
120
|
120
|
response.run();
|
121
|
121
|
sensor.run();
|
122
|
|
- const bool ran_out = response.has_run_out();
|
|
122
|
+ const uint8_t runout_flags = response.has_run_out();
|
123
|
123
|
TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, sei());
|
|
124
|
+ #if MULTI_FILAMENT_SENSOR
|
|
125
|
+ #if ENABLED(WATCH_ALL_RUNOUT_SENSORS)
|
|
126
|
+ const bool ran_out = !!runout_flags; // any sensor triggers
|
|
127
|
+ uint8_t extruder = 0;
|
|
128
|
+ if (ran_out) {
|
|
129
|
+ uint8_t bitmask = runout_flags;
|
|
130
|
+ while (!(bitmask & 1)) {
|
|
131
|
+ bitmask >>= 1;
|
|
132
|
+ extruder++;
|
|
133
|
+ }
|
|
134
|
+ }
|
|
135
|
+ #else
|
|
136
|
+ const bool ran_out = TEST(runout_flags, active_extruder); // suppress non active extruders
|
|
137
|
+ uint8_t extruder = active_extruder;
|
|
138
|
+ #endif
|
|
139
|
+ #else
|
|
140
|
+ const bool ran_out = !!runout_flags;
|
|
141
|
+ uint8_t extruder = active_extruder;
|
|
142
|
+ #endif
|
|
143
|
+
|
|
144
|
+ #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
|
|
145
|
+ if (runout_flags) {
|
|
146
|
+ SERIAL_ECHOPGM("Runout Sensors: ");
|
|
147
|
+ LOOP_L_N(i, 8) SERIAL_ECHO('0' + TEST(runout_flags, i));
|
|
148
|
+ SERIAL_ECHOPAIR(" -> ", extruder);
|
|
149
|
+ if (ran_out) SERIAL_ECHOPGM(" RUN OUT");
|
|
150
|
+ SERIAL_EOL();
|
|
151
|
+ }
|
|
152
|
+ #endif
|
|
153
|
+
|
124
|
154
|
if (ran_out) {
|
125
|
155
|
filament_ran_out = true;
|
126
|
|
- event_filament_runout();
|
|
156
|
+ event_filament_runout(extruder);
|
127
|
157
|
planner.synchronize();
|
128
|
158
|
}
|
129
|
159
|
}
|
|
@@ -280,16 +310,17 @@ class FilamentSensorBase {
|
280
|
310
|
static inline void block_completed(const block_t* const) {}
|
281
|
311
|
|
282
|
312
|
static inline void run() {
|
283
|
|
- const bool out = poll_runout_state(active_extruder);
|
284
|
|
- if (!out) filament_present(active_extruder);
|
285
|
|
- #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
|
286
|
|
- static bool was_out = false;
|
287
|
|
- if (out != was_out) {
|
288
|
|
- was_out = out;
|
289
|
|
- SERIAL_ECHOPGM("Filament ");
|
290
|
|
- SERIAL_ECHOPGM_P(out ? PSTR("OUT\n") : PSTR("IN\n"));
|
291
|
|
- }
|
292
|
|
- #endif
|
|
313
|
+ LOOP_L_N(s, NUM_RUNOUT_SENSORS) {
|
|
314
|
+ const bool out = poll_runout_state(s);
|
|
315
|
+ if (!out) filament_present(s);
|
|
316
|
+ #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
|
|
317
|
+ static uint8_t was_out; // = 0
|
|
318
|
+ if (out != TEST(was_out, s)) {
|
|
319
|
+ TBI(was_out, s);
|
|
320
|
+ SERIAL_ECHOLNPAIR_P(PSTR("Filament Sensor "), '0' + s, out ? PSTR(" OUT") : PSTR(" IN"));
|
|
321
|
+ }
|
|
322
|
+ #endif
|
|
323
|
+ }
|
293
|
324
|
}
|
294
|
325
|
};
|
295
|
326
|
|
|
@@ -305,13 +336,13 @@ class FilamentSensorBase {
|
305
|
336
|
// during a runout condition.
|
306
|
337
|
class RunoutResponseDelayed {
|
307
|
338
|
private:
|
308
|
|
- static volatile float runout_mm_countdown[EXTRUDERS];
|
|
339
|
+ static volatile float runout_mm_countdown[NUM_RUNOUT_SENSORS];
|
309
|
340
|
|
310
|
341
|
public:
|
311
|
342
|
static float runout_distance_mm;
|
312
|
343
|
|
313
|
344
|
static inline void reset() {
|
314
|
|
- LOOP_L_N(i, EXTRUDERS) filament_present(i);
|
|
345
|
+ LOOP_L_N(i, NUM_RUNOUT_SENSORS) filament_present(i);
|
315
|
346
|
}
|
316
|
347
|
|
317
|
348
|
static inline void run() {
|
|
@@ -320,15 +351,17 @@ class FilamentSensorBase {
|
320
|
351
|
const millis_t ms = millis();
|
321
|
352
|
if (ELAPSED(ms, t)) {
|
322
|
353
|
t = millis() + 1000UL;
|
323
|
|
- LOOP_L_N(i, EXTRUDERS)
|
|
354
|
+ LOOP_L_N(i, NUM_RUNOUT_SENSORS)
|
324
|
355
|
SERIAL_ECHOPAIR_P(i ? PSTR(", ") : PSTR("Remaining mm: "), runout_mm_countdown[i]);
|
325
|
356
|
SERIAL_EOL();
|
326
|
357
|
}
|
327
|
358
|
#endif
|
328
|
359
|
}
|
329
|
360
|
|
330
|
|
- static inline bool has_run_out() {
|
331
|
|
- return runout_mm_countdown[active_extruder] < 0;
|
|
361
|
+ static inline uint8_t has_run_out() {
|
|
362
|
+ uint8_t runout_flags = 0;
|
|
363
|
+ LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_mm_countdown[i] < 0) SBI(runout_flags, i);
|
|
364
|
+ return runout_flags;
|
332
|
365
|
}
|
333
|
366
|
|
334
|
367
|
static inline void filament_present(const uint8_t extruder) {
|
|
@@ -353,13 +386,28 @@ class FilamentSensorBase {
|
353
|
386
|
class RunoutResponseDebounced {
|
354
|
387
|
private:
|
355
|
388
|
static constexpr int8_t runout_threshold = FILAMENT_RUNOUT_THRESHOLD;
|
356
|
|
- static int8_t runout_count;
|
|
389
|
+ static int8_t runout_count[NUM_RUNOUT_SENSORS];
|
|
390
|
+
|
357
|
391
|
public:
|
358
|
|
- static inline void reset() { runout_count = runout_threshold; }
|
359
|
|
- static inline void run() { if (runout_count >= 0) runout_count--; }
|
360
|
|
- static inline bool has_run_out() { return runout_count < 0; }
|
361
|
|
- static inline void block_completed(const block_t* const) { }
|
362
|
|
- static inline void filament_present(const uint8_t) { runout_count = runout_threshold; }
|
|
392
|
+ static inline void reset() {
|
|
393
|
+ LOOP_L_N(i, NUM_RUNOUT_SENSORS) filament_present(i);
|
|
394
|
+ }
|
|
395
|
+
|
|
396
|
+ static inline void run() {
|
|
397
|
+ LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_count[i] >= 0) runout_count[i]--;
|
|
398
|
+ }
|
|
399
|
+
|
|
400
|
+ static inline uint8_t has_run_out() {
|
|
401
|
+ uint8_t runout_flags = 0;
|
|
402
|
+ LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_count[i] < 0) SBI(runout_flags, i);
|
|
403
|
+ return runout_flags;
|
|
404
|
+ }
|
|
405
|
+
|
|
406
|
+ static inline void block_completed(const block_t* const) { }
|
|
407
|
+
|
|
408
|
+ static inline void filament_present(const uint8_t extruder) {
|
|
409
|
+ runout_count[extruder] = runout_threshold;
|
|
410
|
+ }
|
363
|
411
|
};
|
364
|
412
|
|
365
|
413
|
#endif // !HAS_FILAMENT_RUNOUT_DISTANCE
|