Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply FILAMENT_RUNOUT_SENSOR to MKS_UI #22595

Open
wants to merge 2 commits into
base: bugfix-2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,8 @@ void DGUSScreenHandlerMKS::extrudeLoadInit() {
}

void DGUSScreenHandlerMKS::runoutInit() {
#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;
Expand All @@ -1399,17 +1399,17 @@ void DGUSScreenHandlerMKS::runoutIdle() {
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;

Expand Down
38 changes: 24 additions & 14 deletions Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
#include "mks_hardware.h"
#include "../../../module/endstops.h"

bool pw_det_sta, pw_off_sta, mt_det_sta;
#if PIN_EXISTS(MT_DET_2)
bool pw_det_sta, pw_off_sta;
#if PIN_EXISTS(FIL_RUNOUT)
bool mt_det_sta;
#endif
#if PIN_EXISTS(FIL_RUNOUT2)
bool mt_det2_sta;
#endif
#if USE_X_MIN
Expand Down Expand Up @@ -105,9 +108,11 @@
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);
#if PIN_EXISTS(FIL_RUNOUT)
mt_det_sta = (READ(FIL_RUNOUT_PIN) == FIL_RUNOUT_STATE);
#endif
#if PIN_EXISTS(FIL_RUNOUT2)
mt_det2_sta = (READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT2_STATE);
#endif
TERN_(USE_X_MIN, endstopx1_min = ESTATE(X_MIN));
TERN_(USE_X_MAX, endstopx1_max = ESTATE(X_MAX));
Expand Down Expand Up @@ -140,9 +145,11 @@
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);
#if PIN_EXISTS(FIL_RUNOUT)
mt_det_sta = (READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_STATE);
#endif
#if PIN_EXISTS(FIL_RUNOUT2)
mt_det2_sta = (READ(FIL_RUNOUT2_PIN) != FIL_RUNOUT2_STATE);
#endif
TERN_(USE_X_MIN, endstopx1_min = !ESTATE(X_MIN));
TERN_(USE_X_MAX, endstopx1_max = !ESTATE(X_MAX));
Expand Down Expand Up @@ -177,11 +184,11 @@
SET_OUTPUT(WIFI_IO0_PIN);
#endif

#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);
Expand Down Expand Up @@ -225,8 +232,11 @@
test_gpio_readlevel_L();
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 (pw_det_sta && pw_off_sta
#if PIN_EXISTS(FIL_RUNOUT)
&& mt_det_sta
#endif
#if PIN_EXISTS(FIL_RUNOUT2)
&& mt_det2_sta
#endif
#if ENABLED(MKS_HARDWARE_TEST_ONLY_E0)
Expand Down
89 changes: 27 additions & 62 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 @@ -101,6 +105,7 @@ void printer_state_polling() {
update_spi_flash();
}
}

#if ENABLED(POWER_LOSS_RECOVERY)
if (uiCfg.print_state == REPRINTED) {
#if HAS_HOTEND
Expand All @@ -118,6 +123,7 @@ void printer_state_polling() {
#endif

recovery.resume();

#if 0
// Move back to the saved XY
char str_1[16], str_2[16];
Expand All @@ -140,75 +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(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
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(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
if (gCfgItems.from_flash_pic)
flash_preview_begin = true;
else
default_preview_flg = true;

if (false
#if PIN_EXISTS(MT_DET_1)
|| fil_det_count_1 >= FIL_DELAY
#endif
#if PIN_EXISTS(MT_DET_2)
|| fil_det_count_2 >= FIL_DELAY
#endif
#if PIN_EXISTS(MT_DET_3)
|| fil_det_count_3 >= FIL_DELAY
#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
16 changes: 9 additions & 7 deletions Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,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
//
Expand Down Expand Up @@ -225,9 +221,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

//
Expand Down
10 changes: 7 additions & 3 deletions Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

//
// Probe enable
//
Expand Down Expand Up @@ -187,8 +191,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
Expand All @@ -205,7 +210,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
Expand Down
8 changes: 3 additions & 5 deletions Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

//
// Probe enable
Expand Down Expand Up @@ -126,11 +129,6 @@
#define POWER_LOSS_PIN PA2 // PW_DET
#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
#endif

#define WIFI_IO0_PIN PC13

//
Expand Down
12 changes: 9 additions & 3 deletions Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,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
Expand Down
Loading