Skip to content

Commit

Permalink
🐛 Apply FILAMENT_RUNOUT_SENSOR to MKS_UI
Browse files Browse the repository at this point in the history
Fixes #22591
  • Loading branch information
thinkyhead committed May 10, 2023
1 parent 03bb28c commit 06cabd8
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 113 deletions.
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
12 changes: 6 additions & 6 deletions Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,9 +1369,9 @@ void DGUSScreenHandlerMKS::DGUS_ExtrudeLoadInit() {
ex_filament.ex_tick_start = 0;
}

void DGUSScreenHandlerMKS::DGUS_RunoutInit() {
#if PIN_EXISTS(MT_DET_1)
SET_INPUT_PULLUP(MT_DET_1_PIN);
void DGUSScreenHandler::DGUS_RunoutInit() {
#if PIN_EXISTS(FIL_RUNOUT)
SET_INPUT_PULLUP(FIL_RUNOUT_PIN);
#endif
runout_mks.de_count = 0;
runout_mks.de_times = 10;
Expand All @@ -1395,17 +1395,17 @@ void DGUSScreenHandlerMKS::DGUS_Runout_Idle() {
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
24 changes: 12 additions & 12 deletions Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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_ENDSTOP
Expand Down Expand Up @@ -83,9 +83,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
TERN_(HAS_X_ENDSTOP, endstopx1_sta = ESTATE(TERN(USE_X_MIN, X_MIN, X_MAX)));
TERN_(HAS_X2_ENDSTOP, endstopx2_sta = ESTATE(TERN(USE_X2_MIN, X2_MIN, X2_MAX)));
Expand All @@ -100,9 +100,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
TERN_(HAS_X_ENDSTOP, endstopx1_sta = !ESTATE(TERN(USE_X_MIN, X_MIN, X_MAX)));
TERN_(HAS_X2_ENDSTOP, endstopx2_sta = !ESTATE(TERN(USE_X2_MIN, X2_MIN, X2_MAX)));
Expand All @@ -119,11 +119,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);
Expand Down Expand Up @@ -168,7 +168,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)
Expand Down
124 changes: 64 additions & 60 deletions Marlin/src/lcd/extui/mks_ui/printer_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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 +119,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 +142,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
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void tft_lvgl_init() {
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)
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 @@ -91,10 +91,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

//
// Steppers
//
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 @@ -201,7 +206,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: 6 additions & 2 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

//
// Steppers
Expand Down Expand Up @@ -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
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 @@ -213,9 +213,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

0 comments on commit 06cabd8

Please sign in to comment.