mmu.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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 yes = false;
  259. if (!automatic) {
  260. yes = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Do you want to switch extruder?"), false);
  261. if(yes) tmp_extruder = choose_extruder_menu();
  262. else tmp_extruder = mmu_extruder;
  263. }
  264. else {
  265. tmp_extruder = (tmp_extruder+1)%5;
  266. }
  267. lcd_update_enable(false);
  268. lcd_clear();
  269. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  270. lcd_print(" ");
  271. lcd_print(tmp_extruder + 1);
  272. snmm_filaments_used |= (1 << tmp_extruder); //for stop print
  273. printf_P(PSTR("T code: %d \n"), tmp_extruder);
  274. mmu_printf_P(PSTR("T%d\n"), tmp_extruder);
  275. manage_response(false, true);
  276. mmu_extruder = tmp_extruder; //filament change is finished
  277. mmu_load_to_nozzle();
  278. st_synchronize();
  279. current_position[E_AXIS]+= FILAMENTCHANGE_FINALFEED ;
  280. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2, active_extruder);
  281. }
  282. void extr_mov(float shift, float feed_rate)
  283. { //move extruder no matter what the current heater temperature is
  284. set_extrude_min_temp(.0);
  285. current_position[E_AXIS] += shift;
  286. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  287. set_extrude_min_temp(EXTRUDE_MINTEMP);
  288. }
  289. void change_extr(int
  290. #ifdef SNMM
  291. extr
  292. #endif //SNMM
  293. ) { //switches multiplexer for extruders
  294. #ifdef SNMM
  295. st_synchronize();
  296. delay(100);
  297. disable_e0();
  298. disable_e1();
  299. disable_e2();
  300. mmu_extruder = extr;
  301. pinMode(E_MUX0_PIN, OUTPUT);
  302. pinMode(E_MUX1_PIN, OUTPUT);
  303. switch (extr) {
  304. case 1:
  305. WRITE(E_MUX0_PIN, HIGH);
  306. WRITE(E_MUX1_PIN, LOW);
  307. break;
  308. case 2:
  309. WRITE(E_MUX0_PIN, LOW);
  310. WRITE(E_MUX1_PIN, HIGH);
  311. break;
  312. case 3:
  313. WRITE(E_MUX0_PIN, HIGH);
  314. WRITE(E_MUX1_PIN, HIGH);
  315. break;
  316. default:
  317. WRITE(E_MUX0_PIN, LOW);
  318. WRITE(E_MUX1_PIN, LOW);
  319. break;
  320. }
  321. delay(100);
  322. #endif
  323. }
  324. int get_ext_nr()
  325. { //reads multiplexer input pins and return current extruder number (counted from 0)
  326. #ifndef SNMM
  327. return(mmu_extruder); //update needed
  328. #else
  329. return(2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  330. #endif
  331. }
  332. void display_loading()
  333. {
  334. switch (mmu_extruder)
  335. {
  336. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  337. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  338. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  339. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  340. }
  341. }
  342. void extr_adj(int extruder) //loading filament for SNMM
  343. {
  344. #ifndef SNMM
  345. printf_P(PSTR("L%d \n"),extruder);
  346. fprintf_P(uart2io, PSTR("L%d\n"), extruder);
  347. //show which filament is currently loaded
  348. lcd_update_enable(false);
  349. lcd_clear();
  350. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  351. //if(strlen(_T(MSG_LOADING_FILAMENT))>18) lcd.setCursor(0, 1);
  352. //else lcd.print(" ");
  353. lcd_print(" ");
  354. lcd_print(mmu_extruder + 1);
  355. // get response
  356. manage_response(false, false);
  357. lcd_update_enable(true);
  358. //lcd_return_to_status();
  359. #else
  360. bool correct;
  361. max_feedrate[E_AXIS] =80;
  362. //max_feedrate[E_AXIS] = 50;
  363. START:
  364. lcd_clear();
  365. lcd_set_cursor(0, 0);
  366. switch (extruder) {
  367. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  368. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  369. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  370. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  371. }
  372. KEEPALIVE_STATE(PAUSED_FOR_USER);
  373. do{
  374. extr_mov(0.001,1000);
  375. delay_keep_alive(2);
  376. } while (!lcd_clicked());
  377. //delay_keep_alive(500);
  378. KEEPALIVE_STATE(IN_HANDLER);
  379. st_synchronize();
  380. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  381. //if (!correct) goto START;
  382. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  383. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  384. extr_mov(bowden_length[extruder], 500);
  385. lcd_clear();
  386. lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  387. if(strlen(_T(MSG_LOADING_FILAMENT))>18) lcd_set_cursor(0, 1);
  388. else lcd_print(" ");
  389. lcd_print(mmu_extruder + 1);
  390. lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  391. st_synchronize();
  392. max_feedrate[E_AXIS] = 50;
  393. lcd_update_enable(true);
  394. lcd_return_to_status();
  395. lcdDrawUpdate = 2;
  396. #endif
  397. }
  398. void extr_unload()
  399. { //unload just current filament for multimaterial printers
  400. #ifdef SNMM
  401. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  402. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  403. uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
  404. #endif
  405. if (degHotend0() > EXTRUDE_MINTEMP)
  406. {
  407. #ifndef SNMM
  408. st_synchronize();
  409. //show which filament is currently unloaded
  410. lcd_update_enable(false);
  411. lcd_clear();
  412. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_UNLOADING_FILAMENT));
  413. lcd_print(" ");
  414. lcd_print(mmu_extruder + 1);
  415. current_position[E_AXIS] -= 80;
  416. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  417. st_synchronize();
  418. printf_P(PSTR("U0\n"));
  419. fprintf_P(uart2io, PSTR("U0\n"));
  420. // get response
  421. manage_response(false, true);
  422. lcd_update_enable(true);
  423. #else //SNMM
  424. lcd_clear();
  425. lcd_display_message_fullscreen_P(PSTR(""));
  426. max_feedrate[E_AXIS] = 50;
  427. lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_UNLOADING_FILAMENT));
  428. lcd_print(" ");
  429. lcd_print(mmu_extruder + 1);
  430. lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  431. if (current_position[Z_AXIS] < 15) {
  432. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  433. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  434. }
  435. current_position[E_AXIS] += 10; //extrusion
  436. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  437. st_current_set(2, E_MOTOR_HIGH_CURRENT);
  438. if (current_temperature[0] < 230) { //PLA & all other filaments
  439. current_position[E_AXIS] += 5.4;
  440. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  441. current_position[E_AXIS] += 3.2;
  442. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  443. current_position[E_AXIS] += 3;
  444. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  445. }
  446. else { //ABS
  447. current_position[E_AXIS] += 3.1;
  448. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  449. current_position[E_AXIS] += 3.1;
  450. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  451. current_position[E_AXIS] += 4;
  452. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  453. /*current_position[X_AXIS] += 23; //delay
  454. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  455. current_position[X_AXIS] -= 23; //delay
  456. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  457. delay_keep_alive(4700);
  458. }
  459. max_feedrate[E_AXIS] = 80;
  460. current_position[E_AXIS] -= (bowden_length[mmu_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  461. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  462. current_position[E_AXIS] -= (bowden_length[mmu_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  463. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  464. st_synchronize();
  465. //st_current_init();
  466. if (SilentMode != SILENT_MODE_OFF) st_current_set(2, tmp_motor[2]); //set back to normal operation currents
  467. else st_current_set(2, tmp_motor_loud[2]);
  468. lcd_update_enable(true);
  469. lcd_return_to_status();
  470. max_feedrate[E_AXIS] = 50;
  471. #endif //SNMM
  472. }
  473. else
  474. {
  475. lcd_clear();
  476. lcd_set_cursor(0, 0);
  477. lcd_puts_P(_T(MSG_ERROR));
  478. lcd_set_cursor(0, 2);
  479. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  480. delay(2000);
  481. lcd_clear();
  482. }
  483. //lcd_return_to_status();
  484. }
  485. //wrapper functions for loading filament
  486. void extr_adj_0()
  487. {
  488. #ifndef SNMM
  489. enquecommand_P(PSTR("M701 E0"));
  490. #else
  491. change_extr(0);
  492. extr_adj(0);
  493. #endif
  494. }
  495. void extr_adj_1()
  496. {
  497. #ifndef SNMM
  498. enquecommand_P(PSTR("M701 E1"));
  499. #else
  500. change_extr(1);
  501. extr_adj(1);
  502. #endif
  503. }
  504. void extr_adj_2()
  505. {
  506. #ifndef SNMM
  507. enquecommand_P(PSTR("M701 E2"));
  508. #else
  509. change_extr(2);
  510. extr_adj(2);
  511. #endif
  512. }
  513. void extr_adj_3()
  514. {
  515. #ifndef SNMM
  516. enquecommand_P(PSTR("M701 E3"));
  517. #else
  518. change_extr(3);
  519. extr_adj(3);
  520. #endif
  521. }
  522. void extr_adj_4()
  523. {
  524. #ifndef SNMM
  525. enquecommand_P(PSTR("M701 E4"));
  526. #else
  527. change_extr(4);
  528. extr_adj(4);
  529. #endif
  530. }
  531. void load_all()
  532. {
  533. #ifndef SNMM
  534. enquecommand_P(PSTR("M701 E0"));
  535. enquecommand_P(PSTR("M701 E1"));
  536. enquecommand_P(PSTR("M701 E2"));
  537. enquecommand_P(PSTR("M701 E3"));
  538. enquecommand_P(PSTR("M701 E4"));
  539. #else
  540. for (int i = 0; i < 4; i++)
  541. {
  542. change_extr(i);
  543. extr_adj(i);
  544. }
  545. #endif
  546. }
  547. //wrapper functions for changing extruders
  548. void extr_change_0()
  549. {
  550. change_extr(0);
  551. lcd_return_to_status();
  552. }
  553. void extr_change_1()
  554. {
  555. change_extr(1);
  556. lcd_return_to_status();
  557. }
  558. void extr_change_2()
  559. {
  560. change_extr(2);
  561. lcd_return_to_status();
  562. }
  563. void extr_change_3()
  564. {
  565. change_extr(3);
  566. lcd_return_to_status();
  567. }
  568. //wrapper functions for unloading filament
  569. void extr_unload_all()
  570. {
  571. if (degHotend0() > EXTRUDE_MINTEMP)
  572. {
  573. for (int i = 0; i < 4; i++)
  574. {
  575. change_extr(i);
  576. extr_unload();
  577. }
  578. }
  579. else
  580. {
  581. lcd_clear();
  582. lcd_set_cursor(0, 0);
  583. lcd_puts_P(_T(MSG_ERROR));
  584. lcd_set_cursor(0, 2);
  585. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  586. delay(2000);
  587. lcd_clear();
  588. lcd_return_to_status();
  589. }
  590. }
  591. //unloading just used filament (for snmm)
  592. void extr_unload_used()
  593. {
  594. if (degHotend0() > EXTRUDE_MINTEMP) {
  595. for (int i = 0; i < 4; i++) {
  596. if (snmm_filaments_used & (1 << i)) {
  597. change_extr(i);
  598. extr_unload();
  599. }
  600. }
  601. snmm_filaments_used = 0;
  602. }
  603. else {
  604. lcd_clear();
  605. lcd_set_cursor(0, 0);
  606. lcd_puts_P(_T(MSG_ERROR));
  607. lcd_set_cursor(0, 2);
  608. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  609. delay(2000);
  610. lcd_clear();
  611. lcd_return_to_status();
  612. }
  613. }
  614. void extr_unload_0()
  615. {
  616. change_extr(0);
  617. extr_unload();
  618. }
  619. void extr_unload_1()
  620. {
  621. change_extr(1);
  622. extr_unload();
  623. }
  624. void extr_unload_2()
  625. {
  626. change_extr(2);
  627. extr_unload();
  628. }
  629. void extr_unload_3()
  630. {
  631. change_extr(3);
  632. extr_unload();
  633. }
  634. void extr_unload_4()
  635. {
  636. change_extr(4);
  637. extr_unload();
  638. }