refactored handling of settings '$' command out of gcode module and into settings module
This commit is contained in:
41
protocol.c
41
protocol.c
@ -33,21 +33,23 @@ static char line[LINE_BUFFER_SIZE];
|
||||
static uint8_t char_counter;
|
||||
|
||||
void status_message(int status_code) {
|
||||
switch(status_code) {
|
||||
case GCSTATUS_OK:
|
||||
printPgmString(PSTR("ok\n\r")); break;
|
||||
case GCSTATUS_BAD_NUMBER_FORMAT:
|
||||
printPgmString(PSTR("error: Bad number format\n\r")); break;
|
||||
case GCSTATUS_EXPECTED_COMMAND_LETTER:
|
||||
printPgmString(PSTR("error: Expected command letter\n\r")); break;
|
||||
case GCSTATUS_UNSUPPORTED_STATEMENT:
|
||||
printPgmString(PSTR("error: Unsupported statement\n\r")); break;
|
||||
case GCSTATUS_FLOATING_POINT_ERROR:
|
||||
printPgmString(PSTR("error: Floating point error\n\r")); break;
|
||||
default:
|
||||
if (status_code == 0) {
|
||||
printPgmString(PSTR("ok\n\r"));
|
||||
} else {
|
||||
printPgmString(PSTR("error: "));
|
||||
printInteger(status_code);
|
||||
printPgmString(PSTR("\n\r"));
|
||||
switch(status_code) {
|
||||
case STATUS_BAD_NUMBER_FORMAT:
|
||||
printPgmString(PSTR("Bad number format\n\r")); break;
|
||||
case STATUS_EXPECTED_COMMAND_LETTER:
|
||||
printPgmString(PSTR("Expected command letter\n\r")); break;
|
||||
case STATUS_UNSUPPORTED_STATEMENT:
|
||||
printPgmString(PSTR("Unsupported statement\n\r")); break;
|
||||
case STATUS_FLOATING_POINT_ERROR:
|
||||
printPgmString(PSTR("Floating point error\n\r")); break;
|
||||
default:
|
||||
printInteger(status_code);
|
||||
printPgmString(PSTR("\n\r"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,6 +60,15 @@ void protocol_init()
|
||||
printPgmString(PSTR("\r\n"));
|
||||
}
|
||||
|
||||
// Executes one line of input according to protocol
|
||||
uint8_t protocol_execute_line(char *line) {
|
||||
if(line[0] == '$') {
|
||||
return(settings_execute_line(line)); // Delegate lines starting with '$' to the settings module
|
||||
} else {
|
||||
return(gc_execute_line(line)); // Everything else is gcode
|
||||
}
|
||||
}
|
||||
|
||||
void protocol_process()
|
||||
{
|
||||
char c;
|
||||
@ -65,7 +76,7 @@ void protocol_process()
|
||||
{
|
||||
if((char_counter > 0) && ((c == '\n') || (c == '\r'))) { // Line is complete. Then execute!
|
||||
line[char_counter] = 0; // treminate string
|
||||
status_message(gc_execute_line(line));
|
||||
status_message(protocol_execute_line(line));
|
||||
char_counter = 0; // reset line buffer index
|
||||
} else if (c <= ' ') { // Throw away whitepace and control characters
|
||||
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
||||
|
Reference in New Issue
Block a user