Browse Source

Merge pull request #3109 from thinkyhead/rc_host_keepalive

Provide feedback to hosts when busy
Scott Lahteine 8 years ago
parent
commit
4ae03df5c2

+ 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

+ 5
- 1
Marlin/Marlin.h View File

@@ -103,7 +103,11 @@ FORCE_INLINE void serialprintPGM(const char* str) {
103 103
 
104 104
 void get_command();
105 105
 
106
-void idle(); // the standard idle routine calls manage_inactivity(false)
106
+void idle(
107
+  #if ENABLED(FILAMENTCHANGEENABLE)
108
+    bool no_stepper_sleep=false  // pass true to keep steppers from disabling on timeout
109
+  #endif
110
+);
107 111
 
108 112
 void manage_inactivity(bool ignore_stepper_queue = false);
109 113
 

+ 75
- 5
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
 
@@ -5412,6 +5469,7 @@ inline void gcode_M503() {
5412 5469
     delay(100);
5413 5470
     LCD_ALERTMESSAGEPGM(MSG_FILAMENTCHANGE);
5414 5471
     millis_t next_tick = 0;
5472
+    KEEPALIVE_STATE(WAIT_FOR_USER);
5415 5473
     while (!lcd_clicked()) {
5416 5474
       #if DISABLED(AUTO_FILAMENT_CHANGE)
5417 5475
         millis_t ms = millis();
@@ -5419,9 +5477,7 @@ inline void gcode_M503() {
5419 5477
           lcd_quick_feedback();
5420 5478
           next_tick = ms + 2500; // feedback every 2.5s while waiting
5421 5479
         }
5422
-        manage_heater();
5423
-        manage_inactivity(true);
5424
-        lcd_update();
5480
+        idle(true);
5425 5481
       #else
5426 5482
         current_position[E_AXIS] += AUTO_FILAMENT_CHANGE_LENGTH;
5427 5483
         destination[E_AXIS] = current_position[E_AXIS];
@@ -5429,6 +5485,7 @@ inline void gcode_M503() {
5429 5485
         st_synchronize();
5430 5486
       #endif
5431 5487
     } // while(!lcd_clicked)
5488
+    KEEPALIVE_STATE(IN_HANDLER);
5432 5489
     lcd_quick_feedback(); // click sound feedback
5433 5490
 
5434 5491
     #if ENABLED(AUTO_FILAMENT_CHANGE)
@@ -5765,6 +5822,8 @@ void process_next_command() {
5765 5822
   seen_pointer = current_command;
5766 5823
   codenum = code_value_short();
5767 5824
 
5825
+  KEEPALIVE_STATE(IN_HANDLER);
5826
+
5768 5827
   // Handle a known G, M, or T
5769 5828
   switch (command_code) {
5770 5829
     case 'G': switch (codenum) {
@@ -6286,6 +6345,8 @@ void process_next_command() {
6286 6345
     default: code_is_good = false;
6287 6346
   }
6288 6347
 
6348
+  KEEPALIVE_STATE(NOT_BUSY);
6349
+
6289 6350
 ExitUnknownCommand:
6290 6351
 
6291 6352
   // Still unknown command? Throw an error
@@ -6972,9 +7033,18 @@ void disable_all_steppers() {
6972 7033
 /**
6973 7034
  * Standard idle routine keeps the machine alive
6974 7035
  */
6975
-void idle() {
7036
+void idle(
7037
+  #if ENABLED(FILAMENTCHANGEENABLE)
7038
+    bool no_stepper_sleep/*=false*/
7039
+  #endif
7040
+) {
6976 7041
   manage_heater();
6977
-  manage_inactivity();
7042
+  manage_inactivity(
7043
+    #if ENABLED(FILAMENTCHANGEENABLE)
7044
+      no_stepper_sleep
7045
+    #endif
7046
+  );
7047
+  host_keepalive();
6978 7048
   lcd_update();
6979 7049
 }
6980 7050
 

+ 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