|
@@ -18,7 +18,7 @@
|
|
class Filament_sensor {
|
|
class Filament_sensor {
|
|
public:
|
|
public:
|
|
virtual void init() = 0;
|
|
virtual void init() = 0;
|
|
- virtual void update() = 0;
|
|
|
|
|
|
+ virtual bool update() = 0;
|
|
virtual bool getFilamentPresent() = 0;
|
|
virtual bool getFilamentPresent() = 0;
|
|
|
|
|
|
enum class SensorActionOnError : uint8_t {
|
|
enum class SensorActionOnError : uint8_t {
|
|
@@ -41,6 +41,10 @@ public:
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ bool getFilamentLoadEvent() {
|
|
|
|
+ return postponedLoadEvent;
|
|
|
|
+ }
|
|
|
|
+
|
|
protected:
|
|
protected:
|
|
void settings_init() {
|
|
void settings_init() {
|
|
autoLoadEnabled = eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED);
|
|
autoLoadEnabled = eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED);
|
|
@@ -51,9 +55,9 @@ protected:
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- void checkFilamentEvents() {
|
|
|
|
|
|
+ bool checkFilamentEvents() {
|
|
if (!ready)
|
|
if (!ready)
|
|
- return;
|
|
|
|
|
|
+ return false;
|
|
|
|
|
|
bool newFilamentPresent = getFilamentPresent();
|
|
bool newFilamentPresent = getFilamentPresent();
|
|
if (oldFilamentPresent != newFilamentPresent) {
|
|
if (oldFilamentPresent != newFilamentPresent) {
|
|
@@ -61,12 +65,15 @@ protected:
|
|
if (newFilamentPresent) { //filament insertion
|
|
if (newFilamentPresent) { //filament insertion
|
|
puts_P(PSTR("filament inserted"));
|
|
puts_P(PSTR("filament inserted"));
|
|
triggerFilamentInserted();
|
|
triggerFilamentInserted();
|
|
|
|
+ postponedLoadEvent = true;
|
|
}
|
|
}
|
|
else { //filament removal
|
|
else { //filament removal
|
|
puts_P(PSTR("filament removed"));
|
|
puts_P(PSTR("filament removed"));
|
|
triggerFilamentRemoved();
|
|
triggerFilamentRemoved();
|
|
}
|
|
}
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
+ return false;
|
|
};
|
|
};
|
|
|
|
|
|
void triggerFilamentInserted() {
|
|
void triggerFilamentInserted() {
|
|
@@ -98,6 +105,7 @@ protected:
|
|
bool runoutEnabled;
|
|
bool runoutEnabled;
|
|
bool oldFilamentPresent; //for creating filament presence switching events.
|
|
bool oldFilamentPresent; //for creating filament presence switching events.
|
|
bool ready;
|
|
bool ready;
|
|
|
|
+ bool postponedLoadEvent; //this event lasts exactly one update cycle. It is long enough to be able to do polling for load event.
|
|
SensorActionOnError sensorActionOnError;
|
|
SensorActionOnError sensorActionOnError;
|
|
};
|
|
};
|
|
|
|
|
|
@@ -109,13 +117,18 @@ public:
|
|
settings_init();
|
|
settings_init();
|
|
}
|
|
}
|
|
|
|
|
|
- void update() {
|
|
|
|
|
|
+ bool update() {
|
|
if (!ready) {
|
|
if (!ready) {
|
|
ready = true; //the IR sensor gets ready instantly as it's just a gpio read operation.
|
|
ready = true; //the IR sensor gets ready instantly as it's just a gpio read operation.
|
|
oldFilamentPresent = getFilamentPresent(); //initialize the current filament state so that we don't create a switching event right after the sensor is ready.
|
|
oldFilamentPresent = getFilamentPresent(); //initialize the current filament state so that we don't create a switching event right after the sensor is ready.
|
|
}
|
|
}
|
|
- checkFilamentEvents();
|
|
|
|
|
|
+
|
|
|
|
+ postponedLoadEvent = false;
|
|
|
|
+ bool event = checkFilamentEvents();
|
|
|
|
+
|
|
;//
|
|
;//
|
|
|
|
+
|
|
|
|
+ return event;
|
|
}
|
|
}
|
|
|
|
|
|
bool getFilamentPresent() {
|
|
bool getFilamentPresent() {
|
|
@@ -135,8 +148,8 @@ public:
|
|
;//
|
|
;//
|
|
}
|
|
}
|
|
|
|
|
|
- void update() {
|
|
|
|
- IR_sensor::update();
|
|
|
|
|
|
+ bool update() {
|
|
|
|
+ bool event = IR_sensor::update();
|
|
if (voltReady) {
|
|
if (voltReady) {
|
|
uint16_t newVoltRaw;
|
|
uint16_t newVoltRaw;
|
|
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
|
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
|
@@ -145,7 +158,10 @@ public:
|
|
}
|
|
}
|
|
printf_P(PSTR("newVoltRaw:%u\n"), newVoltRaw / OVERSAMPLENR);
|
|
printf_P(PSTR("newVoltRaw:%u\n"), newVoltRaw / OVERSAMPLENR);
|
|
}
|
|
}
|
|
|
|
+
|
|
;//
|
|
;//
|
|
|
|
+
|
|
|
|
+ return event;
|
|
}
|
|
}
|
|
|
|
|
|
void voltUpdate(uint16_t raw) { //to be called from the ADC ISR when a cycle is finished
|
|
void voltUpdate(uint16_t raw) { //to be called from the ADC ISR when a cycle is finished
|