Parcourir la source

Simplify & optimize with current_command_args

Scott Lahteine il y a 9 ans
Parent
révision
a0f362c735
1 fichiers modifiés avec 16 ajouts et 12 suppressions
  1. 16
    12
      Marlin/Marlin_main.cpp

+ 16
- 12
Marlin/Marlin_main.cpp Voir le fichier

@@ -236,7 +236,7 @@ bool axis_known_position[3] = { false };
236 236
 
237 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 240
 static int cmd_queue_index_r = 0;
241 241
 static int cmd_queue_index_w = 0;
242 242
 static int commands_in_queue = 0;
@@ -938,7 +938,7 @@ long code_value_long() { return strtol(seen_pointer + 1, NULL, 10); }
938 938
 int16_t code_value_short() { return (int16_t)strtol(seen_pointer + 1, NULL, 10); }
939 939
 
940 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 942
   return (seen_pointer != NULL);  //Return True if a character was found
943 943
 }
944 944
 
@@ -2848,7 +2848,7 @@ inline void gcode_G92() {
2848 2848
    * M1: // M1 - Conditional stop - Wait for user button press on LCD
2849 2849
    */
2850 2850
   inline void gcode_M0_M1() {
2851
-    char *args = current_command + 3;
2851
+    char *args = current_command_args;
2852 2852
 
2853 2853
     millis_t codenum = 0;
2854 2854
     bool hasP = false, hasS = false;
@@ -2935,7 +2935,7 @@ inline void gcode_M17() {
2935 2935
    * M23: Select a file
2936 2936
    */
2937 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,7 +2972,7 @@ inline void gcode_M17() {
2972 2972
    * M28: Start SD Write
2973 2973
    */
2974 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,7 +2989,7 @@ inline void gcode_M17() {
2989 2989
   inline void gcode_M30() {
2990 2990
     if (card.cardOK) {
2991 2991
       card.closefile();
2992
-      card.removeFile(current_command + 4);
2992
+      card.removeFile(current_command_args);
2993 2993
     }
2994 2994
   }
2995 2995
 
@@ -3019,11 +3019,9 @@ inline void gcode_M31() {
3019 3019
     if (card.sdprinting)
3020 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 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 3025
     else
3028 3026
       namestartpos++; //to skip the '!'
3029 3027
 
@@ -3045,7 +3043,7 @@ inline void gcode_M31() {
3045 3043
    * M928: Start SD Write
3046 3044
    */
3047 3045
   inline void gcode_M928() {
3048
-    card.openLogFile(current_command + 5);
3046
+    card.openLogFile(current_command_args);
3049 3047
   }
3050 3048
 
3051 3049
 #endif // SDSUPPORT
@@ -3846,7 +3844,7 @@ inline void gcode_M115() {
3846 3844
  * M117: Set LCD Status Message
3847 3845
  */
3848 3846
 inline void gcode_M117() {
3849
-  lcd_setstatus(current_command + 5);
3847
+  lcd_setstatus(current_command_args);
3850 3848
 }
3851 3849
 
3852 3850
 /**
@@ -5192,6 +5190,12 @@ void process_next_command() {
5192 5190
   // Bail early if there's no code
5193 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 5199
   // Interpret the code int
5196 5200
   codenum = code_value_short();
5197 5201
 

Chargement…
Annuler
Enregistrer