|
@ -34,13 +34,15 @@ |
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h" |
|
|
#include "../inc/MarlinConfig.h" |
|
|
|
|
|
|
|
|
|
|
|
#define FIL_RUNOUT_THRESHOLD 5 |
|
|
|
|
|
|
|
|
class FilamentRunoutSensor { |
|
|
class FilamentRunoutSensor { |
|
|
public: |
|
|
public: |
|
|
FilamentRunoutSensor() {} |
|
|
FilamentRunoutSensor() {} |
|
|
|
|
|
|
|
|
static void setup(); |
|
|
static void setup(); |
|
|
|
|
|
|
|
|
FORCE_INLINE static void reset() { filament_ran_out = false; } |
|
|
FORCE_INLINE static void reset() { runout_count = 0; filament_ran_out = false; } |
|
|
|
|
|
|
|
|
FORCE_INLINE static void run() { |
|
|
FORCE_INLINE static void run() { |
|
|
if ((IS_SD_PRINTING || print_job_timer.isRunning()) && check() && !filament_ran_out) { |
|
|
if ((IS_SD_PRINTING || print_job_timer.isRunning()) && check() && !filament_ran_out) { |
|
@ -51,28 +53,30 @@ class FilamentRunoutSensor { |
|
|
} |
|
|
} |
|
|
private: |
|
|
private: |
|
|
static bool filament_ran_out; |
|
|
static bool filament_ran_out; |
|
|
|
|
|
static uint8_t runout_count; |
|
|
|
|
|
|
|
|
FORCE_INLINE static bool check() { |
|
|
FORCE_INLINE static bool check() { |
|
|
#if NUM_RUNOUT_SENSORS < 2 |
|
|
#if NUM_RUNOUT_SENSORS < 2 |
|
|
// A single sensor applying to all extruders
|
|
|
// A single sensor applying to all extruders
|
|
|
return READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING; |
|
|
const bool is_out = READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING; |
|
|
#else |
|
|
#else |
|
|
// Read the sensor for the active extruder
|
|
|
// Read the sensor for the active extruder
|
|
|
|
|
|
bool is_out; |
|
|
switch (active_extruder) { |
|
|
switch (active_extruder) { |
|
|
case 0: return READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING; |
|
|
case 0: is_out = READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING; break; |
|
|
case 1: return READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_INVERTING; |
|
|
case 1: is_out = READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_INVERTING; break; |
|
|
#if NUM_RUNOUT_SENSORS > 2 |
|
|
#if NUM_RUNOUT_SENSORS > 2 |
|
|
case 2: return READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT_INVERTING; |
|
|
case 2: is_out = READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT_INVERTING; break; |
|
|
#if NUM_RUNOUT_SENSORS > 3 |
|
|
#if NUM_RUNOUT_SENSORS > 3 |
|
|
case 3: return READ(FIL_RUNOUT4_PIN) == FIL_RUNOUT_INVERTING; |
|
|
case 3: is_out = READ(FIL_RUNOUT4_PIN) == FIL_RUNOUT_INVERTING; break; |
|
|
#if NUM_RUNOUT_SENSORS > 4 |
|
|
#if NUM_RUNOUT_SENSORS > 4 |
|
|
case 4: return READ(FIL_RUNOUT5_PIN) == FIL_RUNOUT_INVERTING; |
|
|
case 4: is_out = READ(FIL_RUNOUT5_PIN) == FIL_RUNOUT_INVERTING; break; |
|
|
#endif |
|
|
#endif |
|
|
#endif |
|
|
#endif |
|
|
#endif |
|
|
#endif |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
return false; |
|
|
return (is_out ? ++runout_count : (runout_count = 0)) > FIL_RUNOUT_THRESHOLD; |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|