瀏覽代碼

Split get_command into units, rename to get_available_commands

Scott Lahteine 9 年之前
父節點
當前提交
0b8ef5eba6
共有 2 個檔案被更改,包括 29 行新增19 行删除
  1. 0
    3
      Marlin/Marlin.h
  2. 29
    16
      Marlin/Marlin_main.cpp

+ 0
- 3
Marlin/Marlin.h 查看文件

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

+ 29
- 16
Marlin/Marlin_main.cpp 查看文件

462
  * ***************************************************************************
462
  * ***************************************************************************
463
  */
463
  */
464
 
464
 
465
+void get_available_commands();
465
 void process_next_command();
466
 void process_next_command();
466
 
467
 
467
 void plan_arc(float target[NUM_AXIS], float* offset, uint8_t clockwise);
468
 void plan_arc(float target[NUM_AXIS], float* offset, uint8_t clockwise);
804
  *  - Call LCD update
805
  *  - Call LCD update
805
  */
806
  */
806
 void loop() {
807
 void loop() {
807
-  if (commands_in_queue < BUFSIZE) get_command();
808
+  if (commands_in_queue < BUFSIZE) get_available_commands();
808
 
809
 
809
   #if ENABLED(SDSUPPORT)
810
   #if ENABLED(SDSUPPORT)
810
     card.checkautostart(false);
811
     card.checkautostart(false);
856
   serial_count = 0;
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
   static char serial_line_buffer[MAX_CMD_SIZE];
861
   static char serial_line_buffer[MAX_CMD_SIZE];
868
   static boolean serial_comment_mode = false;
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
   #if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
866
   #if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
873
     static millis_t last_command_time = 0;
867
     static millis_t last_command_time = 0;
874
     millis_t ms = millis();
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
       SERIAL_ECHOLNPGM(MSG_WAIT);
870
       SERIAL_ECHOLNPGM(MSG_WAIT);
878
       last_command_time = ms;
871
       last_command_time = ms;
879
     }
872
     }
988
     }
981
     }
989
 
982
 
990
   } // queue has space, serial has data
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
     static bool stop_buffering = false,
989
     static bool stop_buffering = false,
995
                 sd_comment_mode = false;
990
                 sd_comment_mode = false;
996
 
991
 
1050
         if (!sd_comment_mode) command_queue[cmd_queue_index_w][sd_count++] = sd_char;
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
 bool code_has_value() {
1070
 bool code_has_value() {
7362
       filrunout();
7375
       filrunout();
7363
   #endif
7376
   #endif
7364
 
7377
 
7365
-  if (commands_in_queue < BUFSIZE) get_command();
7378
+  if (commands_in_queue < BUFSIZE) get_available_commands();
7366
 
7379
 
7367
   millis_t ms = millis();
7380
   millis_t ms = millis();
7368
 
7381
 

Loading…
取消
儲存