Allow for distinct runout sensor states

You need to define DISTINCT_FIL_RUNOUT_STATES, and then optionally
FIL_RUNOUT#_STATE for each sensor you want to override.
This commit is contained in:
Costas Basdekis 2020-10-31 11:37:41 +00:00
parent 6071a0835a
commit 683b0c5021
7 changed files with 189 additions and 9 deletions

View file

@ -1176,10 +1176,26 @@
//#define FILAMENT_RUNOUT_SENSOR
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
#define FIL_RUNOUT_ENABLED_DEFAULT true // Enable the sensor on startup. Override with M412 followed by M500.
#define NUM_RUNOUT_SENSORS 1 // Number of sensors, up to one per extruder. Define a FIL_RUNOUT#_PIN for each.
#define NUM_RUNOUT_SENSORS 1 // Number of sensors, up to one per extruder. Define a FIL_RUNOUT#_PIN, and optionally a FIL_RUNOUT#_STATE, for each.
#define FIL_RUNOUT_STATE LOW // Pin state indicating that filament is NOT present.
#define FIL_RUNOUT_PULLUP // Use internal pullup for filament runout pins.
//#define FIL_RUNOUT_PULLDOWN // Use internal pulldown for filament runout pins.
/**
* With this option each sensor can have a separate state than the first one.
* To override the state for a sensor, up to NUM_RUNOUT_SENSORS, set
* FIL_RUNOUT#_STATE, otherwise FIL_RUNOUT_STATE will be used.
*/
//#define DISTINCT_FIL_RUNOUT_STATES
#ifdef DISTINCT_FIL_RUNOUT_STATES
//#define FIL_RUNOUT1_STATE LOW
//#define FIL_RUNOUT2_STATE LOW
//#define FIL_RUNOUT3_STATE LOW
//#define FIL_RUNOUT4_STATE LOW
//#define FIL_RUNOUT5_STATE LOW
//#define FIL_RUNOUT6_STATE LOW
//#define FIL_RUNOUT7_STATE LOW
//#define FIL_RUNOUT8_STATE LOW
#endif
// Set one or more commands to execute on filament runout.
// (After 'M412 H' Marlin will ask the host to handle the process.)

View file

@ -173,9 +173,50 @@ class FilamentSensorBase {
// Return a bitmask of runout flag states (1 bits always indicates runout)
static inline uint8_t poll_runout_states() {
return poll_runout_pins()
#if FIL_RUNOUT_STATE == LOW
^ uint8_t(_BV(NUM_RUNOUT_SENSORS) - 1)
#endif
#if ENABLED(DISTINCT_FIL_RUNOUT_STATES)
#if FIL_RUNOUT1_STATE == LOW
^ uint8_t(_BV(1 - 1))
#endif
#if NUM_RUNOUT_SENSORS > 1
#if FIL_RUNOUT2_STATE == LOW
^ uint8_t(_BV(2 - 1))
#endif
#endif
#if NUM_RUNOUT_SENSORS > 2
#if FIL_RUNOUT3_STATE == LOW
^ uint8_t(_BV(3 - 1))
#endif
#endif
#if NUM_RUNOUT_SENSORS > 3
#if FIL_RUNOUT4_STATE == LOW
^ uint8_t(_BV(4 - 1))
#endif
#endif
#if NUM_RUNOUT_SENSORS > 4
#if FIL_RUNOUT5_STATE == LOW
^ uint8_t(_BV(5 - 1))
#endif
#endif
#if NUM_RUNOUT_SENSORS > 5
#if FIL_RUNOUT6_STATE == LOW
^ uint8_t(_BV(6 - 1))
#endif
#endif
#if NUM_RUNOUT_SENSORS > 6
#if FIL_RUNOUT7_STATE == LOW
^ uint8_t(_BV(7 - 1))
#endif
#endif
#if NUM_RUNOUT_SENSORS > 7
#if FIL_RUNOUT8_STATE == LOW
^ uint8_t(_BV(8 - 1))
#endif
#endif
#else // !ENABLED(DISTINCT_FIL_RUNOUT_STATES)
#if FIL_RUNOUT_STATE == LOW
^ uint8_t(_BV(NUM_RUNOUT_SENSORS) - 1)
#endif
#endif // ENABLED(DISTINCT_FIL_RUNOUT_STATES)
;
}
};

View file

