Skip to content

Commit

Permalink
Add poll_runout_states, which returns 1 for runouts (MarlinFirmware#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and Weruminger committed Jan 6, 2019
1 parent 7040ae8 commit e7cc95c
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions Marlin/src/feature/runout.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class FilamentSensorBase {
static void filament_present(const uint8_t extruder);

public:
static void setup() {
static inline void setup() {
#if ENABLED(FIL_RUNOUT_PULLUP)
#define INIT_RUNOUT_PIN(P) SET_INPUT_PULLUP(P)
#elif ENABLED(FIL_RUNOUT_PULLDOWN)
Expand All @@ -138,14 +138,8 @@ class FilamentSensorBase {
#endif
}

#if FIL_RUNOUT_INVERTING
#define FIL_RUNOUT_INVERT_MASK (_BV(NUM_RUNOUT_SENSORS) - 1)
#else
#define FIL_RUNOUT_INVERT_MASK 0
#endif

// Return a bitmask of all runout sensor states
static uint8_t poll_runout_pins() {
// Return a bitmask of runout pin states
static inline uint8_t poll_runout_pins() {
return (
(READ(FIL_RUNOUT_PIN ) ? _BV(0) : 0)
#if NUM_RUNOUT_SENSORS > 1
Expand All @@ -163,7 +157,18 @@ class FilamentSensorBase {
#endif
#endif
#endif
) ^ FIL_RUNOUT_INVERT_MASK;
);
}

// Return a bitmask of runout flag states (1 bits always indicates runout)
static inline uint8_t poll_runout_states() {
return poll_runout_pins() ^ uint8_t(
#if DISABLED(FIL_RUNOUT_INVERTING)
_BV(NUM_RUNOUT_SENSORS) - 1
#else
0
#endif
);
}
};

Expand Down Expand Up @@ -219,30 +224,30 @@ class FilamentSensorBase {
*/
class FilamentSensorSwitch : public FilamentSensorBase {
private:
static bool poll_runout_pin(const uint8_t extruder) {
const uint8_t runout_bits = poll_runout_pins();
static inline bool poll_runout_state(const uint8_t extruder) {
const uint8_t runout_states = poll_runout_states();
#if NUM_RUNOUT_SENSORS == 1
UNUSED(extruder);
return runout_bits; // A single sensor applying to all extruders
return runout_states; // A single sensor applying to all extruders
#else
#if ENABLED(DUAL_X_CARRIAGE)
if (dual_x_carriage_mode == DXC_DUPLICATION_MODE || dual_x_carriage_mode == DXC_SCALED_DUPLICATION_MODE)
return runout_bits; // Any extruder
return runout_states; // Any extruder
else
#elif ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
if (extruder_duplication_enabled)
return runout_bits; // Any extruder
return runout_states; // Any extruder
else
#endif
return TEST(runout_bits, extruder); // Specific extruder
return TEST(runout_states, extruder); // Specific extruder
#endif
}

public:
static inline void block_completed(const block_t* const b) { UNUSED(b); }

static inline void run() {
const bool out = poll_runout_pin(active_extruder);
const bool out = poll_runout_state(active_extruder);
if (!out) filament_present(active_extruder);
#ifdef FILAMENT_RUNOUT_SENSOR_DEBUG
static bool was_out = false;
Expand Down Expand Up @@ -272,7 +277,7 @@ class FilamentSensorBase {
public:
static float runout_distance_mm;

static void reset() {
static inline void reset() {
LOOP_L_N(i, EXTRUDERS) filament_present(i);
}

Expand Down

0 comments on commit e7cc95c

Please sign in to comment.