Improve PAT9125 UI implementation

This commit is contained in:
Alex Voinea 2022-03-02 12:01:48 +01:00 committed by D.R.racer
parent 340bc87110
commit 329745368e
11 changed files with 71 additions and 46 deletions

View File

@ -865,7 +865,7 @@ void dcode_2130()
}
#endif //TMC2130
#ifdef PAT9125
#if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
/*!
### D9125 - PAT9125 filament sensor <a href="https://reprap.org/wiki/G-code#D9:_Read.2FWrite_ADC">D9125: PAT9125 filament sensor</a>
#### Usage
@ -878,7 +878,6 @@ void dcode_2130()
- `R` - Resolution. Not active in code
- `X` - X values
- `Y` - Y values
- `L` - Activate filament sensor log
*/
void dcode_9125()
{
@ -913,7 +912,7 @@ void dcode_9125()
LOG("pat9125_y=%d\n", pat9125_y);
}
}
#endif //PAT9125
#endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
#endif //DEBUG_DCODES

View File

@ -53,9 +53,9 @@ extern void dcode_81(); //D81 - Bed analysis. This command will log data to SD c
extern void dcode_2130(); //D2130 - TMC2130
#endif //TMC2130
#ifdef PAT9125
#if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
extern void dcode_9125(); //D9125 - PAT9125
#endif //PAT9125
#endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
#endif //DCODES_H

View File

@ -29,6 +29,9 @@ public:
virtual void deinit() = 0;
virtual bool update() = 0;
virtual bool getFilamentPresent() = 0;
#ifdef FSENSOR_PROBING
virtual bool probeOtherType() = 0; //checks if the wrong fsensor type is detected.
#endif
enum class State : uint8_t {
disabled = 0,
@ -238,6 +241,12 @@ public:
return !READ(IR_SENSOR_PIN);
}
#ifdef FSENSOR_PROBING
bool probeOtherType() {
return pat9125_probe();
}
#endif
void settings_init() {
Filament_sensor::settings_init();
}
@ -511,6 +520,17 @@ public:
return filterFilPresent;
}
#ifdef FSENSOR_PROBING
bool probeOtherType() {
SET_INPUT(IR_SENSOR_PIN); //input mode
WRITE(IR_SENSOR_PIN, 1); //pullup
_delay_us(100); //wait for the pullup to pull the line high (might be needed, not really sure. The internal pullups are quite weak and there might be a long wire attached).
bool fsensorDetected = !READ(IR_SENSOR_PIN);
WRITE(IR_SENSOR_PIN, 0); //no pullup
return fsensorDetected;
}
#endif
void setJamDetectionEnabled(bool state, bool updateEEPROM = false) {
jamDetection = state;
oldPos = pat9125_y;

View File

@ -690,9 +690,6 @@ void failstats_reset_print()
eeprom_update_byte((uint8_t *)EEPROM_POWER_COUNT, 0);
eeprom_update_byte((uint8_t *)EEPROM_MMU_FAIL, 0);
eeprom_update_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL, 0);
#if defined(FILAMENT_SENSOR) && defined(PAT9125)
fsensor_softfail = 0;
#endif
}
void softReset()
@ -863,24 +860,14 @@ void show_fw_version_warnings() {
lcd_update_enable(true);
}
#if defined(FILAMENT_SENSOR) && defined(FSENSOR_PROBING)
//! @brief try to check if firmware is on right type of printer
static void check_if_fw_is_on_right_printer(){
#ifdef FILAMENT_SENSOR
if((PRINTER_TYPE == PRINTER_MK3) || (PRINTER_TYPE == PRINTER_MK3S)){
#ifdef IR_SENSOR
if (pat9125_probe()){
lcd_show_fullscreen_message_and_wait_P(_i("MK3S firmware detected on MK3 printer"));}////MSG_MK3S_FIRMWARE_ON_MK3 c=20 r=4
#endif //IR_SENSOR
#ifdef PAT9125
//will return 1 only if IR can detect filament in bondtech extruder so this may fail even when we have IR sensor
const uint8_t ir_detected = fsensor.getFilamentPresent();
if (ir_detected){
lcd_show_fullscreen_message_and_wait_P(_i("MK3 firmware detected on MK3S printer"));}////MSG_MK3_FIRMWARE_ON_MK3S c=20 r=4
#endif //PAT9125
}
#endif //FILAMENT_SENSOR
static void check_if_fw_is_on_right_printer() {
if (fsensor.probeOtherType()) {
lcd_show_fullscreen_message_and_wait_P(_i((PRINTER_NAME " firmware detected on " PRINTER_NAME_ALTERNATE " printer")));////c=20 r=4
}
}
#endif //defined(FILAMENT_SENSOR) && defined(FSENSOR_PROBING)
uint8_t check_printer_version()
{
@ -1500,7 +1487,9 @@ void setup()
KEEPALIVE_STATE(PAUSED_FOR_USER);
if (!farm_mode) {
#if defined(FILAMENT_SENSOR) && defined(FSENSOR_PROBING)
check_if_fw_is_on_right_printer();
#endif //defined(FILAMENT_SENSOR) && defined(FSENSOR_PROBING)
show_fw_version_warnings();
}
@ -6519,9 +6508,9 @@ Sigma_Exit:
axis_steps_per_sqr_second[i] *= factor;
}
cs.axis_steps_per_unit[i] = value;
#if defined(FILAMENT_SENSOR) && defined(PAT9125)
#if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
fsensor.init();
#endif
#endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
}
else {
cs.axis_steps_per_unit[i] = code_value();
@ -8455,10 +8444,10 @@ Sigma_Exit:
cs.axis_steps_per_unit[i] /= fac;
position[i] /= fac;
}
#if defined(FILAMENT_SENSOR) && defined(PAT9125)
#if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
if (i == E_AXIS)
fsensor.init();
#endif
#endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
}
}
}
@ -9089,7 +9078,7 @@ Sigma_Exit:
dcode_2130(); break;
#endif //TMC2130
#if (defined (FILAMENT_SENSOR) && defined(PAT9125))
#if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
/*!
### D9125 - PAT9125 filament sensor <a href="https://reprap.org/wiki/G-code#D9:_Read.2FWrite_ADC">D9125: PAT9125 filament sensor</a>
@ -9107,7 +9096,7 @@ Sigma_Exit:
*/
case 9125:
dcode_9125(); break;
#endif //FILAMENT_SENSOR
#endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
#endif //DEBUG_DCODES

