Browse Source

Split get_command into units, rename to get_available_commands

Scott Lahteine 8 years ago
parent
commit
0b8ef5eba6
2 changed files with 29 additions and 19 deletions
  1. 0
    3
      Marlin/Marlin.h
  2. 29
    16
      Marlin/Marlin_main.cpp

+ 0
- 3
Marlin/Marlin.h View File

@@ -109,7 +109,6 @@ void serial_echopair_P(const char* s_P, float v);
109 109
 void serial_echopair_P(const char* s_P, double v);
110 110
 void serial_echopair_P(const char* s_P, unsigned long v);
111 111
 
112
-
113 112
 // Things to write to serial from Program memory. Saves 400 to 2k of RAM.
114 113
 FORCE_INLINE void serialprintPGM(const char* str) {
115 114
   char ch;
@@ -119,8 +118,6 @@ FORCE_INLINE void serialprintPGM(const char* str) {
119 118
   }
120 119
 }
121 120
 
122
-void get_command();
123
-
124 121
 void idle(
125 122
   #if ENABLED(FILAMENTCHANGEENABLE)
126 123
     bool no_stepper_sleep=false  // pass true to keep steppers from disabling on timeout

+ 29
- 16
Marlin/Marlin_main.cpp View File

@@ -462,6 +462,7 @@ static bool send_ok[BUFSIZE];
462 462
  * ***************************************************************************
463 463
  */
464 464
 
465
+void get_available_commands();
465 466
 void process_next_command();
466 467
 
467 468
 void plan_arc(float target[NUM_AXIS], float* offset, uint8_t clockwise);
@@ -804,7 +805,7 @@ void setup() {
804 805
  *  - Call LCD update
805 806
  */
806 807
 void loop() {
807
-  if (commands_in_queue < BUFSIZE) get_command();
808
+  if (commands_in_queue < BUFSIZE) get_available_commands();
808 809
 
809 810
   #if ENABLED(SDSUPPORT)
810 811
     card.checkautostart(false);
@@ -856,24 +857,16 @@ void gcode_line_error(const char* err, bool doFlush = true) {
856 857
   serial_count = 0;
857 858
 }
858 859
 
859
-/**
860
- * Add to the circular command queue the next command from:
861
- *  - The command-injection queue (queued_commands_P)
862
- *  - The active serial input (usually USB)
863
- *  - The SD card file being actively printed
864
- */
865
-void get_command() {
866
-
860
+inline void get_serial_commands() {
867 861
   static char serial_line_buffer[MAX_CMD_SIZE];
868 862
   static boolean serial_comment_mode = false;
869 863
 
870
-  if (drain_queued_commands_P()) return; // priority is given to non-serial commands
871
-
864
+  // If the command buffer is empty for too long,
865
+  // send "wait" to indicate Marlin is still waiting.
872 866
   #if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
873 867
     static millis_t last_command_time = 0;
874 868
     millis_t ms = millis();
875
-
876
-    if (!MYSERIAL.available() && commands_in_queue == 0 && ms - last_command_time > NO_TIMEOUTS) {
869
+    if (commands_in_queue == 0 && !MYSERIAL.available() && ms > last_command_time + NO_TIMEOUTS) {
877 870
       SERIAL_ECHOLNPGM(MSG_WAIT);
878 871
       last_command_time = ms;
879 872
     }
@@ -988,9 +981,11 @@ void get_command() {
988 981
     }
989 982
 
990 983
   } // queue has space, serial has data
984
+}
991 985
 
992
-  #if ENABLED(SDSUPPORT)
986
+#if ENABLED(SDSUPPORT)
993 987
 
988
+  inline void get_sdcard_commands() {
994 989
     static bool stop_buffering = false,
995 990
                 sd_comment_mode = false;
996 991
 
@@ -1050,8 +1045,26 @@ void get_command() {
1050 1045
         if (!sd_comment_mode) command_queue[cmd_queue_index_w][sd_count++] = sd_char;
1051 1046
       }
1052 1047
     }
1048
+  }
1053 1049
 
1054
-  #endif // SDSUPPORT
1050
+#endif // SDSUPPORT
1051
+
1052
+/**
1053
+ * Add to the circular command queue the next command from:
1054
+ *  - The command-injection queue (queued_commands_P)
1055
+ *  - The active serial input (usually USB)
1056
+ *  - The SD card file being actively printed
1057
+ */
1058
+void get_available_commands() {
1059
+
1060
+  // if any immediate commands remain, don't get other commands yet
1061
+  if (drain_queued_commands_P()) return;
1062
+
1063
+  get_serial_commands();
1064
+
1065
+  #if ENABLED(SDSUPPORT)
1066
+    get_sdcard_commands();
1067
+  #endif
1055 1068
 }
1056 1069
 
1057 1070
 bool code_has_value() {
@@ -7362,7 +7375,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
7362 7375
       filrunout();
7363 7376
   #endif
7364 7377
 
7365
-  if (commands_in_queue < BUFSIZE) get_command();
7378
+  if (commands_in_queue < BUFSIZE) get_available_commands();
7366 7379
 
7367 7380
   millis_t ms = millis();
7368 7381
 

Loading…
Cancel
Save