From a62ae2aa2d74613fe15bf2b8ca4390fca53ebf01 Mon Sep 17 00:00:00 2001 From: Steven Haigh Date: Thu, 20 Aug 2020 09:58:18 +1000 Subject: [PATCH] Default Filament Runout Sensor enabled state (#19013) --- Marlin/Configuration.h | 9 +++++---- Marlin/src/feature/runout.cpp | 8 -------- Marlin/src/feature/runout.h | 35 ++++++++++++++++++++++++---------- Marlin/src/module/settings.cpp | 21 +++++++++++--------- 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index a4b6c51ae..24d7c46a6 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -1178,10 +1178,11 @@ */ //#define FILAMENT_RUNOUT_SENSOR #if ENABLED(FILAMENT_RUNOUT_SENSOR) - #define NUM_RUNOUT_SENSORS 1 // Number of sensors, up to one per extruder. Define a FIL_RUNOUT#_PIN 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. + #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 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. // Set one or more commands to execute on filament runout. // (After 'M412 H' Marlin will ask the host to handle the process.) diff --git a/Marlin/src/feature/runout.cpp b/Marlin/src/feature/runout.cpp index 0b5c0ebc2..71f31f214 100644 --- a/Marlin/src/feature/runout.cpp +++ b/Marlin/src/feature/runout.cpp @@ -44,14 +44,6 @@ bool FilamentMonitorBase::enabled = true, #include "../module/tool_change.h" #endif -/** - * Called by FilamentSensorSwitch::run when filament is detected. - * Called by FilamentSensorEncoder::block_completed when motion is detected. - */ -void FilamentSensorBase::filament_present(const uint8_t extruder) { - runout.filament_present(extruder); // calls response.filament_present(extruder) -} - #if HAS_FILAMENT_RUNOUT_DISTANCE float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM; volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS]; diff --git a/Marlin/src/feature/runout.h b/Marlin/src/feature/runout.h index 450ae1830..a7f836684 100644 --- a/Marlin/src/feature/runout.h +++ b/Marlin/src/feature/runout.h @@ -48,6 +48,24 @@ void event_filament_runout(); +template +class TFilamentMonitor; +class FilamentSensorEncoder; +class FilamentSensorSwitch; +class RunoutResponseDelayed; +class RunoutResponseDebounced; + +/********************************* TEMPLATE SPECIALIZATION *********************************/ + +typedef TFilamentMonitor< + TERN(HAS_FILAMENT_RUNOUT_DISTANCE, RunoutResponseDelayed, RunoutResponseDebounced), + TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch) + > FilamentMonitor; + +extern FilamentMonitor runout; + +/*******************************************************************************************/ + class FilamentMonitorBase { public: static bool enabled, filament_ran_out; @@ -121,7 +139,13 @@ class TFilamentMonitor : public FilamentMonitorBase { class FilamentSensorBase { protected: - static void filament_present(const uint8_t extruder); + /** + * Called by FilamentSensorSwitch::run when filament is detected. + * Called by FilamentSensorEncoder::block_completed when motion is detected. + */ + static inline void filament_present(const uint8_t extruder) { + runout.filament_present(extruder); // ...which calls response.filament_present(extruder) + } public: static inline void setup() { @@ -311,12 +335,3 @@ class FilamentSensorBase { }; #endif // !HAS_FILAMENT_RUNOUT_DISTANCE - -/********************************* TEMPLATE SPECIALIZATION *********************************/ - -typedef TFilamentMonitor< - TERN(HAS_FILAMENT_RUNOUT_DISTANCE, RunoutResponseDelayed, RunoutResponseDebounced), - TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch) - > FilamentMonitor; - -extern FilamentMonitor runout; diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index c84bbb44a..29b12e5ca 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -106,6 +106,9 @@ #if HAS_FILAMENT_SENSOR #include "../feature/runout.h" + #ifndef FIL_RUNOUT_ENABLED_DEFAULT + #define FIL_RUNOUT_ENABLED_DEFAULT true + #endif #endif #if ENABLED(EXTRA_LIN_ADVANCE_K) @@ -646,15 +649,16 @@ void MarlinSettings::postprocess() { #if HAS_FILAMENT_SENSOR const bool &runout_sensor_enabled = runout.enabled; #else - constexpr bool runout_sensor_enabled = true; + constexpr int8_t runout_sensor_enabled = -1; #endif + _FIELD_TEST(runout_sensor_enabled); + EEPROM_WRITE(runout_sensor_enabled); + #if HAS_FILAMENT_RUNOUT_DISTANCE const float &runout_distance_mm = runout.runout_distance(); #else constexpr float runout_distance_mm = 0; #endif - _FIELD_TEST(runout_sensor_enabled); - EEPROM_WRITE(runout_sensor_enabled); EEPROM_WRITE(runout_distance_mm); } @@ -1518,13 +1522,12 @@ void MarlinSettings::postprocess() { // Filament Runout Sensor // { - #if HAS_FILAMENT_SENSOR - const bool &runout_sensor_enabled = runout.enabled; - #else - bool runout_sensor_enabled; - #endif + int8_t runout_sensor_enabled; _FIELD_TEST(runout_sensor_enabled); EEPROM_READ(runout_sensor_enabled); + #if HAS_FILAMENT_SENSOR + runout.enabled = runout_sensor_enabled < 0 ? FIL_RUNOUT_ENABLED_DEFAULT : runout_sensor_enabled; + #endif TERN_(HAS_FILAMENT_SENSOR, if (runout.enabled) runout.reset()); @@ -2476,7 +2479,7 @@ void MarlinSettings::reset() { // #if HAS_FILAMENT_SENSOR - runout.enabled = true; + runout.enabled = FIL_RUNOUT_ENABLED_DEFAULT; runout.reset(); TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM)); #endif