View File

@ -212,14 +212,18 @@ enum class FanCheck : uint_least8_t {
static FanCheck lcd_selftest_fan_auto(uint8_t _fan);
#endif //FANCHECK
#ifdef PAT9125
#ifdef FILAMENT_SENSOR
#if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
static bool lcd_selftest_fsensor();
#endif //PAT9125
#elif FILAMENT_SENSOR_TYPE == FSENSOR_IR
static bool selftest_irsensor();
#elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG
static bool selftest_irsensor();
#if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
static bool lcd_selftest_IRsensor(bool bStandalone=false);
static void lcd_detect_IRsensor();
#endif //IR_SENSOR_ANALOG
#endif
#endif //FILAMENT_SENSOR
static void lcd_selftest_error(TestError error, const char *_error_1, const char *_error_2);
static void lcd_colorprint_change();
@ -1253,13 +1257,7 @@ static void lcd_menu_fails_stats_print()
uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X);
uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y);
lcd_home();
#ifndef PAT9125
lcd_printf_P(failStatsFmt,
_T(MSG_LAST_PRINT_FAILURES),
_T(MSG_POWER_FAILURES), power,
_T(MSG_FIL_RUNOUTS), filam,
_T(MSG_CRASH), crashX, crashY);
#else
#if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
// On the MK3 include detailed PAT9125 statistics about soft failures
lcd_printf_P(PSTR("%S\n"
" %-16.16S%-3d\n"
@ -1269,6 +1267,14 @@ static void lcd_menu_fails_stats_print()
_T(MSG_POWER_FAILURES), power,
_i("Runouts"), filam, //MSG_RUNOUTS c=7
_T(MSG_CRASH), crashX, crashY);
#elif (FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
lcd_printf_P(failStatsFmt,
_T(MSG_LAST_PRINT_FAILURES),
_T(MSG_POWER_FAILURES), power,
_T(MSG_FIL_RUNOUTS), filam,
_T(MSG_CRASH), crashX, crashY);
#else
#error This menu should have a filament sensor defined
#endif
menu_back_if_clicked_fb();
}
@ -6417,7 +6423,7 @@ bool lcd_selftest()
#ifdef FILAMENT_SENSOR
if (_result)
{
#if (FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
if (mmu_enabled)
{
_progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
@ -6427,15 +6433,16 @@ bool lcd_selftest()
_progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
}
} else
#endif //(FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
{
#ifdef PAT9125
#if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
_progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
_result = lcd_selftest_fsensor();
if (_result)
{
_progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
}
#endif //PAT9125
#endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
#if 0
// Intentionally disabled - that's why we moved the detection to runtime by just checking the two voltages.
// The idea is not to force the user to remove and insert the filament on an assembled printer.
@ -6997,7 +7004,7 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const
}
#ifdef FILAMENT_SENSOR
#ifdef PAT9125
#if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
static bool lcd_selftest_fsensor(void)
{
fsensor.init();
@ -7007,8 +7014,9 @@ static bool lcd_selftest_fsensor(void)
}
return (!fsensor.isError());
}
#endif //PAT9125
#endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
#if (FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
//! @brief Self-test of infrared barrier filament sensor mounted on MK3S with MMUv2 printer
//!
//! Test whether sensor is not triggering filament presence when extruder idler is moving without filament.
@ -7076,6 +7084,7 @@ static bool selftest_irsensor()
}
return true;
}
#endif //(FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
#endif //FILAMENT_SENSOR
static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,

