diff --git a/Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.h b/Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.h index 407782f5595e7..076c56092673d 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; @@ -100,7 +105,7 @@ extern EX_FILAMENT_DEF ex_filament; typedef enum { UNRUNOUT_STATUS, RUNOUT_STATUS, - RUNOUT_WAITTING_STATUS, + RUNOUT_WAITING_STATUS, RUNOUT_BEGIN_STATUS, } RUNOUT_MKS_STATUS_DEF; diff --git a/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp index c80191c8e54f2..b5d5f6d3b0d11 100644 --- a/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp @@ -195,7 +195,7 @@ void DGUSScreenHandler::DGUSLCD_SendTMCStepValue(DGUS_VP_Variable &var) { case 0: { // Resume auto cs = getCurrentScreen(); - if (runout_mks.runout_status != RUNOUT_WAITTING_STATUS && runout_mks.runout_status != UNRUNOUT_STATUS) { + if (runout_mks.runout_status != RUNOUT_WAITING_STATUS && runout_mks.runout_status != UNRUNOUT_STATUS) { if (cs == MKSLCD_SCREEN_PRINT || cs == MKSLCD_SCREEN_PAUSE) GotoScreen(MKSLCD_SCREEN_PAUSE); return; @@ -1470,8 +1470,8 @@ void DGUSScreenHandler::DGUS_ExtrudeLoadInit(void) { } void DGUSScreenHandler::DGUS_RunoutInit(void) { - #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 runout_mks.de_count = 0; runout_mks.de_times = 10; @@ -1495,17 +1495,17 @@ void DGUSScreenHandler::DGUS_Runout_Idle(void) { 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) - runout_mks.runout_status = RUNOUT_WAITTING_STATUS; + if (READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_STATE) + runout_mks.runout_status = RUNOUT_WAITING_STATUS; break; - case RUNOUT_WAITTING_STATUS: - if (READ(MT_DET_1_PIN) == MT_DET_PIN_STATE) + case RUNOUT_WAITING_STATUS: + 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 5cd1a4c525e9b..03ce1e1012b99 100644 --- a/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp +++ b/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp @@ -41,7 +41,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 HAS_X_MIN || HAS_X_MAX @@ -82,9 +82,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); @@ -123,9 +123,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); @@ -164,11 +164,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); @@ -216,7 +216,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 362fdeb43df20..fc855cf8d9328 100644 --- a/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp +++ b/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp @@ -100,6 +100,7 @@ void printer_state_polling() { update_spi_flash(); } } + #if ENABLED(POWER_LOSS_RECOVERY) if (uiCfg.print_state == REPRINTED) { #if HAS_HOTEND @@ -117,6 +118,7 @@ void printer_state_polling() { #endif recovery.resume(); + #if 0 // Move back to the saved XY char str_1[16], str_2[16]; @@ -139,75 +141,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 cfd6db15fdaeb..bc1f2ce8b2108 100644 --- a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp @@ -192,12 +192,10 @@ void tft_lvgl_init() { systick_attach_callback(SysTick_Callback); - #if HAS_SPI_FLASH_FONT - init_gb2312_font(); - #endif + 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 21bbd23ca9f61..935f81d2b11c2 100644 --- a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h +++ b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h @@ -93,7 +93,7 @@ #define Z_MAX_PIN PC4 // +Z #ifndef FIL_RUNOUT_PIN - #define FIL_RUNOUT_PIN MT_DET_1_PIN + #define FIL_RUNOUT_PIN FIL_RUNOUT_PIN #endif // @@ -223,9 +223,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 ba5198006512e..bedc7447363d1 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h @@ -190,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 @@ -204,7 +205,10 @@ #else //#define POWER_LOSS_PIN PA2 // PW_DET //#define PS_ON_PIN PB2 // PW_OFF - #define FIL_RUNOUT_PIN PA4 +#endif + +#ifndef FIL_RUNOUT_PIN + #define FIL_RUNOUT_PIN PA4 // MT_DET #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 ae45d8b6d1502..dd18a379a8c78 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.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 975ecb8bd53e9..25e181a06a6d1 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -147,9 +147,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_V2.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h index 49d5476fecda2..e013b0fc61749 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -211,9 +211,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.h b/Marlin/src/pins/stm32f4/pins_MKS_MONSTER8.h index 5c6668562995e..5c4a0df680575 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_MONSTER8.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_MONSTER8.h @@ -212,13 +212,12 @@ // #define PW_DET PC5 // Y+ #define PW_OFF PB12 // Z+ -#define MT_DET_1_PIN PW_DET -#define MT_DET_2_PIN PW_OFF + #ifndef FIL_RUNOUT_PIN - #define FIL_RUNOUT_PIN MT_DET_1_PIN + #define FIL_RUNOUT_PIN PC5 // Y+ #endif #ifndef FIL_RUNOUT2_PIN - #define FIL_RUNOUT2_PIN MT_DET_2_PIN + #define FIL_RUNOUT2_PIN PB12 // Z+ #endif // diff --git a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h index 9193a85511716..887b6dab0973c 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h @@ -179,16 +179,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 MT_DET_1_PIN -#endif -#ifndef FIL_RUNOUT2_PIN - #define FIL_RUNOUT2_PIN MT_DET_2_PIN + #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