1 |
ron |
1 |
/**
|
|
|
2 |
* Marlin 3D Printer Firmware
|
|
|
3 |
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
4 |
*
|
|
|
5 |
* Based on Sprinter and grbl.
|
|
|
6 |
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
7 |
*
|
|
|
8 |
* This program is free software: you can redistribute it and/or modify
|
|
|
9 |
* it under the terms of the GNU General Public License as published by
|
|
|
10 |
* the Free Software Foundation, either version 3 of the License, or
|
|
|
11 |
* (at your option) any later version.
|
|
|
12 |
*
|
|
|
13 |
* This program is distributed in the hope that it will be useful,
|
|
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
16 |
* GNU General Public License for more details.
|
|
|
17 |
*
|
|
|
18 |
* You should have received a copy of the GNU General Public License
|
|
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
*
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* runout.h - Runout sensor support
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
#ifndef _RUNOUT_H_
|
|
|
28 |
#define _RUNOUT_H_
|
|
|
29 |
|
|
|
30 |
#include "cardreader.h"
|
|
|
31 |
#include "printcounter.h"
|
|
|
32 |
#include "stepper.h"
|
|
|
33 |
#include "Marlin.h"
|
|
|
34 |
|
|
|
35 |
#include "MarlinConfig.h"
|
|
|
36 |
|
|
|
37 |
#define FIL_RUNOUT_THRESHOLD 5
|
|
|
38 |
|
|
|
39 |
class FilamentRunoutSensor {
|
|
|
40 |
public:
|
|
|
41 |
FilamentRunoutSensor() {}
|
|
|
42 |
|
|
|
43 |
static void setup();
|
|
|
44 |
|
|
|
45 |
FORCE_INLINE static void reset() { runout_count = 0; filament_ran_out = false; }
|
|
|
46 |
|
|
|
47 |
FORCE_INLINE static void run() {
|
|
|
48 |
if ((IS_SD_PRINTING() || print_job_timer.isRunning()) && check() && !filament_ran_out) {
|
|
|
49 |
filament_ran_out = true;
|
|
|
50 |
enqueue_and_echo_commands_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
|
|
|
51 |
planner.synchronize();
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
private:
|
|
|
55 |
static bool filament_ran_out;
|
|
|
56 |
static uint8_t runout_count;
|
|
|
57 |
|
|
|
58 |
FORCE_INLINE static bool check() {
|
|
|
59 |
#if NUM_RUNOUT_SENSORS < 2
|
|
|
60 |
// A single sensor applying to all extruders
|
|
|
61 |
const bool is_out = READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING;
|
|
|
62 |
#else
|
|
|
63 |
// Read the sensor for the active extruder
|
|
|
64 |
bool is_out;
|
|
|
65 |
switch (active_extruder) {
|
|
|
66 |
case 0: is_out = READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_INVERTING; break;
|
|
|
67 |
case 1: is_out = READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT_INVERTING; break;
|
|
|
68 |
#if NUM_RUNOUT_SENSORS > 2
|
|
|
69 |
case 2: is_out = READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT_INVERTING; break;
|
|
|
70 |
#if NUM_RUNOUT_SENSORS > 3
|
|
|
71 |
case 3: is_out = READ(FIL_RUNOUT4_PIN) == FIL_RUNOUT_INVERTING; break;
|
|
|
72 |
#if NUM_RUNOUT_SENSORS > 4
|
|
|
73 |
case 4: is_out = READ(FIL_RUNOUT5_PIN) == FIL_RUNOUT_INVERTING; break;
|
|
|
74 |
#endif
|
|
|
75 |
#endif
|
|
|
76 |
#endif
|
|
|
77 |
}
|
|
|
78 |
#endif
|
|
|
79 |
return (is_out ? ++runout_count : (runout_count = 0)) > FIL_RUNOUT_THRESHOLD;
|
|
|
80 |
}
|
|
|
81 |
};
|
|
|
82 |
|
|
|
83 |
extern FilamentRunoutSensor runout;
|
|
|
84 |
|
|
|
85 |
#endif // _RUNOUT_H_
|