diff --git a/Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.h b/Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.h index bdcd248dd6cd..822e77cc5b72 100644 --- a/Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.h +++ b/Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.h @@ -24,15 +24,20 @@ #include "../DGUSDisplayDef.h" //#define DGUS_MKS_RUNOUT_SENSOR - -#define LOGO_TIME_DELAY TERN(USE_MKS_GREEN_UI, 8000, 1500) - #if ENABLED(DGUS_MKS_RUNOUT_SENSOR) - #define MT_DET_1_PIN 1 - #define MT_DET_2_PIN 2 - #define MT_DET_PIN_STATE LOW + #ifndef FIL_RUNOUT_PIN + #define FIL_RUNOUT_PIN 1 + #endif + #ifndef FIL_RUNOUT2_PIN + #define FIL_RUNOUT2_PIN 2 + #endif + #ifndef FIL_RUNOUT_STATE + #define FIL_RUNOUT_STATE LOW + #endif #endif +#define LOGO_TIME_DELAY TERN(USE_MKS_GREEN_UI, 8000, 1500) + #define MKS_FINSH extern uint16_t manualMoveStep; diff --git a/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp index 36ab016b35a6..112ab092a6ca 100644 --- a/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp @@ -1456,9 +1456,9 @@ void DGUSScreenHandlerMKS::DGUS_ExtrudeLoadInit() { ex_filament.ex_tick_start = 0; } -void DGUSScreenHandlerMKS::DGUS_RunoutInit() { - #if PIN_EXISTS(MT_DET_1) - SET_INPUT_PULLUP(MT_DET_1_PIN); +void DGUSScreenHandler::DGUS_RunoutInit() { + #if PIN_EXISTS(FIL_RUNOUT) + SET_INPUT_PULLUP(FIL_RUNOUT_PIN); #endif runout_mks.de_count = 0; runout_mks.de_times = 10; @@ -1482,17 +1482,17 @@ void DGUSScreenHandlerMKS::DGUS_Runout_Idle() { break; case UNRUNOUT_STATUS: - if (READ(MT_DET_1_PIN) == MT_DET_PIN_STATE) + if (READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_STATE) runout_mks.runout_status = RUNOUT_STATUS; break; case RUNOUT_BEGIN_STATUS: - if (READ(MT_DET_1_PIN) != MT_DET_PIN_STATE) + if (READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_STATE) runout_mks.runout_status = RUNOUT_WAITING_STATUS; break; case RUNOUT_WAITING_STATUS: - if (READ(MT_DET_1_PIN) == MT_DET_PIN_STATE) + if (READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_STATE) runout_mks.runout_status = RUNOUT_BEGIN_STATUS; break; diff --git a/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp b/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp index 00bb9833fc72..d6c6727a3f47 100644 --- a/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp +++ b/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp @@ -42,7 +42,7 @@ #include "../../../module/endstops.h" bool pw_det_sta, pw_off_sta, mt_det_sta; - #if PIN_EXISTS(MT_DET_2) + #if PIN_EXISTS(FIL_RUNOUT2) bool mt_det2_sta; #endif #if X_HOME_DIR @@ -83,9 +83,9 @@ delay(10); pw_det_sta = (READ(MKS_TEST_POWER_LOSS_PIN) == LOW); pw_off_sta = (READ(MKS_TEST_PS_ON_PIN) == LOW); - mt_det_sta = (READ(MT_DET_1_PIN) == LOW); - #if PIN_EXISTS(MT_DET_2) - mt_det2_sta = (READ(MT_DET_2_PIN) == LOW); + mt_det_sta = (READ(FIL_RUNOUT_PIN) == LOW); + #if PIN_EXISTS(FIL_RUNOUT2) + mt_det2_sta = (READ(FIL_RUNOUT2_PIN) == LOW); #endif #if HAS_X_MIN endstopx1_sta = ESTATE(X_MIN); @@ -124,9 +124,9 @@ delay(10); pw_det_sta = (READ(MKS_TEST_POWER_LOSS_PIN) == HIGH); pw_off_sta = (READ(MKS_TEST_PS_ON_PIN) == HIGH); - mt_det_sta = (READ(MT_DET_1_PIN) == HIGH); - #if PIN_EXISTS(MT_DET_2) - mt_det2_sta = (READ(MT_DET_2_PIN) == HIGH); + mt_det_sta = (READ(FIL_RUNOUT_PIN) == HIGH); + #if PIN_EXISTS(FIL_RUNOUT2) + mt_det2_sta = (READ(FIL_RUNOUT2_PIN) == HIGH); #endif #if HAS_X_MIN endstopx1_sta = !ESTATE(X_MIN); @@ -167,11 +167,11 @@ SET_OUTPUT(WIFI_IO0_PIN); - #if PIN_EXISTS(MT_DET_1) - SET_INPUT_PULLUP(MT_DET_1_PIN); + #if PIN_EXISTS(FIL_RUNOUT) + SET_INPUT_PULLUP(FIL_RUNOUT_PIN); #endif - #if PIN_EXISTS(MT_DET_2) - SET_INPUT_PULLUP(MT_DET_2_PIN); + #if PIN_EXISTS(FIL_RUNOUT2) + SET_INPUT_PULLUP(FIL_RUNOUT2_PIN); #endif SET_INPUT_PULLUP(MKS_TEST_POWER_LOSS_PIN); @@ -214,7 +214,7 @@ test_gpio_readlevel_H(); test_gpio_readlevel_L(); if (pw_det_sta && pw_off_sta && mt_det_sta - #if PIN_EXISTS(MT_DET_2) + #if PIN_EXISTS(FIL_RUNOUT2) && mt_det2_sta #endif #if ENABLED(MKS_HARDWARE_TEST_ONLY_E0) diff --git a/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp b/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp index 8f5b89cf347c..c55cab955a65 100644 --- a/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp +++ b/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp @@ -101,6 +101,7 @@ void printer_state_polling() { update_spi_flash(); } } + #if ENABLED(POWER_LOSS_RECOVERY) if (uiCfg.print_state == REPRINTED) { #if HAS_HOTEND @@ -118,6 +119,7 @@ void printer_state_polling() { #endif recovery.resume(); + #if 0 // Move back to the saved XY char str_1[16], str_2[16]; @@ -140,75 +142,77 @@ void printer_state_polling() { } #endif - if (uiCfg.print_state == WORKING) - filament_check(); + #if ENABLED(FILAMENT_RUNOUT_SENSOR) + if (uiCfg.print_state == WORKING) filament_check(); + #endif TERN_(MKS_WIFI_MODULE, wifi_looping()); } -void filament_pin_setup() { - #if PIN_EXISTS(MT_DET_1) - SET_INPUT_PULLUP(MT_DET_1_PIN); - #endif - #if PIN_EXISTS(MT_DET_2) - SET_INPUT_PULLUP(MT_DET_2_PIN); - #endif - #if PIN_EXISTS(MT_DET_3) - SET_INPUT_PULLUP(MT_DET_3_PIN); - #endif -} +#if ENABLED(FILAMENT_RUNOUT_SENSOR) -void filament_check() { - #if ANY_PIN(MT_DET_1, MT_DET_2, MT_DET_3) - const int FIL_DELAY = 20; - #endif - #if PIN_EXISTS(MT_DET_1) - static int fil_det_count_1 = 0; - if (READ(MT_DET_1_PIN) == MT_DET_PIN_STATE) - fil_det_count_1++; - else if (fil_det_count_1 > 0) - fil_det_count_1--; - #endif - - #if PIN_EXISTS(MT_DET_2) - static int fil_det_count_2 = 0; - if (READ(MT_DET_2_PIN) == MT_DET_PIN_STATE) - fil_det_count_2++; - else if (fil_det_count_2 > 0) - fil_det_count_2--; - #endif - - #if PIN_EXISTS(MT_DET_3) - static int fil_det_count_3 = 0; - if (READ(MT_DET_3_PIN) == MT_DET_PIN_STATE) - fil_det_count_3++; - else if (fil_det_count_3 > 0) - fil_det_count_3--; - #endif + void filament_pin_setup() { + #if PIN_EXISTS(FIL_RUNOUT1) + SET_INPUT_PULLUP(FIL_RUNOUT_PIN); + #endif + #if PIN_EXISTS(FIL_RUNOUT2) && NUM_RUNOUT_SENSORS >= 2 + SET_INPUT_PULLUP(FIL_RUNOUT2_PIN); + #endif + #if PIN_EXISTS(FIL_RUNOUT3) && NUM_RUNOUT_SENSORS >= 3 + SET_INPUT_PULLUP(FIL_RUNOUT3_PIN); + #endif + } - if (false - #if PIN_EXISTS(MT_DET_1) - || fil_det_count_1 >= FIL_DELAY + void filament_check() { + #if PIN_EXISTS(FIL_RUNOUT1) + static int fil_det_count_1 = 0; + if (READ(FIL_RUNOUT_PIN) == FIL_RUNOUT1_STATE) + fil_det_count_1++; + else if (fil_det_count_1 > 0) + fil_det_count_1--; #endif - #if PIN_EXISTS(MT_DET_2) - || fil_det_count_2 >= FIL_DELAY + + #if PIN_EXISTS(FIL_RUNOUT2) && NUM_RUNOUT_SENSORS >= 2 + static int fil_det_count_2 = 0; + if (READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT2_STATE) + fil_det_count_2++; + else if (fil_det_count_2 > 0) + fil_det_count_2--; #endif - #if PIN_EXISTS(MT_DET_3) - || fil_det_count_3 >= FIL_DELAY + + #if PIN_EXISTS(FIL_RUNOUT3) && NUM_RUNOUT_SENSORS >= 3 + static int fil_det_count_3 = 0; + if (READ(FIL_RUNOUT3_PIN) == FIL_RUNOUT3_STATE) + fil_det_count_3++; + else if (fil_det_count_3 > 0) + fil_det_count_3--; #endif - ) { - clear_cur_ui(); - card.pauseSDPrint(); - stop_print_time(); - uiCfg.print_state = PAUSING; - - if (gCfgItems.from_flash_pic) - flash_preview_begin = true; - else - default_preview_flg = true; - - lv_draw_printing(); + + if (false + #if PIN_EXISTS(FIL_RUNOUT1) + || fil_det_count_1 >= FILAMENT_RUNOUT_THRESHOLD + #endif + #if PIN_EXISTS(FIL_RUNOUT2) && NUM_RUNOUT_SENSORS >= 2 + || fil_det_count_2 >= FILAMENT_RUNOUT_THRESHOLD + #endif + #if PIN_EXISTS(FIL_RUNOUT3) && NUM_RUNOUT_SENSORS >= 3 + || fil_det_count_3 >= FILAMENT_RUNOUT_THRESHOLD + #endif + ) { + clear_cur_ui(); + card.pauseSDPrint(); + stop_print_time(); + uiCfg.print_state = PAUSING; + + if (gCfgItems.from_flash_pic) + flash_preview_begin = true; + else + default_preview_flg = true; + + lv_draw_printing(); + } } -} + +#endif // FILAMENT_RUNOUT_SENSOR #endif // HAS_TFT_LVGL_UI diff --git a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp index 38612358110b..ce1028aa1e68 100644 --- a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp @@ -212,7 +212,7 @@ void tft_lvgl_init() { TERN_(HAS_SPI_FLASH_FONT, init_gb2312_font()); tft_style_init(); - filament_pin_setup(); + TERN_(FILAMENT_RUNOUT_SENSOR, filament_pin_setup()); lv_encoder_pin_init(); #if ENABLED(MKS_WIFI_MODULE) diff --git a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h index dd621eb5c126..11ce94cc1dc1 100644 --- a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h +++ b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h @@ -91,10 +91,6 @@ #define Z_MIN_PIN PA11 // -Z #define Z_MAX_PIN PC4 // +Z -#ifndef FIL_RUNOUT_PIN - #define FIL_RUNOUT_PIN PA4 // MT_DET -#endif - // // Steppers // @@ -222,9 +218,15 @@ #endif #if HAS_TFT_LVGL_UI - #define MT_DET_1_PIN PA4 // MT_DET - #define MT_DET_2_PIN PE6 - #define MT_DET_PIN_STATE LOW + #ifndef FIL_RUNOUT_PIN + #define FIL_RUNOUT_PIN PA4 // MT_DET_1 + #endif + #ifndef FIL_RUNOUT2_PIN + #define FIL_RUNOUT2_PIN PE6 // MT_DET_2 + #endif + #ifndef FIL_RUNOUT_STATE + #define FIL_RUNOUT_STATE LOW + #endif #endif // diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h index b8f6f6a330ad..92d5fa4b4e17 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h @@ -80,6 +80,10 @@ #define Z_MIN_PIN PA11 #define Z_MAX_PIN PC4 +#ifndef FIL_RUNOUT_PIN + #define FIL_RUNOUT_PIN PA4 // MT_DET +#endif + // // Steppers // @@ -186,8 +190,9 @@ #define KILL_PIN_STATE HIGH #endif - #define MT_DET_1_PIN PA4 - #define MT_DET_PIN_STATE LOW + #ifndef FIL_RUNOUT_STATE + #define FIL_RUNOUT_STATE LOW + #endif #define WIFI_IO0_PIN PC13 #define WIFI_IO1_PIN PC7 @@ -200,7 +205,6 @@ #else //#define POWER_LOSS_PIN PA2 // PW_DET //#define PS_ON_PIN PB2 // PW_OFF - #define FIL_RUNOUT_PIN PA4 #endif //#define LED_PIN PB2 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h index 0bfc7f5c8d93..cfaa591535f3 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h @@ -70,6 +70,9 @@ #ifndef FIL_RUNOUT_PIN #define FIL_RUNOUT_PIN PA4 // MT_DET #endif +#ifndef FIL_RUNOUT_STATE + #define FIL_RUNOUT_STATE LOW +#endif // // Steppers @@ -120,8 +123,9 @@ #define PS_ON_PIN PA3 // PW_OFF #if HAS_TFT_LVGL_UI - #define MT_DET_1_PIN PA4 // MT_DET - #define MT_DET_PIN_STATE LOW + #ifndef FIL_RUNOUT_PIN + #define FIL_RUNOUT_PIN PA4 // MT_DET + #endif #endif #define WIFI_IO0_PIN PC13 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h index 9c6373bef987..074c379dbc0e 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -212,9 +212,15 @@ // Misc. Functions // #if HAS_TFT_LVGL_UI - #define MT_DET_1_PIN PA4 - #define MT_DET_2_PIN PE6 - #define MT_DET_PIN_STATE LOW + #ifndef FIL_RUNOUT_PIN + #define FIL_RUNOUT_PIN PA4 // MT_DET_1 + #endif + #ifndef FIL_RUNOUT2_PIN + #define FIL_RUNOUT2_PIN PE6 // MT_DET_2 + #endif + #ifndef FIL_RUNOUT_STATE + #define FIL_RUNOUT_STATE LOW + #endif #define WIFI_IO0_PIN PC13 #define WIFI_IO1_PIN PC7 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_common.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_common.h index 6f1a790580ad..f93eb754435f 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_common.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_common.h @@ -142,9 +142,15 @@ // Misc. Functions // #if HAS_TFT_LVGL_UI - #define MT_DET_1_PIN PA4 - #define MT_DET_2_PIN PE6 - #define MT_DET_PIN_STATE LOW + #ifndef FIL_RUNOUT_PIN + #define FIL_RUNOUT_PIN PA4 // MT_DET_1 + #endif + #ifndef FIL_RUNOUT2_PIN + #define FIL_RUNOUT2_PIN PE6 // MT_DET_2 + #endif + #ifndef FIL_RUNOUT_STATE + #define FIL_RUNOUT_STATE LOW + #endif #define WIFI_IO0_PIN PC13 #define WIFI_IO1_PIN PC7 diff --git a/Marlin/src/pins/stm32f4/pins_MKS_MONSTER8_common.h b/Marlin/src/pins/stm32f4/pins_MKS_MONSTER8_common.h index 8a9b72225d79..5f50d2dbc7af 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_MONSTER8_common.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_MONSTER8_common.h @@ -69,6 +69,16 @@ #define Z_MIN_PIN PB13 #define Z_MAX_PIN PB12 +// +// Filament Runout Sensor +// +#ifndef FIL_RUNOUT_PIN + #define FIL_RUNOUT_PIN PC5 // Y+ +#endif +#ifndef FIL_RUNOUT2_PIN + #define FIL_RUNOUT2_PIN PB12 // Z+ +#endif + // // Steppers // diff --git a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3_common.h b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3_common.h index 4ac64ae1d2c4..dca8d120ec70 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3_common.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3_common.h @@ -147,16 +147,15 @@ // Misc. Functions // #if HAS_TFT_LVGL_UI - #define MT_DET_1_PIN PA4 // MT_DET - #define MT_DET_2_PIN PE6 - #define MT_DET_PIN_STATE LOW -#endif - -#ifndef FIL_RUNOUT_PIN - #define FIL_RUNOUT_PIN PA4 -#endif -#ifndef FIL_RUNOUT2_PIN - #define FIL_RUNOUT2_PIN PE6 + #ifndef FIL_RUNOUT_PIN + #define FIL_RUNOUT_PIN PA4 // MT_DET_1 + #endif + #ifndef FIL_RUNOUT2_PIN + #define FIL_RUNOUT2_PIN PE6 // MT_DET_2 + #endif + #ifndef FIL_RUNOUT_STATE + #define FIL_RUNOUT_STATE LOW + #endif #endif #ifndef POWER_LOSS_PIN