11 #define FSENSOR_IR_ANALOG 2
12 #define FSENSOR_PAT9125 3
31 #ifdef FILAMENT_SENSOR
34 enum class State : uint8_t {
41 enum class SensorActionOnError : uint8_t {
44 _Undef = EEPROM_EMPTY_VALUE
47 static void setEnabled(
bool enabled);
49 void setAutoLoadEnabled(
bool state,
bool updateEEPROM =
false);
50 bool getAutoLoadEnabled()
const {
return autoLoadEnabled; }
52 void setRunoutEnabled(
bool state,
bool updateEEPROM =
false);
53 bool getRunoutEnabled()
const {
return runoutEnabled; }
55 void setActionOnError(SensorActionOnError state,
bool updateEEPROM =
false);
56 SensorActionOnError getActionOnError()
const {
return sensorActionOnError; }
58 bool getFilamentLoadEvent()
const {
return postponedLoadEvent; }
60 bool isError()
const {
return state == State::error; }
61 bool isReady()
const {
return state == State::ready; }
62 bool isEnabled()
const {
return state != State::disabled; }
65 void settings_init_common();
67 bool checkFilamentEvents();
69 void triggerFilamentInserted();
71 void triggerFilamentRemoved();
80 bool oldFilamentPresent;
81 bool postponedLoadEvent;
83 SensorActionOnError sensorActionOnError;
86 #if (FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
92 bool getFilamentPresent()
const {
return !READ(IR_SENSOR_PIN); }
93 #ifdef FSENSOR_PROBING
94 static bool probeOtherType();
99 #if (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
100 constexpr
static uint16_t Voltage2Raw(
float V) {
101 return (V * 1023 * OVERSAMPLENR / VOLT_DIV_REF ) + 0.5F;
103 constexpr
static float Raw2Voltage(uint16_t raw) {
104 return VOLT_DIV_REF * (raw / (1023.F * OVERSAMPLENR));
111 void voltUpdate(uint16_t raw);
113 uint16_t __attribute__((noinline)) getVoltRaw();
115 enum class SensorRevision : uint8_t {
118 _Undef = EEPROM_EMPTY_VALUE
121 SensorRevision getSensorRevision()
const {
return sensorRevision; }
123 const char* __attribute__((noinline)) getIRVersionText();
125 void setSensorRevision(SensorRevision rev,
bool updateEEPROM =
false);
127 constexpr
static uint16_t IRsensor_Ldiode_TRESHOLD = Voltage2Raw(0.3F);
128 constexpr
static uint16_t IRsensor_Lmax_TRESHOLD = Voltage2Raw(1.5F);
129 constexpr
static uint16_t IRsensor_Hmin_TRESHOLD = Voltage2Raw(3.0F);
130 constexpr
static uint16_t IRsensor_Hopen_TRESHOLD = Voltage2Raw(4.6F);
131 constexpr
static uint16_t IRsensor_VMax_TRESHOLD = Voltage2Raw(5.F);
134 SensorRevision sensorRevision;
137 bool getVoltReady()
const;
138 void clearVoltReady();
141 bool checkVoltage(uint16_t raw);
143 uint16_t minVolt = Voltage2Raw(6.F);
144 uint16_t maxVolt = 0;
145 uint16_t nFSCheckCount;
146 uint8_t voltageErrorCnt;
148 static constexpr uint16_t FS_CHECK_COUNT = 4;
153 void IR_ANALOG_Check(SensorRevision isVersion, SensorRevision switchTo);
158 #if (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
164 bool getFilamentPresent()
const {
return filterFilPresent; }
165 #ifdef FSENSOR_PROBING
166 bool probeOtherType();
169 void setJamDetectionEnabled(
bool state,
bool updateEEPROM =
false);
170 bool getJamDetectionEnabled()
const {
return jamDetection; }
172 void stStep(
bool rev) {
173 stepCount += rev ? -1 : 1;
176 void settings_init();
178 static constexpr uint16_t pollingPeriod = 10;
179 static constexpr uint8_t filterCnt = 5;
182 uint8_t filterFilPresent;
190 constexpr
void calcChunkSteps(
float u) {
191 chunkSteps = (int16_t)(1.25 * u);
194 int16_t getStepCount();
196 void resetStepCount();
200 bool updatePAT9125();
204 #if FILAMENT_SENSOR_TYPE == FSENSOR_IR
206 #elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG
208 #elif FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
Definition: Filament_sensor.h:17
Definition: Filament_sensor.h:32
void triggerError()
Definition: Filament_sensor.cpp:160
Definition: Filament_sensor.h:107
bool update()
Definition: Filament_sensor.cpp:219
Definition: Filament_sensor.h:87
Definition: Filament_sensor.h:159