mmu.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  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. #include "fsensor.h"
  10. #include "cardreader.h"
  11. #include "ultralcd.h"
  12. #include "sound.h"
  13. #include "printers.h"
  14. #include <avr/pgmspace.h>
  15. #include "io_atmega2560.h"
  16. #ifdef TMC2130
  17. #include "tmc2130.h"
  18. #endif //TMC2130
  19. #define CHECK_FINDA ((IS_SD_PRINTING || is_usb_printing) && (mcode_in_progress != 600) && !saved_printing && e_active())
  20. #define MMU_TODELAY 100
  21. #define MMU_TIMEOUT 10
  22. #define MMU_CMD_TIMEOUT 300000ul //5min timeout for mmu commands (except P0)
  23. #define MMU_P0_TIMEOUT 3000ul //timeout for P0 command: 3seconds
  24. #ifdef MMU_HWRESET
  25. #define MMU_RST_PIN 76
  26. #endif //MMU_HWRESET
  27. bool mmu_enabled = false;
  28. bool mmu_ready = false;
  29. static int8_t mmu_state = 0;
  30. uint8_t mmu_cmd = 0;
  31. #ifdef MMU_IDLER_SENSOR_PIN
  32. uint8_t mmu_idl_sens = 0;
  33. #endif //MMU_IDLER_SENSOR_PIN
  34. uint8_t mmu_extruder = MMU_FILAMENT_UNKNOWN;
  35. //! This variable probably has no meaning and is planed to be removed
  36. uint8_t tmp_extruder = MMU_FILAMENT_UNKNOWN;
  37. int8_t mmu_finda = -1;
  38. int16_t mmu_version = -1;
  39. int16_t mmu_buildnr = -1;
  40. uint32_t mmu_last_request = 0;
  41. uint32_t mmu_last_response = 0;
  42. //clear rx buffer
  43. void mmu_clr_rx_buf(void)
  44. {
  45. while (fgetc(uart2io) >= 0);
  46. }
  47. //send command - puts
  48. int mmu_puts_P(const char* str)
  49. {
  50. mmu_clr_rx_buf(); //clear rx buffer
  51. int r = fputs_P(str, uart2io); //send command
  52. mmu_last_request = millis();
  53. return r;
  54. }
  55. //send command - printf
  56. int mmu_printf_P(const char* format, ...)
  57. {
  58. va_list args;
  59. va_start(args, format);
  60. mmu_clr_rx_buf(); //clear rx buffer
  61. int r = vfprintf_P(uart2io, format, args); //send command
  62. va_end(args);
  63. mmu_last_request = millis();
  64. return r;
  65. }
  66. //check 'ok' response
  67. int8_t mmu_rx_ok(void)
  68. {
  69. int8_t res = uart2_rx_str_P(PSTR("ok\n"));
  70. if (res == 1) mmu_last_response = millis();
  71. return res;
  72. }
  73. //check 'start' response
  74. int8_t mmu_rx_start(void)
  75. {
  76. int8_t res = uart2_rx_str_P(PSTR("start\n"));
  77. if (res == 1) mmu_last_response = millis();
  78. return res;
  79. }
  80. //initialize mmu2 unit - first part - should be done at begining of startup process
  81. void mmu_init(void)
  82. {
  83. #ifdef MMU_HWRESET
  84. digitalWrite(MMU_RST_PIN, HIGH);
  85. pinMode(MMU_RST_PIN, OUTPUT); //setup reset pin
  86. #endif //MMU_HWRESET
  87. uart2_init(); //init uart2
  88. _delay_ms(10); //wait 10ms for sure
  89. mmu_reset(); //reset mmu (HW or SW), do not wait for response
  90. mmu_state = -1;
  91. #ifdef MMU_IDLER_SENSOR_PIN
  92. PIN_INP(MMU_IDLER_SENSOR_PIN); //input mode
  93. PIN_SET(MMU_IDLER_SENSOR_PIN); //pullup
  94. #endif //MMU_IDLER_SENSOR_PIN
  95. }
  96. //mmu main loop - state machine processing
  97. void mmu_loop(void)
  98. {
  99. int filament = 0;
  100. // printf_P(PSTR("MMU loop, state=%d\n"), mmu_state);
  101. switch (mmu_state)
  102. {
  103. case 0:
  104. return;
  105. case -1:
  106. if (mmu_rx_start() > 0)
  107. {
  108. #ifdef MMU_DEBUG
  109. puts_P(PSTR("MMU => 'start'"));
  110. puts_P(PSTR("MMU <= 'S1'"));
  111. #endif //MMU_DEBUG
  112. mmu_puts_P(PSTR("S1\n")); //send 'read version' request
  113. mmu_state = -2;
  114. }
  115. else if (millis() > 30000) //30sec after reset disable mmu
  116. {
  117. puts_P(PSTR("MMU not responding - DISABLED"));
  118. mmu_state = 0;
  119. }
  120. return;
  121. case -2:
  122. if (mmu_rx_ok() > 0)
  123. {
  124. fscanf_P(uart2io, PSTR("%u"), &mmu_version); //scan version from buffer
  125. #ifdef MMU_DEBUG
  126. printf_P(PSTR("MMU => '%dok'\n"), mmu_version);
  127. puts_P(PSTR("MMU <= 'S2'"));
  128. #endif //MMU_DEBUG
  129. mmu_puts_P(PSTR("S2\n")); //send 'read buildnr' request
  130. mmu_state = -3;
  131. }
  132. return;
  133. case -3:
  134. if (mmu_rx_ok() > 0)
  135. {
  136. fscanf_P(uart2io, PSTR("%u"), &mmu_buildnr); //scan buildnr from buffer
  137. #ifdef MMU_DEBUG
  138. printf_P(PSTR("MMU => '%dok'\n"), mmu_buildnr);
  139. #endif //MMU_DEBUG
  140. bool version_valid = mmu_check_version();
  141. if (!version_valid) mmu_show_warning();
  142. else puts_P(PSTR("MMU version valid"));
  143. if ((PRINTER_TYPE == PRINTER_MK3) || (PRINTER_TYPE == PRINTER_MK3_SNMM))
  144. {
  145. #ifdef MMU_DEBUG
  146. puts_P(PSTR("MMU <= 'P0'"));
  147. #endif //MMU_DEBUG
  148. mmu_puts_P(PSTR("P0\n")); //send 'read finda' request
  149. mmu_state = -4;
  150. }
  151. else
  152. {
  153. #ifdef MMU_DEBUG
  154. puts_P(PSTR("MMU <= 'M1'"));
  155. #endif //MMU_DEBUG
  156. mmu_puts_P(PSTR("M1\n")); //set mmu mode to stealth
  157. mmu_state = -5;
  158. }
  159. }
  160. return;
  161. case -5:
  162. if (mmu_rx_ok() > 0)
  163. {
  164. #ifdef MMU_DEBUG
  165. puts_P(PSTR("MMU <= 'P0'"));
  166. #endif //MMU_DEBUG
  167. mmu_puts_P(PSTR("P0\n")); //send 'read finda' request
  168. mmu_state = -4;
  169. }
  170. return;
  171. case -4:
  172. if (mmu_rx_ok() > 0)
  173. {
  174. fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
  175. #ifdef MMU_DEBUG
  176. printf_P(PSTR("MMU => '%dok'\n"), mmu_finda);
  177. #endif //MMU_DEBUG
  178. puts_P(PSTR("MMU - ENABLED"));
  179. mmu_enabled = true;
  180. mmu_state = 1;
  181. }
  182. return;
  183. case 1:
  184. if (mmu_cmd) //command request ?
  185. {
  186. if ((mmu_cmd >= MMU_CMD_T0) && (mmu_cmd <= MMU_CMD_T4))
  187. {
  188. filament = mmu_cmd - MMU_CMD_T0;
  189. #ifdef MMU_DEBUG
  190. printf_P(PSTR("MMU <= 'T%d'\n"), filament);
  191. #endif //MMU_DEBUG
  192. mmu_printf_P(PSTR("T%d\n"), filament);
  193. mmu_state = 3; // wait for response
  194. #ifdef MMU_IDLER_SENSOR_PIN
  195. mmu_idl_sens = 1; //enable idler sensor
  196. #endif //MMU_IDLER_SENSOR_PIN
  197. }
  198. else if ((mmu_cmd >= MMU_CMD_L0) && (mmu_cmd <= MMU_CMD_L4))
  199. {
  200. filament = mmu_cmd - MMU_CMD_L0;
  201. #ifdef MMU_DEBUG
  202. printf_P(PSTR("MMU <= 'L%d'\n"), filament);
  203. #endif //MMU_DEBUG
  204. mmu_printf_P(PSTR("L%d\n"), filament);
  205. mmu_state = 3; // wait for response
  206. }
  207. else if (mmu_cmd == MMU_CMD_C0)
  208. {
  209. #ifdef MMU_DEBUG
  210. printf_P(PSTR("MMU <= 'C0'\n"));
  211. #endif //MMU_DEBUG
  212. mmu_puts_P(PSTR("C0\n")); //send 'continue loading'
  213. mmu_state = 3;
  214. #ifdef MMU_IDLER_SENSOR_PIN
  215. mmu_idl_sens = 1; //enable idler sensor
  216. #endif //MMU_IDLER_SENSOR_PIN
  217. }
  218. else if (mmu_cmd == MMU_CMD_U0)
  219. {
  220. #ifdef MMU_DEBUG
  221. printf_P(PSTR("MMU <= 'U0'\n"));
  222. #endif //MMU_DEBUG
  223. mmu_puts_P(PSTR("U0\n")); //send 'unload current filament'
  224. mmu_state = 3;
  225. }
  226. else if ((mmu_cmd >= MMU_CMD_E0) && (mmu_cmd <= MMU_CMD_E4))
  227. {
  228. int filament = mmu_cmd - MMU_CMD_E0;
  229. #ifdef MMU_DEBUG
  230. printf_P(PSTR("MMU <= 'E%d'\n"), filament);
  231. #endif //MMU_DEBUG
  232. mmu_printf_P(PSTR("E%d\n"), filament); //send eject filament
  233. mmu_state = 3; // wait for response
  234. }
  235. else if (mmu_cmd == MMU_CMD_R0)
  236. {
  237. #ifdef MMU_DEBUG
  238. printf_P(PSTR("MMU <= 'R0'\n"));
  239. #endif //MMU_DEBUG
  240. mmu_puts_P(PSTR("R0\n")); //send recover after eject
  241. mmu_state = 3; // wait for response
  242. }
  243. mmu_cmd = 0;
  244. }
  245. else if ((mmu_last_response + 300) < millis()) //request every 300ms
  246. {
  247. #ifdef MMU_DEBUG
  248. puts_P(PSTR("MMU <= 'P0'"));
  249. #endif //MMU_DEBUG
  250. mmu_puts_P(PSTR("P0\n")); //send 'read finda' request
  251. mmu_state = 2;
  252. }
  253. return;
  254. case 2: //response to command P0
  255. if (mmu_rx_ok() > 0)
  256. {
  257. fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
  258. #ifdef MMU_DEBUG
  259. printf_P(PSTR("MMU => '%dok'\n"), mmu_finda);
  260. #endif //MMU_DEBUG
  261. //printf_P(PSTR("Eact: %d\n"), int(e_active()));
  262. if (!mmu_finda && CHECK_FINDA && fsensor_enabled) {
  263. fsensor_stop_and_save_print();
  264. enquecommand_front_P(PSTR("FSENSOR_RECOVER")); //then recover
  265. if (lcd_autoDepleteEnabled()) enquecommand_front_P(PSTR("M600 AUTO")); //save print and run M600 command
  266. else enquecommand_front_P(PSTR("M600")); //save print and run M600 command
  267. }
  268. mmu_state = 1;
  269. if (mmu_cmd == 0)
  270. mmu_ready = true;
  271. }
  272. else if ((mmu_last_request + MMU_P0_TIMEOUT) < millis())
  273. { //resend request after timeout (30s)
  274. mmu_state = 1;
  275. }
  276. return;
  277. case 3: //response to mmu commands
  278. #ifdef MMU_IDLER_SENSOR_PIN
  279. if (mmu_idl_sens)
  280. {
  281. if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0)
  282. {
  283. #ifdef MMU_DEBUG
  284. printf_P(PSTR("MMU <= 'A'\n"));
  285. #endif //MMU_DEBUG
  286. mmu_puts_P(PSTR("A\n")); //send 'abort' request
  287. mmu_idl_sens = 0;
  288. //printf_P(PSTR("MMU IDLER_SENSOR = 0 - ABORT\n"));
  289. }
  290. //else
  291. //printf_P(PSTR("MMU IDLER_SENSOR = 1 - WAIT\n"));
  292. }
  293. #endif //MMU_IDLER_SENSOR_PIN
  294. if (mmu_rx_ok() > 0)
  295. {
  296. #ifdef MMU_DEBUG
  297. printf_P(PSTR("MMU => 'ok'\n"));
  298. #endif //MMU_DEBUG
  299. mmu_ready = true;
  300. mmu_state = 1;
  301. }
  302. else if ((mmu_last_request + MMU_CMD_TIMEOUT) < millis())
  303. { //resend request after timeout (5 min)
  304. mmu_state = 1;
  305. }
  306. return;
  307. }
  308. }
  309. void mmu_reset(void)
  310. {
  311. #ifdef MMU_HWRESET //HW - pulse reset pin
  312. digitalWrite(MMU_RST_PIN, LOW);
  313. _delay_us(100);
  314. digitalWrite(MMU_RST_PIN, HIGH);
  315. #else //SW - send X0 command
  316. mmu_puts_P(PSTR("X0\n"));
  317. #endif
  318. }
  319. int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament)
  320. {
  321. printf_P(PSTR("MMU <= 'F%d %d'\n"), extruder, filament);
  322. mmu_printf_P(PSTR("F%d %d\n"), extruder, filament);
  323. unsigned char timeout = MMU_TIMEOUT; //10x100ms
  324. while ((mmu_rx_ok() <= 0) && (--timeout))
  325. delay_keep_alive(MMU_TODELAY);
  326. return timeout?1:0;
  327. }
  328. void mmu_command(uint8_t cmd)
  329. {
  330. #ifdef TMC2130
  331. if ((cmd >= MMU_CMD_T0) && (cmd <= MMU_CMD_T4))
  332. {
  333. //disable extruder motor
  334. tmc2130_set_pwr(E_AXIS, 0);
  335. //printf_P(PSTR("E-axis disabled\n"));
  336. }
  337. #endif //TMC2130
  338. mmu_cmd = cmd;
  339. mmu_ready = false;
  340. }
  341. bool mmu_get_response(void)
  342. {
  343. // printf_P(PSTR("mmu_get_response - begin\n"));
  344. KEEPALIVE_STATE(IN_PROCESS);
  345. while (mmu_cmd != 0)
  346. {
  347. // mmu_loop();
  348. delay_keep_alive(100);
  349. }
  350. while (!mmu_ready)
  351. {
  352. // mmu_loop();
  353. if (mmu_state != 3)
  354. break;
  355. delay_keep_alive(100);
  356. }
  357. bool ret = mmu_ready;
  358. mmu_ready = false;
  359. // printf_P(PSTR("mmu_get_response - end %d\n"), ret?1:0);
  360. return ret;
  361. /* //waits for "ok" from mmu
  362. //function returns true if "ok" was received
  363. //if timeout is set to true function return false if there is no "ok" received before timeout
  364. bool response = true;
  365. LongTimer mmu_get_reponse_timeout;
  366. KEEPALIVE_STATE(IN_PROCESS);
  367. mmu_get_reponse_timeout.start();
  368. while (mmu_rx_ok() <= 0)
  369. {
  370. delay_keep_alive(100);
  371. if (timeout && mmu_get_reponse_timeout.expired(5 * 60 * 1000ul))
  372. { //5 minutes timeout
  373. response = false;
  374. break;
  375. }
  376. }
  377. printf_P(PSTR("mmu_get_response - end %d\n"), response?1:0);
  378. return response;*/
  379. }
  380. void manage_response(bool move_axes, bool turn_off_nozzle)
  381. {
  382. bool response = false;
  383. mmu_print_saved = false;
  384. bool lcd_update_was_enabled = false;
  385. float hotend_temp_bckp = degTargetHotend(active_extruder);
  386. float z_position_bckp = current_position[Z_AXIS];
  387. float x_position_bckp = current_position[X_AXIS];
  388. float y_position_bckp = current_position[Y_AXIS];
  389. uint8_t screen = 0; //used for showing multiscreen messages
  390. while(!response)
  391. {
  392. response = mmu_get_response(); //wait for "ok" from mmu
  393. if (!response) { //no "ok" was received in reserved time frame, user will fix the issue on mmu unit
  394. if (!mmu_print_saved) { //first occurence, we are saving current position, park print head in certain position and disable nozzle heater
  395. if (lcd_update_enabled) {
  396. lcd_update_was_enabled = true;
  397. lcd_update_enable(false);
  398. }
  399. st_synchronize();
  400. mmu_print_saved = true;
  401. printf_P(PSTR("MMU not responding\n"));
  402. hotend_temp_bckp = degTargetHotend(active_extruder);
  403. if (move_axes) {
  404. z_position_bckp = current_position[Z_AXIS];
  405. x_position_bckp = current_position[X_AXIS];
  406. y_position_bckp = current_position[Y_AXIS];
  407. //lift z
  408. current_position[Z_AXIS] += Z_PAUSE_LIFT;
  409. if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS;
  410. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder);
  411. st_synchronize();
  412. //Move XY to side
  413. current_position[X_AXIS] = X_PAUSE_POS;
  414. current_position[Y_AXIS] = Y_PAUSE_POS;
  415. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder);
  416. st_synchronize();
  417. }
  418. if (turn_off_nozzle) {
  419. //set nozzle target temperature to 0
  420. setAllTargetHotends(0);
  421. }
  422. }
  423. //first three lines are used for printing multiscreen message; last line contains measured and target nozzle temperature
  424. if (screen == 0) { //screen 0
  425. lcd_display_message_fullscreen_P(_i("MMU needs user attention."));
  426. screen++;
  427. }
  428. else { //screen 1
  429. if((degTargetHotend(active_extruder) == 0) && turn_off_nozzle) lcd_display_message_fullscreen_P(_i("Press the knob to resume nozzle temperature."));
  430. else lcd_display_message_fullscreen_P(_i("Fix the issue and then press button on MMU unit."));
  431. screen=0;
  432. }
  433. lcd_set_degree();
  434. lcd_set_cursor(0, 4); //line 4
  435. //Print the hotend temperature (9 chars total) and fill rest of the line with space
  436. int chars = lcd_printf_P(_N("%c%3d/%d%c"), LCD_STR_THERMOMETER[0],(int)(degHotend(active_extruder) + 0.5), (int)(degTargetHotend(active_extruder) + 0.5), LCD_STR_DEGREE[0]);
  437. lcd_space(9 - chars);
  438. //5 seconds delay
  439. for (uint8_t i = 0; i < 50; i++) {
  440. if (lcd_clicked()) {
  441. setTargetHotend(hotend_temp_bckp, active_extruder);
  442. break;
  443. }
  444. delay_keep_alive(100);
  445. }
  446. }
  447. else if (mmu_print_saved) {
  448. printf_P(PSTR("MMU starts responding\n"));
  449. if (turn_off_nozzle)
  450. {
  451. lcd_clear();
  452. setTargetHotend(hotend_temp_bckp, active_extruder);
  453. if (((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5)) {
  454. lcd_display_message_fullscreen_P(_i("MMU OK. Resuming temperature..."));
  455. delay_keep_alive(3000);
  456. }
  457. while ((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5)
  458. {
  459. delay_keep_alive(1000);
  460. lcd_wait_for_heater();
  461. }
  462. }
  463. if (move_axes) {
  464. lcd_clear();
  465. lcd_display_message_fullscreen_P(_i("MMU OK. Resuming position..."));
  466. current_position[X_AXIS] = x_position_bckp;
  467. current_position[Y_AXIS] = y_position_bckp;
  468. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder);
  469. st_synchronize();
  470. current_position[Z_AXIS] = z_position_bckp;
  471. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder);
  472. st_synchronize();
  473. }
  474. else {
  475. lcd_clear();
  476. lcd_display_message_fullscreen_P(_i("MMU OK. Resuming..."));
  477. delay_keep_alive(1000); //delay just for showing MMU OK message for a while in case that there are no xyz movements
  478. }
  479. }
  480. }
  481. if (lcd_update_was_enabled) lcd_update_enable(true);
  482. #ifdef TMC2130
  483. //enable extruder motor (disabled in mmu_command, start of T-code processing)
  484. tmc2130_set_pwr(E_AXIS, 1);
  485. //printf_P(PSTR("E-axis enabled\n"));
  486. #endif //TMC2130
  487. }
  488. //! @brief load filament to nozzle of multimaterial printer
  489. //!
  490. //! This function is used only only after T? (user select filament) and M600 (change filament).
  491. //! It is not used after T0 .. T4 command (select filament), in such case, gcode is responsible for loading
  492. //! filament to nozzle.
  493. //!
  494. void mmu_load_to_nozzle()
  495. {
  496. st_synchronize();
  497. bool saved_e_relative_mode = axis_relative_modes[E_AXIS];
  498. if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true;
  499. current_position[E_AXIS] += 7.2f;
  500. float feedrate = 562;
  501. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder);
  502. st_synchronize();
  503. current_position[E_AXIS] += 14.4f;
  504. feedrate = 871;
  505. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder);
  506. st_synchronize();
  507. current_position[E_AXIS] += 36.0f;
  508. feedrate = 1393;
  509. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder);
  510. st_synchronize();
  511. current_position[E_AXIS] += 14.4f;
  512. feedrate = 871;
  513. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder);
  514. st_synchronize();
  515. if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = false;
  516. }
  517. void mmu_M600_wait_and_beep() {
  518. //Beep and wait for user to remove old filament and prepare new filament for load
  519. KEEPALIVE_STATE(PAUSED_FOR_USER);
  520. int counterBeep = 0;
  521. lcd_display_message_fullscreen_P(_i("Remove old filament and press the knob to start loading new filament."));
  522. bool bFirst=true;
  523. while (!lcd_clicked()){
  524. manage_heater();
  525. manage_inactivity(true);
  526. #if BEEPER > 0
  527. if (counterBeep == 500) {
  528. counterBeep = 0;
  529. }
  530. SET_OUTPUT(BEEPER);
  531. if (counterBeep == 0) {
  532. if((eSoundMode==e_SOUND_MODE_LOUD)||((eSoundMode==e_SOUND_MODE_ONCE)&&bFirst))
  533. {
  534. bFirst=false;
  535. WRITE(BEEPER, HIGH);
  536. }
  537. }
  538. if (counterBeep == 20) {
  539. WRITE(BEEPER, LOW);
  540. }
  541. counterBeep++;
  542. #endif //BEEPER > 0
  543. delay_keep_alive(4);
  544. }
  545. WRITE(BEEPER, LOW);
  546. }
  547. void mmu_M600_load_filament(bool automatic)
  548. {
  549. //load filament for mmu v2
  550. tmp_extruder = mmu_extruder;
  551. if (!automatic) {
  552. #ifdef MMU_M600_SWITCH_EXTRUDER
  553. bool yes = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Do you want to switch extruder?"), false);
  554. if(yes) tmp_extruder = choose_extruder_menu();
  555. #endif //MMU_M600_SWITCH_EXTRUDER
  556. }
  557. else {
  558. tmp_extruder = (tmp_extruder+1)%5;
  559. }
  560. lcd_update_enable(false);
  561. lcd_clear();
  562. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  563. lcd_print(" ");
  564. lcd_print(tmp_extruder + 1);
  565. snmm_filaments_used |= (1 << tmp_extruder); //for stop print
  566. // printf_P(PSTR("T code: %d \n"), tmp_extruder);
  567. // mmu_printf_P(PSTR("T%d\n"), tmp_extruder);
  568. mmu_command(MMU_CMD_T0 + tmp_extruder);
  569. manage_response(false, true);
  570. mmu_continue_loading();
  571. mmu_extruder = tmp_extruder; //filament change is finished
  572. mmu_load_to_nozzle();
  573. load_filament_final_feed();
  574. st_synchronize();
  575. }
  576. #ifdef SNMM
  577. void extr_mov(float shift, float feed_rate)
  578. { //move extruder no matter what the current heater temperature is
  579. set_extrude_min_temp(.0);
  580. current_position[E_AXIS] += shift;
  581. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  582. set_extrude_min_temp(EXTRUDE_MINTEMP);
  583. }
  584. #endif //SNMM
  585. void change_extr(int
  586. #ifdef SNMM
  587. extr
  588. #endif //SNMM
  589. ) { //switches multiplexer for extruders
  590. #ifdef SNMM
  591. st_synchronize();
  592. delay(100);
  593. disable_e0();
  594. disable_e1();
  595. disable_e2();
  596. mmu_extruder = extr;
  597. pinMode(E_MUX0_PIN, OUTPUT);
  598. pinMode(E_MUX1_PIN, OUTPUT);
  599. switch (extr) {
  600. case 1:
  601. WRITE(E_MUX0_PIN, HIGH);
  602. WRITE(E_MUX1_PIN, LOW);
  603. break;
  604. case 2:
  605. WRITE(E_MUX0_PIN, LOW);
  606. WRITE(E_MUX1_PIN, HIGH);
  607. break;
  608. case 3:
  609. WRITE(E_MUX0_PIN, HIGH);
  610. WRITE(E_MUX1_PIN, HIGH);
  611. break;
  612. default:
  613. WRITE(E_MUX0_PIN, LOW);
  614. WRITE(E_MUX1_PIN, LOW);
  615. break;
  616. }
  617. delay(100);
  618. #endif
  619. }
  620. int get_ext_nr()
  621. { //reads multiplexer input pins and return current extruder number (counted from 0)
  622. #ifndef SNMM
  623. return(mmu_extruder); //update needed
  624. #else
  625. return(2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  626. #endif
  627. }
  628. void display_loading()
  629. {
  630. switch (mmu_extruder)
  631. {
  632. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  633. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  634. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  635. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  636. }
  637. }
  638. void extr_adj(int extruder) //loading filament for SNMM
  639. {
  640. #ifndef SNMM
  641. uint8_t cmd = MMU_CMD_L0 + extruder;
  642. if (cmd > MMU_CMD_L4)
  643. {
  644. printf_P(PSTR("Filament out of range %d \n"),extruder);
  645. return;
  646. }
  647. mmu_command(cmd);
  648. //show which filament is currently loaded
  649. lcd_update_enable(false);
  650. lcd_clear();
  651. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  652. //if(strlen(_T(MSG_LOADING_FILAMENT))>18) lcd.setCursor(0, 1);
  653. //else lcd.print(" ");
  654. lcd_print(" ");
  655. lcd_print(extruder + 1);
  656. // get response
  657. manage_response(false, false);
  658. lcd_update_enable(true);
  659. //lcd_return_to_status();
  660. #else
  661. bool correct;
  662. max_feedrate[E_AXIS] =80;
  663. //max_feedrate[E_AXIS] = 50;
  664. START:
  665. lcd_clear();
  666. lcd_set_cursor(0, 0);
  667. switch (extruder) {
  668. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  669. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  670. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  671. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  672. }
  673. KEEPALIVE_STATE(PAUSED_FOR_USER);
  674. do{
  675. extr_mov(0.001,1000);
  676. delay_keep_alive(2);
  677. } while (!lcd_clicked());
  678. //delay_keep_alive(500);
  679. KEEPALIVE_STATE(IN_HANDLER);
  680. st_synchronize();
  681. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  682. //if (!correct) goto START;
  683. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  684. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  685. extr_mov(bowden_length[extruder], 500);
  686. lcd_clear();
  687. lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  688. if(strlen(_T(MSG_LOADING_FILAMENT))>18) lcd_set_cursor(0, 1);
  689. else lcd_print(" ");
  690. lcd_print(mmu_extruder + 1);
  691. lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  692. st_synchronize();
  693. max_feedrate[E_AXIS] = 50;
  694. lcd_update_enable(true);
  695. lcd_return_to_status();
  696. lcdDrawUpdate = 2;
  697. #endif
  698. }
  699. struct E_step
  700. {
  701. float extrude; //!< extrude distance in mm
  702. float feed_rate; //!< feed rate in mm/s
  703. };
  704. static const E_step ramming_sequence[] PROGMEM =
  705. {
  706. {1.0, 1000.0/60},
  707. {1.0, 1500.0/60},
  708. {2.0, 2000.0/60},
  709. {1.5, 3000.0/60},
  710. {2.5, 4000.0/60},
  711. {-15.0, 5000.0/60},
  712. {-14.0, 1200.0/60},
  713. {-6.0, 600.0/60},
  714. {10.0, 700.0/60},
  715. {-10.0, 400.0/60},
  716. {-50.0, 2000.0/60},
  717. };
  718. //! @brief Unload sequence to optimize shape of the tip of the unloaded filament
  719. static void filament_ramming()
  720. {
  721. for(uint8_t i = 0; i < (sizeof(ramming_sequence)/sizeof(E_step));++i)
  722. {
  723. current_position[E_AXIS] += pgm_read_float(&(ramming_sequence[i].extrude));
  724. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS],
  725. current_position[E_AXIS], pgm_read_float(&(ramming_sequence[i].feed_rate)), active_extruder);
  726. st_synchronize();
  727. }
  728. }
  729. void extr_unload()
  730. { //unload just current filament for multimaterial printers
  731. #ifdef SNMM
  732. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  733. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  734. uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
  735. #endif
  736. if (degHotend0() > EXTRUDE_MINTEMP)
  737. {
  738. #ifndef SNMM
  739. st_synchronize();
  740. //show which filament is currently unloaded
  741. lcd_update_enable(false);
  742. lcd_clear();
  743. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_UNLOADING_FILAMENT));
  744. lcd_print(" ");
  745. if (mmu_extruder == MMU_FILAMENT_UNKNOWN) lcd_print("?");
  746. else lcd_print(mmu_extruder + 1);
  747. filament_ramming();
  748. mmu_command(MMU_CMD_U0);
  749. // get response
  750. manage_response(false, true);
  751. lcd_update_enable(true);
  752. #else //SNMM
  753. lcd_clear();
  754. lcd_display_message_fullscreen_P(PSTR(""));
  755. max_feedrate[E_AXIS] = 50;
  756. lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_UNLOADING_FILAMENT));
  757. lcd_print(" ");
  758. lcd_print(mmu_extruder + 1);
  759. lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  760. if (current_position[Z_AXIS] < 15) {
  761. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  762. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  763. }
  764. current_position[E_AXIS] += 10; //extrusion
  765. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  766. st_current_set(2, E_MOTOR_HIGH_CURRENT);
  767. if (current_temperature[0] < 230) { //PLA & all other filaments
  768. current_position[E_AXIS] += 5.4;
  769. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  770. current_position[E_AXIS] += 3.2;
  771. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  772. current_position[E_AXIS] += 3;
  773. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  774. }
  775. else { //ABS
  776. current_position[E_AXIS] += 3.1;
  777. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  778. current_position[E_AXIS] += 3.1;
  779. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  780. current_position[E_AXIS] += 4;
  781. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  782. /*current_position[X_AXIS] += 23; //delay
  783. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  784. current_position[X_AXIS] -= 23; //delay
  785. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  786. delay_keep_alive(4700);
  787. }
  788. max_feedrate[E_AXIS] = 80;
  789. current_position[E_AXIS] -= (bowden_length[mmu_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  790. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  791. current_position[E_AXIS] -= (bowden_length[mmu_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  792. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  793. st_synchronize();
  794. //st_current_init();
  795. if (SilentMode != SILENT_MODE_OFF) st_current_set(2, tmp_motor[2]); //set back to normal operation currents
  796. else st_current_set(2, tmp_motor_loud[2]);
  797. lcd_update_enable(true);
  798. lcd_return_to_status();
  799. max_feedrate[E_AXIS] = 50;
  800. #endif //SNMM
  801. }
  802. else
  803. {
  804. show_preheat_nozzle_warning();
  805. }
  806. //lcd_return_to_status();
  807. }
  808. //wrapper functions for loading filament
  809. void extr_adj_0()
  810. {
  811. #ifndef SNMM
  812. enquecommand_P(PSTR("M701 E0"));
  813. #else
  814. change_extr(0);
  815. extr_adj(0);
  816. #endif
  817. }
  818. void extr_adj_1()
  819. {
  820. #ifndef SNMM
  821. enquecommand_P(PSTR("M701 E1"));
  822. #else
  823. change_extr(1);
  824. extr_adj(1);
  825. #endif
  826. }
  827. void extr_adj_2()
  828. {
  829. #ifndef SNMM
  830. enquecommand_P(PSTR("M701 E2"));
  831. #else
  832. change_extr(2);
  833. extr_adj(2);
  834. #endif
  835. }
  836. void extr_adj_3()
  837. {
  838. #ifndef SNMM
  839. enquecommand_P(PSTR("M701 E3"));
  840. #else
  841. change_extr(3);
  842. extr_adj(3);
  843. #endif
  844. }
  845. void extr_adj_4()
  846. {
  847. #ifndef SNMM
  848. enquecommand_P(PSTR("M701 E4"));
  849. #else
  850. change_extr(4);
  851. extr_adj(4);
  852. #endif
  853. }
  854. void mmu_load_to_nozzle_0()
  855. {
  856. lcd_mmu_load_to_nozzle(0);
  857. }
  858. void mmu_load_to_nozzle_1()
  859. {
  860. lcd_mmu_load_to_nozzle(1);
  861. }
  862. void mmu_load_to_nozzle_2()
  863. {
  864. lcd_mmu_load_to_nozzle(2);
  865. }
  866. void mmu_load_to_nozzle_3()
  867. {
  868. lcd_mmu_load_to_nozzle(3);
  869. }
  870. void mmu_load_to_nozzle_4()
  871. {
  872. lcd_mmu_load_to_nozzle(4);
  873. }
  874. void mmu_eject_fil_0()
  875. {
  876. mmu_eject_filament(0, true);
  877. }
  878. void mmu_eject_fil_1()
  879. {
  880. mmu_eject_filament(1, true);
  881. }
  882. void mmu_eject_fil_2()
  883. {
  884. mmu_eject_filament(2, true);
  885. }
  886. void mmu_eject_fil_3()
  887. {
  888. mmu_eject_filament(3, true);
  889. }
  890. void mmu_eject_fil_4()
  891. {
  892. mmu_eject_filament(4, true);
  893. }
  894. void load_all()
  895. {
  896. #ifndef SNMM
  897. enquecommand_P(PSTR("M701 E0"));
  898. enquecommand_P(PSTR("M701 E1"));
  899. enquecommand_P(PSTR("M701 E2"));
  900. enquecommand_P(PSTR("M701 E3"));
  901. enquecommand_P(PSTR("M701 E4"));
  902. #else
  903. for (int i = 0; i < 4; i++)
  904. {
  905. change_extr(i);
  906. extr_adj(i);
  907. }
  908. #endif
  909. }
  910. //wrapper functions for changing extruders
  911. void extr_change_0()
  912. {
  913. change_extr(0);
  914. lcd_return_to_status();
  915. }
  916. void extr_change_1()
  917. {
  918. change_extr(1);
  919. lcd_return_to_status();
  920. }
  921. void extr_change_2()
  922. {
  923. change_extr(2);
  924. lcd_return_to_status();
  925. }
  926. void extr_change_3()
  927. {
  928. change_extr(3);
  929. lcd_return_to_status();
  930. }
  931. #ifdef SNMM
  932. //wrapper functions for unloading filament
  933. void extr_unload_all()
  934. {
  935. if (degHotend0() > EXTRUDE_MINTEMP)
  936. {
  937. for (int i = 0; i < 4; i++)
  938. {
  939. change_extr(i);
  940. extr_unload();
  941. }
  942. }
  943. else
  944. {
  945. show_preheat_nozzle_warning();
  946. lcd_return_to_status();
  947. }
  948. }
  949. //unloading just used filament (for snmm)
  950. void extr_unload_used()
  951. {
  952. if (degHotend0() > EXTRUDE_MINTEMP) {
  953. for (int i = 0; i < 4; i++) {
  954. if (snmm_filaments_used & (1 << i)) {
  955. change_extr(i);
  956. extr_unload();
  957. }
  958. }
  959. snmm_filaments_used = 0;
  960. }
  961. else {
  962. show_preheat_nozzle_warning();
  963. lcd_return_to_status();
  964. }
  965. }
  966. #endif //SNMM
  967. void extr_unload_0()
  968. {
  969. change_extr(0);
  970. extr_unload();
  971. }
  972. void extr_unload_1()
  973. {
  974. change_extr(1);
  975. extr_unload();
  976. }
  977. void extr_unload_2()
  978. {
  979. change_extr(2);
  980. extr_unload();
  981. }
  982. void extr_unload_3()
  983. {
  984. change_extr(3);
  985. extr_unload();
  986. }
  987. void extr_unload_4()
  988. {
  989. change_extr(4);
  990. extr_unload();
  991. }
  992. bool mmu_check_version()
  993. {
  994. return (mmu_buildnr >= MMU_REQUIRED_FW_BUILDNR);
  995. }
  996. void mmu_show_warning()
  997. {
  998. printf_P(PSTR("MMU2 firmware version invalid. Required version: build number %d or higher."), MMU_REQUIRED_FW_BUILDNR);
  999. kill(_i("Please update firmware in your MMU2. Waiting for reset."));
  1000. }
  1001. void lcd_mmu_load_to_nozzle(uint8_t filament_nr)
  1002. {
  1003. if (degHotend0() > EXTRUDE_MINTEMP)
  1004. {
  1005. tmp_extruder = filament_nr;
  1006. lcd_update_enable(false);
  1007. lcd_clear();
  1008. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  1009. lcd_print(" ");
  1010. lcd_print(tmp_extruder + 1);
  1011. mmu_command(MMU_CMD_T0 + tmp_extruder);
  1012. manage_response(true, true);
  1013. mmu_continue_loading();
  1014. mmu_extruder = tmp_extruder; //filament change is finished
  1015. mmu_load_to_nozzle();
  1016. load_filament_final_feed();
  1017. st_synchronize();
  1018. custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
  1019. lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT));
  1020. lcd_return_to_status();
  1021. lcd_update_enable(true);
  1022. lcd_load_filament_color_check();
  1023. lcd_setstatuspgm(_T(WELCOME_MSG));
  1024. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  1025. }
  1026. else
  1027. {
  1028. show_preheat_nozzle_warning();
  1029. }
  1030. }
  1031. void mmu_eject_filament(uint8_t filament, bool recover)
  1032. {
  1033. if (filament < 5)
  1034. {
  1035. if (degHotend0() > EXTRUDE_MINTEMP)
  1036. {
  1037. st_synchronize();
  1038. {
  1039. LcdUpdateDisabler disableLcdUpdate;
  1040. lcd_clear();
  1041. lcd_set_cursor(0, 1); lcd_puts_P(_i("Ejecting filament"));
  1042. current_position[E_AXIS] -= 80;
  1043. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  1044. st_synchronize();
  1045. mmu_command(MMU_CMD_E0 + filament);
  1046. manage_response(false, false);
  1047. if (recover)
  1048. {
  1049. lcd_show_fullscreen_message_and_wait_P(_i("Please remove filament and then press the knob."));
  1050. mmu_command(MMU_CMD_R0);
  1051. manage_response(false, false);
  1052. }
  1053. }
  1054. }
  1055. else
  1056. {
  1057. show_preheat_nozzle_warning();
  1058. }
  1059. }
  1060. else
  1061. {
  1062. puts_P(PSTR("Filament nr out of range!"));
  1063. }
  1064. }
  1065. void mmu_continue_loading()
  1066. {
  1067. #ifdef MMU_IDLER_SENSOR_PIN
  1068. for (uint8_t i = 0; i < MMU_IDLER_SENSOR_ATTEMPTS_NR; i++) {
  1069. #ifdef MMU_DEBUG
  1070. printf_P(PSTR("Additional load attempt nr. %d\n"), i);
  1071. #endif // MMU_DEBUG
  1072. if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) break;
  1073. mmu_command(MMU_CMD_C0);
  1074. manage_response(true, true);
  1075. }
  1076. #else
  1077. mmu_command(MMU_CMD_C0);
  1078. #endif //MMU_IDLER_SENSOR_PIN
  1079. }