Skip to content

Commit

Permalink
Status reporting finalized.
Browse files Browse the repository at this point in the history
Firmware now reports status on each line it received. It's in the
format of one line with capital letters used as flags/markers.  When
used as markers they have an alpha-numeric (non-uppercase) parameter
following them.

Also '!' is a special marker that may occur at the first pos and
indicates that the hardware is in stop mode. Typically stop made is
caused by limits being hit, power being turned off, or requested with a
'!'. The machine can be reactivated only by sending a '~' char or
reestablishing the serial connection).

The following characters are used as flags:
! ... hardware is in stop mode
P ... stop: power off
L ... stop: limit hit
L1 ... stop: limit x1 hit
L2 ... stop: limit x2 hit
L3 ... stop: limit y1 hit
L4 ... stop: limit y2 hit
R ... stop requested by serial
O ... stop: other reason
D ... warning: door open
C ... warning: chiller off
N ... warning: bad number format
E ... warning: expected command letter
U ... warning: unsupported statement
W ... warning: other reason

The following are used as markers for values (only returned when
queried with the '?' command):
Xx.xxx ... current x pos
Yy.yyy ... current y pos
Vvv.vvv ... version number

BUGFIX: SENSE_DOOR_OPEN had to be reversed
  • Loading branch information
Stefan Hechenberger committed Aug 5, 2012
1 parent c84097a commit 9d27676
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 57 deletions.
5 changes: 3 additions & 2 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
#include <inttypes.h>
#include <stdbool.h>


#define LASAURGRBL_VERSION "v12.02i"
// Version number
// (must not contain capital letters)
#define LASAURGRBL_VERSION "12.02i"
#define BAUD_RATE 9600


