From 705f098b1c6b301e0b4975cd4f5d32cf4da48496 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Tue, 28 Aug 2018 23:50:31 +0200 Subject: [PATCH 1/2] eject filament: initial version --- Firmware/mmu.cpp | 29 ++++++++++++++++++++++++----- Firmware/mmu.h | 7 +++++++ Firmware/ultralcd.cpp | 2 +- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index de093df4..d8a1449f 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -103,6 +103,7 @@ void mmu_init(void) //mmu main loop - state machine processing void mmu_loop(void) { + int filament = 0; // printf_P(PSTR("MMU loop, state=%d\n"), mmu_state); switch (mmu_state) { @@ -160,14 +161,14 @@ void mmu_loop(void) { if ((mmu_cmd >= MMU_CMD_T0) && (mmu_cmd <= MMU_CMD_T4)) { - int extruder = mmu_cmd - MMU_CMD_T0; - printf_P(PSTR("MMU <= 'T%d'\n"), extruder); - mmu_printf_P(PSTR("T%d\n"), extruder); + filament = mmu_cmd - MMU_CMD_T0; + printf_P(PSTR("MMU <= 'T%d'\n"), filament); + mmu_printf_P(PSTR("T%d\n"), filament); mmu_state = 3; // wait for response } else if ((mmu_cmd >= MMU_CMD_L0) && (mmu_cmd <= MMU_CMD_L4)) { - int filament = mmu_cmd - MMU_CMD_L0; + filament = mmu_cmd - MMU_CMD_L0; printf_P(PSTR("MMU <= 'L%d'\n"), filament); mmu_printf_P(PSTR("L%d\n"), filament); mmu_state = 3; // wait for response @@ -184,6 +185,19 @@ void mmu_loop(void) mmu_puts_P(PSTR("U0\n")); //send 'unload current filament' mmu_state = 3; } + else if ((mmu_cmd >= MMU_CMD_E0) && (mmu_cmd <= MMU_CMD_E4)) + { + int filament = mmu_cmd - MMU_CMD_E0; + printf_P(PSTR("MMU <= 'E%d'\n"), filament); + mmu_printf_P(PSTR("E%d\n"), filament); //send eject filament + mmu_state = 3; // wait for response + } + else if (mmu_cmd == MMU_CMD_R0) + { + printf_P(PSTR("MMU <= 'R0'\n")); + mmu_puts_P(PSTR("R0\n")); //send recover after eject + mmu_state = 3; // wait for response + } mmu_cmd = 0; } else if ((mmu_last_response + 300) < millis()) //request every 300ms @@ -214,7 +228,7 @@ void mmu_loop(void) mmu_state = 1; } return; - case 3: //response to commands T0-T4 + case 3: //response to mmu commands if (mmu_rx_ok() > 0) { printf_P(PSTR("MMU => 'ok'\n")); @@ -900,3 +914,8 @@ void mmu_show_warning() printf_P(PSTR("MMU2 firmware version invalid. Required version: build number %d or higher."), MMU_REQUIRED_FW_BUILDNR); kill(_i("Please update firmware in your MMU2. Waiting for reset.")); } + +static void mmu_eject_filament(uint8_t filament) +{ + if (filament < 5) mmu_command(MMU_CMD_E0 + filament); +} \ No newline at end of file diff --git a/Firmware/mmu.h b/Firmware/mmu.h index e7ad6030..2a80f948 100644 --- a/Firmware/mmu.h +++ b/Firmware/mmu.h @@ -30,6 +30,13 @@ extern int16_t mmu_buildnr; #define MMU_CMD_L4 0x24 #define MMU_CMD_C0 0x30 #define MMU_CMD_U0 0x40 +#define MMU_CMD_E0 0x50 +#define MMU_CMD_E1 0x51 +#define MMU_CMD_E2 0x52 +#define MMU_CMD_E3 0x53 +#define MMU_CMD_E4 0x54 +#define MMU_CMD_R0 0x60 + extern int mmu_puts_P(const char* str); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 3ba483fc..d24bbbfe 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5559,7 +5559,7 @@ static void lcd_main_menu() }*/ - + if ( ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) { MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8 From 515e78cfd1743989153f247815c5e61e78ddd6c4 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Wed, 29 Aug 2018 01:58:28 +0200 Subject: [PATCH 2/2] Eject filament feature in menu, M600: if it was envoked by FINDA, eject filament --- Firmware/Marlin_main.cpp | 13 ++++++++++ Firmware/mmu.cpp | 51 ++++++++++++++++++++++++++++++++++++---- Firmware/mmu.h | 7 +++++- Firmware/ultralcd.cpp | 14 +++++++++++ 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 677f081b..31424d9e 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3120,7 +3120,20 @@ void gcode_M600(bool automatic, float x_position, float y_position, float z_shif } if (mmu_enabled) + { + if (saved_printing) mmu_eject_filament(mmu_extruder, false); //if M600 was invoked by filament senzor (FINDA) eject filament so user can easily remove it + if (!automatic) mmu_M600_wait_and_beep(); + if (saved_printing) { + + lcd_clear(); + lcd_set_cursor(0, 2); + lcd_puts_P(_T(MSG_PLEASE_WAIT)); + + mmu_command(MMU_CMD_R0); + manage_response(false, false); + } mmu_M600_load_filament(automatic); + } else M600_load_filament(); diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index b960a6a7..12319d97 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -22,7 +22,7 @@ #define MMU_HWRESET #define MMU_RST_PIN 76 -#define MMU_REQUIRED_FW_BUILDNR 81 +#define MMU_REQUIRED_FW_BUILDNR 83 bool mmu_enabled = false; @@ -470,7 +470,6 @@ void mmu_M600_load_filament(bool automatic) bool yes = false; tmp_extruder = mmu_extruder; if (!automatic) { - mmu_M600_wait_and_beep(); #ifdef MMU_M600_SWITCH_EXTRUDER yes = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Do you want to switch extruder?"), false); if(yes) tmp_extruder = choose_extruder_menu(); @@ -790,6 +789,36 @@ void extr_adj_4() #endif } +void mmu_eject_fil_0() +{ + mmu_eject_filament(0, true); +} + +void mmu_eject_fil_1() +{ + mmu_eject_filament(1, true); +} + +void mmu_eject_fil_2() +{ + mmu_eject_filament(2, true); +} + +void mmu_eject_fil_3() +{ + mmu_eject_filament(3, true); +} + +void mmu_eject_fil_4() +{ + mmu_eject_filament(4, true); +} + +void mmu_eject_fil_5() +{ + mmu_eject_filament(5, true); +} + void load_all() { #ifndef SNMM @@ -921,7 +950,21 @@ void mmu_show_warning() kill(_i("Please update firmware in your MMU2. Waiting for reset.")); } -static void mmu_eject_filament(uint8_t filament) +void mmu_eject_filament(uint8_t filament, bool recover) { - if (filament < 5) mmu_command(MMU_CMD_E0 + filament); + if (filament < 5) + { + mmu_command(MMU_CMD_E0 + filament); + manage_response(false, false); + if (recover) + { + lcd_show_fullscreen_message_and_wait_P(_i("Please remove filament and then press the knob.")); + mmu_command(MMU_CMD_R0); + manage_response(false, false); + } + } + else + { + puts_P(PSTR("Filament nr out of range!")); + } } \ No newline at end of file diff --git a/Firmware/mmu.h b/Firmware/mmu.h index 2a80f948..35c1e18c 100644 --- a/Firmware/mmu.h +++ b/Firmware/mmu.h @@ -91,4 +91,9 @@ extern void extr_unload_4(); extern bool mmu_check_version(); extern void mmu_show_warning(); - +extern void mmu_eject_filament(uint8_t filament, bool recover); +extern void mmu_eject_fil_0(); +extern void mmu_eject_fil_1(); +extern void mmu_eject_fil_2(); +extern void mmu_eject_fil_3(); +extern void mmu_eject_fil_4(); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 85ea86dd..69bf7212 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5203,6 +5203,19 @@ static void fil_load_menu() MENU_END(); } +static void mmu_fil_eject_menu() +{ + MENU_BEGIN(); + MENU_ITEM_BACK_P(_T(MSG_MAIN)); + MENU_ITEM_FUNCTION_P(_i("Eject filament 1"), mmu_eject_fil_0); + MENU_ITEM_FUNCTION_P(_i("Eject filament 2"), mmu_eject_fil_1); + MENU_ITEM_FUNCTION_P(_i("Eject filament 3"), mmu_eject_fil_2); + MENU_ITEM_FUNCTION_P(_i("Eject filament 4"), mmu_eject_fil_3); + MENU_ITEM_FUNCTION_P(_i("Eject filament 5"), mmu_eject_fil_4); + + MENU_END(); +} + static void fil_unload_menu() { MENU_BEGIN(); @@ -5651,6 +5664,7 @@ static void lcd_main_menu() if (mmu_enabled) { MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu); + MENU_ITEM_SUBMENU_P(_i("Eject filament"), mmu_fil_eject_menu); if (mmu_enabled) MENU_ITEM_GCODE_P(_T(MSG_UNLOAD_FILAMENT), PSTR("M702 C")); else