mmu.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. //mmu.cpp
  2. #include "mmu.h"
  3. #include "planner.h"
  4. #include "language.h"
  5. #include "lcd.h"
  6. #include "uart2.h"
  7. #include "temperature.h"
  8. #include "Configuration_prusa.h"
  9. extern const char* lcd_display_message_fullscreen_P(const char *msg);
  10. extern void lcd_show_fullscreen_message_and_wait_P(const char *msg);
  11. extern int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, bool default_yes = false);
  12. extern void lcd_return_to_status();
  13. extern void lcd_wait_for_heater();
  14. extern char choose_extruder_menu();
  15. #define MMU_TODELAY 100
  16. #define MMU_TIMEOUT 10
  17. #define MMU_HWRESET
  18. #define MMU_RST_PIN 76
  19. bool mmu_enabled = false;
  20. bool mmu_ready = false;
  21. int8_t mmu_state = 0;
  22. uint8_t mmu_cmd = 0;
  23. uint8_t mmu_extruder = 0;
  24. uint8_t tmp_extruder = 0;
  25. int8_t mmu_finda = -1;
  26. int16_t mmu_version = -1;
  27. int16_t mmu_buildnr = -1;
  28. uint32_t mmu_last_request = 0;
  29. uint32_t mmu_last_response = 0;
  30. //clear rx buffer
  31. void mmu_clr_rx_buf(void)
  32. {
  33. while (fgetc(uart2io) >= 0);
  34. }
  35. //send command - puts
  36. int mmu_puts_P(const char* str)
  37. {
  38. mmu_clr_rx_buf(); //clear rx buffer
  39. int r = fputs_P(str, uart2io); //send command
  40. mmu_last_request = millis();
  41. return r;
  42. }
  43. //send command - printf
  44. int mmu_printf_P(const char* format, ...)
  45. {
  46. va_list args;
  47. va_start(args, format);
  48. mmu_clr_rx_buf(); //clear rx buffer
  49. int r = vfprintf_P(uart2io, format, args); //send command
  50. va_end(args);
  51. mmu_last_request = millis();
  52. return r;
  53. }
  54. //check 'ok' response
  55. int8_t mmu_rx_ok(void)
  56. {
  57. int8_t res = uart2_rx_str_P(PSTR("ok\n"));
  58. if (res == 1) mmu_last_response = millis();
  59. return res;
  60. }
  61. //check 'start' response
  62. int8_t mmu_rx_start(void)
  63. {
  64. int8_t res = uart2_rx_str_P(PSTR("start\n"));
  65. if (res == 1) mmu_last_response = millis();
  66. return res;
  67. }
  68. //initialize mmu2 unit - first part - should be done at begining of startup process
  69. void mmu_init(void)
  70. {
  71. digitalWrite(MMU_RST_PIN, HIGH);
  72. pinMode(MMU_RST_PIN, OUTPUT); //setup reset pin
  73. uart2_init(); //init uart2
  74. _delay_ms(10); //wait 10ms for sure
  75. mmu_reset(); //reset mmu (HW or SW), do not wait for response
  76. mmu_state = -1;
  77. }
  78. //mmu main loop - state machine processing
  79. void mmu_loop(void)
  80. {
  81. // printf_P(PSTR("MMU loop, state=%d\n"), mmu_state);
  82. switch (mmu_state)
  83. {
  84. case 0:
  85. return;
  86. case -1:
  87. if (mmu_rx_start() > 0)
  88. {
  89. puts_P(PSTR("MMU => 'start'"));
  90. puts_P(PSTR("MMU <= 'S1'"));
  91. mmu_puts_P(PSTR("S1\n")); //send 'read version' request
  92. mmu_state = -2;
  93. }
  94. else if (millis() > 30000) //30sec after reset disable mmu
  95. {
  96. puts_P(PSTR("MMU not responding - DISABLED"));
  97. mmu_state = 0;
  98. }
  99. return;
  100. case -2:
  101. if (mmu_rx_ok() > 0)
  102. {
  103. fscanf_P(uart2io, PSTR("%u"), &mmu_version); //scan version from buffer
  104. printf_P(PSTR("MMU => '%dok'\n"), mmu_version);
  105. puts_P(PSTR("MMU <= 'S2'"));
  106. mmu_puts_P(PSTR("S2\n")); //send 'read buildnr' request
  107. mmu_state = -3;
  108. }
  109. return;
  110. case -3:
  111. if (mmu_rx_ok() > 0)
  112. {
  113. fscanf_P(uart2io, PSTR("%u"), &mmu_buildnr); //scan buildnr from buffer
  114. printf_P(PSTR("MMU => '%dok'\n"), mmu_buildnr);
  115. puts_P(PSTR("MMU <= 'P0'"));
  116. mmu_puts_P(PSTR("P0\n")); //send 'read finda' request
  117. mmu_state = -4;
  118. }
  119. return;
  120. case -4:
  121. if (mmu_rx_ok() > 0)
  122. {
  123. fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
  124. printf_P(PSTR("MMU => '%dok'\n"), mmu_finda);
  125. puts_P(PSTR("MMU - ENABLED"));
  126. mmu_enabled = true;
  127. mmu_state = 1;
  128. }
  129. return;
  130. case 1:
  131. if (mmu_cmd) //command request ?
  132. {
  133. if ((mmu_cmd >= MMU_CMD_T0) && (mmu_cmd <= MMU_CMD_T4))
  134. {
  135. int extruder = mmu_cmd - MMU_CMD_T0;
  136. printf_P(PSTR("MMU <= 'T%d'\n"), extruder);
  137. mmu_printf_P(PSTR("T%d\n"), extruder);
  138. mmu_state = 3; // wait for response
  139. }
  140. mmu_cmd = 0;
  141. }
  142. else if ((mmu_last_response + 1000) < millis()) //request every 1s
  143. {
  144. puts_P(PSTR("MMU <= 'P0'"));
  145. mmu_puts_P(PSTR("P0\n")); //send 'read finda' request
  146. mmu_state = 2;
  147. }
  148. return;
  149. case 2: //response to command P0
  150. if (mmu_rx_ok() > 0)
  151. {
  152. fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
  153. printf_P(PSTR("MMU => '%dok'\n"), mmu_finda);
  154. mmu_state = 1;
  155. mmu_ready = true;
  156. }
  157. else if ((mmu_last_request + 30000) < millis())
  158. { //resend request after timeout (30s)
  159. mmu_state = 1;
  160. }
  161. return;
  162. case 3: //response to commands T0-T4
  163. if (mmu_rx_ok() > 0)
  164. {
  165. printf_P(PSTR("MMU => 'ok'\n"), mmu_finda);
  166. mmu_ready = true;
  167. mmu_state = 1;
  168. }
  169. else if ((mmu_last_request + 30000) < millis())
  170. { //resend request after timeout (30s)
  171. mmu_state = 1;
  172. }
  173. return;
  174. }
  175. }
  176. void mmu_reset(void)
  177. {
  178. #ifdef MMU_HWRESET //HW - pulse reset pin
  179. digitalWrite(MMU_RST_PIN, LOW);
  180. _delay_us(100);
  181. digitalWrite(MMU_RST_PIN, HIGH);
  182. #else //SW - send X0 command
  183. mmu_puts_P(PSTR("X0\n"));
  184. #endif
  185. }
  186. int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament)
  187. {
  188. printf_P(PSTR("MMU <= 'F%d %d'\n"), extruder, filament);
  189. mmu_printf_P(PSTR("F%d %d\n"), extruder, filament);
  190. unsigned char timeout = MMU_TIMEOUT; //10x100ms
  191. while ((mmu_rx_ok() <= 0) && (--timeout))
  192. delay_keep_alive(MMU_TODELAY);
  193. return timeout?1:0;
  194. }
  195. void mmu_command(uint8_t cmd)
  196. {
  197. mmu_cmd = cmd;
  198. mmu_ready = false;
  199. }
  200. bool mmu_get_response(void)
  201. {
  202. KEEPALIVE_STATE(IN_PROCESS);
  203. while (!mmu_ready)
  204. {
  205. mmu_loop();
  206. if (mmu_state != 3)
  207. break;
  208. }
  209. bool ret = mmu_ready;
  210. mmu_ready = false;
  211. return ret;
  212. /* printf_P(PSTR("mmu_get_response - begin\n"));
  213. //waits for "ok" from mmu
  214. //function returns true if "ok" was received
  215. //if timeout is set to true function return false if there is no "ok" received before timeout
  216. bool response = true;
  217. LongTimer mmu_get_reponse_timeout;
  218. KEEPALIVE_STATE(IN_PROCESS);
  219. mmu_get_reponse_timeout.start();
  220. while (mmu_rx_ok() <= 0)
  221. {
  222. delay_keep_alive(100);
  223. if (timeout && mmu_get_reponse_timeout.expired(5 * 60 * 1000ul))
  224. { //5 minutes timeout
  225. response = false;
  226. break;
  227. }
  228. }
  229. printf_P(PSTR("mmu_get_response - end %d\n"), response?1:0);
  230. return response;*/
  231. }
  232. void manage_response(bool move_axes, bool turn_off_nozzle)
  233. {
  234. bool response = false;
  235. mmu_print_saved = false;
  236. bool lcd_update_was_enabled = false;
  237. float hotend_temp_bckp = degTargetHotend(active_extruder);
  238. float z_position_bckp = current_position[Z_AXIS];
  239. float x_position_bckp = current_position[X_AXIS];
  240. float y_position_bckp = current_position[Y_AXIS];
  241. while(!response)
  242. {
  243. response = mmu_get_response(); //wait for "ok" from mmu
  244. if (!response) { //no "ok" was received in reserved time frame, user will fix the issue on mmu unit
  245. if (!mmu_print_saved) { //first occurence, we are saving current position, park print head in certain position and disable nozzle heater
  246. if (lcd_update_enabled) {
  247. lcd_update_was_enabled = true;
  248. lcd_update_enable(false);
  249. }
  250. st_synchronize();
  251. mmu_print_saved = true;
  252. hotend_temp_bckp = degTargetHotend(active_extruder);
  253. if (move_axes) {
  254. z_position_bckp = current_position[Z_AXIS];
  255. x_position_bckp = current_position[X_AXIS];
  256. y_position_bckp = current_position[Y_AXIS];
  257. //lift z
  258. current_position[Z_AXIS] += Z_PAUSE_LIFT;
  259. if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS;
  260. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder);
  261. st_synchronize();
  262. //Move XY to side
  263. current_position[X_AXIS] = X_PAUSE_POS;
  264. current_position[Y_AXIS] = Y_PAUSE_POS;
  265. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder);
  266. st_synchronize();
  267. }
  268. if (turn_off_nozzle) {
  269. //set nozzle target temperature to 0
  270. setAllTargetHotends(0);
  271. printf_P(PSTR("MMU not responding\n"));
  272. lcd_show_fullscreen_message_and_wait_P(_i("MMU needs user attention. Please press knob to resume nozzle target temperature."));
  273. setTargetHotend(hotend_temp_bckp, active_extruder);
  274. while ((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5) {
  275. delay_keep_alive(1000);
  276. lcd_wait_for_heater();
  277. }
  278. }
  279. }
  280. lcd_display_message_fullscreen_P(_i("Check MMU. Fix the issue and then press button on MMU unit."));
  281. }
  282. else if (mmu_print_saved) {
  283. printf_P(PSTR("MMU start responding\n"));
  284. lcd_clear();
  285. lcd_display_message_fullscreen_P(_i("MMU OK. Resuming..."));
  286. if (move_axes) {
  287. current_position[X_AXIS] = x_position_bckp;
  288. current_position[Y_AXIS] = y_position_bckp;
  289. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder);
  290. st_synchronize();
  291. current_position[Z_AXIS] = z_position_bckp;
  292. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder);
  293. st_synchronize();
  294. }
  295. else {
  296. delay_keep_alive(1000); //delay just for showing MMU OK message for a while in case that there are no xyz movements
  297. }
  298. }
  299. }
  300. if (lcd_update_was_enabled) lcd_update_enable(true);
  301. }
  302. void mmu_load_to_nozzle()
  303. {
  304. st_synchronize();
  305. bool saved_e_relative_mode = axis_relative_modes[E_AXIS];
  306. if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true;
  307. current_position[E_AXIS] += 7.2f;
  308. float feedrate = 562;
  309. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder);
  310. st_synchronize();
  311. current_position[E_AXIS] += 14.4f;
  312. feedrate = 871;
  313. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder);
  314. st_synchronize();
  315. current_position[E_AXIS] += 36.0f;
  316. feedrate = 1393;
  317. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder);
  318. st_synchronize();
  319. current_position[E_AXIS] += 14.4f;
  320. feedrate = 871;
  321. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder);
  322. st_synchronize();
  323. if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = false;
  324. }
  325. void mmu_M600_load_filament(bool automatic)
  326. {
  327. //load filament for mmu v2
  328. bool response = false;
  329. bool yes = false;
  330. if (!automatic) {
  331. yes = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Do you want to switch extruder?"), false);
  332. if(yes) tmp_extruder = choose_extruder_menu();
  333. else tmp_extruder = mmu_extruder;
  334. }
  335. else {
  336. tmp_extruder = (tmp_extruder+1)%5;
  337. }
  338. lcd_update_enable(false);
  339. lcd_clear();
  340. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  341. lcd_print(" ");
  342. lcd_print(tmp_extruder + 1);
  343. snmm_filaments_used |= (1 << tmp_extruder); //for stop print
  344. // printf_P(PSTR("T code: %d \n"), tmp_extruder);
  345. // mmu_printf_P(PSTR("T%d\n"), tmp_extruder);
  346. mmu_command(MMU_CMD_T0 + tmp_extruder);
  347. manage_response(false, true);
  348. mmu_extruder = tmp_extruder; //filament change is finished
  349. mmu_load_to_nozzle();
  350. st_synchronize();
  351. current_position[E_AXIS]+= FILAMENTCHANGE_FINALFEED ;
  352. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2, active_extruder);
  353. }
  354. void extr_mov(float shift, float feed_rate)
  355. { //move extruder no matter what the current heater temperature is
  356. set_extrude_min_temp(.0);
  357. current_position[E_AXIS] += shift;
  358. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  359. set_extrude_min_temp(EXTRUDE_MINTEMP);
  360. }
  361. void change_extr(int extr) { //switches multiplexer for extruders
  362. #ifdef SNMM
  363. st_synchronize();
  364. delay(100);
  365. disable_e0();
  366. disable_e1();
  367. disable_e2();
  368. mmu_extruder = extr;
  369. pinMode(E_MUX0_PIN, OUTPUT);
  370. pinMode(E_MUX1_PIN, OUTPUT);
  371. switch (extr) {
  372. case 1:
  373. WRITE(E_MUX0_PIN, HIGH);
  374. WRITE(E_MUX1_PIN, LOW);
  375. break;
  376. case 2:
  377. WRITE(E_MUX0_PIN, LOW);
  378. WRITE(E_MUX1_PIN, HIGH);
  379. break;
  380. case 3:
  381. WRITE(E_MUX0_PIN, HIGH);
  382. WRITE(E_MUX1_PIN, HIGH);
  383. break;
  384. default:
  385. WRITE(E_MUX0_PIN, LOW);
  386. WRITE(E_MUX1_PIN, LOW);
  387. break;
  388. }
  389. delay(100);
  390. #endif
  391. }
  392. int get_ext_nr()
  393. { //reads multiplexer input pins and return current extruder number (counted from 0)
  394. #ifndef SNMM
  395. return(mmu_extruder); //update needed
  396. #else
  397. return(2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  398. #endif
  399. }
  400. void display_loading()
  401. {
  402. switch (mmu_extruder)
  403. {
  404. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  405. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  406. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  407. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  408. }
  409. }
  410. void extr_adj(int extruder) //loading filament for SNMM
  411. {
  412. #ifndef SNMM
  413. printf_P(PSTR("L%d \n"),extruder);
  414. fprintf_P(uart2io, PSTR("L%d\n"), extruder);
  415. //show which filament is currently loaded
  416. lcd_update_enable(false);
  417. lcd_clear();
  418. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  419. //if(strlen(_T(MSG_LOADING_FILAMENT))>18) lcd.setCursor(0, 1);
  420. //else lcd.print(" ");
  421. lcd_print(" ");
  422. lcd_print(mmu_extruder + 1);
  423. // get response
  424. manage_response(false, false);
  425. lcd_update_enable(true);
  426. //lcd_return_to_status();
  427. #else
  428. bool correct;
  429. max_feedrate[E_AXIS] =80;
  430. //max_feedrate[E_AXIS] = 50;
  431. START:
  432. lcd_clear();
  433. lcd_set_cursor(0, 0);
  434. switch (extruder) {
  435. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  436. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  437. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  438. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  439. }
  440. KEEPALIVE_STATE(PAUSED_FOR_USER);
  441. do{
  442. extr_mov(0.001,1000);
  443. delay_keep_alive(2);
  444. } while (!lcd_clicked());
  445. //delay_keep_alive(500);
  446. KEEPALIVE_STATE(IN_HANDLER);
  447. st_synchronize();
  448. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  449. //if (!correct) goto START;
  450. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  451. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  452. extr_mov(bowden_length[extruder], 500);
  453. lcd_clear();
  454. lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  455. if(strlen(_T(MSG_LOADING_FILAMENT))>18) lcd_set_cursor(0, 1);
  456. else lcd_print(" ");
  457. lcd_print(mmu_extruder + 1);
  458. lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  459. st_synchronize();
  460. max_feedrate[E_AXIS] = 50;
  461. lcd_update_enable(true);
  462. lcd_return_to_status();
  463. lcdDrawUpdate = 2;
  464. #endif
  465. }
  466. void extr_unload()
  467. { //unload just current filament for multimaterial printers
  468. #ifdef SNMM
  469. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  470. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  471. uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
  472. #endif
  473. if (degHotend0() > EXTRUDE_MINTEMP)
  474. {
  475. #ifndef SNMM
  476. st_synchronize();
  477. //show which filament is currently unloaded
  478. lcd_update_enable(false);
  479. lcd_clear();
  480. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_UNLOADING_FILAMENT));
  481. lcd_print(" ");
  482. lcd_print(mmu_extruder + 1);
  483. current_position[E_AXIS] -= 80;
  484. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  485. st_synchronize();
  486. printf_P(PSTR("U0\n"));
  487. fprintf_P(uart2io, PSTR("U0\n"));
  488. // get response
  489. manage_response(false, true);
  490. lcd_update_enable(true);
  491. #else //SNMM
  492. lcd_clear();
  493. lcd_display_message_fullscreen_P(PSTR(""));
  494. max_feedrate[E_AXIS] = 50;
  495. lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_UNLOADING_FILAMENT));
  496. lcd_print(" ");
  497. lcd_print(mmu_extruder + 1);
  498. lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  499. if (current_position[Z_AXIS] < 15) {
  500. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  501. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  502. }
  503. current_position[E_AXIS] += 10; //extrusion
  504. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  505. st_current_set(2, E_MOTOR_HIGH_CURRENT);
  506. if (current_temperature[0] < 230) { //PLA & all other filaments
  507. current_position[E_AXIS] += 5.4;
  508. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  509. current_position[E_AXIS] += 3.2;
  510. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  511. current_position[E_AXIS] += 3;
  512. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  513. }
  514. else { //ABS
  515. current_position[E_AXIS] += 3.1;
  516. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  517. current_position[E_AXIS] += 3.1;
  518. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  519. current_position[E_AXIS] += 4;
  520. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  521. /*current_position[X_AXIS] += 23; //delay
  522. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  523. current_position[X_AXIS] -= 23; //delay
  524. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  525. delay_keep_alive(4700);
  526. }
  527. max_feedrate[E_AXIS] = 80;
  528. current_position[E_AXIS] -= (bowden_length[mmu_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  529. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  530. current_position[E_AXIS] -= (bowden_length[mmu_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  531. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  532. st_synchronize();
  533. //st_current_init();
  534. if (SilentMode != SILENT_MODE_OFF) st_current_set(2, tmp_motor[2]); //set back to normal operation currents
  535. else st_current_set(2, tmp_motor_loud[2]);
  536. lcd_update_enable(true);
  537. lcd_return_to_status();
  538. max_feedrate[E_AXIS] = 50;
  539. #endif //SNMM
  540. }
  541. else
  542. {
  543. lcd_clear();
  544. lcd_set_cursor(0, 0);
  545. lcd_puts_P(_T(MSG_ERROR));
  546. lcd_set_cursor(0, 2);
  547. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  548. delay(2000);
  549. lcd_clear();
  550. }
  551. //lcd_return_to_status();
  552. }
  553. //wrapper functions for loading filament
  554. void extr_adj_0()
  555. {
  556. #ifndef SNMM
  557. enquecommand_P(PSTR("M701 E0"));
  558. #else
  559. change_extr(0);
  560. extr_adj(0);
  561. #endif
  562. }
  563. void extr_adj_1()
  564. {
  565. #ifndef SNMM
  566. enquecommand_P(PSTR("M701 E1"));
  567. #else
  568. change_extr(1);
  569. extr_adj(1);
  570. #endif
  571. }
  572. void extr_adj_2()
  573. {
  574. #ifndef SNMM
  575. enquecommand_P(PSTR("M701 E2"));
  576. #else
  577. change_extr(2);
  578. extr_adj(2);
  579. #endif
  580. }
  581. void extr_adj_3()
  582. {
  583. #ifndef SNMM
  584. enquecommand_P(PSTR("M701 E3"));
  585. #else
  586. change_extr(3);
  587. extr_adj(3);
  588. #endif
  589. }
  590. void extr_adj_4()
  591. {
  592. #ifndef SNMM
  593. enquecommand_P(PSTR("M701 E4"));
  594. #else
  595. change_extr(4);
  596. extr_adj(4);
  597. #endif
  598. }
  599. void load_all()
  600. {
  601. #ifndef SNMM
  602. enquecommand_P(PSTR("M701 E0"));
  603. enquecommand_P(PSTR("M701 E1"));
  604. enquecommand_P(PSTR("M701 E2"));
  605. enquecommand_P(PSTR("M701 E3"));
  606. enquecommand_P(PSTR("M701 E4"));
  607. #else
  608. for (int i = 0; i < 4; i++)
  609. {
  610. change_extr(i);
  611. extr_adj(i);
  612. }
  613. #endif
  614. }
  615. //wrapper functions for changing extruders
  616. void extr_change_0()
  617. {
  618. change_extr(0);
  619. lcd_return_to_status();
  620. }
  621. void extr_change_1()
  622. {
  623. change_extr(1);
  624. lcd_return_to_status();
  625. }
  626. void extr_change_2()
  627. {
  628. change_extr(2);
  629. lcd_return_to_status();
  630. }
  631. void extr_change_3()
  632. {
  633. change_extr(3);
  634. lcd_return_to_status();
  635. }
  636. //wrapper functions for unloading filament
  637. void extr_unload_all()
  638. {
  639. if (degHotend0() > EXTRUDE_MINTEMP)
  640. {
  641. for (int i = 0; i < 4; i++)
  642. {
  643. change_extr(i);
  644. extr_unload();
  645. }
  646. }
  647. else
  648. {
  649. lcd_clear();
  650. lcd_set_cursor(0, 0);
  651. lcd_puts_P(_T(MSG_ERROR));
  652. lcd_set_cursor(0, 2);
  653. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  654. delay(2000);
  655. lcd_clear();
  656. lcd_return_to_status();
  657. }
  658. }
  659. //unloading just used filament (for snmm)
  660. void extr_unload_used()
  661. {
  662. if (degHotend0() > EXTRUDE_MINTEMP) {
  663. for (int i = 0; i < 4; i++) {
  664. if (snmm_filaments_used & (1 << i)) {
  665. change_extr(i);
  666. extr_unload();
  667. }
  668. }
  669. snmm_filaments_used = 0;
  670. }
  671. else {
  672. lcd_clear();
  673. lcd_set_cursor(0, 0);
  674. lcd_puts_P(_T(MSG_ERROR));
  675. lcd_set_cursor(0, 2);
  676. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  677. delay(2000);
  678. lcd_clear();
  679. lcd_return_to_status();
  680. }
  681. }
  682. void extr_unload_0()
  683. {
  684. change_extr(0);
  685. extr_unload();
  686. }
  687. void extr_unload_1()
  688. {
  689. change_extr(1);
  690. extr_unload();
  691. }
  692. void extr_unload_2()
  693. {
  694. change_extr(2);
  695. extr_unload();
  696. }
  697. void extr_unload_3()
  698. {
  699. change_extr(3);
  700. extr_unload();
  701. }
  702. void extr_unload_4()
  703. {
  704. change_extr(4);
  705. extr_unload();
  706. }