fsensor add deinit

This commit is contained in:
Alex Voinea 2022-02-25 07:50:48 +01:00 committed by D.R.racer
parent ea23e6d924
commit 52b44ad178
2 changed files with 23 additions and 6 deletions

View File

@ -6,4 +6,4 @@ IR_sensor fsensor;
#elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG #elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG
IR_sensor_analog fsensor; IR_sensor_analog fsensor;
#endif #endif
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR

View File

@ -24,6 +24,7 @@
class Filament_sensor { class Filament_sensor {
public: public:
virtual void init() = 0; virtual void init() = 0;
virtual void deinit() = 0;
virtual bool update() = 0; virtual bool update() = 0;
virtual bool getFilamentPresent() = 0; virtual bool getFilamentPresent() = 0;
@ -41,8 +42,14 @@ public:
}; };
void setEnabled(bool enabled) { void setEnabled(bool enabled) {
state = enabled ? State::initializing : State::disabled;
eeprom_update_byte((uint8_t *)EEPROM_FSENSOR, enabled); eeprom_update_byte((uint8_t *)EEPROM_FSENSOR, enabled);
if (enabled) {
init();
}
else {
deinit();
}
state = enabled ? State::initializing : State::disabled;
} }
void setAutoLoadEnabled(bool state, bool updateEEPROM = false) { void setAutoLoadEnabled(bool state, bool updateEEPROM = false) {
@ -156,9 +163,8 @@ protected:
} }
void triggerError() { void triggerError() {
// deinit(); //not sure if I should call this here.
state = State::error; state = State::error;
autoLoadEnabled = false;
runoutEnabled = false;
/// some message, idk /// some message, idk
;// ;//
@ -176,10 +182,17 @@ protected:
class IR_sensor: public Filament_sensor { class IR_sensor: public Filament_sensor {
public: public:
void init() { void init() {
puts_P(PSTR("fsensor::init()"));
SET_INPUT(IR_SENSOR_PIN); //input mode SET_INPUT(IR_SENSOR_PIN); //input mode
WRITE(IR_SENSOR_PIN, 1); //pullup WRITE(IR_SENSOR_PIN, 1); //pullup
settings_init(); settings_init(); //also sets the state to State::initializing
state = State::initializing; }
void deinit() {
puts_P(PSTR("fsensor::deinit()"));
SET_INPUT(IR_SENSOR_PIN); //input mode
WRITE(IR_SENSOR_PIN, 0); //no pullup
state = State::disabled;
} }
bool update() { bool update() {
@ -221,6 +234,10 @@ public:
settings_init(); settings_init();
} }
void deinit() {
IR_sensor::deinit();
}
bool update() { bool update() {
bool event = IR_sensor::update(); bool event = IR_sensor::update();
if (state == State::ready) { if (state == State::ready) {