diff --git a/gcode_parse.c b/gcode_parse.c index 0ea6c2d..f3aa6b6 100644 --- a/gcode_parse.c +++ b/gcode_parse.c @@ -100,9 +100,16 @@ void gcode_init(void) { #endif } -/// Character Received - add it to our command -/// \param c the next character to process -void gcode_parse_char(uint8_t c) { +/** Character received - add it to our command. + + \param c The next character to process. + + \return Wether end of line was reached. + + This parser operates character by character, so there's no need for a + buffer holding the entire line of G-code. +*/ +uint8_t gcode_parse_char(uint8_t c) { uint8_t checksum_char = c; // uppercase @@ -401,6 +408,8 @@ void gcode_parse_char(uint8_t c) { if (next_target.option_all_relative || next_target.option_e_relative) { next_target.target.axis[E] = 0; } + + return 1; } #ifdef SD @@ -417,6 +426,8 @@ void gcode_parse_char(uint8_t c) { } } #endif /* SD */ + + return 0; } /***************************************************************************\ diff --git a/gcode_parse.h b/gcode_parse.h index 5b19b90..8666375 100644 --- a/gcode_parse.h +++ b/gcode_parse.h @@ -72,7 +72,7 @@ extern GCODE_COMMAND next_target; void gcode_init(void); /// accept the next character and process it -void gcode_parse_char(uint8_t c); +uint8_t gcode_parse_char(uint8_t c); // uses the global variable next_target.N void request_resend(void); diff --git a/mendel.c b/mendel.c index c63e5e3..5964f5e 100644 --- a/mendel.c +++ b/mendel.c @@ -271,14 +271,14 @@ int main (void) { // if queue is full, no point in reading chars- host will just have to wait if (queue_full() == 0) { - uint8_t c; + uint8_t c, line_done; if (( ! gcode_active || gcode_active & GCODE_SOURCE_SERIAL) && serial_rxchars() != 0) { gcode_active = GCODE_SOURCE_SERIAL; c = serial_popchar(); - gcode_parse_char(c); - if (c == '\r' || c == '\n') + line_done = gcode_parse_char(c); + if (line_done) gcode_active = 0; } @@ -294,8 +294,8 @@ int main (void) } else { gcode_active = GCODE_SOURCE_SD; - gcode_parse_char(c); - if (c == '\r' || c == '\n') + line_done = gcode_parse_char(c); + if (line_done) gcode_active = 0; } }