diff --git a/Marlin/src/feature/runout.h b/Marlin/src/feature/runout.h index a001459e9d99..0c1b2d212448 100644 --- a/Marlin/src/feature/runout.h +++ b/Marlin/src/feature/runout.h @@ -340,8 +340,10 @@ class FilamentSensorBase { typedef struct { float runout[NUM_RUNOUT_SENSORS]; + bool runout_reset[NUM_RUNOUT_SENSORS]; // flag to reset runout later if it is not possible to reset now #if ENABLED(FILAMENT_SWITCH_AND_MOTION) float motion[NUM_MOTION_SENSORS]; + bool motion_reset[NUM_MOTION_SENSORS]; // flag to reset motion later if it is not possible to reset now #endif } countdown_t; @@ -389,24 +391,50 @@ class FilamentSensorBase { } static void filament_present(const uint8_t extruder) { - mm_countdown.runout[extruder] = runout_distance_mm; + if (mm_countdown.runout[extruder]steps.x || b->steps.y || b->steps.z || did_pause_print) { // Allow pause purge move to re-trigger runout state - // Only trigger on extrusion with XYZ movement to allow filament change and retract/recover. + if (b->steps.e && (did_pause_print || printingIsActive())) { + // execute calculation if there is any extruder movement + // and if printer on pause or it is printing + // there is no need to ignore retract/unretract movement as they compensate each other const uint8_t e = b->extruder; const int32_t steps = b->steps.e; const float mm = (b->direction_bits.e ? steps : -steps) * planner.mm_per_step[E_AXIS_N(e)]; - if (e < NUM_RUNOUT_SENSORS) mm_countdown.runout[e] -= mm; + if (e < NUM_RUNOUT_SENSORS) { + mm_countdown.runout[e] -= mm; + if (mm_countdown.runout_reset[e]) filament_present(e); // if reset is pending, try to reset + } #if ENABLED(FILAMENT_SWITCH_AND_MOTION) - if (e < NUM_MOTION_SENSORS) mm_countdown.motion[e] -= mm; + if (e < NUM_MOTION_SENSORS) { + mm_countdown.motion[e] -= mm; + if (mm_countdown.motion_reset[e]) filament_motion_present(e); // if reset is pending, try to reset + } #endif } }