|
@@ -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);
|