diff --git a/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp b/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp index dc47cdb357be..80286d08bb9e 100644 --- a/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp +++ b/Marlin/src/lcd/extui/mks_ui/printer_operation.cpp @@ -39,9 +39,8 @@ #include "../../../feature/powerloss.h" #endif -#define FILAMENT_IS_OUT(N...) (READ(FIL_RUNOUT##N##_PIN) == FIL_RUNOUT##N##_STATE) -#ifndef FILAMENT_RUNOUT_THRESHOLD - #define FILAMENT_RUNOUT_THRESHOLD 20 +#if ENABLED(FILAMENT_RUNOUT_SENSOR) + #include "../../../feature/runout.h" #endif extern uint32_t To_pre_view; @@ -147,71 +146,35 @@ 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(FIL_RUNOUT1) - SET_INPUT_PULLUP(FIL_RUNOUT1_PIN); - #endif - #if PIN_EXISTS(FIL_RUNOUT2) - SET_INPUT_PULLUP(FIL_RUNOUT2_PIN); - #endif - #if PIN_EXISTS(FIL_RUNOUT3) - SET_INPUT_PULLUP(FIL_RUNOUT3_PIN); - #endif -} - -void filament_check() { - #if PIN_EXISTS(FIL_RUNOUT1) - static int fil_det_count_1 = 0; - if (FILAMENT_IS_OUT(1)) - fil_det_count_1++; - else if (fil_det_count_1 > 0) - fil_det_count_1--; - #endif +#if ENABLED(FILAMENT_RUNOUT_SENSOR) - #if PIN_EXISTS(FIL_RUNOUT2) - static int fil_det_count_2 = 0; - if (FILAMENT_IS_OUT(2)) - fil_det_count_2++; - else if (fil_det_count_2 > 0) - fil_det_count_2--; - #endif + void filament_check() { + static bool ranout = false; + if (runout.filament_ran_out != ranout) { + ranout = runout.filament_ran_out; + if (ranout) { + clear_cur_ui(); + card.pauseSDPrint(); + stop_print_time(); + uiCfg.print_state = PAUSING; - #if PIN_EXISTS(FIL_RUNOUT3) - static int fil_det_count_3 = 0; - if (FILAMENT_IS_OUT(3)) - fil_det_count_3++; - else if (fil_det_count_3 > 0) - fil_det_count_3--; - #endif + if (gCfgItems.from_flash_pic) + flash_preview_begin = true; + else + default_preview_flg = true; - if (false - #if PIN_EXISTS(FIL_RUNOUT1) - || fil_det_count_1 >= FILAMENT_RUNOUT_THRESHOLD - #endif - #if PIN_EXISTS(FIL_RUNOUT2) - || fil_det_count_2 >= FILAMENT_RUNOUT_THRESHOLD - #endif - #if PIN_EXISTS(FIL_RUNOUT3) - || 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(); + lv_draw_printing(); + } + } } -} + +#endif // FILAMENT_RUNOUT_SENSOR #endif // HAS_TFT_LVGL_UI diff --git a/Marlin/src/lcd/extui/mks_ui/printer_operation.h b/Marlin/src/lcd/extui/mks_ui/printer_operation.h index d9c0b741f23e..eb063291f9a2 100644 --- a/Marlin/src/lcd/extui/mks_ui/printer_operation.h +++ b/Marlin/src/lcd/extui/mks_ui/printer_operation.h @@ -28,7 +28,6 @@ #define MIN_FILE_PRINTED 100 //5000 void printer_state_polling(); -void filament_pin_setup(); void filament_check(); #ifdef __cplusplus 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 f8dda5bd7b93..076965ee8188 100644 --- a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp @@ -215,7 +215,6 @@ void tft_lvgl_init() { TERN_(HAS_SPI_FLASH_FONT, init_gb2312_font()); tft_style_init(); - filament_pin_setup(); #if ENABLED(MKS_WIFI_MODULE) mks_esp_wifi_init();