mmu.cpp 20 KB

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