Browse Source

Remove OQ and add fancy autoload interaction

Alex Voinea 2 years ago
parent
commit
7224b5c2b6

+ 23 - 7
Firmware/Filament_sensor.h

@@ -18,7 +18,7 @@
 class Filament_sensor {
 public:
     virtual void init() = 0;
-    virtual void update() = 0;
+    virtual bool update() = 0;
     virtual bool getFilamentPresent() = 0;
     
     enum class SensorActionOnError : uint8_t {
@@ -41,6 +41,10 @@ public:
         }
     }
     
+    bool getFilamentLoadEvent() {
+        return postponedLoadEvent;
+    }
+    
 protected:
     void settings_init() {
         autoLoadEnabled = eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED);
@@ -51,9 +55,9 @@ protected:
         }
     }
     
-    void checkFilamentEvents() {
+    bool checkFilamentEvents() {
         if (!ready)
-            return;
+            return false;
         
         bool newFilamentPresent = getFilamentPresent();
         if (oldFilamentPresent != newFilamentPresent) {
@@ -61,12 +65,15 @@ protected:
             if (newFilamentPresent) { //filament insertion
                 puts_P(PSTR("filament inserted"));
                 triggerFilamentInserted();
+                postponedLoadEvent = true;
             }
             else { //filament removal
                 puts_P(PSTR("filament removed"));
                 triggerFilamentRemoved();
             }
+            return true;
         }
+        return false;
     };
     
     void triggerFilamentInserted() {
@@ -98,6 +105,7 @@ protected:
     bool runoutEnabled;
     bool oldFilamentPresent; //for creating filament presence switching events.
     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;
 };
 
@@ -109,13 +117,18 @@ public:
         settings_init();
     }
     
-    void update() {
+    bool update() {
         if (!ready) {
             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.
         }
-        checkFilamentEvents();
+        
+        postponedLoadEvent = false;
+        bool event = checkFilamentEvents();
+        
         ;//
+        
+        return event;
     }
     
     bool getFilamentPresent() {
@@ -135,8 +148,8 @@ public:
         ;//
     }
     
-    void update() {
-        IR_sensor::update();
+    bool update() {
+        bool event = IR_sensor::update();
         if (voltReady) {
             uint16_t newVoltRaw;
             ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
@@ -145,7 +158,10 @@ public:
             }
             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

+ 11 - 31
Firmware/Marlin_main.cpp

@@ -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);
     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
     fsensor.settings_init();
 #endif
@@ -3657,7 +3652,7 @@ void gcode_M701()
 		load_filament_final_feed(); //slow sequence
 		st_synchronize();
 
-    Sound_MakeCustom(50,500,false);
+		Sound_MakeCustom(50,500,false);
 
 		if (!farm_mode && loading_flag) {
 			lcd_load_filament_color_check();
@@ -3679,10 +3674,10 @@ void gcode_M701()
             lcd_update(2);
             if (disable)
                 fsensor_disable();
-        }
-#endif //FSENSOR_QUALITY
 	}
-    
+	
+	eFilamentAction = FilamentAction::None;
+	
 #ifdef FILAMENT_SENSOR
 	fsensor.settings_init(); //restore filament runout state.
 #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
 {
 #ifdef FILAMENT_SENSOR
-    fsensor.update();
-#endif // IR_SENSOR_ANALOG
+    if (fsensor.update()) {
+        lcd_draw_update = 1; //cause lcd update so that fsensor event polling can be done from the lcd draw routine.
+    }
+#endif
 
 #ifdef SAFETYTIMER
 	handleSafetyTimer();
@@ -11586,9 +11583,8 @@ void M600_load_filament() {
 		manage_heater();
 		manage_inactivity(true);
 #ifdef FILAMENT_SENSOR
-		if (fsensor_check_autoload())
-		{
-      Sound_MakeCustom(50,1000,false);
+		if (fsensor.getFilamentLoadEvent()) {
+			Sound_MakeCustom(50,1000,false);
 			break;
 		}
 #endif //FILAMENT_SENSOR
@@ -11598,26 +11594,10 @@ void M600_load_filament() {
 #endif //PAT9125
 	KEEPALIVE_STATE(IN_HANDLER);
 
-#ifdef FSENSOR_QUALITY
-	fsensor_oq_meassure_start(70);
-#endif //FSENSOR_QUALITY
-
 	M600_load_filament_movements();
 
-      Sound_MakeCustom(50,1000,false);
-
-#ifdef FSENSOR_QUALITY
-	fsensor_oq_meassure_stop();
+	Sound_MakeCustom(50,1000,false);
 
-	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);
 }
 

+ 0 - 2
Firmware/fsensor.cpp

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

+ 0 - 11
Firmware/fsensor.h

@@ -44,7 +44,6 @@ extern void fsensor_disable(bool bUpdateEEPROM=true);
 extern bool fsensor_autoload_enabled;
 extern void fsensor_autoload_set(bool State);
 
-extern void fsensor_update(void);
 #ifdef PAT9125
 //! setup pin-change interrupt
 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_stop(void);
 #endif //PAT9125
-extern bool fsensor_check_autoload(void);
 //! @}
 
 #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
 //! @{
 extern void fsensor_st_block_chunk(int cnt);

+ 6 - 16
Firmware/ultralcd.cpp

@@ -32,6 +32,7 @@
 #ifdef FILAMENT_SENSOR
 #include "pat9125.h"
 #include "fsensor.h"
+#include "Filament_sensor.h"
 #endif //FILAMENT_SENSOR
 
 #ifdef TMC2130
@@ -1795,14 +1796,6 @@ void lcd_set_filament_autoload() {
      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'
 bool bFilamentPreheatState;
 bool bFilamentAction=false;
@@ -1834,7 +1827,7 @@ switch(eFilamentAction)
      case FilamentAction::Lay1Cal:
           break;
      }
-if(lcd_clicked())
+    if(lcd_clicked() || (((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad)) && fsensor.getFilamentLoadEvent()))
      {
      nLevel=2;
      if(!bFilamentPreheatState)
@@ -4253,13 +4246,9 @@ do\
         if (mmu_enabled == false)\
         {\
             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\
-                MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_OFF), lcd_set_filament_autoload);\
-            /*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*/\
+                MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_OFF), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_OFF c=17*/\
         }\
     }\
 }\
@@ -5241,6 +5230,7 @@ void unload_filament(bool automatic)
 	lcd_setstatuspgm(MSG_WELCOME);
 	custom_message_type = CustomMsg::Status;
 
+	eFilamentAction = FilamentAction::None;
 }
 
 #include "xflash.h"
@@ -7726,7 +7716,7 @@ void menu_lcd_lcdupdate_func(void)
 	}
 #endif//CARDINSERTED
 	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)
 		{

+ 0 - 2
Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h

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

+ 0 - 2
Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h

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

+ 0 - 2
Firmware/variants/1_75mm_MK25S-RAMBo10a-E3Dv6full.h

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

+ 0 - 2
Firmware/variants/1_75mm_MK25S-RAMBo13a-E3Dv6full.h

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

+ 0 - 2
Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h

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

+ 0 - 2
Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h

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