Expand Down
112 changes: 66 additions & 46 deletions gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void gcode_process_line() {
int numChars = 0;
uint8_t iscomment = false;
int status_code;
int line_processed = false;

while ((numChars==0) || (chr != '\n')) {
chr = serial_read();
Expand Down Expand Up @@ -140,59 +141,78 @@ void gcode_process_line() {
}

if (stepper_stop_requested()) {
printString("!"); // report harware is in stop mode
status_code = stepper_stop_status();
} else if (rx_line[0] == '$') {
printPgmString(PSTR("\nLasaurGrbl " LASAURGRBL_VERSION));
status_code = STATUS_OK;
} else if (rx_line[0] == '?') {
// trigger a status line
status_code = STATUS_OK;
} else {
// report stop conditions
if ( status_code == STATUS_POWER_OFF) {
printString("P"); // Stop: Power Off
} else if (status_code == STATUS_LIMIT_HIT) {
printString("L"); // Stop: Limit Hit
} else if (status_code == STATUS_SERIAL_STOP_REQUEST) {
printString("R"); // Stop: Serial Request
} else {
printString("O"); // Stop: Other error
printInteger(status_code);
}
} else if (rx_line[0] != '?') {
// process the next line of G-code
status_code = gcode_execute_line(rx_line);
line_processed = true;
// report parse errors
if (status_code == STATUS_OK) {
// pass
} else if (status_code == STATUS_BAD_NUMBER_FORMAT) {
printString("N"); // Warning: Bad number format
} else if (status_code == STATUS_EXPECTED_COMMAND_LETTER) {
printString("E"); // Warning: Expected command letter
} else if (status_code == STATUS_UNSUPPORTED_STATEMENT) {
printString("U"); // Warning: Unsupported statement
} else {
printString("W"); // Warning: Other error
printInteger(status_code);
}
}

//// door and chiller status
if (SENSE_DOOR_OPEN) {
printString("D"); // Warning: Door is open
}
if (SENSE_CHILLER_OFF) {
printString("C"); // Warning: Chiller is off
}
// power
if (SENSE_POWER_OFF) {
printString("P"); // Power Off
}
} else {
// empty or comment line, send ok for consistency
status_code = STATUS_OK;
}

//// return error status
if (status_code != STATUS_OK) {
switch(status_code) {
case STATUS_BAD_NUMBER_FORMAT:
printString("N1"); break; // Error: Bad number format
case STATUS_EXPECTED_COMMAND_LETTER:
printString("E1"); break; // Error: Expected command letter
case STATUS_UNSUPPORTED_STATEMENT:
printString("U1"); break; // Error: Unsupported statement
case STATUS_FLOATING_POINT_ERROR:
printString("F1"); break; // Error: Floating point error
case STATUS_POWER_OFF:
printString("P1"); break; // Error: Power Off
case STATUS_LIMIT_HIT:
printString("L1"); break; // Error: Limit Hit
default:
printPgmString(PSTR("ERROR"));
printInteger(status_code);
// limit
if (SENSE_LIMITS) {
if (SENSE_X1_LIMIT) {
printString("L1"); // Limit X1 Hit
}
if (SENSE_X2_LIMIT) {
printString("L2"); // Limit X2 Hit
}
if (SENSE_Y1_LIMIT) {
printString("L3"); // Limit Y1 Hit
}
if (SENSE_Y2_LIMIT) {
printString("L4"); // Limit Y21 Hit
}
}

//
if (!line_processed) {
// position
printString("X");
printFloat(stepper_get_position_x());
printString("Y");
printFloat(stepper_get_position_y());
// version
printPgmString(PSTR("V" LASAURGRBL_VERSION));
}
printString("\n");
}

//// compile and send status to serial
if (SENSE_DOOR_OPEN) {
printString("D1");
} else {
printString("D0"); // Warning: Door is open
}
if (SENSE_CHILLER_OFF) {
printString("C1"); // Warning: Chiller is off
} else {
printString("C0");
}
// printString("X");
// printFloat(stepper_get_position_x());
// printString("Y");
// printFloat(stepper_get_position_y());
printString("\n");
}


Expand Down
11 changes: 5 additions & 6 deletions gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
#define STATUS_BAD_NUMBER_FORMAT 1
#define STATUS_EXPECTED_COMMAND_LETTER 2
#define STATUS_UNSUPPORTED_STATEMENT 3
#define STATUS_FLOATING_POINT_ERROR 4
#define STATUS_SERIAL_STOP_REQUEST 5
#define STATUS_LIMIT_HIT 6
#define STATUS_POWER_OFF 7
#define STATUS_DOOR_OPEN 8
#define STATUS_CHILLER_OFF 9
#define STATUS_SERIAL_STOP_REQUEST 4
#define STATUS_LIMIT_HIT 5
#define STATUS_POWER_OFF 6
// #define STATUS_DOOR_OPEN 7
// #define STATUS_CHILLER_OFF 8


// Initialize the parser
Expand Down
2 changes: 1 addition & 1 deletion sense_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
void sense_init();
#define SENSE_POWER_OFF !((SENSE_PIN >> POWER_BIT) & 1)
#define SENSE_CHILLER_OFF !((SENSE_PIN >> CHILLER_BIT) & 1)
#define SENSE_DOOR_OPEN !((SENSE_PIN >> DOOR_BIT) & 1)
#define SENSE_DOOR_OPEN ((SENSE_PIN >> DOOR_BIT) & 1)
#define SENSE_X1_LIMIT !((LIMIT_PIN >> X1_LIMIT_BIT) & 1)
#define SENSE_X2_LIMIT !((LIMIT_PIN >> X2_LIMIT_BIT) & 1)
#define SENSE_Y1_LIMIT !((LIMIT_PIN >> Y1_LIMIT_BIT) & 1)
Expand Down
4 changes: 2 additions & 2 deletions serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void serial_init() {
xon_flag = 1;
UCSR0B |= (1 << UDRIE0); // enable tx interrupt

printPgmString(PSTR("\r\nLasaurGrbl " LASAURGRBL_VERSION));
printPgmString(PSTR("\r\n"));
printPgmString(PSTR("LasaurGrbl " LASAURGRBL_VERSION));
printPgmString(PSTR("\n"));
}

void serial_write(uint8_t data) {
Expand Down

0 comments on commit 9d27676

Please sign in to comment.