@@ -131,6 +131,7 @@ class TFilamentMonitor : public FilamentMonitorBase {
131
131
132
132
// Handle a block completion. RunoutResponseDelayed uses this to
133
133
// add up the length of filament moved while the filament is out.
134
+ // Called from ISR context!
134
135
static void block_completed (const block_t * const b) {
135
136
if (enabled) {
136
137
response.block_completed (b);
@@ -174,7 +175,7 @@ class TFilamentMonitor : public FilamentMonitorBase {
174
175
}
175
176
}
176
177
177
- // Reinitialize the response
178
+ // Reset after a filament runout or upon resuming a job
178
179
static void init_for_restart (const bool onoff=true ) {
179
180
response.init_for_restart (onoff);
180
181
}
@@ -275,6 +276,7 @@ class FilamentSensorBase {
275
276
}
276
277
277
278
public:
279
+ // Called from ISR context to indicate a block was completed
278
280
static void block_completed (const block_t * const b) {
279
281
// If the sensor wheel has moved since the last call to
280
282
// this method reset the runout counter for the extruder.
@@ -311,6 +313,7 @@ class FilamentSensorBase {
311
313
}
312
314
313
315
public:
316
+ // Called from ISR context to indicate a block was completed
314
317
static void block_completed (const block_t * const ) {}
315
318
316
319
static void run () {
@@ -340,6 +343,7 @@ class FilamentSensorBase {
340
343
TERN_ (HAS_FILAMENT_SWITCH, static FilamentSensorSwitch switch_sensor);
341
344
342
345
public:
346
+ // Called from ISR context to indicate a block was completed
343
347
static void block_completed (const block_t * const b) {
344
348
TERN_ (HAS_FILAMENT_MOTION, encoder_sensor.block_completed (b));
345
349
TERN_ (HAS_FILAMENT_SWITCH, switch_sensor.block_completed (b));
@@ -404,9 +408,12 @@ class FilamentSensorBase {
404
408
#endif
405
409
}
406
410
411
+ // Get runout status for all presence sensors and motion sensors
407
412
static runout_flags_t has_run_out () {
408
413
runout_flags_t runout_flags{0 };
414
+ // Runout based on filament presence
409
415
for (uint8_t i = 0 ; i < NUM_RUNOUT_SENSORS; ++i) if (mm_countdown.runout [i] < 0 ) runout_flags.set (i);
416
+ // Runout based on filament motion
410
417
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
411
418
if (!ignore_motion)
412
419
for (uint8_t i = 0 ; i < NUM_MOTION_SENSORS; ++i) if (mm_countdown.motion [i] < 0 ) runout_flags.set (i);
@@ -443,22 +450,26 @@ class FilamentSensorBase {
443
450
}
444
451
#endif
445
452
453
+ // Called from ISR context to indicate a block was completed
446
454
static void block_completed (const block_t * const b) {
447
- const int32_t esteps = b->steps .e ;
448
- if (!esteps) return ;
449
-
450
455
// No calculation unless paused or printing
451
456
if (!should_monitor_runout ()) return ;
452
457
458
+ // Only extrusion moves are examined
459
+ const int32_t esteps = b->steps .e ;
460
+ if (!esteps) return ;
461
+
453
462
// No need to ignore retract/unretract movement since they complement each other
454
463
const uint8_t e = b->extruder ;
455
464
const float mm = (b->direction_bits .e ? esteps : -esteps) * planner.mm_per_step [E_AXIS_N (e)];
456
465
466
+ // Apply E distance to runout countdown, reset if flagged
457
467
if (e < NUM_RUNOUT_SENSORS) {
458
468
mm_countdown.runout [e] -= mm;
459
469
if (mm_countdown.runout_reset [e]) filament_present (e); // Reset pending. Try to reset.
460
470
}
461
471
472
+ // Apply E distance to motion countdown, reset if flagged
462
473
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
463
474
if (!ignore_motion && e < NUM_MOTION_SENSORS) {
464
475
mm_countdown.motion [e] -= mm;
@@ -467,6 +478,7 @@ class FilamentSensorBase {
467
478
#endif
468
479
}
469
480
481
+ // Reset after a filament runout or upon resuming a job
470
482
static void init_for_restart (const bool onoff=true ) {
471
483
UNUSED (onoff);
472
484
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
@@ -501,12 +513,14 @@ class FilamentSensorBase {
501
513
return runout_flags;
502
514
}
503
515
516
+ // Called from ISR context to indicate a block was completed
504
517
static void block_completed (const block_t * const ) { }
505
518
506
519
static void filament_present (const uint8_t extruder) {
507
520
runout_count[extruder] = runout_threshold;
508
521
}
509
522
523
+ // Reset after a filament runout or upon resuming a job
510
524
static void init_for_restart (const bool =true ) { reset (); }
511
525
};
512
526
0 commit comments