2017-10-10 02:35:20 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* feature/runout.h - Runout sensor support
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _RUNOUT_H_
|
|
|
|
#define _RUNOUT_H_
|
|
|
|
|
2018-02-18 02:42:09 -06:00
|
|
|
#include "../sd/cardreader.h"
|
|
|
|
#include "../module/printcounter.h"
|
|
|
|
#include "../module/stepper.h"
|
|
|
|
#include "../gcode/queue.h"
|
2017-10-10 02:35:20 -05:00
|
|
|
|
2018-02-18 02:42:09 -06:00
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
2018-03-05 01:49:30 -06:00
|
|
|
#define FIL_RUNOUT_THRESHOLD 5
|
|
|
|
|
2018-02-18 02:42:09 -06:00
|
|
|
class FilamentRunoutSensor {
|
2018-02-22 12:26:14 -06:00
|
|
|
public:
|
|
|
|
FilamentRunoutSensor() {}
|
2018-02-18 02:42:09 -06:00
|
|
|
|
2018-02-22 12:26:14 -06:00
|
|
|
static void setup();
|
2018-02-18 02:42:09 -06:00
|
|
|
|
2018-03-05 01:49:30 -06:00
|
|
|
FORCE_INLINE static void reset() { runout_count = 0; filament_ran_out = false; }
|
2018-02-18 02:42:09 -06:00
|
|
|
|
2018-02-22 12:26:14 -06:00
|
|
|
FORCE_INLINE static void run() {
|
|
|
|
if ((IS_SD_PRINTING || print_job_timer.isRunning()) && check() && !filament_ran_out) {
|
|
|
|
filament_ran_out = true;
|
|
|
|
enqueue_and_echo_commands_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
|
2018-05-12 01:38:02 -05:00
|
|
|
planner.synchronize();
|
2018-02-22 12:26:14 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
static bool filament_ran_out;
|
2018-03-05 01:49:30 -06:00
|
|
|
static uint8_t runout_count;
|
2018-02-18 02:42:09 -06:00
|
|
|
|
2018-02-22 12:26:14 -06:00
|
|
|
FORCE_INLINE static bool check() {
|
|
|
|
#if NUM_RUNOUT_SENSORS < 2
|
|
|
|
// A single sensor applying to all extruders
|
2018-03-05 01:49:30 -06:00
|
|
|
const bool is_out = READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
|
2018-02-22 12:26:14 -06:00
|
|
|
#else
|
|
|
|
// Read the sensor for the active extruder
|
2018-03-05 01:49:30 -06:00
|
|
|
bool is_out;
|
2018-02-22 12:26:14 -06:00
|
|
|
switch (active_extruder) {
|
2018-03-05 01:49:30 -06:00
|
|
|
case 0: is_out = READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING; break;
|
|
|
|
case 1: is_out = READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_INVERTING; break;
|
2018-02-22 12:26:14 -06:00
|
|
|
#if NUM_RUNOUT_SENSORS > 2
|
2018-03-05 01:49:30 -06:00
|
|
|
case 2: is_out = READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT_INVERTING; break;
|
2018-02-22 12:26:14 -06:00
|
|
|
#if NUM_RUNOUT_SENSORS > 3
|
2018-03-05 01:49:30 -06:00
|
|
|
case 3: is_out = READ(FIL_RUNOUT4_PIN) == FIL_RUNOUT_INVERTING; break;
|
2018-02-22 12:26:14 -06:00
|
|
|
#if NUM_RUNOUT_SENSORS > 4
|
2018-03-05 01:49:30 -06:00
|
|
|
case 4: is_out = READ(FIL_RUNOUT5_PIN) == FIL_RUNOUT_INVERTING; break;
|
2018-09-13 01:35:55 -05:00
|
|
|
#if NUM_RUNOUT_SENSORS > 5
|
|
|
|
case 5: is_out = READ(FIL_RUNOUT6_PIN) == FIL_RUNOUT_INVERTING; break;
|
|
|
|
#endif
|
2018-02-22 12:26:14 -06:00
|
|
|
#endif
|
2018-02-18 02:42:09 -06:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-02-22 12:26:14 -06:00
|
|
|
}
|
|
|
|
#endif
|
2018-03-05 01:49:30 -06:00
|
|
|
return (is_out ? ++runout_count : (runout_count = 0)) > FIL_RUNOUT_THRESHOLD;
|
2018-02-18 02:42:09 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern FilamentRunoutSensor runout;
|
2017-10-10 02:35:20 -05:00
|
|
|
|
|
|
|
#endif // _RUNOUT_H_
|