Przeglądaj źródła

Slight improvement to the line parsing logic, saving 8 cycles per character

etagle 6 lat temu
rodzic
commit
2864ef8c7f
1 zmienionych plików z 5 dodań i 4 usunięć
  1. 5
    4
      Marlin/Marlin_main.cpp

+ 5
- 4
Marlin/Marlin_main.cpp Wyświetl plik

@@ -1094,9 +1094,10 @@ inline void get_serial_commands() {
1094 1094
   /**
1095 1095
    * Loop while serial characters are incoming and the queue is not full
1096 1096
    */
1097
-  while (commands_in_queue < BUFSIZE && MYSERIAL.available() > 0) {
1097
+  int c;
1098
+  while (commands_in_queue < BUFSIZE && (c = MYSERIAL.read()) >= 0) {
1098 1099
 
1099
-    char serial_char = MYSERIAL.read();
1100
+	char serial_char = c;
1100 1101
 
1101 1102
     /**
1102 1103
      * If the character ends the line
@@ -1196,9 +1197,9 @@ inline void get_serial_commands() {
1196 1197
       // The command will be injected when EOL is reached
1197 1198
     }
1198 1199
     else if (serial_char == '\\') {  // Handle escapes
1199
-      if (MYSERIAL.available() > 0) {
1200
+      if ((c = MYSERIAL.read()) >= 0) {
1200 1201
         // if we have one more character, copy it over
1201
-        serial_char = MYSERIAL.read();
1202
+        serial_char = c;
1202 1203
         if (!serial_comment_mode) serial_line_buffer[serial_count++] = serial_char;
1203 1204
       }
1204 1205
       // otherwise do nothing

Ładowanie…
Anuluj
Zapisz