Browse Source

Simplify & optimize with current_command_args

Scott Lahteine 9 years ago
parent
commit
a0f362c735
1 changed files with 16 additions and 12 deletions
  1. 16
    12
      Marlin/Marlin_main.cpp

+ 16
- 12
Marlin/Marlin_main.cpp View File

236
 
236
 
237
 static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0;
237
 static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0;
238
 
238
 
239
-static char *current_command;
239
+static char *current_command, *current_command_args;
240
 static int cmd_queue_index_r = 0;
240
 static int cmd_queue_index_r = 0;
241
 static int cmd_queue_index_w = 0;
241
 static int cmd_queue_index_w = 0;
242
 static int commands_in_queue = 0;
242
 static int commands_in_queue = 0;
938
 int16_t code_value_short() { return (int16_t)strtol(seen_pointer + 1, NULL, 10); }
938
 int16_t code_value_short() { return (int16_t)strtol(seen_pointer + 1, NULL, 10); }
939
 
939
 
940
 bool code_seen(char code) {
940
 bool code_seen(char code) {
941
-  seen_pointer = strchr(current_command + 3, code); // +3 since "G0 " is the shortest prefix
941
+  seen_pointer = strchr(current_command_args, code); // +3 since "G0 " is the shortest prefix
942
   return (seen_pointer != NULL);  //Return True if a character was found
942
   return (seen_pointer != NULL);  //Return True if a character was found
943
 }
943
 }
944
 
944
 
2848
    * M1: // M1 - Conditional stop - Wait for user button press on LCD
2848
    * M1: // M1 - Conditional stop - Wait for user button press on LCD
2849
    */
2849
    */
2850
   inline void gcode_M0_M1() {
2850
   inline void gcode_M0_M1() {
2851
-    char *args = current_command + 3;
2851
+    char *args = current_command_args;
2852
 
2852
 
2853
     millis_t codenum = 0;
2853
     millis_t codenum = 0;
2854
     bool hasP = false, hasS = false;
2854
     bool hasP = false, hasS = false;
2935
    * M23: Select a file
2935
    * M23: Select a file
2936
    */
2936
    */
2937
   inline void gcode_M23() {
2937
   inline void gcode_M23() {
2938
-    card.openFile(current_command + 4, true);
2938
+    card.openFile(current_command_args, true);
2939
   }
2939
   }
2940
 
2940
 
2941
   /**
2941
   /**
2972
    * M28: Start SD Write
2972
    * M28: Start SD Write
2973
    */
2973
    */
2974
   inline void gcode_M28() {
2974
   inline void gcode_M28() {
2975
-    card.openFile(current_command + 4, false);
2975
+    card.openFile(current_command_args, false);
2976
   }
2976
   }
2977
 
2977
 
2978
   /**
2978
   /**
2989
   inline void gcode_M30() {
2989
   inline void gcode_M30() {
2990
     if (card.cardOK) {
2990
     if (card.cardOK) {
2991
       card.closefile();
2991
       card.closefile();
2992
-      card.removeFile(current_command + 4);
2992
+      card.removeFile(current_command_args);
2993
     }
2993
     }
2994
   }
2994
   }
2995
 
2995
 
3019
     if (card.sdprinting)
3019
     if (card.sdprinting)
3020
       st_synchronize();
3020
       st_synchronize();
3021
 
3021
 
3022
-    char* args = current_command + 4;
3023
-
3024
-    char* namestartpos = strchr(args, '!');  // Find ! to indicate filename string start.
3022
+    char* namestartpos = strchr(current_command_args, '!');  // Find ! to indicate filename string start.
3025
     if (!namestartpos)
3023
     if (!namestartpos)
3026
-      namestartpos = args; // Default name position, 4 letters after the M
3024
+      namestartpos = current_command_args; // Default name position, 4 letters after the M
3027
     else
3025
     else
3028
       namestartpos++; //to skip the '!'
3026
       namestartpos++; //to skip the '!'
3029
 
3027
 
3045
    * M928: Start SD Write
3043
    * M928: Start SD Write
3046
    */
3044
    */
3047
   inline void gcode_M928() {
3045
   inline void gcode_M928() {
3048
-    card.openLogFile(current_command + 5);
3046
+    card.openLogFile(current_command_args);
3049
   }
3047
   }
3050
 
3048
 
3051
 #endif // SDSUPPORT
3049
 #endif // SDSUPPORT
3846
  * M117: Set LCD Status Message
3844
  * M117: Set LCD Status Message
3847
  */
3845
  */
3848
 inline void gcode_M117() {
3846
 inline void gcode_M117() {
3849
-  lcd_setstatus(current_command + 5);
3847
+  lcd_setstatus(current_command_args);
3850
 }
3848
 }
3851
 
3849
 
3852
 /**
3850
 /**
5192
   // Bail early if there's no code
5190
   // Bail early if there's no code
5193
   if (!code_is_good) goto ExitUnknownCommand;
5191
   if (!code_is_good) goto ExitUnknownCommand;
5194
 
5192
 
5193
+  // Args pointer optimizes code_seen, especially those taking XYZEF
5194
+  // This wastes a little cpu on commands that expect no arguments.
5195
+  current_command_args = current_command;
5196
+  while (*current_command_args != ' ') ++current_command_args;
5197
+  while (*current_command_args == ' ') ++current_command_args;
5198
+
5195
   // Interpret the code int
5199
   // Interpret the code int
5196
   codenum = code_value_short();
5200
   codenum = code_value_short();
5197
 
5201
 

Loading…
Cancel
Save