@ -88,7 +88,7 @@ void GcodeSuite::M600() {
// In this case, for duplicating modes set DXC_ext to the extruder that ran out.
#if HAS_FILAMENT_SENSOR && NUM_RUNOUT_SENSORS > 1
if (idex_is_duplicating())
DXC_ext = (READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_STATE) ? 1 : 0;
DXC_ext = (READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT2_STATE) ? 1 : 0;
#else
DXC_ext = active_extruder;
#endif

View file

@ -675,6 +675,78 @@
#define HAS_BED_PROBE 1
#endif
#if ENABLED(DISTINCT_FIL_RUNOUT_STATES)
#ifndef FIL_RUNOUT1_STATE
#define FIL_RUNOUT1_STATE FIL_RUNOUT_STATE
#endif
#if NUM_RUNOUT_SENSORS > 1
#ifndef FIL_RUNOUT2_STATE
#define FIL_RUNOUT2_STATE FIL_RUNOUT_STATE
#endif
#endif
#if NUM_RUNOUT_SENSORS > 2
#ifndef FIL_RUNOUT3_STATE
#define FIL_RUNOUT3_STATE FIL_RUNOUT_STATE
#endif
#endif
#if NUM_RUNOUT_SENSORS > 3
#ifndef FIL_RUNOUT4_STATE
#define FIL_RUNOUT4_STATE FIL_RUNOUT_STATE
#endif
#endif
#if NUM_RUNOUT_SENSORS > 4
#ifndef FIL_RUNOUT5_STATE
#define FIL_RUNOUT5_STATE FIL_RUNOUT_STATE
#endif
#endif
#if NUM_RUNOUT_SENSORS > 5
#ifndef FIL_RUNOUT6_STATE
#define FIL_RUNOUT6_STATE FIL_RUNOUT_STATE
#endif
#endif
#if NUM_RUNOUT_SENSORS > 6
#ifndef FIL_RUNOUT7_STATE
#define FIL_RUNOUT7_STATE FIL_RUNOUT_STATE
#endif
#endif
#if NUM_RUNOUT_SENSORS > 7
#ifndef FIL_RUNOUT8_STATE
#define FIL_RUNOUT8_STATE FIL_RUNOUT_STATE
#endif
#endif
#else // !ENABLED(DISTINCT_FIL_RUNOUT_STATES)
#undef FIL_RUNOUT1_STATE
#define FIL_RUNOUT1_STATE FIL_RUNOUT_STATE
#undef FIL_RUNOUT2_STATE
#if NUM_RUNOUT_SENSORS > 1
#define FIL_RUNOUT2_STATE FIL_RUNOUT_STATE
#endif
#undef FIL_RUNOUT3_STATE
#if NUM_RUNOUT_SENSORS > 2
#define FIL_RUNOUT3_STATE FIL_RUNOUT_STATE
#endif
#undef FIL_RUNOUT4_STATE
#if NUM_RUNOUT_SENSORS > 3
#define FIL_RUNOUT4_STATE FIL_RUNOUT_STATE
#endif
#undef FIL_RUNOUT5_STATE
#if NUM_RUNOUT_SENSORS > 4
#define FIL_RUNOUT5_STATE FIL_RUNOUT_STATE
#endif
#undef FIL_RUNOUT6_STATE
#if NUM_RUNOUT_SENSORS > 5
#define FIL_RUNOUT6_STATE FIL_RUNOUT_STATE
#endif
#undef FIL_RUNOUT7_STATE
#if NUM_RUNOUT_SENSORS > 6
#define FIL_RUNOUT7_STATE FIL_RUNOUT_STATE
#endif
#undef FIL_RUNOUT8_STATE
#if NUM_RUNOUT_SENSORS > 7
#define FIL_RUNOUT8_STATE FIL_RUNOUT_STATE
#endif
#endif // ENABLED(DISTINCT_FIL_RUNOUT_STATES)
#if ANY(HAS_BED_PROBE, PROBE_MANUALLY, MESH_BED_LEVELING)
#define PROBE_SELECTED 1
#endif

View file

@ -831,6 +831,46 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#elif DISABLED(ADVANCED_PAUSE_FEATURE)
static_assert(nullptr == strstr(FILAMENT_RUNOUT_SCRIPT, "M600"), "ADVANCED_PAUSE_FEATURE is required to use M600 with FILAMENT_RUNOUT_SENSOR.");
#endif
#if DISABLED(DISTINCT_FIL_RUNOUT_STATES)
#ifdef FIL_RUNOUT1_STATE
#warning "You have defined FIL_RUNOUT1_STATE but you haven't defined DISTINCT_FIL_RUNOUT_STATES"
#endif
#if NUM_RUNOUT_SENSORS > 1
#ifdef FIL_RUNOUT2_STATE
#warning "You have defined FIL_RUNOUT2_STATE but you haven't defined DISTINCT_FIL_RUNOUT_STATES"
#endif
#endif
#if NUM_RUNOUT_SENSORS > 2
#ifdef FIL_RUNOUT3_STATE
#warning "You have defined FIL_RUNOUT3_STATE but you haven't defined DISTINCT_FIL_RUNOUT_STATES"
#endif
#endif
#if NUM_RUNOUT_SENSORS > 3
#ifdef FIL_RUNOUT4_STATE
#warning "You have defined FIL_RUNOUT4_STATE but you haven't defined DISTINCT_FIL_RUNOUT_STATES"
#endif
#endif
#if NUM_RUNOUT_SENSORS > 4
#ifdef FIL_RUNOUT5_STATE
#warning "You have defined FIL_RUNOUT5_STATE but you haven't defined DISTINCT_FIL_RUNOUT_STATES"
#endif
#endif
#if NUM_RUNOUT_SENSORS > 5
#ifdef FIL_RUNOUT6_STATE
#warning "You have defined FIL_RUNOUT6_STATE but you haven't defined DISTINCT_FIL_RUNOUT_STATES"
#endif
#endif
#if NUM_RUNOUT_SENSORS > 6
#ifdef FIL_RUNOUT7_STATE
#warning "You have defined FIL_RUNOUT7_STATE but you haven't defined DISTINCT_FIL_RUNOUT_STATES"
#endif
#endif
#if NUM_RUNOUT_SENSORS > 7
#ifdef FIL_RUNOUT8_STATE
#warning "You have defined FIL_RUNOUT8_STATE but you haven't defined DISTINCT_FIL_RUNOUT_STATES"
#endif
#endif
#endif // DISABLED(DISTINCT_FIL_RUNOUT_STATES)
#endif
/**

View file

@ -92,12 +92,12 @@ void EndstopStatesScreen::onRedraw(draw_mode_t) {
PIN_DISABLED(5, 3, PSTR(STR_Z_MIN), Z_MIN)
#endif
#if ENABLED(FILAMENT_RUNOUT_SENSOR) && PIN_EXISTS(FIL_RUNOUT)
PIN_ENABLED (1, 4, GET_TEXT_F(MSG_RUNOUT_1), FIL_RUNOUT, FIL_RUNOUT_STATE)
PIN_ENABLED (1, 4, GET_TEXT_F(MSG_RUNOUT_1), FIL_RUNOUT, FIL_RUNOUT1_STATE)
#else
PIN_DISABLED(1, 4, GET_TEXT_F(MSG_RUNOUT_1), FIL_RUNOUT)
#endif
#if BOTH(HAS_MULTI_EXTRUDER, FILAMENT_RUNOUT_SENSOR) && PIN_EXISTS(FIL_RUNOUT2)
PIN_ENABLED (3, 4, GET_TEXT_F(MSG_RUNOUT_2), FIL_RUNOUT2, FIL_RUNOUT_STATE)
PIN_ENABLED (3, 4, GET_TEXT_F(MSG_RUNOUT_2), FIL_RUNOUT2, FIL_RUNOUT2_STATE)
#else
PIN_DISABLED(3, 4, GET_TEXT_F(MSG_RUNOUT_2), FIL_RUNOUT2)
#endif

View file

@ -461,16 +461,27 @@ void _O2 Endstops::report_states() {
#if NUM_RUNOUT_SENSORS == 1
print_es_state(READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_STATE, PSTR(STR_FILAMENT_RUNOUT_SENSOR));
#else
#define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; break;
#if ENABLED(DISTINCT_FIL_RUNOUT_STATES)
#define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; state = FIL_RUNOUT##N##_STATE; break;
#else
#define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; break;
#endif
LOOP_S_LE_N(i, 1, NUM_RUNOUT_SENSORS) {
pin_t pin;
#if ENABLED(DISTINCT_FIL_RUNOUT_STATES)
uint8_t state;
#endif
switch (i) {
default: continue;
REPEAT_S(1, INCREMENT(NUM_RUNOUT_SENSORS), _CASE_RUNOUT)
}
SERIAL_ECHOPGM(STR_FILAMENT_RUNOUT_SENSOR);
if (i > 1) SERIAL_CHAR(' ', '0' + i);
print_es_state(extDigitalRead(pin) != FIL_RUNOUT_STATE);
#if ENABLED(DISTINCT_FIL_RUNOUT_STATES)
print_es_state(extDigitalRead(pin) != state);
#else
print_es_state(extDigitalRead(pin) != FIL_RUNOUT_STATE);
#endif
}
#undef _CASE_RUNOUT
#endif