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)
}
#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
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS];
#else
int8_t RunoutResponseDebounced::runout_count; // = 0
#endif

View file

@ -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(HAS_FILAMENT_RUNOUT_DISTANCE, RunoutResponseDelayed, RunoutResponseDebounced),
TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch)
#else
RunoutResponseDebounced, FilamentSensorSwitch
#endif
> FilamentMonitor;
extern FilamentMonitor runout;

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
);

View file

@ -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 {