Filament sensor cleanup

This commit is contained in:
Scott Lahteine 2021-02-28 19:50:17 -06:00 committed by Scott Lahteine
parent dd42831cba
commit 1aa421efe5
8 changed files with 20 additions and 20 deletions

View File

@ -192,11 +192,7 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
KEEPALIVE_STATE(PAUSED_FOR_USER); KEEPALIVE_STATE(PAUSED_FOR_USER);
wait_for_user = true; // LCD click or M108 will clear this wait_for_user = true; // LCD click or M108 will clear this
#if ENABLED(HOST_PROMPT_SUPPORT) #if ENABLED(HOST_PROMPT_SUPPORT)
const char tool = '0' const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, active_extruder);
#if NUM_RUNOUT_SENSORS > 1
+ active_extruder
#endif
;
host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Load Filament T"), tool, CONTINUE_STR); host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Load Filament T"), tool, CONTINUE_STR);
#endif #endif

View File

@ -88,11 +88,7 @@ void event_filament_runout() {
TERN_(EXTENSIBLE_UI, ExtUI::onFilamentRunout(ExtUI::getActiveTool())); TERN_(EXTENSIBLE_UI, ExtUI::onFilamentRunout(ExtUI::getActiveTool()));
#if EITHER(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS) #if EITHER(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS)
const char tool = '0' const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, active_extruder);
#if NUM_RUNOUT_SENSORS > 1
+ active_extruder
#endif
;
#endif #endif
//action:out_of_filament //action:out_of_filament

View File

@ -230,7 +230,7 @@ class FilamentSensorBase {
change = old_state ^ new_state; change = old_state ^ new_state;
old_state = new_state; old_state = new_state;
#ifdef FILAMENT_RUNOUT_SENSOR_DEBUG #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
if (change) { if (change) {
SERIAL_ECHOPGM("Motion detected:"); SERIAL_ECHOPGM("Motion detected:");
LOOP_L_N(e, NUM_RUNOUT_SENSORS) LOOP_L_N(e, NUM_RUNOUT_SENSORS)
@ -266,12 +266,12 @@ class FilamentSensorBase {
private: private:
static inline bool poll_runout_state(const uint8_t extruder) { static inline bool poll_runout_state(const uint8_t extruder) {
const uint8_t runout_states = poll_runout_states(); const uint8_t runout_states = poll_runout_states();
#if NUM_RUNOUT_SENSORS == 1 #if MULTI_FILAMENT_SENSOR
UNUSED(extruder);
#else
if ( !TERN0(DUAL_X_CARRIAGE, idex_is_duplicating()) if ( !TERN0(DUAL_X_CARRIAGE, idex_is_duplicating())
&& !TERN0(MULTI_NOZZLE_DUPLICATION, extruder_duplication_enabled) && !TERN0(MULTI_NOZZLE_DUPLICATION, extruder_duplication_enabled)
) return TEST(runout_states, extruder); // A specific extruder ran out ) return TEST(runout_states, extruder); // A specific extruder ran out
#else
UNUSED(extruder);
#endif #endif
return !!runout_states; // Any extruder ran out return !!runout_states; // Any extruder ran out
} }
@ -282,7 +282,7 @@ class FilamentSensorBase {
static inline void run() { static inline void run() {
const bool out = poll_runout_state(active_extruder); const bool out = poll_runout_state(active_extruder);
if (!out) filament_present(active_extruder); if (!out) filament_present(active_extruder);
#ifdef FILAMENT_RUNOUT_SENSOR_DEBUG #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
static bool was_out = false; static bool was_out = false;
if (out != was_out) { if (out != was_out) {
was_out = out; was_out = out;
@ -315,7 +315,7 @@ class FilamentSensorBase {
} }
static inline void run() { static inline void run() {
#ifdef FILAMENT_RUNOUT_SENSOR_DEBUG #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
static millis_t t = 0; static millis_t t = 0;
const millis_t ms = millis(); const millis_t ms = millis();
if (ELAPSED(ms, t)) { if (ELAPSED(ms, t)) {

View File

@ -83,7 +83,7 @@ void GcodeSuite::M600() {
int8_t DXC_ext = target_extruder; int8_t DXC_ext = target_extruder;
if (!parser.seen('T')) { // If no tool index is specified, M600 was (probably) sent in response to filament runout. if (!parser.seen('T')) { // If no tool index is specified, M600 was (probably) sent in response to filament runout.
// In this case, for duplicating modes set DXC_ext to the extruder that ran out. // In this case, for duplicating modes set DXC_ext to the extruder that ran out.
#if HAS_FILAMENT_SENSOR && NUM_RUNOUT_SENSORS > 1 #if MULTI_FILAMENT_SENSOR
if (idex_is_duplicating()) if (idex_is_duplicating())
DXC_ext = (READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT2_STATE) ? 1 : 0; DXC_ext = (READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT2_STATE) ? 1 : 0;
#else #else

View File

@ -128,6 +128,9 @@
#if ENABLED(FILAMENT_RUNOUT_SENSOR) #if ENABLED(FILAMENT_RUNOUT_SENSOR)
#define HAS_FILAMENT_SENSOR 1 #define HAS_FILAMENT_SENSOR 1
#if NUM_RUNOUT_SENSORS > 1
#define MULTI_FILAMENT_SENSOR 1
#endif
#ifdef FILAMENT_RUNOUT_DISTANCE_MM #ifdef FILAMENT_RUNOUT_DISTANCE_MM
#define HAS_FILAMENT_RUNOUT_DISTANCE 1 #define HAS_FILAMENT_RUNOUT_DISTANCE 1
#endif #endif

View File

@ -340,8 +340,10 @@ namespace ExtUI {
#endif #endif
} }
extruder_t getActiveTool() { extruder_t getTool(const uint8_t extruder) {
switch (active_extruder) { switch (extruder) {
case 7: return E7;
case 6: return E6;
case 5: return E5; case 5: return E5;
case 4: return E4; case 4: return E4;
case 3: return E3; case 3: return E3;
@ -351,6 +353,8 @@ namespace ExtUI {
} }
} }
extruder_t getActiveTool() { return getTool(active_extruder); }
bool isMoving() { return planner.has_blocks_queued(); } bool isMoving() { return planner.has_blocks_queued(); }
bool canMove(const axis_t axis) { bool canMove(const axis_t axis) {

View File

@ -215,6 +215,7 @@ namespace ExtUI {
void setAxisMaxJerk_mm_s(const float, const extruder_t); void setAxisMaxJerk_mm_s(const float, const extruder_t);
#endif #endif
extruder_t getTool(const uint8_t extruder);
extruder_t getActiveTool(); extruder_t getActiveTool();
void setActiveTool(const extruder_t, bool no_move); void setActiveTool(const extruder_t, bool no_move);

View File

@ -35,7 +35,7 @@
#define MOSFET_D_PIN 7 #define MOSFET_D_PIN 7
#define FIL_RUNOUT_PIN 2 #define FIL_RUNOUT_PIN 2
#if NUM_RUNOUT_SENSORS > 1 #if NUM_RUNOUT_SENSORS >= 2
#define FIL_RUNOUT2_PIN 15 // Creality CR-X can use dual runout sensors #define FIL_RUNOUT2_PIN 15 // Creality CR-X can use dual runout sensors
#endif #endif