revilor пре 6 година
родитељ
комит
69aaf5d096
2 измењених фајлова са 32 додато и 21 уклоњено
  1. 19
    20
      Marlin/src/feature/prusa_MMU2/mmu2.cpp
  2. 13
    1
      Marlin/src/feature/prusa_MMU2/mmu2.h

+ 19
- 20
Marlin/src/feature/prusa_MMU2/mmu2.cpp Прегледај датотеку

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

+ 13
- 1
Marlin/src/feature/prusa_MMU2/mmu2.h Прегледај датотеку

24
 
24
 
25
 #include "../../inc/MarlinConfig.h"
25
 #include "../../inc/MarlinConfig.h"
26
 
26
 
27
+#if ENABLED(FILAMENT_RUNOUT_SENSOR)
28
+  #include "../runout.h"
29
+#endif
30
+
27
 struct E_Step;
31
 struct E_Step;
28
 
32
 
29
 class MMU2 {
33
 class MMU2 {
75
   static volatile int8_t finda;
79
   static volatile int8_t finda;
76
   static volatile bool findaRunoutValid;
80
   static volatile bool findaRunoutValid;
77
   static int16_t version, buildnr;
81
   static int16_t version, buildnr;
78
-  static millis_t next_request, next_response;
82
+  static millis_t last_request, next_P0_request;
79
   static char rx_buffer[16], tx_buffer[16];
83
   static char rx_buffer[16], tx_buffer[16];
84
+
85
+  static inline void set_runout_valid(const bool valid) {
86
+    findaRunoutValid = valid;
87
+    #if ENABLED(FILAMENT_RUNOUT_SENSOR)
88
+      if (valid) runout.reset();
89
+    #endif
90
+  }
91
+
80
 };
92
 };
81
 
93
 
82
 extern MMU2 mmu2;
94
 extern MMU2 mmu2;

Loading…
Откажи
Сачувај