|
@@ -54,6 +54,8 @@ MMU2 mmu2;
|
54
|
54
|
#define MMU_CMD_TIMEOUT 45000UL // 45s timeout for mmu commands (except P0)
|
55
|
55
|
#define MMU_P0_TIMEOUT 3000UL // Timeout for P0 command: 3seconds
|
56
|
56
|
|
|
57
|
+#define MMU2_COMMAND(S) tx_str_P(PSTR(S "\n"))
|
|
58
|
+
|
57
|
59
|
#if ENABLED(MMU_EXTRUDER_SENSOR)
|
58
|
60
|
uint8_t mmu_idl_sens = 0;
|
59
|
61
|
static bool mmu_loading_flag = false;
|
|
@@ -152,7 +154,7 @@ void MMU2::reset() {
|
152
|
154
|
safe_delay(20);
|
153
|
155
|
WRITE(MMU2_RST_PIN, HIGH);
|
154
|
156
|
#else
|
155
|
|
- tx_str_P(PSTR("X0\n")); // Send soft reset
|
|
157
|
+ MMU2_COMMAND("X0"); // Send soft reset
|
156
|
158
|
#endif
|
157
|
159
|
}
|
158
|
160
|
|
|
@@ -175,9 +177,7 @@ void MMU2::mmu_loop() {
|
175
|
177
|
DEBUG_ECHOLNPGM("MMU => 'start'");
|
176
|
178
|
DEBUG_ECHOLNPGM("MMU <= 'S1'");
|
177
|
179
|
|
178
|
|
- // send "read version" request
|
179
|
|
- tx_str_P(PSTR("S1\n"));
|
180
|
|
-
|
|
180
|
+ MMU2_COMMAND("S1"); // Read Version
|
181
|
181
|
state = -2;
|
182
|
182
|
}
|
183
|
183
|
else if (millis() > 3000000) {
|
|
@@ -192,7 +192,7 @@ void MMU2::mmu_loop() {
|
192
|
192
|
|
193
|
193
|
DEBUG_ECHOLNPAIR("MMU => ", version, "\nMMU <= 'S2'");
|
194
|
194
|
|
195
|
|
- tx_str_P(PSTR("S2\n")); // read build number
|
|
195
|
+ MMU2_COMMAND("S2"); // Read Build Number
|
196
|
196
|
state = -3;
|
197
|
197
|
}
|
198
|
198
|
break;
|
|
@@ -208,13 +208,13 @@ void MMU2::mmu_loop() {
|
208
|
208
|
#if ENABLED(MMU2_MODE_12V)
|
209
|
209
|
DEBUG_ECHOLNPGM("MMU <= 'M1'");
|
210
|
210
|
|
211
|
|
- tx_str_P(PSTR("M1\n")); // switch to stealth mode
|
|
211
|
+ MMU2_COMMAND("M1"); // Stealth Mode
|
212
|
212
|
state = -5;
|
213
|
213
|
|
214
|
214
|
#else
|
215
|
215
|
DEBUG_ECHOLNPGM("MMU <= 'P0'");
|
216
|
216
|
|
217
|
|
- tx_str_P(PSTR("P0\n")); // read finda
|
|
217
|
+ MMU2_COMMAND("P0"); // Read FINDA
|
218
|
218
|
state = -4;
|
219
|
219
|
#endif
|
220
|
220
|
}
|
|
@@ -228,7 +228,7 @@ void MMU2::mmu_loop() {
|
228
|
228
|
|
229
|
229
|
DEBUG_ECHOLNPGM("MMU <= 'P0'");
|
230
|
230
|
|
231
|
|
- tx_str_P(PSTR("P0\n")); // read finda
|
|
231
|
+ MMU2_COMMAND("P0"); // Read FINDA
|
232
|
232
|
state = -4;
|
233
|
233
|
}
|
234
|
234
|
break;
|
|
@@ -266,14 +266,14 @@ void MMU2::mmu_loop() {
|
266
|
266
|
else if (cmd == MMU_CMD_C0) {
|
267
|
267
|
// continue loading
|
268
|
268
|
DEBUG_ECHOLNPGM("MMU <= 'C0'");
|
269
|
|
- tx_str_P(PSTR("C0\n"));
|
|
269
|
+ MMU2_COMMAND("C0");
|
270
|
270
|
state = 3; // wait for response
|
271
|
271
|
}
|
272
|
272
|
else if (cmd == MMU_CMD_U0) {
|
273
|
273
|
// unload current
|
274
|
274
|
DEBUG_ECHOLNPGM("MMU <= 'U0'");
|
275
|
275
|
|
276
|
|
- tx_str_P(PSTR("U0\n"));
|
|
276
|
+ MMU2_COMMAND("U0");
|
277
|
277
|
state = 3; // wait for response
|
278
|
278
|
}
|
279
|
279
|
else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E4)) {
|
|
@@ -286,7 +286,7 @@ void MMU2::mmu_loop() {
|
286
|
286
|
else if (cmd == MMU_CMD_R0) {
|
287
|
287
|
// recover after eject
|
288
|
288
|
DEBUG_ECHOLNPGM("MMU <= 'R0'");
|
289
|
|
- tx_str_P(PSTR("R0\n"));
|
|
289
|
+ MMU2_COMMAND("R0");
|
290
|
290
|
state = 3; // wait for response
|
291
|
291
|
}
|
292
|
292
|
else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F4)) {
|
|
@@ -303,8 +303,7 @@ void MMU2::mmu_loop() {
|
303
|
303
|
cmd = MMU_CMD_NONE;
|
304
|
304
|
}
|
305
|
305
|
else if (ELAPSED(millis(), prev_P0_request + 300)) {
|
306
|
|
- // read FINDA
|
307
|
|
- tx_str_P(PSTR("P0\n"));
|
|
306
|
+ MMU2_COMMAND("P0"); // Read FINDA
|
308
|
307
|
state = 2; // wait for response
|
309
|
308
|
}
|
310
|
309
|
|
|
@@ -332,19 +331,32 @@ void MMU2::mmu_loop() {
|
332
|
331
|
#if ENABLED(MMU_EXTRUDER_SENSOR)
|
333
|
332
|
if (mmu_idl_sens) {
|
334
|
333
|
if (FILAMENT_PRESENT() && mmu_loading_flag) {
|
335
|
|
- DEBUG_ECHOLNPGM("MMU <= 'A'\n");
|
336
|
|
- tx_str_P(PSTR("A\n")); // send 'abort' request
|
|
334
|
+ DEBUG_ECHOLNPGM("MMU <= 'A'");
|
|
335
|
+ MMU2_COMMAND("A"); // send 'abort' request
|
337
|
336
|
mmu_idl_sens = 0;
|
338
|
|
- DEBUG_ECHOLNPGM("MMU IDLER_SENSOR = 0 - ABORT\n");
|
|
337
|
+ DEBUG_ECHOLNPGM("MMU IDLER_SENSOR = 0 - ABORT");
|
339
|
338
|
}
|
340
|
339
|
}
|
341
|
340
|
#endif
|
342
|
341
|
|
343
|
342
|
if (rx_ok()) {
|
344
|
|
- DEBUG_ECHOLNPGM("MMU => 'ok'");
|
345
|
|
- ready = true;
|
346
|
|
- state = 1;
|
347
|
|
- last_cmd = MMU_CMD_NONE;
|
|
343
|
+ // response to C0 mmu command in PRUSA_MMU2_S_MODE
|
|
344
|
+ bool can_reset = true;
|
|
345
|
+ if (ENABLED(PRUSA_MMU2_S_MODE) && last_cmd == MMU_CMD_C0) {
|
|
346
|
+ if (!mmu2s_triggered) {
|
|
347
|
+ can_reset = false;
|
|
348
|
+ // MMU ok received but filament sensor not triggered, retrying...
|
|
349
|
+ DEBUG_ECHOLNPGM("MMU => 'ok' (filament not present in gears)");
|
|
350
|
+ DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)");
|
|
351
|
+ MMU2_COMMAND("C0");
|
|
352
|
+ }
|
|
353
|
+ }
|
|
354
|
+ if (can_reset) {
|
|
355
|
+ DEBUG_ECHOLNPGM("MMU => 'ok'");
|
|
356
|
+ ready = true;
|
|
357
|
+ state = 1;
|
|
358
|
+ last_cmd = MMU_CMD_NONE;
|
|
359
|
+ }
|
348
|
360
|
}
|
349
|
361
|
else if (ELAPSED(millis(), prev_request + MMU_CMD_TIMEOUT)) {
|
350
|
362
|
// resend request after timeout
|
|
@@ -862,9 +874,18 @@ void MMU2::filament_runout() {
|
862
|
874
|
|
863
|
875
|
void MMU2::check_filament() {
|
864
|
876
|
const bool present = FILAMENT_PRESENT();
|
865
|
|
- if (present && !mmu2s_triggered) {
|
866
|
|
- DEBUG_ECHOLNPGM("MMU <= 'A'");
|
867
|
|
- tx_str_P(PSTR("A\n"));
|
|
877
|
+ if (cmd == MMU_CMD_NONE && last_cmd == MMU_CMD_C0) {
|
|
878
|
+ if (present && !mmu2s_triggered) {
|
|
879
|
+ DEBUG_ECHOLNPGM("MMU <= 'A'");
|
|
880
|
+ tx_str_P(PSTR("A\n"));
|
|
881
|
+ }
|
|
882
|
+ // Slowly spin the extruder during C0
|
|
883
|
+ else {
|
|
884
|
+ while (planner.movesplanned() < 3) {
|
|
885
|
+ current_position.e += 0.25;
|
|
886
|
+ line_to_current_position(MMM_TO_MMS(120));
|
|
887
|
+ }
|
|
888
|
+ }
|
868
|
889
|
}
|
869
|
890
|
mmu2s_triggered = present;
|
870
|
891
|
}
|