Browse Source

Send a Busy signal to hosts during long processes, wait for input, etc

If Marlin is blocking the serial input or command queue for any length
of time (for example more than 2 seconds), it needs to send a message
to serial out to inform the host that it is busy. Marlin should only
send these messages out when busy, and preferably not when trying to
print formatted output.
Scott Lahteine 8 years ago
parent
commit
7ec7bb31c4

+ 7
- 0
Marlin/Conditionals.h View File

@@ -315,6 +315,13 @@
315 315
   #endif
316 316
 
317 317
   /**
318
+   * Avoid double-negatives for enabling features
319
+   */
320
+  #if DISABLED(DISABLE_HOST_KEEPALIVE)
321
+    #define HOST_KEEPALIVE_FEATURE
322
+  #endif
323
+
324
+  /**
318 325
    * MAX_STEP_FREQUENCY differs for TOSHIBA
319 326
    */
320 327
   #if ENABLED(CONFIG_STEPPERS_TOSHIBA)

+ 8
- 0
Marlin/Configuration.h View File

@@ -647,6 +647,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
647 647
 #endif
648 648
 
649 649
 //
650
+// Host Keepalive
651
+//
652
+// By default Marlin will send a busy status message to the host
653
+// every 2 seconds when it can't accept commands.
654
+//
655
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
656
+
657
+//
650 658
 // M100 Free Memory Watcher
651 659
 //
652 660
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 72
- 3
Marlin/Marlin_main.cpp View File

@@ -426,6 +426,26 @@ static uint8_t target_extruder;
426 426
   int lpq_len = 20;
427 427
 #endif
428 428
 
429
+#if ENABLED(HOST_KEEPALIVE_FEATURE)
430
+
431
+  // States for managing Marlin and host communication
432
+  // Marlin sends messages if blocked or busy
433
+  enum MarlinBusyState {
434
+    NOT_BUSY,           // Not in a handler
435
+    IN_HANDLER,         // Processing a GCode
436
+    IN_PROCESS,         // Known to be blocking command input (as in G29)
437
+    PAUSED_FOR_USER,    // Blocking pending any input
438
+    PAUSED_FOR_INPUT    // Blocking pending text input (concept)
439
+  };
440
+
441
+  static MarlinBusyState busy_state = NOT_BUSY;
442
+  static millis_t next_busy_signal_ms = -1;
443
+  #define KEEPALIVE_STATE(n) do{ busy_state = n; }while(0)
444
+#else
445
+  #define host_keepalive() ;
446
+  #define KEEPALIVE_STATE(n) ;
447
+#endif // HOST_KEEPALIVE_FEATURE
448
+
429 449
 //===========================================================================
430 450
 //================================ Functions ================================
431 451
 //===========================================================================
@@ -2130,6 +2150,35 @@ void unknown_command_error() {
2130 2150
   SERIAL_ECHOPGM("\"\n");
2131 2151
 }
2132 2152
 
2153
+#if ENABLED(HOST_KEEPALIVE_FEATURE)
2154
+
2155
+  void host_keepalive() {
2156
+    millis_t ms = millis();
2157
+    if (busy_state != NOT_BUSY) {
2158
+      if (ms < next_busy_signal_ms) return;
2159
+      switch (busy_state) {
2160
+        case NOT_BUSY:
2161
+          break;
2162
+        case IN_HANDLER:
2163
+        case IN_PROCESS:
2164
+          SERIAL_ECHO_START;
2165
+          SERIAL_ECHOLNPGM(MSG_BUSY_PROCESSING);
2166
+          break;
2167
+        case PAUSED_FOR_USER:
2168
+          SERIAL_ECHO_START;
2169
+          SERIAL_ECHOLNPGM(MSG_BUSY_PAUSED_FOR_USER);
2170
+          break;
2171
+        case PAUSED_FOR_INPUT:
2172
+          SERIAL_ECHO_START;
2173
+          SERIAL_ECHOLNPGM(MSG_BUSY_PAUSED_FOR_INPUT);
2174
+          break;
2175
+      }
2176
+    }
2177
+    next_busy_signal_ms = ms + 2000UL;
2178
+  }
2179
+
2180
+#endif //HOST_KEEPALIVE_FEATURE
2181
+
2133 2182
 /**
2134 2183
  * G0, G1: Coordinated movement of X Y Z E axes
2135 2184
  */
