Remove OQ and add fancy autoload interaction

This commit is contained in:
Alex Voinea 2022-02-22 17:43:29 +01:00 committed by D.R.racer
parent d84e6bda63
commit 7224b5c2b6
11 changed files with 40 additions and 79 deletions

View File

@ -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() { bool update() {
IR_sensor::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

View File

@ -3604,11 +3604,6 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
sprintf_P(cmd, PSTR("M220 S%i"), feedmultiplyBckp); sprintf_P(cmd, PSTR("M220 S%i"), feedmultiplyBckp);
enquecommand(cmd); enquecommand(cmd);
#ifdef IR_SENSOR
//this will set fsensor_watch_autoload to correct value and prevent possible M701 gcode enqueuing when M600 is finished
fsensor_check_autoload();
#endif //IR_SENSOR
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
fsensor.settings_init(); fsensor.settings_init();
#endif #endif
@ -3657,7 +3652,7 @@ void gcode_M701()
load_filament_final_feed(); //slow sequence load_filament_final_feed(); //slow sequence
st_synchronize(); st_synchronize();
Sound_MakeCustom(50,500,false); Sound_MakeCustom(50,500,false);
if (!farm_mode && loading_flag) { if (!farm_mode && loading_flag) {
lcd_load_filament_color_check(); lcd_load_filament_color_check();
@ -3679,10 +3674,10 @@ void gcode_M701()
lcd_update(2); lcd_update(2);
if (disable) if (disable)
fsensor_disable(); fsensor_disable();
}
#endif //FSENSOR_QUALITY
} }
eFilamentAction = FilamentAction::None;
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
fsensor.settings_init(); //restore filament runout state. fsensor.settings_init(); //restore filament runout state.
#endif #endif
@ -9440,8 +9435,10 @@ void manage_inactivity_IR_ANALOG_Check(uint16_t &nFSCheckCount, ClFsensorPCB isV
void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h
{ {
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
fsensor.update(); if (fsensor.update()) {
#endif // IR_SENSOR_ANALOG lcd_draw_update = 1; //cause lcd update so that fsensor event polling can be done from the lcd draw routine.
}
#endif
#ifdef SAFETYTIMER #ifdef SAFETYTIMER
handleSafetyTimer(); handleSafetyTimer();
@ -11586,9 +11583,8 @@ void M600_load_filament() {
manage_heater(); manage_heater();
manage_inactivity(true); manage_inactivity(true);
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
if (fsensor_check_autoload()) if (fsensor.getFilamentLoadEvent()) {
{ Sound_MakeCustom(50,1000,false);
Sound_MakeCustom(50,1000,false);
break; break;
} }
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR
@ -11598,26 +11594,10 @@ void M600_load_filament() {
#endif //PAT9125 #endif //PAT9125
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
#ifdef FSENSOR_QUALITY
fsensor_oq_meassure_start(70);
#endif //FSENSOR_QUALITY
M600_load_filament_movements(); M600_load_filament_movements();
Sound_MakeCustom(50,1000,false); Sound_MakeCustom(50,1000,false);
#ifdef FSENSOR_QUALITY
fsensor_oq_meassure_stop();
if (!fsensor_oq_result())
{
bool disable = lcd_show_fullscreen_message_yes_no_and_wait_P(_n("Fil. sensor response is poor, disable it?"), false, true);
lcd_update_enable(true);
lcd_update(2);
if (disable)
fsensor_disable();
}
#endif //FSENSOR_QUALITY
lcd_update_enable(false); lcd_update_enable(false);
} }

View File

@ -54,8 +54,6 @@ bool fsensor_not_responding = false;
uint8_t fsensor_int_pin_old = 0; uint8_t fsensor_int_pin_old = 0;
//! optical checking "chunk lenght" (already in steps) //! optical checking "chunk lenght" (already in steps)
int16_t fsensor_chunk_len = 0; int16_t fsensor_chunk_len = 0;
//! enable/disable quality meassurement
bool fsensor_oq_meassure_enabled = false;
//! number of errors, updated in ISR //! number of errors, updated in ISR
uint8_t fsensor_err_cnt = 0; uint8_t fsensor_err_cnt = 0;
//! variable for accumulating step count (updated callbacks from stepper and ISR) //! variable for accumulating step count (updated callbacks from stepper and ISR)

View File

@ -44,7 +44,6 @@ extern void fsensor_disable(bool bUpdateEEPROM=true);
extern bool fsensor_autoload_enabled; extern bool fsensor_autoload_enabled;
extern void fsensor_autoload_set(bool State); extern void fsensor_autoload_set(bool State);
extern void fsensor_update(void);
#ifdef PAT9125 #ifdef PAT9125
//! setup pin-change interrupt //! setup pin-change interrupt
extern void fsensor_setup_interrupt(void); extern void fsensor_setup_interrupt(void);
@ -55,19 +54,9 @@ extern void fsensor_setup_interrupt(void);
extern void fsensor_autoload_check_start(void); extern void fsensor_autoload_check_start(void);
extern void fsensor_autoload_check_stop(void); extern void fsensor_autoload_check_stop(void);
#endif //PAT9125 #endif //PAT9125
extern bool fsensor_check_autoload(void);
//! @} //! @}
#ifdef PAT9125 #ifdef PAT9125
//! @name optical quality measurement support
//! @{
extern bool fsensor_oq_meassure_enabled;
extern void fsensor_oq_meassure_set(bool State);
extern void fsensor_oq_meassure_start(uint8_t skip);
extern void fsensor_oq_meassure_stop(void);
extern bool fsensor_oq_result(void);
//! @}
//! @name callbacks from stepper //! @name callbacks from stepper
//! @{ //! @{
extern void fsensor_st_block_chunk(int cnt); extern void fsensor_st_block_chunk(int cnt);

View File

@ -32,6 +32,7 @@
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
#include "pat9125.h" #include "pat9125.h"
#include "fsensor.h" #include "fsensor.h"
#include "Filament_sensor.h"
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR
#ifdef TMC2130 #ifdef TMC2130
@ -1795,14 +1796,6 @@ void lcd_set_filament_autoload() {
fsensor_autoload_set(!fsensor_autoload_enabled); fsensor_autoload_set(!fsensor_autoload_enabled);
} }
#if defined(FILAMENT_SENSOR) && defined(PAT9125)
void lcd_set_filament_oq_meass()
{
fsensor_oq_meassure_set(!fsensor_oq_meassure_enabled);
}
#endif
FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad' FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad'
bool bFilamentPreheatState; bool bFilamentPreheatState;
bool bFilamentAction=false; bool bFilamentAction=false;
@ -1834,7 +1827,7 @@ switch(eFilamentAction)
case FilamentAction::Lay1Cal: case FilamentAction::Lay1Cal:
break; break;
} }
if(lcd_clicked()) if(lcd_clicked() || (((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad)) && fsensor.getFilamentLoadEvent()))
{ {
nLevel=2; nLevel=2;
if(!bFilamentPreheatState) if(!bFilamentPreheatState)
@ -4253,13 +4246,9 @@ do\
if (mmu_enabled == false)\ if (mmu_enabled == false)\
{\ {\
if (fsensor_autoload_enabled)\ if (fsensor_autoload_enabled)\
MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_ON), lcd_set_filament_autoload);\ MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_ON), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_ON c=17*/\
else\ else\
MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_OFF), lcd_set_filament_autoload);\ MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_OFF), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_OFF c=17*/\
/*if (fsensor_oq_meassure_enabled)*/\
/*MENU_ITEM_FUNCTION_P(_i("F. OQ meass. [on]"), lcd_set_filament_oq_meass);*//*////MSG_FSENS_OQMEASS_ON c=17*/\
/*else*/\
/*MENU_ITEM_FUNCTION_P(_i("F. OQ meass.[off]"), lcd_set_filament_oq_meass);*//*////MSG_FSENS_OQMEASS_OFF c=17*/\
}\ }\
}\ }\
}\ }\
@ -5241,6 +5230,7 @@ void unload_filament(bool automatic)
lcd_setstatuspgm(MSG_WELCOME); lcd_setstatuspgm(MSG_WELCOME);
custom_message_type = CustomMsg::Status; custom_message_type = CustomMsg::Status;
eFilamentAction = FilamentAction::None;
} }
#include "xflash.h" #include "xflash.h"
@ -7726,7 +7716,7 @@ void menu_lcd_lcdupdate_func(void)
} }
#endif//CARDINSERTED #endif//CARDINSERTED
backlight_update(); backlight_update();
if (lcd_next_update_millis < _millis()) if (lcd_next_update_millis < _millis() || lcd_draw_update)
{ {
if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
{ {

View File

@ -158,8 +158,6 @@
//#define CMD_DIAGNOSTICS //Show cmd queue length on printer display //#define CMD_DIAGNOSTICS //Show cmd queue length on printer display
#endif /* DEBUG_BUILD */ #endif /* DEBUG_BUILD */
//#define FSENSOR_QUALITY
/*------------------------------------ /*------------------------------------
EXTRUDER SETTINGS EXTRUDER SETTINGS

View File

@ -159,8 +159,6 @@
//#define CMD_DIAGNOSTICS //Show cmd queue length on printer display //#define CMD_DIAGNOSTICS //Show cmd queue length on printer display
#endif /* DEBUG_BUILD */ #endif /* DEBUG_BUILD */
//#define FSENSOR_QUALITY
/*------------------------------------ /*------------------------------------
EXTRUDER SETTINGS EXTRUDER SETTINGS

View File

@ -158,8 +158,6 @@
//#define CMD_DIAGNOSTICS //Show cmd queue length on printer display //#define CMD_DIAGNOSTICS //Show cmd queue length on printer display
#endif /* DEBUG_BUILD */ #endif /* DEBUG_BUILD */
//#define FSENSOR_QUALITY
/*------------------------------------ /*------------------------------------
EXTRUDER SETTINGS EXTRUDER SETTINGS

View File

@ -159,8 +159,6 @@
//#define CMD_DIAGNOSTICS //Show cmd queue length on printer display //#define CMD_DIAGNOSTICS //Show cmd queue length on printer display
#endif /* DEBUG_BUILD */ #endif /* DEBUG_BUILD */
//#define FSENSOR_QUALITY
/*------------------------------------ /*------------------------------------
EXTRUDER SETTINGS EXTRUDER SETTINGS

View File

@ -202,8 +202,6 @@
#define CMD_DIAGNOSTICS //Show cmd queue length on printer display #define CMD_DIAGNOSTICS //Show cmd queue length on printer display
#endif /* DEBUG_BUILD */ #endif /* DEBUG_BUILD */
//#define FSENSOR_QUALITY
#define LINEARITY_CORRECTION #define LINEARITY_CORRECTION
#define TMC2130_LINEARITY_CORRECTION #define TMC2130_LINEARITY_CORRECTION

View File

@ -204,8 +204,6 @@
#define CMD_DIAGNOSTICS //Show cmd queue length on printer display #define CMD_DIAGNOSTICS //Show cmd queue length on printer display
#endif /* DEBUG_BUILD */ #endif /* DEBUG_BUILD */
//#define FSENSOR_QUALITY
#define LINEARITY_CORRECTION #define LINEARITY_CORRECTION
#define TMC2130_LINEARITY_CORRECTION #define TMC2130_LINEARITY_CORRECTION