Skip to content

Commit

Permalink
Simplify & optimize with current_command_args
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 18, 2015
1 parent adc8fcb commit a0f362c
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ bool axis_known_position[3] = { false };

static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0;

static char *current_command;
static char *current_command, *current_command_args;
static int cmd_queue_index_r = 0;
static int cmd_queue_index_w = 0;
static int commands_in_queue = 0;
Expand Down Expand Up @@ -938,7 +938,7 @@ long code_value_long() { return strtol(seen_pointer + 1, NULL, 10); }
int16_t code_value_short() { return (int16_t)strtol(seen_pointer + 1, NULL, 10); }

bool code_seen(char code) {
seen_pointer = strchr(current_command + 3, code); // +3 since "G0 " is the shortest prefix
seen_pointer = strchr(current_command_args, code); // +3 since "G0 " is the shortest prefix
return (seen_pointer != NULL); //Return True if a character was found
}

Expand Down Expand Up @@ -2848,7 +2848,7 @@ inline void gcode_G92() {
* M1: // M1 - Conditional stop - Wait for user button press on LCD
*/
inline void gcode_M0_M1() {
char *args = current_command + 3;
char *args = current_command_args;

millis_t codenum = 0;
bool hasP = false, hasS = false;
Expand Down Expand Up @@ -2935,7 +2935,7 @@ inline void gcode_M17() {
* M23: Select a file
*/
inline void gcode_M23() {
card.openFile(current_command + 4, true);
card.openFile(current_command_args, true);
}

/**
Expand Down Expand Up @@ -2972,7 +2972,7 @@ inline void gcode_M17() {
* M28: Start SD Write
*/
inline void gcode_M28() {
card.openFile(current_command + 4, false);
card.openFile(current_command_args, false);
}

/**
Expand All @@ -2989,7 +2989,7 @@ inline void gcode_M17() {
inline void gcode_M30() {
if (card.cardOK) {
card.closefile();
card.removeFile(current_command + 4);
card.removeFile(current_command_args);
}
}

Expand Down Expand Up @@ -3019,11 +3019,9 @@ inline void gcode_M31() {
if (card.sdprinting)
st_synchronize();

char* args = current_command + 4;

char* namestartpos = strchr(args, '!'); // Find ! to indicate filename string start.
char* namestartpos = strchr(current_command_args, '!'); // Find ! to indicate filename string start.
if (!namestartpos)
namestartpos = args; // Default name position, 4 letters after the M
namestartpos = current_command_args; // Default name position, 4 letters after the M
else
namestartpos++; //to skip the '!'

Expand All @@ -3045,7 +3043,7 @@ inline void gcode_M31() {
* M928: Start SD Write
*/
inline void gcode_M928() {
card.openLogFile(current_command + 5);
card.openLogFile(current_command_args);
}

#endif // SDSUPPORT
Expand Down Expand Up @@ -3846,7 +3844,7 @@ inline void gcode_M115() {
* M117: Set LCD Status Message
*/
inline void gcode_M117() {
lcd_setstatus(current_command + 5);
lcd_setstatus(current_command_args);
}

/**
Expand Down Expand Up @@ -5192,6 +5190,12 @@ void process_next_command() {
// Bail early if there's no code
if (!code_is_good) goto ExitUnknownCommand;

// Args pointer optimizes code_seen, especially those taking XYZEF
// This wastes a little cpu on commands that expect no arguments.
current_command_args = current_command;
while (*current_command_args != ' ') ++current_command_args;
while (*current_command_args == ' ') ++current_command_args;

// Interpret the code int
codenum = code_value_short();

Expand Down

0 comments on commit a0f362c

Please sign in to comment.