Add HAS_FILAMENT_RUNOUT_DISTANCE

This commit is contained in:
Scott Lahteine
2020-05-05 23:18:23 -05:00
parent 45488a431a
commit cfd31ff70e
10 changed files with 32 additions and 46 deletions

View File

@ -51,13 +51,12 @@ void FilamentSensorBase::filament_present(const uint8_t extruder) {
runout.filament_present(extruder); // calls response.filament_present(extruder)
}
#if ENABLED(FILAMENT_MOTION_SENSOR)
uint8_t FilamentSensorEncoder::motion_detected;
#endif
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
#if HAS_FILAMENT_RUNOUT_DISTANCE
float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS];
#if ENABLED(FILAMENT_MOTION_SENSOR)
uint8_t FilamentSensorEncoder::motion_detected;
#endif
#else
int8_t RunoutResponseDebounced::runout_count; // = 0
#endif

View File

@ -84,7 +84,7 @@ class TFilamentMonitor : public FilamentMonitorBase {
response.filament_present(extruder);
}
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
#if HAS_FILAMENT_RUNOUT_DISTANCE
static inline float& runout_distance() { return response.runout_distance_mm; }
static inline void set_runout_distance(const float &mm) { response.runout_distance_mm = mm; }
#endif
@ -103,15 +103,11 @@ class TFilamentMonitor : public FilamentMonitorBase {
if ( enabled && !filament_ran_out
&& (printingIsActive() || TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print))
) {
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
cli(); // Prevent RunoutResponseDelayed::block_completed from accumulating here
#endif
TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, cli()); // Prevent RunoutResponseDelayed::block_completed from accumulating here
response.run();
sensor.run();
const bool ran_out = response.has_run_out();
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
sei();
#endif
TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, sei());
if (ran_out) {
filament_ran_out = true;
event_filament_runout();
@ -242,7 +238,7 @@ class FilamentSensorBase {
/********************************* RESPONSE TYPE *********************************/
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
#if HAS_FILAMENT_RUNOUT_DISTANCE
// RunoutResponseDelayed triggers a runout event only if the length
// of filament specified by FILAMENT_RUNOUT_DISTANCE_MM has been fed
@ -293,7 +289,7 @@ class FilamentSensorBase {
}
};
#else // !FILAMENT_RUNOUT_DISTANCE_MM
#else // !HAS_FILAMENT_RUNOUT_DISTANCE
// RunoutResponseDebounced triggers a runout event after a runout
// condition has been detected runout_threshold times in a row.
@ -310,17 +306,13 @@ class FilamentSensorBase {
static inline void filament_present(const uint8_t) { runout_count = runout_threshold; }
};
#endif // !FILAMENT_RUNOUT_DISTANCE_MM
#endif // !HAS_FILAMENT_RUNOUT_DISTANCE
/********************************* TEMPLATE SPECIALIZATION *********************************/
typedef TFilamentMonitor<
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
RunoutResponseDelayed,
TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch)
#else
RunoutResponseDebounced, FilamentSensorSwitch
#endif
> FilamentMonitor;
TERN(HAS_FILAMENT_RUNOUT_DISTANCE, RunoutResponseDelayed, RunoutResponseDebounced),
TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch)
> FilamentMonitor;
extern FilamentMonitor runout;