Skip to content

Commit

Permalink
Use FILAMENT_RUNOUT_SENSOR feature
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 25, 2023
1 parent e09b616 commit d1a1833
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 60 deletions.
83 changes: 25 additions & 58 deletions Marlin/src/lcd/extui/mks_ui/printer_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#include "../../../feature/powerloss.h"
#endif

#if ENABLED(FILAMENT_RUNOUT_SENSOR)
#include "../../../feature/runout.h"
#endif

extern uint32_t To_pre_view;
extern bool flash_preview_begin, default_preview_flg, gcode_preview_over;

Expand Down Expand Up @@ -142,71 +146,34 @@ 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_RUNOUT)
SET_INPUT_PULLUP(FIL_RUNOUT_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_RUNOUT)
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 ENABLED(FILAMENT_RUNOUT_SENSOR)

#if PIN_EXISTS(FIL_RUNOUT2)
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
void filament_check() {
static bool ranout = false;
if (runout.filament_ran_out != ranout) {
ranout = runout.filament_ran_out;
if (ranout) {
clear_cur_ui();
stop_print_time();
uiCfg.print_state = PAUSING;

#if PIN_EXISTS(FIL_RUNOUT3)
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
if (gCfgItems.from_flash_pic)
flash_preview_begin = true;
else
default_preview_flg = true;

if (false
#if PIN_EXISTS(FIL_RUNOUT)
|| 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
1 change: 0 additions & 1 deletion Marlin/src/lcd/extui/mks_ui/printer_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#define MIN_FILE_PRINTED 100 //5000

void printer_state_polling();
void filament_pin_setup();
void filament_check();

#ifdef __cplusplus
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ void tft_lvgl_init() {
TERN_(HAS_SPI_FLASH_FONT, init_gb2312_font());

tft_style_init();
filament_pin_setup();
lv_encoder_pin_init();

#if ENABLED(MKS_WIFI_MODULE)
Expand Down

0 comments on commit d1a1833

Please sign in to comment.