2017-10-10 07:35:20 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 14:00:57 +00:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-10-10 07:35:20 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-10-10 07:35:20 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 03:20:14 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-10-10 07:35:20 +00:00
|
|
|
*
|
|
|
|
*/
|
2018-10-16 12:28:52 +00:00
|
|
|
#pragma once
|
2017-10-10 07:35:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* feature/runout.h - Runout sensor support
|
|
|
|
*/
|
|
|
|
|
2018-02-18 08:42:09 +00:00
|
|
|
#include "../sd/cardreader.h"
|
|
|
|
#include "../module/printcounter.h"
|
2019-09-14 08:05:10 +00:00
|
|
|
#include "../module/planner.h"
|
|
|
|
#include "../module/stepper.h" // for block_t
|
2018-02-18 08:42:09 +00:00
|
|
|
#include "../gcode/queue.h"
|
2021-01-25 14:39:24 +00:00
|
|
|
#include "../feature/pause.h"
|
2017-10-10 07:35:20 +00:00
|
|
|
|
2018-02-18 08:42:09 +00:00
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
2018-10-08 20:44:05 +00:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
2020-03-13 21:29:29 +00:00
|
|
|
#include "../lcd/extui/ui_api.h"
|
2018-10-08 20:44:05 +00:00
|
|
|
#endif
|
|
|
|
|
2018-10-16 12:28:52 +00:00
|
|
|
//#define FILAMENT_RUNOUT_SENSOR_DEBUG
|
2019-05-07 18:58:10 +00:00
|
|
|
#ifndef FILAMENT_RUNOUT_THRESHOLD
|
|
|
|
#define FILAMENT_RUNOUT_THRESHOLD 5
|
|
|
|
#endif
|
2018-03-05 07:49:30 +00:00
|
|
|
|
2021-03-01 02:16:22 +00:00
|
|
|
void event_filament_runout(const uint8_t extruder);
|
2019-10-02 23:51:25 +00:00
|
|
|
|
2020-08-19 23:58:18 +00:00
|
|
|
template<class RESPONSE_T, class SENSOR_T>
|
|
|
|
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;
|
|
|
|
|
|
|
|
/*******************************************************************************************/
|
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
class FilamentMonitorBase {
|
2018-02-22 18:26:14 +00:00
|
|
|
public:
|
2019-02-12 21:55:47 +00:00
|
|
|
static bool enabled, filament_ran_out;
|
|
|
|
|
|
|
|
#if ENABLED(HOST_ACTION_COMMANDS)
|
|
|
|
static bool host_handling;
|
|
|
|
#else
|
2019-04-04 08:06:19 +00:00
|
|
|
static constexpr bool host_handling = false;
|
2019-02-12 21:55:47 +00:00
|
|
|
#endif
|
2018-10-16 12:28:52 +00:00
|
|
|
};
|
2018-02-18 08:42:09 +00:00
|
|
|
|
2018-10-16 12:28:52 +00:00
|
|
|
template<class RESPONSE_T, class SENSOR_T>
|
2018-11-14 17:45:57 +00:00
|
|
|
class TFilamentMonitor : public FilamentMonitorBase {
|
2018-10-16 12:28:52 +00:00
|
|
|
private:
|
|
|
|
typedef RESPONSE_T response_t;
|
|
|
|
typedef SENSOR_T sensor_t;
|
2018-11-14 17:45:57 +00:00
|
|
|
static response_t response;
|
|
|
|
static sensor_t sensor;
|
2018-02-18 08:42:09 +00:00
|
|
|
|
2018-10-16 12:28:52 +00:00
|
|
|
public:
|
2018-11-14 17:45:57 +00:00
|
|
|
static inline void setup() {
|
2018-10-16 12:28:52 +00:00
|
|
|
sensor.setup();
|
2018-11-14 17:45:57 +00:00
|
|
|
reset();
|
2018-10-16 12:28:52 +00:00
|
|
|
}
|
2018-02-18 08:42:09 +00:00
|
|
|
|
2018-11-02 04:14:20 +00:00
|
|
|
static inline void reset() {
|
2018-10-16 12:28:52 +00:00
|
|
|
filament_ran_out = false;
|
|
|
|
response.reset();
|
|
|
|
}
|
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
// Call this method when filament is present,
|
|
|
|
// so the response can reset its counter.
|
2018-11-02 04:14:20 +00:00
|
|
|
static inline void filament_present(const uint8_t extruder) {
|
2018-10-16 12:28:52 +00:00
|
|
|
response.filament_present(extruder);
|
|
|
|
}
|
|
|
|
|
2020-05-06 04:18:23 +00:00
|
|
|
#if HAS_FILAMENT_RUNOUT_DISTANCE
|
2019-05-04 04:53:15 +00:00
|
|
|
static inline float& runout_distance() { return response.runout_distance_mm; }
|
2021-04-01 22:59:57 +00:00
|
|
|
static inline void set_runout_distance(const_float_t mm) { response.runout_distance_mm = mm; }
|
2019-05-04 04:53:15 +00:00
|
|
|
#endif
|
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
// Handle a block completion. RunoutResponseDelayed uses this to
|
|
|
|
// add up the length of filament moved while the filament is out.
|
2021-03-30 01:36:37 +00:00
|
|
|
static inline void block_completed(const block_t * const b) {
|
2018-11-14 17:45:57 +00:00
|
|
|
if (enabled) {
|
|
|
|
response.block_completed(b);
|
|
|
|
sensor.block_completed(b);
|
|
|
|
}
|
2018-10-16 12:28:52 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
// Give the response a chance to update its counter.
|
|
|
|
static inline void run() {
|
2021-01-21 09:40:07 +00:00
|
|
|
if (enabled && !filament_ran_out && (printingIsActive() || did_pause_print)) {
|
2020-05-06 04:18:23 +00:00
|
|
|
TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, cli()); // Prevent RunoutResponseDelayed::block_completed from accumulating here
|
2018-10-16 12:28:52 +00:00
|
|
|
response.run();
|
|
|
|
sensor.run();
|
2021-03-01 02:16:22 +00:00
|
|
|
const uint8_t runout_flags = response.has_run_out();
|
2020-05-06 04:18:23 +00:00
|
|
|
TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, sei());
|
2021-03-01 02:16:22 +00:00
|
|
|
#if MULTI_FILAMENT_SENSOR
|
|
|
|
#if ENABLED(WATCH_ALL_RUNOUT_SENSORS)
|
|
|
|
const bool ran_out = !!runout_flags; // any sensor triggers
|
|
|
|
uint8_t extruder = 0;
|
|
|
|
if (ran_out) {
|
|
|
|
uint8_t bitmask = runout_flags;
|
|
|
|
while (!(bitmask & 1)) {
|
|
|
|
bitmask >>= 1;
|
|
|
|
extruder++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
const bool ran_out = TEST(runout_flags, active_extruder); // suppress non active extruders
|
|
|
|
uint8_t extruder = active_extruder;
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
const bool ran_out = !!runout_flags;
|
|
|
|
uint8_t extruder = active_extruder;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
|
|
|
|
if (runout_flags) {
|
|
|
|
SERIAL_ECHOPGM("Runout Sensors: ");
|
|
|
|
LOOP_L_N(i, 8) SERIAL_ECHO('0' + TEST(runout_flags, i));
|
|
|
|
SERIAL_ECHOPAIR(" -> ", extruder);
|
|
|
|
if (ran_out) SERIAL_ECHOPGM(" RUN OUT");
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
if (ran_out) {
|
2018-10-16 12:28:52 +00:00
|
|
|
filament_ran_out = true;
|
2021-03-01 02:16:22 +00:00
|
|
|
event_filament_runout(extruder);
|
2018-10-16 12:28:52 +00:00
|
|
|
planner.synchronize();
|
|
|
|
}
|
2018-02-22 18:26:14 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-16 12:28:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*************************** FILAMENT PRESENCE SENSORS ***************************/
|
2018-02-18 08:42:09 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
class FilamentSensorBase {
|
2018-10-16 12:28:52 +00:00
|
|
|
protected:
|
2020-08-19 23:58:18 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
}
|
2018-10-16 12:28:52 +00:00
|
|
|
|
|
|
|
public:
|
2018-11-28 02:13:24 +00:00
|
|
|
static inline void setup() {
|
2020-11-21 23:56:56 +00:00
|
|
|
#define _INIT_RUNOUT_PIN(P,S,U,D) do{ if (ENABLED(U)) SET_INPUT_PULLUP(P); else if (ENABLED(D)) SET_INPUT_PULLDOWN(P); else SET_INPUT(P); }while(0)
|
|
|
|
#define INIT_RUNOUT_PIN(N) _INIT_RUNOUT_PIN(FIL_RUNOUT##N##_PIN, FIL_RUNOUT##N##_STATE, FIL_RUNOUT##N##_PULLUP, FIL_RUNOUT##N##_PULLDOWN)
|
2020-11-11 06:39:23 +00:00
|
|
|
#if NUM_RUNOUT_SENSORS >= 1
|
|
|
|
INIT_RUNOUT_PIN(1);
|
2018-10-16 12:28:52 +00:00
|
|
|
#endif
|
2020-11-11 06:39:23 +00:00
|
|
|
#if NUM_RUNOUT_SENSORS >= 2
|
|
|
|
INIT_RUNOUT_PIN(2);
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 3
|
|
|
|
INIT_RUNOUT_PIN(3);
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 4
|
|
|
|
INIT_RUNOUT_PIN(4);
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 5
|
|
|
|
INIT_RUNOUT_PIN(5);
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 6
|
|
|
|
INIT_RUNOUT_PIN(6);
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 7
|
|
|
|
INIT_RUNOUT_PIN(7);
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 8
|
|
|
|
INIT_RUNOUT_PIN(8);
|
|
|
|
#endif
|
|
|
|
#undef _INIT_RUNOUT_PIN
|
|
|
|
#undef INIT_RUNOUT_PIN
|
2018-10-16 12:28:52 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 02:13:24 +00:00
|
|
|
// Return a bitmask of runout pin states
|
|
|
|
static inline uint8_t poll_runout_pins() {
|
2020-02-02 03:00:53 +00:00
|
|
|
#define _OR_RUNOUT(N) | (READ(FIL_RUNOUT##N##_PIN) ? _BV((N) - 1) : 0)
|
2021-05-08 06:41:40 +00:00
|
|
|
return (0 REPEAT_1(NUM_RUNOUT_SENSORS, _OR_RUNOUT));
|
2020-02-02 03:00:53 +00:00
|
|
|
#undef _OR_RUNOUT
|
2018-11-28 02:13:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return a bitmask of runout flag states (1 bits always indicates runout)
|
|
|
|
static inline uint8_t poll_runout_states() {
|
2020-11-11 06:39:23 +00:00
|
|
|
return poll_runout_pins() ^ uint8_t(0
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 1
|
|
|
|
| (FIL_RUNOUT1_STATE ? 0 : _BV(1 - 1))
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 2
|
|
|
|
| (FIL_RUNOUT2_STATE ? 0 : _BV(2 - 1))
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 3
|
|
|
|
| (FIL_RUNOUT3_STATE ? 0 : _BV(3 - 1))
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 4
|
|
|
|
| (FIL_RUNOUT4_STATE ? 0 : _BV(4 - 1))
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 5
|
|
|
|
| (FIL_RUNOUT5_STATE ? 0 : _BV(5 - 1))
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 6
|
|
|
|
| (FIL_RUNOUT6_STATE ? 0 : _BV(6 - 1))
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 7
|
|
|
|
| (FIL_RUNOUT7_STATE ? 0 : _BV(7 - 1))
|
|
|
|
#endif
|
|
|
|
#if NUM_RUNOUT_SENSORS >= 8
|
|
|
|
| (FIL_RUNOUT8_STATE ? 0 : _BV(8 - 1))
|
2020-07-06 04:14:12 +00:00
|
|
|
#endif
|
2020-11-11 06:39:23 +00:00
|
|
|
);
|
2018-10-16 12:28:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
#if ENABLED(FILAMENT_MOTION_SENSOR)
|
2018-10-16 12:28:52 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
/**
|
|
|
|
* This sensor uses a magnetic encoder disc and a Hall effect
|
|
|
|
* sensor (or a slotted disc and optical sensor). The state
|
|
|
|
* will toggle between 0 and 1 on filament movement. It can detect
|
|
|
|
* filament runout and stripouts or jams.
|
|
|
|
*/
|
|
|
|
class FilamentSensorEncoder : public FilamentSensorBase {
|
|
|
|
private:
|
|
|
|
static uint8_t motion_detected;
|
|
|
|
|
|
|
|
static inline void poll_motion_sensor() {
|
|
|
|
static uint8_t old_state;
|
|
|
|
const uint8_t new_state = poll_runout_pins(),
|
|
|
|
change = old_state ^ new_state;
|
|
|
|
old_state = new_state;
|
|
|
|
|
2021-03-01 01:50:17 +00:00
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
|
2018-11-27 22:41:26 +00:00
|
|
|
if (change) {
|
2018-11-29 22:58:58 +00:00
|
|
|
SERIAL_ECHOPGM("Motion detected:");
|
2020-03-14 04:18:16 +00:00
|
|
|
LOOP_L_N(e, NUM_RUNOUT_SENSORS)
|
2020-01-09 00:31:57 +00:00
|
|
|
if (TEST(change, e)) SERIAL_CHAR(' ', '0' + e);
|
2018-11-27 22:41:26 +00:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
2018-09-17 06:06:22 +00:00
|
|
|
#endif
|
2018-10-16 12:28:52 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
motion_detected |= change;
|
|
|
|
}
|
2018-10-16 12:28:52 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
public:
|
2021-03-30 01:36:37 +00:00
|
|
|
static inline void block_completed(const block_t * const b) {
|
2018-11-14 17:45:57 +00:00
|
|
|
// If the sensor wheel has moved since the last call to
|
|
|
|
// this method reset the runout counter for the extruder.
|
|
|
|
if (TEST(motion_detected, b->extruder))
|
|
|
|
filament_present(b->extruder);
|
|
|
|
|
|
|
|
// Clear motion triggers for next block
|
|
|
|
motion_detected = 0;
|
|
|
|
}
|
2018-02-18 08:42:09 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
static inline void run() { poll_motion_sensor(); }
|
|
|
|
};
|
2018-10-16 12:28:52 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
#else
|
2018-10-16 12:28:52 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
/**
|
|
|
|
* This is a simple endstop switch in the path of the filament.
|
|
|
|
* It can detect filament runout, but not stripouts or jams.
|
|
|
|
*/
|
|
|
|
class FilamentSensorSwitch : public FilamentSensorBase {
|
|
|
|
private:
|
2018-11-28 02:13:24 +00:00
|
|
|
static inline bool poll_runout_state(const uint8_t extruder) {
|
|
|
|
const uint8_t runout_states = poll_runout_states();
|
2021-03-01 01:50:17 +00:00
|
|
|
#if MULTI_FILAMENT_SENSOR
|
2020-10-16 21:59:55 +00:00
|
|
|
if ( !TERN0(DUAL_X_CARRIAGE, idex_is_duplicating())
|
2020-04-25 22:53:06 +00:00
|
|
|
&& !TERN0(MULTI_NOZZLE_DUPLICATION, extruder_duplication_enabled)
|
|
|
|
) return TEST(runout_states, extruder); // A specific extruder ran out
|
2021-03-01 01:50:17 +00:00
|
|
|
#else
|
|
|
|
UNUSED(extruder);
|
2019-03-13 05:42:50 +00:00
|
|
|
#endif
|
2020-04-25 22:53:06 +00:00
|
|
|
return !!runout_states; // Any extruder ran out
|
2018-11-14 17:45:57 +00:00
|
|
|
}
|
2018-10-16 12:28:52 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
public:
|
2021-03-30 01:36:37 +00:00
|
|
|
static inline void block_completed(const block_t * const) {}
|
2018-10-16 12:28:52 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
static inline void run() {
|
2021-03-01 02:16:22 +00:00
|
|
|
LOOP_L_N(s, NUM_RUNOUT_SENSORS) {
|
|
|
|
const bool out = poll_runout_state(s);
|
|
|
|
if (!out) filament_present(s);
|
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
|
|
|
|
static uint8_t was_out; // = 0
|
|
|
|
if (out != TEST(was_out, s)) {
|
|
|
|
TBI(was_out, s);
|
|
|
|
SERIAL_ECHOLNPAIR_P(PSTR("Filament Sensor "), '0' + s, out ? PSTR(" OUT") : PSTR(" IN"));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2018-11-14 17:45:57 +00:00
|
|
|
}
|
|
|
|
};
|
2018-10-16 12:28:52 +00:00
|
|
|
|
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
#endif // !FILAMENT_MOTION_SENSOR
|
2018-10-16 12:28:52 +00:00
|
|
|
|
|
|
|
/********************************* RESPONSE TYPE *********************************/
|
|
|
|
|
2020-05-06 04:18:23 +00:00
|
|
|
#if HAS_FILAMENT_RUNOUT_DISTANCE
|
2018-10-16 12:28:52 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
// RunoutResponseDelayed triggers a runout event only if the length
|
|
|
|
// of filament specified by FILAMENT_RUNOUT_DISTANCE_MM has been fed
|
|
|
|
// during a runout condition.
|
2018-10-16 12:28:52 +00:00
|
|
|
class RunoutResponseDelayed {
|
|
|
|
private:
|
2021-03-01 02:16:22 +00:00
|
|
|
static volatile float runout_mm_countdown[NUM_RUNOUT_SENSORS];
|
2018-10-16 12:28:52 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
static float runout_distance_mm;
|
|
|
|
|
2018-11-28 02:13:24 +00:00
|
|
|
static inline void reset() {
|
2021-03-01 02:16:22 +00:00
|
|
|
LOOP_L_N(i, NUM_RUNOUT_SENSORS) filament_present(i);
|
2018-10-16 12:28:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void run() {
|
2021-03-01 01:50:17 +00:00
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
|
2018-11-14 17:45:57 +00:00
|
|
|
static millis_t t = 0;
|
|
|
|
const millis_t ms = millis();
|
|
|
|
if (ELAPSED(ms, t)) {
|
|
|
|
t = millis() + 1000UL;
|
2021-03-01 02:16:22 +00:00
|
|
|
LOOP_L_N(i, NUM_RUNOUT_SENSORS)
|
2021-03-01 01:43:46 +00:00
|
|
|
SERIAL_ECHOPAIR_P(i ? PSTR(", ") : PSTR("Remaining mm: "), runout_mm_countdown[i]);
|
2018-10-16 12:28:52 +00:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-03-01 02:16:22 +00:00
|
|
|
static inline uint8_t has_run_out() {
|
|
|
|
uint8_t runout_flags = 0;
|
|
|
|
LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_mm_countdown[i] < 0) SBI(runout_flags, i);
|
|
|
|
return runout_flags;
|
2018-11-14 17:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void filament_present(const uint8_t extruder) {
|
|
|
|
runout_mm_countdown[extruder] = runout_distance_mm;
|
2018-10-16 12:28:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 01:36:37 +00:00
|
|
|
static inline void block_completed(const block_t * const b) {
|
2021-01-21 09:40:07 +00:00
|
|
|
if (b->steps.x || b->steps.y || b->steps.z || did_pause_print) { // Allow pause purge move to re-trigger runout state
|
2018-11-27 19:45:25 +00:00
|
|
|
// Only trigger on extrusion with XYZ movement to allow filament change and retract/recover.
|
|
|
|
const uint8_t e = b->extruder;
|
2019-09-29 09:25:39 +00:00
|
|
|
const int32_t steps = b->steps.e;
|
2018-11-27 19:45:25 +00:00
|
|
|
runout_mm_countdown[e] -= (TEST(b->direction_bits, E_AXIS) ? -steps : steps) * planner.steps_to_mm[E_AXIS_N(e)];
|
|
|
|
}
|
2018-10-16 12:28:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-06 04:18:23 +00:00
|
|
|
#else // !HAS_FILAMENT_RUNOUT_DISTANCE
|
2018-10-16 12:28:52 +00:00
|
|
|
|
2018-11-14 17:45:57 +00:00
|
|
|
// RunoutResponseDebounced triggers a runout event after a runout
|
|
|
|
// condition has been detected runout_threshold times in a row.
|
2017-10-10 07:35:20 +00:00
|
|
|
|
2018-10-16 12:28:52 +00:00
|
|
|
class RunoutResponseDebounced {
|
|
|
|
private:
|
2019-05-07 18:58:10 +00:00
|
|
|
static constexpr int8_t runout_threshold = FILAMENT_RUNOUT_THRESHOLD;
|
2021-03-01 02:16:22 +00:00
|
|
|
static int8_t runout_count[NUM_RUNOUT_SENSORS];
|
|
|
|
|
2018-10-16 12:28:52 +00:00
|
|
|
public:
|
2021-03-01 02:16:22 +00:00
|
|
|
static inline void reset() {
|
|
|
|
LOOP_L_N(i, NUM_RUNOUT_SENSORS) filament_present(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void run() {
|
|
|
|
LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_count[i] >= 0) runout_count[i]--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t has_run_out() {
|
|
|
|
uint8_t runout_flags = 0;
|
|
|
|
LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_count[i] < 0) SBI(runout_flags, i);
|
|
|
|
return runout_flags;
|
|
|
|
}
|
|
|
|
|
2021-03-30 01:36:37 +00:00
|
|
|
static inline void block_completed(const block_t * const) { }
|
2021-03-01 02:16:22 +00:00
|
|
|
|
|
|
|
static inline void filament_present(const uint8_t extruder) {
|
|
|
|
runout_count[extruder] = runout_threshold;
|
|
|
|
}
|
2018-10-16 12:28:52 +00:00
|
|
|
};
|
|
|
|
|
2020-05-06 04:18:23 +00:00
|
|
|
#endif // !HAS_FILAMENT_RUNOUT_DISTANCE
|