@@ -3219,6 +3268,8 @@ inline void gcode_G28() {
3219 3268
       st_synchronize();
3220 3269
     #endif
3221 3270
 
3271
+    KEEPALIVE_STATE(IN_HANDLER);
3272
+
3222 3273
     #if ENABLED(DEBUG_LEVELING_FEATURE)
3223 3274
       if (marlin_debug_flags & DEBUG_LEVELING) {
3224 3275
         SERIAL_ECHOLNPGM("<<< gcode_G29");
@@ -3325,12 +3376,16 @@ inline void gcode_G92() {
3325 3376
     refresh_cmd_timeout();
3326 3377
     if (codenum > 0) {
3327 3378
       codenum += previous_cmd_ms;  // wait until this time for a click
3379
+      KEEPALIVE_STATE(PAUSED_FOR_USER);
3328 3380
       while (millis() < codenum && !lcd_clicked()) idle();
3381
+      KEEPALIVE_STATE(IN_HANDLER);
3329 3382
       lcd_ignore_click(false);
3330 3383
     }
3331 3384
     else {
3332 3385
       if (!lcd_detected()) return;
3386
+      KEEPALIVE_STATE(PAUSED_FOR_USER);
3333 3387
       while (!lcd_clicked()) idle();
3388
+      KEEPALIVE_STATE(IN_HANDLER);
3334 3389
     }
3335 3390
     if (IS_SD_PRINTING)
3336 3391
       LCD_MESSAGEPGM(MSG_RESUMING);
@@ -4963,6 +5018,8 @@ inline void gcode_M303() {
4963 5018
 
4964 5019
   if (e >=0 && e < EXTRUDERS)
4965 5020
     target_extruder = e;
5021
+
5022
+  KEEPALIVE_STATE(NOT_BUSY);
4966 5023
   PID_autotune(temp, e, c);
4967 5024
 }
4968 5025
 
@@ -5334,6 +5391,13 @@ inline void gcode_M503() {
5334 5391
 
5335 5392
 #if ENABLED(FILAMENTCHANGEENABLE)
5336 5393
 
5394
+  inline void idle2() {
5395
+    manage_heater();
5396
+    manage_inactivity(true);
5397
+    host_keepalive();
5398
+    lcd_update();
5399
+  }
5400
+
5337 5401
   /**
5338 5402
    * M600: Pause for filament change
5339 5403
    *
@@ -5412,6 +5476,7 @@ inline void gcode_M503() {
5412 5476
     delay(100);
5413 5477
     LCD_ALERTMESSAGEPGM(MSG_FILAMENTCHANGE);
5414 5478
     millis_t next_tick = 0;
5479
+    KEEPALIVE_STATE(WAIT_FOR_USER);
5415 5480
     while (!lcd_clicked()) {
5416 5481
       #if DISABLED(AUTO_FILAMENT_CHANGE)
5417 5482
         millis_t ms = millis();
@@ -5419,9 +5484,7 @@ inline void gcode_M503() {
5419 5484
           lcd_quick_feedback();
5420 5485
           next_tick = ms + 2500; // feedback every 2.5s while waiting
5421 5486
         }
5422
-        manage_heater();
5423
-        manage_inactivity(true);
5424
-        lcd_update();
5487
+        idle2();
5425 5488
       #else
5426 5489
         current_position[E_AXIS] += AUTO_FILAMENT_CHANGE_LENGTH;
5427 5490
         destination[E_AXIS] = current_position[E_AXIS];
@@ -5429,6 +5492,7 @@ inline void gcode_M503() {
5429 5492
         st_synchronize();
5430 5493
       #endif
5431 5494
     } // while(!lcd_clicked)
5495
+    KEEPALIVE_STATE(IN_HANDLER);
5432 5496
     lcd_quick_feedback(); // click sound feedback
5433 5497
 
5434 5498
     #if ENABLED(AUTO_FILAMENT_CHANGE)
@@ -5765,6 +5829,8 @@ void process_next_command() {
5765 5829
   seen_pointer = current_command;
5766 5830
   codenum = code_value_short();
5767 5831
 
5832
+  KEEPALIVE_STATE(IN_HANDLER);
5833
+
5768 5834
   // Handle a known G, M, or T
5769 5835
   switch (command_code) {
5770 5836
     case 'G': switch (codenum) {
@@ -6286,6 +6352,8 @@ void process_next_command() {
6286 6352
     default: code_is_good = false;
6287 6353
   }
6288 6354
 
6355
+  KEEPALIVE_STATE(NOT_BUSY);
6356
+
6289 6357
 ExitUnknownCommand:
6290 6358
 
6291 6359
   // Still unknown command? Throw an error
@@ -6975,6 +7043,7 @@ void disable_all_steppers() {
6975 7043
 void idle() {
6976 7044
   manage_heater();
6977 7045
   manage_inactivity();
7046
+  host_keepalive();
6978 7047
   lcd_update();
6979 7048
 }
6980 7049
 

+ 8
- 0
Marlin/example_configurations/Felix/Configuration.h View File

@@ -630,6 +630,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
630 630
 #endif
631 631
 
632 632
 //
633
+// Host Keepalive
634
+//
635
+// By default Marlin will send a busy status message to the host
636
+// every 2 seconds when it can't accept commands.
637
+//
638
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
639
+
640
+//
633 641
 // M100 Free Memory Watcher
634 642
 //
635 643
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/Felix/Configuration_DUAL.h View File

@@ -627,6 +627,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
627 627
 #endif
628 628
 
629 629
 //
630
+// Host Keepalive
631
+//
632
+// By default Marlin will send a busy status message to the host
633
+// every 2 seconds when it can't accept commands.
634
+//
635
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
636
+
637
+//
630 638
 // M100 Free Memory Watcher
631 639
 //
632 640
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/Hephestos/Configuration.h View File

@@ -639,6 +639,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo
639 639
 #endif
640 640
 
641 641
 //
642
+// Host Keepalive
643
+//
644
+// By default Marlin will send a busy status message to the host
645
+// every 2 seconds when it can't accept commands.
646
+//
647
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
648
+
649
+//
642 650
 // M100 Free Memory Watcher
643 651
 //
644 652
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/Hephestos_2/Configuration.h View File

@@ -642,6 +642,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
642 642
 #endif
643 643
 
644 644
 //
645
+// Host Keepalive
646
+//
647
+// By default Marlin will send a busy status message to the host
648
+// every 2 seconds when it can't accept commands.
649
+//
650
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
651
+
652
+//
645 653
 // M100 Free Memory Watcher
646 654
 //
647 655
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/K8200/Configuration.h View File

@@ -662,6 +662,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
662 662
 #endif
663 663
 
664 664
 //
665
+// Host Keepalive
666
+//
667
+// By default Marlin will send a busy status message to the host
668
+// every 2 seconds when it can't accept commands.
669
+//
670
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
671
+
672
+//
665 673
 // M100 Free Memory Watcher
666 674
 //
667 675
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h View File

@@ -647,6 +647,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
647 647
 #endif
648 648
 
649 649
 //
650
+// Host Keepalive
651
+//
652
+// By default Marlin will send a busy status message to the host
653
+// every 2 seconds when it can't accept commands.
654
+//
655
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
656
+
657
+//
650 658
 // M100 Free Memory Watcher
651 659
 //
652 660
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/RigidBot/Configuration.h View File

@@ -642,6 +642,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
642 642
 #endif
643 643
 
644 644
 //
645
+// Host Keepalive
646
+//
647
+// By default Marlin will send a busy status message to the host
648
+// every 2 seconds when it can't accept commands.
649
+//
650
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
651
+
652
+//
645 653
 // M100 Free Memory Watcher
646 654
 //
647 655
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/SCARA/Configuration.h View File

@@ -655,6 +655,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
655 655
 #endif
656 656
 
657 657
 //
658
+// Host Keepalive
659
+//
660
+// By default Marlin will send a busy status message to the host
661
+// every 2 seconds when it can't accept commands.
662
+//
663
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
664
+
665
+//
658 666
 // M100 Free Memory Watcher
659 667
 //
660 668
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/TAZ4/Configuration.h View File

@@ -667,6 +667,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
667 667
 #endif
668 668
 
669 669
 //
670
+// Host Keepalive
671
+//
672
+// By default Marlin will send a busy status message to the host
673
+// every 2 seconds when it can't accept commands.
674
+//
675
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
676
+
677
+//
670 678
 // M100 Free Memory Watcher
671 679
 //
672 680
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/WITBOX/Configuration.h View File

@@ -639,6 +639,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo
639 639
 #endif
640 640
 
641 641
 //
642
+// Host Keepalive
643
+//
644
+// By default Marlin will send a busy status message to the host
645
+// every 2 seconds when it can't accept commands.
646
+//
647
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
648
+
649
+//
642 650
 // M100 Free Memory Watcher
643 651
 //
644 652
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/adafruit/ST7565/Configuration.h View File

@@ -647,6 +647,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
647 647
 #endif
648 648
 
649 649
 //
650
+// Host Keepalive
651
+//
652
+// By default Marlin will send a busy status message to the host
653
+// every 2 seconds when it can't accept commands.
654
+//
655
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
656
+
657
+//
650 658
 // M100 Free Memory Watcher
651 659
 //
652 660
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/delta/biv2.5/Configuration.h View File

@@ -769,6 +769,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo
769 769
 #endif
770 770
 
771 771
 //
772
+// Host Keepalive
773
+//
774
+// By default Marlin will send a busy status message to the host
775
+// every 2 seconds when it can't accept commands.
776
+//
777
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
778
+
779
+//
772 780
 // M100 Free Memory Watcher
773 781
 //
774 782
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/delta/generic/Configuration.h View File

@@ -769,6 +769,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo
769 769
 #endif
770 770
 
771 771
 //
772
+// Host Keepalive
773
+//
774
+// By default Marlin will send a busy status message to the host
775
+// every 2 seconds when it can't accept commands.
776
+//
777
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
778
+
779
+//
772 780
 // M100 Free Memory Watcher
773 781
 //
774 782
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/delta/kossel_mini/Configuration.h View File

@@ -773,6 +773,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
773 773
 #endif
774 774
 
775 775
 //
776
+// Host Keepalive
777
+//
778
+// By default Marlin will send a busy status message to the host
779
+// every 2 seconds when it can't accept commands.
780
+//
781
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
782
+
783
+//
776 784
 // M100 Free Memory Watcher
777 785
 //
778 786
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/delta/kossel_pro/Configuration.h View File

@@ -764,6 +764,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
764 764
 #endif
765 765
 
766 766
 //
767
+// Host Keepalive
768
+//
769
+// By default Marlin will send a busy status message to the host
770
+// every 2 seconds when it can't accept commands.
771
+//
772
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
773
+
774
+//
767 775
 // M100 Free Memory Watcher
768 776
 //
769 777
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/delta/kossel_xl/Configuration.h View File

@@ -683,6 +683,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
683 683
 #endif
684 684
 
685 685
 //
686
+// Host Keepalive
687
+//
688
+// By default Marlin will send a busy status message to the host
689
+// every 2 seconds when it can't accept commands.
690
+//
691
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
692
+
693
+//
686 694
 // M100 Free Memory Watcher
687 695
 //
688 696
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/makibox/Configuration.h View File

@@ -650,6 +650,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
650 650
 #endif
651 651
 
652 652
 //
653
+// Host Keepalive
654
+//
655
+// By default Marlin will send a busy status message to the host
656
+// every 2 seconds when it can't accept commands.
657
+//
658
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
659
+
660
+//
653 661
 // M100 Free Memory Watcher
654 662
 //
655 663
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 8
- 0
Marlin/example_configurations/tvrrug/Round2/Configuration.h View File

@@ -641,6 +641,14 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo
641 641
 #endif
642 642
 
643 643
 //
644
+// Host Keepalive
645
+//
646
+// By default Marlin will send a busy status message to the host
647
+// every 2 seconds when it can't accept commands.
648
+//
649
+//#define DISABLE_HOST_KEEPALIVE // Enable this option if your host doesn't like keepalive messages.
650
+
651
+//
644 652
 // M100 Free Memory Watcher
645 653
 //
646 654
 //#define M100_FREE_MEMORY_WATCHER // uncomment to add the M100 Free Memory Watcher for debug purpose

+ 3
- 0
Marlin/language.h View File

@@ -124,6 +124,9 @@
124 124
 #define MSG_COUNT_A                         " Count A: "
125 125
 #define MSG_ERR_KILLED                      "Printer halted. kill() called!"
126 126
 #define MSG_ERR_STOPPED                     "Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)"
127
+#define MSG_BUSY_PROCESSING                 "busy: processing"
128
+#define MSG_BUSY_PAUSED_FOR_USER            "busy: paused for user"
129
+#define MSG_BUSY_PAUSED_FOR_INPUT           "busy: paused for input"
127 130
 #define MSG_RESEND                          "Resend: "
128 131
 #define MSG_UNKNOWN_COMMAND                 "Unknown command: \""
129 132
 #define MSG_ACTIVE_EXTRUDER                 "Active Extruder: "

Loading…
Cancel
Save