From cfd31ff70ee949eb5eea61bf30eac24aef9fcb9c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 5 May 2020 23:18:23 -0500 Subject: [PATCH] Add HAS_FILAMENT_RUNOUT_DISTANCE --- Marlin/src/feature/runout.cpp | 9 +++---- Marlin/src/feature/runout.h | 26 +++++++------------ Marlin/src/gcode/feature/runout/M412.cpp | 12 +++------ Marlin/src/inc/Conditionals_adv.h | 3 +++ .../screens/filament_runout_screen.cpp | 4 +-- Marlin/src/lcd/extui/ui_api.cpp | 2 +- Marlin/src/lcd/extui/ui_api.h | 2 +- Marlin/src/lcd/menu/menu_advanced.cpp | 4 +-- Marlin/src/module/configuration_store.cpp | 10 +++---- Marlin/src/module/stepper.cpp | 6 ++--- 10 files changed, 32 insertions(+), 46 deletions(-) diff --git a/Marlin/src/feature/runout.cpp b/Marlin/src/feature/runout.cpp index bba4f4b1f..452781b7f 100644 --- a/Marlin/src/feature/runout.cpp +++ b/Marlin/src/feature/runout.cpp @@ -51,13 +51,12 @@ void FilamentSensorBase::filament_present(const uint8_t extruder) { runout.filament_present(extruder); // calls response.filament_present(extruder) } -#if ENABLED(FILAMENT_MOTION_SENSOR) - uint8_t FilamentSensorEncoder::motion_detected; -#endif - -#ifdef FILAMENT_RUNOUT_DISTANCE_MM +#if HAS_FILAMENT_RUNOUT_DISTANCE float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM; volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS]; + #if ENABLED(FILAMENT_MOTION_SENSOR) + uint8_t FilamentSensorEncoder::motion_detected; + #endif #else int8_t RunoutResponseDebounced::runout_count; // = 0 #endif diff --git a/Marlin/src/feature/runout.h b/Marlin/src/feature/runout.h index a170d5e32..ad96d495c 100644 --- a/Marlin/src/feature/runout.h +++ b/Marlin/src/feature/runout.h @@ -84,7 +84,7 @@ class TFilamentMonitor : public FilamentMonitorBase { response.filament_present(extruder); } - #ifdef FILAMENT_RUNOUT_DISTANCE_MM + #if HAS_FILAMENT_RUNOUT_DISTANCE static inline float& runout_distance() { return response.runout_distance_mm; } static inline void set_runout_distance(const float &mm) { response.runout_distance_mm = mm; } #endif @@ -103,15 +103,11 @@ class TFilamentMonitor : public FilamentMonitorBase { if ( enabled && !filament_ran_out && (printingIsActive() || TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print)) ) { - #ifdef FILAMENT_RUNOUT_DISTANCE_MM - cli(); // Prevent RunoutResponseDelayed::block_completed from accumulating here - #endif + TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, cli()); // Prevent RunoutResponseDelayed::block_completed from accumulating here response.run(); sensor.run(); const bool ran_out = response.has_run_out(); - #ifdef FILAMENT_RUNOUT_DISTANCE_MM - sei(); - #endif + TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, sei()); if (ran_out) { filament_ran_out = true; event_filament_runout(); @@ -242,7 +238,7 @@ class FilamentSensorBase { /********************************* RESPONSE TYPE *********************************/ -#ifdef FILAMENT_RUNOUT_DISTANCE_MM +#if HAS_FILAMENT_RUNOUT_DISTANCE // RunoutResponseDelayed triggers a runout event only if the length // of filament specified by FILAMENT_RUNOUT_DISTANCE_MM has been fed @@ -293,7 +289,7 @@ class FilamentSensorBase { } }; -#else // !FILAMENT_RUNOUT_DISTANCE_MM +#else // !HAS_FILAMENT_RUNOUT_DISTANCE // RunoutResponseDebounced triggers a runout event after a runout // condition has been detected runout_threshold times in a row. @@ -310,17 +306,13 @@ class FilamentSensorBase { static inline void filament_present(const uint8_t) { runout_count = runout_threshold; } }; -#endif // !FILAMENT_RUNOUT_DISTANCE_MM +#endif // !HAS_FILAMENT_RUNOUT_DISTANCE /********************************* TEMPLATE SPECIALIZATION *********************************/ typedef TFilamentMonitor< - #ifdef FILAMENT_RUNOUT_DISTANCE_MM - RunoutResponseDelayed, - TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch) - #else - RunoutResponseDebounced, FilamentSensorSwitch - #endif -> FilamentMonitor; + TERN(HAS_FILAMENT_RUNOUT_DISTANCE, RunoutResponseDelayed, RunoutResponseDebounced), + TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch) + > FilamentMonitor; extern FilamentMonitor runout; diff --git a/Marlin/src/gcode/feature/runout/M412.cpp b/Marlin/src/gcode/feature/runout/M412.cpp index f746dddfa..f9833623c 100644 --- a/Marlin/src/gcode/feature/runout/M412.cpp +++ b/Marlin/src/gcode/feature/runout/M412.cpp @@ -32,12 +32,8 @@ */ void GcodeSuite::M412() { if (parser.seen("RS" - #ifdef FILAMENT_RUNOUT_DISTANCE_MM - "D" - #endif - #if ENABLED(HOST_ACTION_COMMANDS) - "H" - #endif + TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, "D") + TERN_(HOST_ACTION_COMMANDS, "H") )) { #if ENABLED(HOST_ACTION_COMMANDS) if (parser.seen('H')) runout.host_handling = parser.value_bool(); @@ -45,7 +41,7 @@ void GcodeSuite::M412() { const bool seenR = parser.seen('R'), seenS = parser.seen('S'); if (seenR || seenS) runout.reset(); if (seenS) runout.enabled = parser.value_bool(); - #ifdef FILAMENT_RUNOUT_DISTANCE_MM + #if HAS_FILAMENT_RUNOUT_DISTANCE if (parser.seen('D')) runout.set_runout_distance(parser.value_linear_units()); #endif } @@ -53,7 +49,7 @@ void GcodeSuite::M412() { SERIAL_ECHO_START(); SERIAL_ECHOPGM("Filament runout "); serialprintln_onoff(runout.enabled); - #ifdef FILAMENT_RUNOUT_DISTANCE_MM + #if HAS_FILAMENT_RUNOUT_DISTANCE SERIAL_ECHOLNPAIR("Filament runout distance (mm): ", runout.runout_distance()); #endif } diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 70a133303..5dc9e9e8d 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -70,6 +70,9 @@ #if ENABLED(FILAMENT_RUNOUT_SENSOR) #define HAS_FILAMENT_SENSOR 1 + #ifdef FILAMENT_RUNOUT_DISTANCE_MM + #define HAS_FILAMENT_RUNOUT_DISTANCE 1 + #endif #endif // Let SD_FINISHED_RELEASECOMMAND stand in for SD_FINISHED_STEPPERRELEASE diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/filament_runout_screen.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/filament_runout_screen.cpp index 9830123ab..f1b0a69ad 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/filament_runout_screen.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/filament_runout_screen.cpp @@ -35,7 +35,7 @@ void FilamentRunoutScreen::onRedraw(draw_mode_t what) { w.heading( GET_TEXT_F(MSG_FILAMENT)); w.toggle( 2, GET_TEXT_F(MSG_RUNOUT_SENSOR), getFilamentRunoutEnabled()); - #ifdef FILAMENT_RUNOUT_DISTANCE_MM + #if HAS_FILAMENT_RUNOUT_DISTANCE extern const char NUL_STR[]; w.heading(GET_TEXT_F(MSG_RUNOUT_DISTANCE_MM)); w.units(GET_TEXT_F(MSG_UNITS_MM)); @@ -51,7 +51,7 @@ bool FilamentRunoutScreen::onTouchHeld(uint8_t tag) { const float increment = getIncrement(); switch (tag) { case 2: setFilamentRunoutEnabled(!getFilamentRunoutEnabled()); break; - #ifdef FILAMENT_RUNOUT_DISTANCE_MM + #if HAS_FILAMENT_RUNOUT_DISTANCE case 10: UI_DECREMENT(FilamentRunoutDistance_mm); break; case 11: UI_INCREMENT(FilamentRunoutDistance_mm); break; #endif diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index e1c8dd9ac..65518908c 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -591,7 +591,7 @@ namespace ExtUI { bool getFilamentRunoutEnabled() { return runout.enabled; } void setFilamentRunoutEnabled(const bool value) { runout.enabled = value; } - #ifdef FILAMENT_RUNOUT_DISTANCE_MM + #if HAS_FILAMENT_RUNOUT_DISTANCE float getFilamentRunoutDistance_mm() { return runout.runout_distance(); } void setFilamentRunoutDistance_mm(const float value) { runout.set_runout_distance(constrain(value, 0, 999)); } #endif diff --git a/Marlin/src/lcd/extui/ui_api.h b/Marlin/src/lcd/extui/ui_api.h index 506157f9a..0f9c6ff48 100644 --- a/Marlin/src/lcd/extui/ui_api.h +++ b/Marlin/src/lcd/extui/ui_api.h @@ -237,7 +237,7 @@ namespace ExtUI { bool getFilamentRunoutEnabled(); void setFilamentRunoutEnabled(const bool); - #ifdef FILAMENT_RUNOUT_DISTANCE_MM + #if HAS_FILAMENT_RUNOUT_DISTANCE float getFilamentRunoutDistance_mm(); void setFilamentRunoutDistance_mm(const float); #endif diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index aec0b867f..bc7464362 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -43,7 +43,7 @@ #include "../../module/temperature.h" #endif -#if ENABLED(FILAMENT_RUNOUT_SENSOR) && FILAMENT_RUNOUT_DISTANCE_MM +#if HAS_FILAMENT_RUNOUT_DISTANCE #include "../../feature/runout.h" #endif @@ -142,7 +142,7 @@ void menu_cancelobject(); #endif #endif - #if ENABLED(FILAMENT_RUNOUT_SENSOR) && FILAMENT_RUNOUT_DISTANCE_MM + #if HAS_FILAMENT_RUNOUT_DISTANCE editable.decimal = runout.runout_distance(); EDIT_ITEM(float3, MSG_RUNOUT_DISTANCE_MM, &editable.decimal, 1, 30, []{ runout.set_runout_distance(editable.decimal); }, true diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index d86016db6..ead9ea060 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -604,7 +604,7 @@ void MarlinSettings::postprocess() { #else constexpr bool runout_sensor_enabled = true; #endif - #if HAS_FILAMENT_SENSOR && defined(FILAMENT_RUNOUT_DISTANCE_MM) + #if HAS_FILAMENT_RUNOUT_DISTANCE const float &runout_distance_mm = runout.runout_distance(); #else constexpr float runout_distance_mm = 0; @@ -1460,7 +1460,7 @@ void MarlinSettings::postprocess() { float runout_distance_mm; EEPROM_READ(runout_distance_mm); - #if HAS_FILAMENT_SENSOR && defined(FILAMENT_RUNOUT_DISTANCE_MM) + #if HAS_FILAMENT_RUNOUT_DISTANCE if (!validating) runout.set_runout_distance(runout_distance_mm); #endif } @@ -2384,9 +2384,7 @@ void MarlinSettings::reset() { #if HAS_FILAMENT_SENSOR runout.enabled = true; runout.reset(); - #ifdef FILAMENT_RUNOUT_DISTANCE_MM - runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM); - #endif + TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM)); #endif // @@ -3551,7 +3549,7 @@ void MarlinSettings::reset() { CONFIG_ECHO_START(); SERIAL_ECHOLNPAIR( " M412 S", int(runout.enabled) - #ifdef FILAMENT_RUNOUT_DISTANCE_MM + #if HAS_FILAMENT_RUNOUT_DISTANCE , " D", LINEAR_UNIT(runout.runout_distance()) #endif ); diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 63fee87d0..3b1b787af 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -118,7 +118,7 @@ Stepper stepper; // Singleton #include "../feature/mixing.h" #endif -#ifdef FILAMENT_RUNOUT_DISTANCE_MM +#if HAS_FILAMENT_RUNOUT_DISTANCE #include "../feature/runout.h" #endif @@ -1808,9 +1808,7 @@ uint32_t Stepper::block_phase_isr() { PAGE_SEGMENT_UPDATE_POS(E); } #endif - #ifdef FILAMENT_RUNOUT_DISTANCE_MM - runout.block_completed(current_block); - #endif + TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.block_completed(current_block)); discard_current_block(); } else {