diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 2ab9c093..fff37bf3 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -467,12 +467,8 @@ void gcode_M701(); void proc_commands(); -void manage_response(bool move_axes, bool turn_off_nozzle); -bool mmu_get_response(bool timeout); -void mmu_not_responding(); -void mmu_load_to_nozzle(); + void M600_load_filament(); -void mmu_M600_load_filament(bool automatic); void M600_load_filament_movements(); void M600_wait_for_user(); void M600_check_state(); \ No newline at end of file diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index fe5553a2..b20b8254 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -508,7 +508,6 @@ unsigned long starttime=0; unsigned long stoptime=0; unsigned long _usb_timer = 0; -static uint8_t tmp_extruder; bool extruder_under_pressure = true; @@ -6336,21 +6335,14 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) //currently three different materials are needed (default, flex and PVA) //add storing this information for different load/unload profiles etc. in the future //firmware does not wait for "ok" from mmu - - uint8_t extruder; - uint8_t filament; - - if(code_seen('E')) extruder = code_value(); - if(code_seen('F')) filament = code_value(); - - printf_P(PSTR("Extruder: %d; "), extruder); - switch (filament) { - case FILAMENT_FLEX: printf_P(PSTR("Flex\n")); break; - case FILAMENT_PVA: printf_P(PSTR("PVA\n")); break; - default: printf_P(PSTR("Default\n")); break; + if (mmu_enabled) + { + uint8_t extruder; + uint8_t filament; + if(code_seen('E')) extruder = code_value(); + if(code_seen('F')) filament = code_value(); + mmu_set_filament_type(extruder, filament); } - printf_P(PSTR("F%d%d\n"), extruder, filament); - mmu_printf_P(PSTR("F%d%d\n"), extruder, filament); } break; @@ -8872,7 +8864,8 @@ uint16_t print_time_remaining() { return print_t; } -uint8_t print_percent_done() { +uint8_t print_percent_done() +{ //in case that we have information from M73 gcode return percentage counted by slicer, else return percentage counted as byte_printed/filesize uint8_t percent_done = 0; if (SilentModeMenu == SILENT_MODE_OFF && print_percent_done_normal <= 100) { @@ -8887,135 +8880,17 @@ uint8_t print_percent_done() { return percent_done; } -static void print_time_remaining_init() { +static void print_time_remaining_init() +{ print_time_remaining_normal = PRINT_TIME_REMAINING_INIT; print_time_remaining_silent = PRINT_TIME_REMAINING_INIT; print_percent_done_normal = PRINT_PERCENT_DONE_INIT; print_percent_done_silent = PRINT_PERCENT_DONE_INIT; } -bool mmu_get_response(bool timeout) { - //waits for "ok" from mmu - //function returns true if "ok" was received - //if timeout is set to true function return false if there is no "ok" received before timeout - bool response = true; - LongTimer mmu_get_reponse_timeout; - KEEPALIVE_STATE(IN_PROCESS); - mmu_get_reponse_timeout.start(); - while (mmu_rx_ok() <= 0) - { - delay_keep_alive(100); - if (timeout && mmu_get_reponse_timeout.expired(5 * 60 * 1000ul)) { //5 minutes timeout - response = false; - break; - } - } - return response; -} - -void manage_response(bool move_axes, bool turn_off_nozzle) { - - bool response = false; - mmu_print_saved = false; - bool lcd_update_was_enabled = false; - float hotend_temp_bckp = degTargetHotend(active_extruder); - float z_position_bckp = current_position[Z_AXIS]; - float x_position_bckp = current_position[X_AXIS]; - float y_position_bckp = current_position[Y_AXIS]; - while(!response) { - response = mmu_get_response(true); //wait for "ok" from mmu - if (!response) { //no "ok" was received in reserved time frame, user will fix the issue on mmu unit - if (!mmu_print_saved) { //first occurence, we are saving current position, park print head in certain position and disable nozzle heater - if (lcd_update_enabled) { - lcd_update_was_enabled = true; - lcd_update_enable(false); - } - st_synchronize(); - mmu_print_saved = true; - - hotend_temp_bckp = degTargetHotend(active_extruder); - if (move_axes) { - z_position_bckp = current_position[Z_AXIS]; - x_position_bckp = current_position[X_AXIS]; - y_position_bckp = current_position[Y_AXIS]; - - //lift z - current_position[Z_AXIS] += Z_PAUSE_LIFT; - if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); - st_synchronize(); - - //Move XY to side - current_position[X_AXIS] = X_PAUSE_POS; - current_position[Y_AXIS] = Y_PAUSE_POS; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); - st_synchronize(); - } - if (turn_off_nozzle) { - //set nozzle target temperature to 0 - setAllTargetHotends(0); - printf_P(PSTR("MMU not responding\n")); - lcd_show_fullscreen_message_and_wait_P(_i("MMU needs user attention. Please press knob to resume nozzle target temperature.")); - setTargetHotend(hotend_temp_bckp, active_extruder); - while ((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5) { - delay_keep_alive(1000); - lcd_wait_for_heater(); - } - } - } - lcd_display_message_fullscreen_P(_i("Check MMU. Fix the issue and then press button on MMU unit.")); - } - else if (mmu_print_saved) { - printf_P(PSTR("MMU start responding\n")); - lcd_clear(); - lcd_display_message_fullscreen_P(_i("MMU OK. Resuming...")); - if (move_axes) { - current_position[X_AXIS] = x_position_bckp; - current_position[Y_AXIS] = y_position_bckp; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); - st_synchronize(); - current_position[Z_AXIS] = z_position_bckp; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); - st_synchronize(); - } - else { - delay_keep_alive(1000); //delay just for showing MMU OK message for a while in case that there are no xyz movements - } - } - } - if (lcd_update_was_enabled) lcd_update_enable(true); -} - -void mmu_load_to_nozzle() { - st_synchronize(); - - bool saved_e_relative_mode = axis_relative_modes[E_AXIS]; - if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true; - current_position[E_AXIS] += 7.2f; - float feedrate = 562; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - current_position[E_AXIS] += 14.4f; - feedrate = 871; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - current_position[E_AXIS] += 36.0f; - feedrate = 1393; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - current_position[E_AXIS] += 14.4f; - feedrate = 871; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = false; -} - -void mmu_switch_extruder(uint8_t extruder) { - -} - -void M600_check_state() { +void M600_check_state() +{ //Wait for user to check the state lcd_change_fil_state = 0; @@ -9129,40 +9004,6 @@ void M600_wait_for_user() { WRITE(BEEPER, LOW); } -void mmu_M600_load_filament(bool automatic) -{ - //load filament for mmu v2 - - bool response = false; - bool yes = false; - if (!automatic) { - 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(); - else tmp_extruder = mmu_extruder; - - } - else { - tmp_extruder = (tmp_extruder+1)%5; - } - lcd_update_enable(false); - lcd_clear(); - lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT)); - lcd_print(" "); - lcd_print(tmp_extruder + 1); - snmm_filaments_used |= (1 << tmp_extruder); //for stop print - printf_P(PSTR("T code: %d \n"), tmp_extruder); - mmu_printf_P(PSTR("T%d\n"), tmp_extruder); - - manage_response(false, true); - mmu_extruder = tmp_extruder; //filament change is finished - - mmu_load_to_nozzle(); - - st_synchronize(); - current_position[E_AXIS]+= FILAMENTCHANGE_FINALFEED ; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2, active_extruder); -} - void M600_load_filament_movements() { #ifdef SNMM diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 70cc4ef3..de760d0c 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -10,14 +10,26 @@ extern const char* lcd_display_message_fullscreen_P(const char *msg); +extern void lcd_show_fullscreen_message_and_wait_P(const char *msg); +extern int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, bool default_yes = false); extern void lcd_return_to_status(); +extern void lcd_wait_for_heater(); +extern char choose_extruder_menu(); + + +#define MMU_TODELAY 100 +#define MMU_TIMEOUT 10 + +#define MMU_HWRESET +#define MMU_RST_PIN 76 -#define MMU_TIMEOUT 100 bool mmu_enabled = false; uint8_t mmu_extruder = 0; +uint8_t tmp_extruder = 0; + int8_t mmu_finda = -1; int16_t mmu_version = -1; @@ -62,6 +74,8 @@ int8_t mmu_rx_start(void) //initialize mmu_unit bool mmu_init(void) { + digitalWrite(MMU_RST_PIN, HIGH); + pinMode(MMU_RST_PIN, OUTPUT); //setup reset pin uart2_init(); //init uart2 _delay_ms(10); //wait 10ms for sure if (mmu_reset()) //reset mmu @@ -75,10 +89,16 @@ bool mmu_init(void) bool mmu_reset(void) { +#ifdef MMU_HWRESET + digitalWrite(MMU_RST_PIN, LOW); + _delay_us(100); + digitalWrite(MMU_RST_PIN, HIGH); +#else mmu_puts_P(PSTR("X0\n")); //send command - unsigned char timeout = 10; //timeout = 10x100ms +#endif + unsigned char timeout = MMU_TIMEOUT; //timeout = 10x100ms while ((mmu_rx_start() <= 0) && (--timeout)) - delay_keep_alive(MMU_TIMEOUT); + delay_keep_alive(MMU_TODELAY); mmu_enabled = timeout?true:false; return mmu_enabled; } @@ -86,9 +106,9 @@ bool mmu_reset(void) int8_t mmu_read_finda(void) { mmu_puts_P(PSTR("P0\n")); - unsigned char timeout = 10; //10x100ms + unsigned char timeout = MMU_TIMEOUT; //10x100ms while ((mmu_rx_ok() <= 0) && (--timeout)) - delay_keep_alive(MMU_TIMEOUT); + delay_keep_alive(MMU_TODELAY); mmu_finda = -1; if (timeout) fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); @@ -98,14 +118,182 @@ int8_t mmu_read_finda(void) int16_t mmu_read_version(void) { mmu_puts_P(PSTR("S1\n")); - unsigned char timeout = 10; //10x100ms + unsigned char timeout = MMU_TIMEOUT; //10x100ms while ((mmu_rx_ok() <= 0) && (--timeout)) - delay_keep_alive(MMU_TIMEOUT); + delay_keep_alive(MMU_TODELAY); if (timeout) fscanf_P(uart2io, PSTR("%u"), &mmu_version); return mmu_version; } +int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament) +{ + printf_P(PSTR("MMU <= 'F%d %d'\n"), extruder, filament); + mmu_printf_P(PSTR("F%d %d\n"), extruder, filament); + unsigned char timeout = MMU_TIMEOUT; //10x100ms + while ((mmu_rx_ok() <= 0) && (--timeout)) + delay_keep_alive(MMU_TODELAY); + return timeout?1:0; +} + +bool mmu_get_response(bool timeout) +{ + printf_P(PSTR("mmu_get_response - begin\n")); + //waits for "ok" from mmu + //function returns true if "ok" was received + //if timeout is set to true function return false if there is no "ok" received before timeout + bool response = true; + LongTimer mmu_get_reponse_timeout; + KEEPALIVE_STATE(IN_PROCESS); + mmu_get_reponse_timeout.start(); + while (mmu_rx_ok() <= 0) + { + delay_keep_alive(100); + if (timeout && mmu_get_reponse_timeout.expired(5 * 60 * 1000ul)) + { //5 minutes timeout + response = false; + break; + } + } + printf_P(PSTR("mmu_get_response - end %d\n"), response?1:0); + return response; +} + + +void manage_response(bool move_axes, bool turn_off_nozzle) +{ + bool response = false; + mmu_print_saved = false; + bool lcd_update_was_enabled = false; + float hotend_temp_bckp = degTargetHotend(active_extruder); + float z_position_bckp = current_position[Z_AXIS]; + float x_position_bckp = current_position[X_AXIS]; + float y_position_bckp = current_position[Y_AXIS]; + while(!response) + { + response = mmu_get_response(true); //wait for "ok" from mmu + if (!response) { //no "ok" was received in reserved time frame, user will fix the issue on mmu unit + if (!mmu_print_saved) { //first occurence, we are saving current position, park print head in certain position and disable nozzle heater + if (lcd_update_enabled) { + lcd_update_was_enabled = true; + lcd_update_enable(false); + } + st_synchronize(); + mmu_print_saved = true; + + hotend_temp_bckp = degTargetHotend(active_extruder); + if (move_axes) { + z_position_bckp = current_position[Z_AXIS]; + x_position_bckp = current_position[X_AXIS]; + y_position_bckp = current_position[Y_AXIS]; + + //lift z + current_position[Z_AXIS] += Z_PAUSE_LIFT; + if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); + st_synchronize(); + + //Move XY to side + current_position[X_AXIS] = X_PAUSE_POS; + current_position[Y_AXIS] = Y_PAUSE_POS; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); + st_synchronize(); + } + if (turn_off_nozzle) { + //set nozzle target temperature to 0 + setAllTargetHotends(0); + printf_P(PSTR("MMU not responding\n")); + lcd_show_fullscreen_message_and_wait_P(_i("MMU needs user attention. Please press knob to resume nozzle target temperature.")); + setTargetHotend(hotend_temp_bckp, active_extruder); + while ((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5) { + delay_keep_alive(1000); + lcd_wait_for_heater(); + } + } + } + lcd_display_message_fullscreen_P(_i("Check MMU. Fix the issue and then press button on MMU unit.")); + } + else if (mmu_print_saved) { + printf_P(PSTR("MMU start responding\n")); + lcd_clear(); + lcd_display_message_fullscreen_P(_i("MMU OK. Resuming...")); + if (move_axes) { + current_position[X_AXIS] = x_position_bckp; + current_position[Y_AXIS] = y_position_bckp; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); + st_synchronize(); + current_position[Z_AXIS] = z_position_bckp; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); + st_synchronize(); + } + else { + delay_keep_alive(1000); //delay just for showing MMU OK message for a while in case that there are no xyz movements + } + } + } + if (lcd_update_was_enabled) lcd_update_enable(true); +} + +void mmu_load_to_nozzle() +{ + st_synchronize(); + + bool saved_e_relative_mode = axis_relative_modes[E_AXIS]; + if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true; + current_position[E_AXIS] += 7.2f; + float feedrate = 562; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + current_position[E_AXIS] += 14.4f; + feedrate = 871; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + current_position[E_AXIS] += 36.0f; + feedrate = 1393; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + current_position[E_AXIS] += 14.4f; + feedrate = 871; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = false; +} + +void mmu_M600_load_filament(bool automatic) +{ + //load filament for mmu v2 + + bool response = false; + bool yes = false; + if (!automatic) { + 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(); + else tmp_extruder = mmu_extruder; + + } + else { + tmp_extruder = (tmp_extruder+1)%5; + } + lcd_update_enable(false); + lcd_clear(); + lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT)); + lcd_print(" "); + lcd_print(tmp_extruder + 1); + snmm_filaments_used |= (1 << tmp_extruder); //for stop print + printf_P(PSTR("T code: %d \n"), tmp_extruder); + mmu_printf_P(PSTR("T%d\n"), tmp_extruder); + + manage_response(false, true); + mmu_extruder = tmp_extruder; //filament change is finished + + mmu_load_to_nozzle(); + + st_synchronize(); + current_position[E_AXIS]+= FILAMENTCHANGE_FINALFEED ; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2, active_extruder); +} + + void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is set_extrude_min_temp(.0); diff --git a/Firmware/mmu.h b/Firmware/mmu.h index 91a1f511..65bce969 100644 --- a/Firmware/mmu.h +++ b/Firmware/mmu.h @@ -7,6 +7,8 @@ extern bool mmu_enabled; extern uint8_t mmu_extruder; +extern uint8_t tmp_extruder; + extern int8_t mmu_finda; extern int16_t mmu_version; @@ -27,6 +29,17 @@ extern int8_t mmu_read_finda(void); extern int16_t mmu_read_version(void); +extern int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament); + + +extern bool mmu_get_response(bool timeout); + +extern void manage_response(bool move_axes, bool turn_off_nozzle); + +extern void mmu_load_to_nozzle(); + +extern void mmu_M600_load_filament(bool automatic); + extern void extr_mov(float shift, float feed_rate); extern void change_extr(int extr);