Skip to content

Commit 1273082

Browse files
committed
comments
1 parent e24f677 commit 1273082

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Marlin/src/feature/runout.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class TFilamentMonitor : public FilamentMonitorBase {
131131

132132
// Handle a block completion. RunoutResponseDelayed uses this to
133133
// add up the length of filament moved while the filament is out.
134+
// Called from ISR context!
134135
static void block_completed(const block_t * const b) {
135136
if (enabled) {
136137
response.block_completed(b);
@@ -174,7 +175,7 @@ class TFilamentMonitor : public FilamentMonitorBase {
174175
}
175176
}
176177

177-
// Reinitialize the response
178+
// Reset after a filament runout or upon resuming a job
178179
static void init_for_restart(const bool onoff=true) {
179180
response.init_for_restart(onoff);
180181
}
@@ -275,6 +276,7 @@ class FilamentSensorBase {
275276
}
276277

277278
public:
279+
// Called from ISR context to indicate a block was completed
278280
static void block_completed(const block_t * const b) {
279281
// If the sensor wheel has moved since the last call to
280282
// this method reset the runout counter for the extruder.
@@ -311,6 +313,7 @@ class FilamentSensorBase {
311313
}
312314

313315
public:
316+
// Called from ISR context to indicate a block was completed
314317
static void block_completed(const block_t * const) {}
315318

316319
static void run() {
@@ -340,6 +343,7 @@ class FilamentSensorBase {
340343
TERN_(HAS_FILAMENT_SWITCH, static FilamentSensorSwitch switch_sensor);
341344

342345
public:
346+
// Called from ISR context to indicate a block was completed
343347
static void block_completed(const block_t * const b) {
344348
TERN_(HAS_FILAMENT_MOTION, encoder_sensor.block_completed(b));
345349
TERN_(HAS_FILAMENT_SWITCH, switch_sensor.block_completed(b));
@@ -404,9 +408,12 @@ class FilamentSensorBase {
404408
#endif
405409
}
406410

411+
// Get runout status for all presence sensors and motion sensors
407412
static runout_flags_t has_run_out() {
408413
runout_flags_t runout_flags{0};
414+
// Runout based on filament presence
409415
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
410417
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
411418
if (!ignore_motion)
412419
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 {
443450
}
444451
#endif
445452

453+
// Called from ISR context to indicate a block was completed
446454
static void block_completed(const block_t * const b) {
447-
const int32_t esteps = b->steps.e;
448-
if (!esteps) return;
449-
450455
// No calculation unless paused or printing
451456
if (!should_monitor_runout()) return;
452457

458+
// Only extrusion moves are examined
459+
const int32_t esteps = b->steps.e;
460+
if (!esteps) return;
461+
453462
// No need to ignore retract/unretract movement since they complement each other
454463
const uint8_t e = b->extruder;
455464
const float mm = (b->direction_bits.e ? esteps : -esteps) * planner.mm_per_step[E_AXIS_N(e)];
456465

466+
// Apply E distance to runout countdown, reset if flagged
457467
if (e < NUM_RUNOUT_SENSORS) {
458468
mm_countdown.runout[e] -= mm;
459469
if (mm_countdown.runout_reset[e]) filament_present(e); // Reset pending. Try to reset.
460470
}
461471

472+
// Apply E distance to motion countdown, reset if flagged
462473
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
463474
if (!ignore_motion && e < NUM_MOTION_SENSORS) {
464475
mm_countdown.motion[e] -= mm;
@@ -467,6 +478,7 @@ class FilamentSensorBase {
467478
#endif
468479
}
469480

481+
// Reset after a filament runout or upon resuming a job
470482
static void init_for_restart(const bool onoff=true) {
471483
UNUSED(onoff);
472484
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
@@ -501,12 +513,14 @@ class FilamentSensorBase {
501513
return runout_flags;
502514
}
503515

516+
// Called from ISR context to indicate a block was completed
504517
static void block_completed(const block_t * const) { }
505518

506519
static void filament_present(const uint8_t extruder) {
507520
runout_count[extruder] = runout_threshold;
508521
}
509522

523+
// Reset after a filament runout or upon resuming a job
510524
static void init_for_restart(const bool=true) { reset(); }
511525
};
512526

0 commit comments

Comments
 (0)