Skip to content

Commit

Permalink
🐛 Apply FILAMENT_RUNOUT_SENSOR to MKS_UI
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 19, 2021
1 parent 368a12a commit ebc76e2
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 120 deletions.
19 changes: 12 additions & 7 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 Expand Up @@ -100,7 +105,7 @@ extern EX_FILAMENT_DEF ex_filament;
typedef enum {
UNRUNOUT_STATUS,
RUNOUT_STATUS,
RUNOUT_WAITTING_STATUS,
RUNOUT_WAITING_STATUS,
RUNOUT_BEGIN_STATUS,
} RUNOUT_MKS_STATUS_DEF;

Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void DGUSScreenHandler::DGUSLCD_SendTMCStepValue(DGUS_VP_Variable &var) {
case 0: { // Resume

auto cs = getCurrentScreen();
if (runout_mks.runout_status != RUNOUT_WAITTING_STATUS && runout_mks.runout_status != UNRUNOUT_STATUS) {
if (runout_mks.runout_status != RUNOUT_WAITING_STATUS && runout_mks.runout_status != UNRUNOUT_STATUS) {
if (cs == MKSLCD_SCREEN_PRINT || cs == MKSLCD_SCREEN_PAUSE)
GotoScreen(MKSLCD_SCREEN_PAUSE);
return;
Expand Down Expand Up @@ -1470,8 +1470,8 @@ void DGUSScreenHandler::DGUS_ExtrudeLoadInit(void) {
}

void DGUSScreenHandler::DGUS_RunoutInit(void) {
#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 @@ -1495,17 +1495,17 @@ void DGUSScreenHandler::DGUS_Runout_Idle(void) {
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)
runout_mks.runout_status = RUNOUT_WAITTING_STATUS;
if (READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_STATE)
runout_mks.runout_status = RUNOUT_WAITING_STATUS;
break;

case RUNOUT_WAITTING_STATUS:
if (READ(MT_DET_1_PIN) == MT_DET_PIN_STATE)
case RUNOUT_WAITING_STATUS:
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 @@ -41,7 +41,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_MIN || HAS_X_MAX
Expand Down Expand Up @@ -82,9 +82,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
#if HAS_X_MIN
endstopx1_sta = ESTATE(X_MIN);
Expand Down Expand Up @@ -123,9 +123,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
#if HAS_X_MIN
endstopx1_sta = !ESTATE(X_MIN);
Expand Down Expand Up @@ -164,11 +164,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 @@ -216,7 +216,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 @@ -100,6 +100,7 @@ void printer_state_polling() {
update_spi_flash();
}
}

#if ENABLED(POWER_LOSS_RECOVERY)
if (uiCfg.print_state == REPRINTED) {
#if HAS_HOTEND
Expand All @@ -117,6 +118,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 @@ -139,75 +141,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
6 changes: 2 additions & 4 deletions Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,10 @@ void tft_lvgl_init() {

systick_attach_callback(SysTick_Callback);

#if HAS_SPI_FLASH_FONT
init_gb2312_font();
#endif
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
14 changes: 10 additions & 4 deletions Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
#define Z_MAX_PIN PC4 // +Z

#ifndef FIL_RUNOUT_PIN
#define FIL_RUNOUT_PIN MT_DET_1_PIN
#define FIL_RUNOUT_PIN FIL_RUNOUT_PIN
#endif

//
Expand Down Expand Up @@ -223,9 +223,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 @@ -190,8 +190,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 @@ -204,7 +205,10 @@
#else
//#define POWER_LOSS_PIN PA2 // PW_DET
//#define PS_ON_PIN PB2 // PW_OFF
#define FIL_RUNOUT_PIN PA4
#endif

#ifndef FIL_RUNOUT_PIN
#define FIL_RUNOUT_PIN PA4 // MT_DET
#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
Loading

0 comments on commit ebc76e2

Please sign in to comment.