added error messages and dropped echoing of command input

This commit is contained in:
Simen Svale Skogsrud 2011-02-05 00:39:34 +01:00
parent 9f5365aac9
commit 682e23eb7b
2 changed files with 19 additions and 6 deletions

View File

@ -27,8 +27,7 @@
#define GCSTATUS_BAD_NUMBER_FORMAT 1
#define GCSTATUS_EXPECTED_COMMAND_LETTER 2
#define GCSTATUS_UNSUPPORTED_STATEMENT 3
#define GCSTATUS_MOTION_CONTROL_ERROR 4
#define GCSTATUS_FLOATING_POINT_ERROR 5
#define GCSTATUS_FLOATING_POINT_ERROR 4
// Initialize the parser
void gc_init();

View File

@ -31,6 +31,21 @@
static char line[LINE_BUFFER_SIZE];
static uint8_t char_counter;
void status_message(int status_code) {
if (status_code) {
switch(status_code) {
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;
}
}
}
void prompt() {
printPgmString(PSTR("ok\r\n"));
}
@ -50,10 +65,9 @@ void sp_process()
while((c = serialRead()) != -1)
{
if((char_counter > 0) && ((c == '\n') || (c == '\r'))) { // Line is complete. Then execute!
line[char_counter] = 0;
printString(line); printPgmString(PSTR("\r\n"));
gc_execute_line(line);
char_counter = 0;
line[char_counter] = 0; // treminate string
status_message(gc_execute_line(line));
char_counter = 0; // reset line buffer index
prompt();
} else if (c <= ' ') { // Throw away whitepace and control characters
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase