Skip to content

Commit

Permalink
🚸 Use Marlin runout sensor code
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jan 14, 2025
1 parent fb3d3e4 commit e6c6d56
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 63 deletions.
85 changes: 24 additions & 61 deletions Marlin/src/lcd/extui/mks_ui/printer_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
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();

#if ENABLED(MKS_WIFI_MODULE)
mks_esp_wifi_init();
Expand Down

0 comments on commit e6c6d56

Please sign in to comment.