Support for multiple filament runout sensors

This commit is contained in:
Studiodyne
2018-02-18 09:42:09 +01:00
committed by Scott Lahteine
parent 0106c3e476
commit d3ca82d8c2
7 changed files with 98 additions and 41 deletions

View File

@ -500,7 +500,7 @@ void resume_print(const float &load_length/*=0*/, const float &purge_length/*=AD
planner.set_e_position_mm(destination[E_AXIS] = current_position[E_AXIS] = resume_position[E_AXIS]);
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
filament_ran_out = false;
runout.reset();
#endif
#if ENABLED(ULTIPANEL)

View File

@ -24,21 +24,39 @@
* feature/runout.cpp - Runout sensor support
*/
#include "../inc/MarlinConfig.h"
#include "../inc/MarlinConfigPre.h"
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
#include "../module/stepper.h"
#include "../gcode/queue.h"
#include "runout.h"
bool filament_ran_out = false;
FilamentRunoutSensor runout;
void handle_filament_runout() {
if (!filament_ran_out) {
filament_ran_out = true;
enqueue_and_echo_commands_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
stepper.synchronize();
}
bool FilamentRunoutSensor::filament_ran_out; // = false;
void FilamentRunoutSensor::setup() {
#if ENABLED(FIL_RUNOUT_PULLUP)
#define INIT_RUNOUT_PIN(P) SET_INPUT_PULLUP(P)
#elif ENABLED(FIL_RUNOUT_PULLDOWN)
#define INIT_RUNOUT_PIN(P) SET_INPUT_PULLDOWN(P)
#else
#define INIT_RUNOUT_PIN(P) SET_INPUT(P)
#endif
INIT_RUNOUT_PIN(FIL_RUNOUT_PIN);
#if NUM_RUNOUT_SENSORS > 1
INIT_RUNOUT_PIN(FIL_RUNOUT2_PIN);
#if NUM_RUNOUT_SENSORS > 2
INIT_RUNOUT_PIN(FIL_RUNOUT3_PIN);
#if NUM_RUNOUT_SENSORS > 3
INIT_RUNOUT_PIN(FIL_RUNOUT4_PIN);
#if NUM_RUNOUT_SENSORS > 4
INIT_RUNOUT_PIN(FIL_RUNOUT5_PIN);
#endif
#endif
#endif
#endif
}
#endif // FILAMENT_RUNOUT_SENSOR

View File

@ -27,8 +27,55 @@
#ifndef _RUNOUT_H_
#define _RUNOUT_H_
extern bool filament_ran_out;
#include "../sd/cardreader.h"
#include "../module/printcounter.h"
#include "../module/stepper.h"
#include "../gcode/queue.h"
void handle_filament_runout();
#include "../inc/MarlinConfig.h"
class FilamentRunoutSensor {
FilamentRunoutSensor() {}
static bool filament_ran_out;
static void setup();
FORCE_INLINE static reset() { filament_ran_out = false; }
FORCE_INLINE static bool check() {
#if NUM_RUNOUT_SENSORS < 2
// A single sensor applying to all extruders
return READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
#else
// Read the sensor for the active extruder
switch (active_extruder) {
case 0: return READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
case 1: return READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_INVERTING;
#if NUM_RUNOUT_SENSORS > 2
case 2: return READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT_INVERTING;
#if NUM_RUNOUT_SENSORS > 3
case 3: return READ(FIL_RUNOUT4_PIN) == FIL_RUNOUT_INVERTING;
#if NUM_RUNOUT_SENSORS > 4
case 4: return READ(FIL_RUNOUT5_PIN) == FIL_RUNOUT_INVERTING;
#endif
#endif
#endif
}
#endif
return false;
}
FORCE_INLINE static void run() {
if ((IS_SD_PRINTING || print_job_timer.isRunning()) && check() && !filament_ran_out) {
filament_ran_out = true;
enqueue_and_echo_commands_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
stepper.synchronize();
}
}
};
extern FilamentRunoutSensor runout;
#endif // _RUNOUT_H_