Add HAS_FILAMENT_RUNOUT_DISTANCE

This commit is contained in:
Scott Lahteine 2020-05-05 23:18:23 -05:00
parent 45488a431a
commit cfd31ff70e
10 changed files with 32 additions and 46 deletions

View file

@ -51,13 +51,12 @@ void FilamentSensorBase::filament_present(const uint8_t extruder) {
runout.filament_present(extruder); // calls response.filament_present(extruder) runout.filament_present(extruder); // calls response.filament_present(extruder)
} }
#if ENABLED(FILAMENT_MOTION_SENSOR) #if HAS_FILAMENT_RUNOUT_DISTANCE
uint8_t FilamentSensorEncoder::motion_detected;
#endif
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM; float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS]; volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS];
#if ENABLED(FILAMENT_MOTION_SENSOR)
uint8_t FilamentSensorEncoder::motion_detected;
#endif
#else #else
int8_t RunoutResponseDebounced::runout_count; // = 0 int8_t RunoutResponseDebounced::runout_count; // = 0
#endif #endif

View file

@ -84,7 +84,7 @@ class TFilamentMonitor : public FilamentMonitorBase {
response.filament_present(extruder); 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 float& runout_distance() { return response.runout_distance_mm; }
static inline void set_runout_distance(const float &mm) { response.runout_distance_mm = mm; } static inline void set_runout_distance(const float &mm) { response.runout_distance_mm = mm; }
#endif #endif
@ -103,15 +103,11 @@ class TFilamentMonitor : public FilamentMonitorBase {
if ( enabled && !filament_ran_out if ( enabled && !filament_ran_out
&& (printingIsActive() || TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print)) && (printingIsActive() || TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print))
) { ) {
#ifdef FILAMENT_RUNOUT_DISTANCE_MM TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, cli()); // Prevent RunoutResponseDelayed::block_completed from accumulating here
cli(); // Prevent RunoutResponseDelayed::block_completed from accumulating here
#endif
response.run(); response.run();
sensor.run(); sensor.run();
const bool ran_out = response.has_run_out(); const bool ran_out = response.has_run_out();
#ifdef FILAMENT_RUNOUT_DISTANCE_MM TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, sei());
sei();
#endif
if (ran_out) { if (ran_out) {
filament_ran_out = true; filament_ran_out = true;
event_filament_runout(); event_filament_runout();
@ -242,7 +238,7 @@ class FilamentSensorBase {
/********************************* RESPONSE TYPE *********************************/ /********************************* RESPONSE TYPE *********************************/
#ifdef FILAMENT_RUNOUT_DISTANCE_MM #if HAS_FILAMENT_RUNOUT_DISTANCE
// RunoutResponseDelayed triggers a runout event only if the length // RunoutResponseDelayed triggers a runout event only if the length
// of filament specified by FILAMENT_RUNOUT_DISTANCE_MM has been fed // 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 // RunoutResponseDebounced triggers a runout event after a runout
// condition has been detected runout_threshold times in a row. // 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; } static inline void filament_present(const uint8_t) { runout_count = runout_threshold; }
}; };
#endif // !FILAMENT_RUNOUT_DISTANCE_MM #endif // !HAS_FILAMENT_RUNOUT_DISTANCE
/********************************* TEMPLATE SPECIALIZATION *********************************/ /********************************* TEMPLATE SPECIALIZATION *********************************/
typedef TFilamentMonitor< typedef TFilamentMonitor<
#ifdef FILAMENT_RUNOUT_DISTANCE_MM TERN(HAS_FILAMENT_RUNOUT_DISTANCE, RunoutResponseDelayed, RunoutResponseDebounced),
RunoutResponseDelayed, TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch)
TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch) > FilamentMonitor;
#else
RunoutResponseDebounced, FilamentSensorSwitch
#endif
> FilamentMonitor;
extern FilamentMonitor runout; extern FilamentMonitor runout;

View file

@ -32,12 +32,8 @@
*/ */
void GcodeSuite::M412() { void GcodeSuite::M412() {
if (parser.seen("RS" if (parser.seen("RS"
#ifdef FILAMENT_RUNOUT_DISTANCE_MM TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, "D")
"D" TERN_(HOST_ACTION_COMMANDS, "H")
#endif
#if ENABLED(HOST_ACTION_COMMANDS)
"H"
#endif
)) { )) {
#if ENABLED(HOST_ACTION_COMMANDS) #if ENABLED(HOST_ACTION_COMMANDS)
if (parser.seen('H')) runout.host_handling = parser.value_bool(); 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'); const bool seenR = parser.seen('R'), seenS = parser.seen('S');
if (seenR || seenS) runout.reset(); if (seenR || seenS) runout.reset();
if (seenS) runout.enabled = parser.value_bool(); 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()); if (parser.seen('D')) runout.set_runout_distance(parser.value_linear_units());
#endif #endif
} }
@ -53,7 +49,7 @@ void GcodeSuite::M412() {
SERIAL_ECHO_START(); SERIAL_ECHO_START();
SERIAL_ECHOPGM("Filament runout "); SERIAL_ECHOPGM("Filament runout ");
serialprintln_onoff(runout.enabled); serialprintln_onoff(runout.enabled);
#ifdef FILAMENT_RUNOUT_DISTANCE_MM #if HAS_FILAMENT_RUNOUT_DISTANCE
SERIAL_ECHOLNPAIR("Filament runout distance (mm): ", runout.runout_distance()); SERIAL_ECHOLNPAIR("Filament runout distance (mm): ", runout.runout_distance());
#endif #endif
} }

View file

@ -70,6 +70,9 @@
#if ENABLED(FILAMENT_RUNOUT_SENSOR) #if ENABLED(FILAMENT_RUNOUT_SENSOR)
#define HAS_FILAMENT_SENSOR 1 #define HAS_FILAMENT_SENSOR 1
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
#define HAS_FILAMENT_RUNOUT_DISTANCE 1
#endif
#endif #endif
// Let SD_FINISHED_RELEASECOMMAND stand in for SD_FINISHED_STEPPERRELEASE // Let SD_FINISHED_RELEASECOMMAND stand in for SD_FINISHED_STEPPERRELEASE

View file

@ -35,7 +35,7 @@ void FilamentRunoutScreen::onRedraw(draw_mode_t what) {
w.heading( GET_TEXT_F(MSG_FILAMENT)); w.heading( GET_TEXT_F(MSG_FILAMENT));
w.toggle( 2, GET_TEXT_F(MSG_RUNOUT_SENSOR), getFilamentRunoutEnabled()); 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[]; extern const char NUL_STR[];
w.heading(GET_TEXT_F(MSG_RUNOUT_DISTANCE_MM)); w.heading(GET_TEXT_F(MSG_RUNOUT_DISTANCE_MM));
w.units(GET_TEXT_F(MSG_UNITS_MM)); w.units(GET_TEXT_F(MSG_UNITS_MM));
@ -51,7 +51,7 @@ bool FilamentRunoutScreen::onTouchHeld(uint8_t tag) {
const float increment = getIncrement(); const float increment = getIncrement();
switch (tag) { switch (tag) {
case 2: setFilamentRunoutEnabled(!getFilamentRunoutEnabled()); break; case 2: setFilamentRunoutEnabled(!getFilamentRunoutEnabled()); break;
#ifdef FILAMENT_RUNOUT_DISTANCE_MM #if HAS_FILAMENT_RUNOUT_DISTANCE
case 10: UI_DECREMENT(FilamentRunoutDistance_mm); break; case 10: UI_DECREMENT(FilamentRunoutDistance_mm); break;
case 11: UI_INCREMENT(FilamentRunoutDistance_mm); break; case 11: UI_INCREMENT(FilamentRunoutDistance_mm); break;
#endif #endif

View file

@ -591,7 +591,7 @@ namespace ExtUI {
bool getFilamentRunoutEnabled() { return runout.enabled; } bool getFilamentRunoutEnabled() { return runout.enabled; }
void setFilamentRunoutEnabled(const bool value) { runout.enabled = value; } 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(); } float getFilamentRunoutDistance_mm() { return runout.runout_distance(); }
void setFilamentRunoutDistance_mm(const float value) { runout.set_runout_distance(constrain(value, 0, 999)); } void setFilamentRunoutDistance_mm(const float value) { runout.set_runout_distance(constrain(value, 0, 999)); }
#endif #endif

View file

@ -237,7 +237,7 @@ namespace ExtUI {
bool getFilamentRunoutEnabled(); bool getFilamentRunoutEnabled();
void setFilamentRunoutEnabled(const bool); void setFilamentRunoutEnabled(const bool);
#ifdef FILAMENT_RUNOUT_DISTANCE_MM #if HAS_FILAMENT_RUNOUT_DISTANCE
float getFilamentRunoutDistance_mm(); float getFilamentRunoutDistance_mm();
void setFilamentRunoutDistance_mm(const float); void setFilamentRunoutDistance_mm(const float);
#endif #endif

View file

@ -43,7 +43,7 @@
#include "../../module/temperature.h" #include "../../module/temperature.h"
#endif #endif
#if ENABLED(FILAMENT_RUNOUT_SENSOR) && FILAMENT_RUNOUT_DISTANCE_MM #if HAS_FILAMENT_RUNOUT_DISTANCE
#include "../../feature/runout.h" #include "../../feature/runout.h"
#endif #endif
@ -142,7 +142,7 @@ void menu_cancelobject();
#endif #endif
#endif #endif
#if ENABLED(FILAMENT_RUNOUT_SENSOR) && FILAMENT_RUNOUT_DISTANCE_MM #if HAS_FILAMENT_RUNOUT_DISTANCE
editable.decimal = runout.runout_distance(); editable.decimal = runout.runout_distance();
EDIT_ITEM(float3, MSG_RUNOUT_DISTANCE_MM, &editable.decimal, 1, 30, EDIT_ITEM(float3, MSG_RUNOUT_DISTANCE_MM, &editable.decimal, 1, 30,
[]{ runout.set_runout_distance(editable.decimal); }, true []{ runout.set_runout_distance(editable.decimal); }, true

View file

@ -604,7 +604,7 @@ void MarlinSettings::postprocess() {
#else #else
constexpr bool runout_sensor_enabled = true; constexpr bool runout_sensor_enabled = true;
#endif #endif
#if HAS_FILAMENT_SENSOR && defined(FILAMENT_RUNOUT_DISTANCE_MM) #if HAS_FILAMENT_RUNOUT_DISTANCE
const float &runout_distance_mm = runout.runout_distance(); const float &runout_distance_mm = runout.runout_distance();
#else #else
constexpr float runout_distance_mm = 0; constexpr float runout_distance_mm = 0;
@ -1460,7 +1460,7 @@ void MarlinSettings::postprocess() {
float runout_distance_mm; float runout_distance_mm;
EEPROM_READ(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); if (!validating) runout.set_runout_distance(runout_distance_mm);
#endif #endif
} }
@ -2384,9 +2384,7 @@ void MarlinSettings::reset() {
#if HAS_FILAMENT_SENSOR #if HAS_FILAMENT_SENSOR
runout.enabled = true; runout.enabled = true;
runout.reset(); runout.reset();
#ifdef FILAMENT_RUNOUT_DISTANCE_MM TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM));
runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM);
#endif
#endif #endif
// //
@ -3551,7 +3549,7 @@ void MarlinSettings::reset() {
CONFIG_ECHO_START(); CONFIG_ECHO_START();
SERIAL_ECHOLNPAIR( SERIAL_ECHOLNPAIR(
" M412 S", int(runout.enabled) " M412 S", int(runout.enabled)
#ifdef FILAMENT_RUNOUT_DISTANCE_MM #if HAS_FILAMENT_RUNOUT_DISTANCE
, " D", LINEAR_UNIT(runout.runout_distance()) , " D", LINEAR_UNIT(runout.runout_distance())
#endif #endif
); );

View file

@ -118,7 +118,7 @@ Stepper stepper; // Singleton
#include "../feature/mixing.h" #include "../feature/mixing.h"
#endif #endif
#ifdef FILAMENT_RUNOUT_DISTANCE_MM #if HAS_FILAMENT_RUNOUT_DISTANCE
#include "../feature/runout.h" #include "../feature/runout.h"
#endif #endif
@ -1808,9 +1808,7 @@ uint32_t Stepper::block_phase_isr() {
PAGE_SEGMENT_UPDATE_POS(E); PAGE_SEGMENT_UPDATE_POS(E);
} }
#endif #endif
#ifdef FILAMENT_RUNOUT_DISTANCE_MM TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.block_completed(current_block));
runout.block_completed(current_block);
#endif
discard_current_block(); discard_current_block();
} }
else { else {