grbl-LPC-CoreXY/serial_protocol.c

67 lines
1.7 KiB
C
Raw Normal View History

2009-01-25 00:48:56 +01:00
/*
serial_protocol.c - the serial protocol master control unit
Part of Grbl
Copyright (c) 2009-2011 Simen Svale Skogsrud
2009-01-25 00:48:56 +01:00
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
#include "serial_protocol.h"
#include "gcode.h"
#include "wiring_serial.h"
#include "config.h"
#include <math.h>
#include "nuts_bolts.h"
2010-03-07 23:10:41 +01:00
#include <avr/pgmspace.h>
#define LINE_BUFFER_SIZE 50
2009-01-25 00:48:56 +01:00
char line[LINE_BUFFER_SIZE];
2010-03-03 13:04:51 +01:00
uint8_t char_counter;
2009-01-25 00:48:56 +01:00
void prompt() {
2010-03-07 23:10:41 +01:00
printPgmString(PSTR("ok\r\n"));
2009-01-25 00:48:56 +01:00
}
void sp_init()
{
beginSerial(BAUD_RATE);
2010-03-07 23:10:41 +01:00
printPgmString(PSTR("\r\nGrbl "));
printPgmString(PSTR(VERSION));
printPgmString(PSTR("\r\n"));
2009-01-25 00:48:56 +01:00
prompt();
}
void sp_process()
{
char c;
while((c = serialRead()) != -1)
{
if((c == '\n')) { // Line is complete. Then execute!
2010-03-03 13:04:51 +01:00
line[char_counter] = 0;
printString(line); printPgmString(PSTR("\r\n"));
2009-01-25 00:48:56 +01:00
gc_execute_line(line);
2010-03-03 13:04:51 +01:00
char_counter = 0;
2009-01-25 00:48:56 +01:00
prompt();
} else if (c <= ' ') { // Throw away whitepace and control characters
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
2010-03-03 13:04:51 +01:00
line[char_counter++] = c-'a'+'A';
2009-01-25 00:48:56 +01:00
} else {
2010-03-03 13:04:51 +01:00
line[char_counter++] = c;
2009-01-25 00:48:56 +01:00
}
}
}