View File

@ -10,6 +10,7 @@
// Printer revision
#define PRINTER_TYPE PRINTER_MK25
#define PRINTER_NAME PRINTER_MK25_NAME
#define PRINTER_NAME_ALTERNATE PRINTER_MK25S_NAME //the other similar printer to this.
#define PRINTER_MMU_TYPE PRINTER_MK25_MMU2
#define PRINTER_MMU_NAME PRINTER_MK25_MMU2_NAME
#define FILAMENT_SIZE "1_75mm_MK25"

View File

@ -10,6 +10,7 @@
// Printer revision
#define PRINTER_TYPE PRINTER_MK25
#define PRINTER_NAME PRINTER_MK25_NAME
#define PRINTER_NAME_ALTERNATE PRINTER_MK25S_NAME //the other similar printer to this.
#define PRINTER_MMU_TYPE PRINTER_MK25_MMU2
#define PRINTER_MMU_NAME PRINTER_MK25_MMU2_NAME
#define FILAMENT_SIZE "1_75mm_MK25"

View File

@ -10,6 +10,7 @@
// Printer revision
#define PRINTER_TYPE PRINTER_MK25S
#define PRINTER_NAME PRINTER_MK25S_NAME
#define PRINTER_NAME_ALTERNATE PRINTER_MK25_NAME //the other similar printer to this.
#define PRINTER_MMU_TYPE PRINTER_MK25S_MMU2
#define PRINTER_MMU_NAME PRINTER_MK25S_MMU2_NAME
#define FILAMENT_SIZE "1_75mm_MK25S"

View File

@ -10,6 +10,7 @@
// Printer revision
#define PRINTER_TYPE PRINTER_MK25S
#define PRINTER_NAME PRINTER_MK25S_NAME
#define PRINTER_NAME_ALTERNATE PRINTER_MK25_NAME //the other similar printer to this.
#define PRINTER_MMU_TYPE PRINTER_MK25S_MMU2
#define PRINTER_MMU_NAME PRINTER_MK25S_MMU2_NAME
#define FILAMENT_SIZE "1_75mm_MK25S"

View File

@ -11,6 +11,7 @@
// Printer revision
#define PRINTER_TYPE PRINTER_MK3
#define PRINTER_NAME PRINTER_MK3_NAME
#define PRINTER_NAME_ALTERNATE PRINTER_MK3S_NAME //the other similar printer to this.
#define PRINTER_MMU_TYPE PRINTER_MK3_MMU2
#define PRINTER_MMU_NAME PRINTER_MK3_MMU2_NAME
#define FILAMENT_SIZE "1_75mm_MK3"
@ -151,6 +152,7 @@
// Filament sensor
#define FILAMENT_SENSOR
#define FILAMENT_SENSOR_TYPE FSENSOR_PAT9125
#define FSENSOR_PROBING
// Backlash -
//#define BACKLASH_X

View File

@ -10,6 +10,7 @@
// Printer revision
#define PRINTER_TYPE PRINTER_MK3S
#define PRINTER_NAME PRINTER_MK3S_NAME
#define PRINTER_NAME_ALTERNATE PRINTER_MK3_NAME //the other similar printer to this.
#define PRINTER_MMU_TYPE PRINTER_MK3S_MMU2
#define PRINTER_MMU_NAME PRINTER_MK3S_MMU2_NAME
#define FILAMENT_SIZE "1_75mm_MK3S"
@ -153,6 +154,7 @@
// Filament sensor
#define FILAMENT_SENSOR
#define FILAMENT_SENSOR_TYPE FSENSOR_IR_ANALOG
#define FSENSOR_PROBING
// Backlash -
//#define BACKLASH_X