|
@@ -38,10 +38,6 @@ MMU2 mmu2;
|
38
|
38
|
#include "../../module/stepper_indirection.h"
|
39
|
39
|
#include "../../Marlin.h"
|
40
|
40
|
|
41
|
|
-#if ENABLED(FILAMENT_RUNOUT_SENSOR)
|
42
|
|
- #include "../runout.h"
|
43
|
|
-#endif
|
44
|
|
-
|
45
|
41
|
#define MMU_TODELAY 100
|
46
|
42
|
#define MMU_TIMEOUT 10
|
47
|
43
|
#define MMU_CMD_TIMEOUT 60000ul //5min timeout for mmu commands (except P0)
|
|
@@ -89,7 +85,7 @@ int8_t MMU2::state = 0;
|
89
|
85
|
volatile int8_t MMU2::finda = 1;
|
90
|
86
|
volatile bool MMU2::findaRunoutValid;
|
91
|
87
|
int16_t MMU2::version = -1, MMU2::buildnr = -1;
|
92
|
|
-millis_t MMU2::next_request, MMU2::next_response;
|
|
88
|
+millis_t MMU2::last_request, MMU2::next_P0_request;
|
93
|
89
|
char MMU2::rx_buffer[16], MMU2::tx_buffer[16];
|
94
|
90
|
|
95
|
91
|
#if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
|
|
@@ -109,7 +105,8 @@ MMU2::MMU2() {
|
109
|
105
|
}
|
110
|
106
|
|
111
|
107
|
void MMU2::init() {
|
112
|
|
- findaRunoutValid = false;
|
|
108
|
+
|
|
109
|
+ set_runout_valid(false);
|
113
|
110
|
|
114
|
111
|
#if PIN_EXISTS(MMU2_RST)
|
115
|
112
|
// TODO use macros for this
|
|
@@ -321,7 +318,7 @@ void MMU2::mmuLoop() {
|
321
|
318
|
last_cmd = cmd;
|
322
|
319
|
cmd = MMU_CMD_NONE;
|
323
|
320
|
}
|
324
|
|
- else if (ELAPSED(millis(), next_response)) {
|
|
321
|
+ else if (ELAPSED(millis(), next_P0_request)) {
|
325
|
322
|
// read FINDA
|
326
|
323
|
tx_str_P(PSTR("P0\n"));
|
327
|
324
|
state = 2; // wait for response
|
|
@@ -350,7 +347,7 @@ void MMU2::mmuLoop() {
|
350
|
347
|
|
351
|
348
|
if (!finda && findaRunoutValid) filamentRunout();
|
352
|
349
|
}
|
353
|
|
- else if (ELAPSED(millis(), next_request)) // Resend request after timeout (30s)
|
|
350
|
+ else if (ELAPSED(millis(), last_request + MMU_P0_TIMEOUT)) // Resend request after timeout (30s)
|
354
|
351
|
state = 1;
|
355
|
352
|
|
356
|
353
|
break;
|
|
@@ -365,7 +362,7 @@ void MMU2::mmuLoop() {
|
365
|
362
|
state = 1;
|
366
|
363
|
last_cmd = MMU_CMD_NONE;
|
367
|
364
|
}
|
368
|
|
- else if (ELAPSED(millis(), next_request)) {
|
|
365
|
+ else if (ELAPSED(millis(), last_request + MMU_CMD_TIMEOUT)) {
|
369
|
366
|
// resend request after timeout
|
370
|
367
|
if (last_cmd) {
|
371
|
368
|
#if ENABLED(MMU2_DEBUG)
|
|
@@ -388,7 +385,7 @@ void MMU2::mmuLoop() {
|
388
|
385
|
bool MMU2::rx_start() {
|
389
|
386
|
// check for start message
|
390
|
387
|
if (rx_str_P(PSTR("start\n"))) {
|
391
|
|
- next_response = millis() + 300;
|
|
388
|
+ next_P0_request = millis() + 300;
|
392
|
389
|
return true;
|
393
|
390
|
}
|
394
|
391
|
return false;
|
|
@@ -439,7 +436,7 @@ void MMU2::tx_str_P(const char* str) {
|
439
|
436
|
uint8_t len = strlen_P(str);
|
440
|
437
|
for (uint8_t i = 0; i < len; i++) mmuSerial.write(pgm_read_byte(str++));
|
441
|
438
|
rx_buffer[0] = '\0';
|
442
|
|
- next_request = millis() + MMU_P0_TIMEOUT;
|
|
439
|
+ last_request = millis();
|
443
|
440
|
}
|
444
|
441
|
|
445
|
442
|
|
|
@@ -451,7 +448,7 @@ void MMU2::tx_printf_P(const char* format, int argument = -1) {
|
451
|
448
|
uint8_t len = sprintf_P(tx_buffer, format, argument);
|
452
|
449
|
for (uint8_t i = 0; i < len; i++) mmuSerial.write(tx_buffer[i]);
|
453
|
450
|
rx_buffer[0] = '\0';
|
454
|
|
- next_request = millis() + MMU_P0_TIMEOUT;
|
|
451
|
+ last_request = millis();
|
455
|
452
|
}
|
456
|
453
|
|
457
|
454
|
|
|
@@ -463,7 +460,7 @@ void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
|
463
|
460
|
uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
|
464
|
461
|
for (uint8_t i = 0; i < len; i++) mmuSerial.write(tx_buffer[i]);
|
465
|
462
|
rx_buffer[0] = '\0';
|
466
|
|
- next_request = millis() + MMU_P0_TIMEOUT;
|
|
463
|
+ last_request = millis();
|
467
|
464
|
}
|
468
|
465
|
|
469
|
466
|
|
|
@@ -481,7 +478,7 @@ void MMU2::clear_rx_buffer() {
|
481
|
478
|
*/
|
482
|
479
|
bool MMU2::rx_ok() {
|
483
|
480
|
if (rx_str_P(PSTR("ok\n"))) {
|
484
|
|
- next_response = millis() + 300;
|
|
481
|
+ next_P0_request = millis() + 300;
|
485
|
482
|
return true;
|
486
|
483
|
}
|
487
|
484
|
return false;
|
|
@@ -508,7 +505,7 @@ void MMU2::toolChange(uint8_t index) {
|
508
|
505
|
|
509
|
506
|
if (!enabled) return;
|
510
|
507
|
|
511
|
|
- findaRunoutValid = false;
|
|
508
|
+ set_runout_valid(false);
|
512
|
509
|
|
513
|
510
|
if (index != extruder) {
|
514
|
511
|
|
|
@@ -534,7 +531,7 @@ void MMU2::toolChange(uint8_t index) {
|
534
|
531
|
KEEPALIVE_STATE(NOT_BUSY);
|
535
|
532
|
}
|
536
|
533
|
|
537
|
|
- findaRunoutValid = true;
|
|
534
|
+ set_runout_valid(true);
|
538
|
535
|
}
|
539
|
536
|
|
540
|
537
|
|
|
@@ -553,7 +550,7 @@ void MMU2::toolChange(const char* special) {
|
553
|
550
|
|
554
|
551
|
#if ENABLED(MMU2_MENUS)
|
555
|
552
|
|
556
|
|
- findaRunoutValid = false;
|
|
553
|
+ set_runout_valid(false);
|
557
|
554
|
KEEPALIVE_STATE(IN_HANDLER);
|
558
|
555
|
|
559
|
556
|
switch(*special) {
|
|
@@ -585,7 +582,7 @@ void MMU2::toolChange(const char* special) {
|
585
|
582
|
|
586
|
583
|
KEEPALIVE_STATE(NOT_BUSY);
|
587
|
584
|
|
588
|
|
- findaRunoutValid = true;
|
|
585
|
+ set_runout_valid(true);
|
589
|
586
|
|
590
|
587
|
#endif
|
591
|
588
|
}
|
|
@@ -806,7 +803,8 @@ void MMU2::filamentRunout() {
|
806
|
803
|
|
807
|
804
|
// no active tool
|
808
|
805
|
extruder = MMU2_NO_TOOL;
|
809
|
|
- findaRunoutValid = false;
|
|
806
|
+
|
|
807
|
+ set_runout_valid(false);
|
810
|
808
|
|
811
|
809
|
BUZZ(200, 404);
|
812
|
810
|
|
|
@@ -845,7 +843,8 @@ void MMU2::filamentRunout() {
|
845
|
843
|
|
846
|
844
|
// no active tool
|
847
|
845
|
extruder = MMU2_NO_TOOL;
|
848
|
|
- findaRunoutValid = false;
|
|
846
|
+
|
|
847
|
+ set_runout_valid(false);
|
849
|
848
|
|
850
|
849
|
KEEPALIVE_STATE(NOT_BUSY);
|
851
|
850
|
|