Skip to content

Commit 909feb7

Browse files
committed
Re-organized status messages to be more coherent and centralized.
- Reorganized all of the status message feedback from both the g-code parser and settings modules to be centralized into two message modules: status feedback from executing a line and warnings for misc feedback. - Pulled out the printPgmString() messages in settings.c and placed it into the new module. (settings_dump() not moved). - Some other minor edits. Renaming defines, comment updates, etc.
1 parent 39e11b6 commit 909feb7

File tree

7 files changed

+123
-81
lines changed

7 files changed

+123
-81
lines changed

config.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@
150150
// of your successes or difficulties, as we will monitor this and possibly integrate this as a
151151
// standard feature for future releases. However, we suggest to first try our direction delay
152152
// hack/solution posted in the Wiki involving inverting the stepper pin mask.
153-
// NOTE: Uncomment to enable. The recommended delay should be > 3us and the total step pulse
154-
// time, which includes the Grbl settings pulse microseconds, should not exceed 127us.
155-
// #define STEP_PULSE_DELAY 5 // Step pulse delay in microseconds. Default disabled.
153+
// NOTE: Uncomment to enable. The recommended delay must be > 3us and the total step pulse
154+
// time, which includes the Grbl settings pulse microseconds, must not exceed 127us. Reported
155+
// successful values for certain setups have ranged from 10 to 20us.
156+
// #define STEP_PULSE_DELAY 10 // Step pulse delay in microseconds. Default disabled.
156157

157158
// ---------------------------------------------------------------------------------------
158159

@@ -167,7 +168,8 @@
167168
// entering g-code into grbl, i.e. locating part zero or simple manual machining. If the axes drift,
168169
// grbl has no way to know this has happened, since stepper motors are open-loop control. Depending
169170
// on the machine, this parameter may need to be larger or smaller than the default time.
170-
// NOTE: If the define commented, the stepper lock will be disabled upon compiling.
171+
// NOTE: If set to zero, no lock will occur. If set to max 255, the lock will never release, in other
172+
// words, the steppers never disable for users that require this.
171173
// -> NOW INSTALLED IN SETTINGS #define STEPPER_IDLE_LOCK_TIME 25 // (milliseconds) - Integer > 0
172174

173175

gcode.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ uint8_t gc_execute_line(char *line)
265265
switch(letter) {
266266
case 'G': case 'M': case 'N': break; // Ignore command statements and line numbers
267267
case 'F':
268-
if (value <= 0) { FAIL(STATUS_INVALID_COMMAND); } // Must be greater than zero
268+
if (value <= 0) { FAIL(STATUS_INVALID_STATEMENT); } // Must be greater than zero
269269
if (gc.inverse_feed_rate_mode) {
270270
inverse_feed_rate = to_millimeters(value); // seconds per motion for this motion only
271271
} else {
@@ -277,11 +277,11 @@ uint8_t gc_execute_line(char *line)
277277
case 'P': p = value; break;
278278
case 'R': r = to_millimeters(value); break;
279279
case 'S':
280-
if (value < 0) { FAIL(STATUS_INVALID_COMMAND); } // Cannot be negative
280+
if (value < 0) { FAIL(STATUS_INVALID_STATEMENT); } // Cannot be negative
281281
gc.spindle_speed = value;
282282
break;
283283
case 'T':
284-
if (value < 0) { FAIL(STATUS_INVALID_COMMAND); } // Cannot be negative
284+
if (value < 0) { FAIL(STATUS_INVALID_STATEMENT); } // Cannot be negative
285285
gc.tool = trunc(value);
286286
break;
287287
case 'X': target[X_AXIS] = to_millimeters(value); bit_true(axis_words,bit(X_AXIS)); break;
@@ -299,7 +299,7 @@ uint8_t gc_execute_line(char *line)
299299
NOTE: Independent non-motion/settings parameters are set out of this order for code efficiency
300300
and simplicity purposes, but this should not affect proper g-code execution. */
301301

302-
// ([M6]: Tool change execution should be executed here.)
302+
// ([M6]: Tool change should be executed here.)
303303

304304
// [M3,M4,M5]: Update spindle state
305305
spindle_run(gc.spindle_direction, gc.spindle_speed);
@@ -313,7 +313,7 @@ uint8_t gc_execute_line(char *line)
313313
switch (non_modal_action) {
314314
case NON_MODAL_DWELL:
315315
if (p < 0) { // Time cannot be negative.
316-
FAIL(STATUS_INVALID_COMMAND);
316+
FAIL(STATUS_INVALID_STATEMENT);
317317
} else {
318318
mc_dwell(p);
319319
}
@@ -323,7 +323,7 @@ uint8_t gc_execute_line(char *line)
323323
if (l != 2 || (int_value < 1 || int_value > N_COORDINATE_SYSTEM)) { // L2 only. P1=G54, P2=G55, ...
324324
FAIL(STATUS_UNSUPPORTED_STATEMENT);
325325
} else if (!axis_words) { // No axis words.
326-
FAIL(STATUS_INVALID_COMMAND);
326+
FAIL(STATUS_INVALID_STATEMENT);
327327
} else {
328328
int_value--; // Adjust p to be inline with row array index.
329329
// Update axes defined only in block. Always in machine coordinates. Can change non-active system.
@@ -358,7 +358,7 @@ uint8_t gc_execute_line(char *line)
358358
break;
359359
case NON_MODAL_SET_COORDINATE_OFFSET:
360360
if (!axis_words) { // No axis words
361-
FAIL(STATUS_INVALID_COMMAND);
361+
FAIL(STATUS_INVALID_STATEMENT);
362362
} else {
363363
// Update axes defined only in block. Offsets current system to defined value. Does not update when
364364
// active coordinate system is selected, but is still active unless G92.1 disables it.
@@ -384,12 +384,12 @@ uint8_t gc_execute_line(char *line)
384384
// G1,G2,G3 require F word in inverse time mode.
385385
if ( gc.inverse_feed_rate_mode ) {
386386
if (inverse_feed_rate < 0 && gc.motion_mode != MOTION_MODE_CANCEL) {
387-
FAIL(STATUS_INVALID_COMMAND);
387+
FAIL(STATUS_INVALID_STATEMENT);
388388
}
389389
}
390390
// Absolute override G53 only valid with G0 and G1 active.
391391
if ( absolute_override && !(gc.motion_mode == MOTION_MODE_SEEK || gc.motion_mode == MOTION_MODE_LINEAR)) {
392-
FAIL(STATUS_INVALID_COMMAND);
392+
FAIL(STATUS_INVALID_STATEMENT);
393393
}
394394
// Report any errors.
395395
if (gc.status_code) { return(gc.status_code); }
@@ -414,14 +414,14 @@ uint8_t gc_execute_line(char *line)
414414

415415
switch (gc.motion_mode) {
416416
case MOTION_MODE_CANCEL:
417-
if (axis_words) { FAIL(STATUS_INVALID_COMMAND); } // No axis words allowed while active.
417+
if (axis_words) { FAIL(STATUS_INVALID_STATEMENT); } // No axis words allowed while active.
418418
break;
419419
case MOTION_MODE_SEEK:
420-
if (!axis_words) { FAIL(STATUS_INVALID_COMMAND);}
420+
if (!axis_words) { FAIL(STATUS_INVALID_STATEMENT);}
421421
else { mc_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], settings.default_seek_rate, false); }
422422
break;
423423
case MOTION_MODE_LINEAR:
424-
if (!axis_words) { FAIL(STATUS_INVALID_COMMAND);}
424+
if (!axis_words) { FAIL(STATUS_INVALID_STATEMENT);}
425425
else { mc_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS],
426426
(gc.inverse_feed_rate_mode) ? inverse_feed_rate : gc.feed_rate, gc.inverse_feed_rate_mode); }
427427
break;
@@ -430,7 +430,7 @@ uint8_t gc_execute_line(char *line)
430430
// format arc mode, also check for at least one of the IJK axes of the selected plane was sent.
431431
if ( !( bit_false(axis_words,bit(gc.plane_axis_2)) ) ||
432432
( !r && !offset[gc.plane_axis_0] && !offset[gc.plane_axis_1] ) ) {
433-
FAIL(STATUS_INVALID_COMMAND);
433+
FAIL(STATUS_INVALID_STATEMENT);
434434
} else {
435435
if (r != 0) { // Arc Radius Mode
436436
/*

protocol.c

+63-25
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,70 @@ static char line[LINE_BUFFER_SIZE]; // Line to be executed. Zero-terminated.
3636
static uint8_t char_counter; // Last character counter in line variable.
3737
static uint8_t iscomment; // Comment/block delete flag for processor to ignore comment characters.
3838

39+
// Prints all status messages, an 'ok' or 'error', after Grbl has processed a line of incoming
40+
// serial data, whether this was a g-code block or grbl setting command.
3941
void protocol_status_message(int8_t status_code)
4042
{
41-
if (status_code == 0) {
43+
// TODO: Compile time option to only return numeric codes for GUIs.
44+
if (status_code == 0) { // STATUS_OK
4245
printPgmString(PSTR("ok\r\n"));
4346
} else {
4447
printPgmString(PSTR("error: "));
45-
switch(status_code) {
46-
case STATUS_BAD_NUMBER_FORMAT:
47-
printPgmString(PSTR("Bad number format\r\n")); break;
48-
case STATUS_EXPECTED_COMMAND_LETTER:
49-
printPgmString(PSTR("Expected command letter\r\n")); break;
50-
case STATUS_UNSUPPORTED_STATEMENT:
51-
printPgmString(PSTR("Unsupported statement\r\n")); break;
52-
case STATUS_FLOATING_POINT_ERROR:
53-
printPgmString(PSTR("Floating point error\r\n")); break;
54-
case STATUS_MODAL_GROUP_VIOLATION:
55-
printPgmString(PSTR("Modal group violation\r\n")); break;
56-
case STATUS_INVALID_COMMAND:
57-
printPgmString(PSTR("Invalid command\r\n")); break;
58-
case STATUS_SETTING_DISABLED:
59-
printPgmString(PSTR("Grbl setting disabled\r\n")); break;
60-
case STATUS_HARD_LIMIT:
61-
printPgmString(PSTR("Limit triggered <Check and Reset>\r\n")); break;
62-
default:
63-
printInteger(status_code);
64-
printPgmString(PSTR("\r\n"));
48+
// All critical error codes are greater than zero. These are defined to be any error
49+
// that may cause damage by crashing or improper g-code inputs and that are susceptible
50+
// to Grbl's alarm mode which will stop all processes, if the user enables this option.
51+
if (status_code > 0) {
52+
// TODO: Install option to enter alarm mode upon any critical error.
53+
switch(status_code) {
54+
case STATUS_BAD_NUMBER_FORMAT:
55+
printPgmString(PSTR("Bad number format")); break;
56+
case STATUS_EXPECTED_COMMAND_LETTER:
57+
printPgmString(PSTR("Expected command letter")); break;
58+
case STATUS_UNSUPPORTED_STATEMENT:
59+
printPgmString(PSTR("Unsupported statement")); break;
60+
case STATUS_FLOATING_POINT_ERROR:
61+
printPgmString(PSTR("Floating point error")); break;
62+
case STATUS_MODAL_GROUP_VIOLATION:
63+
printPgmString(PSTR("Modal group violation")); break;
64+
case STATUS_INVALID_STATEMENT:
65+
printPgmString(PSTR("Invalid gcode statement")); break;
66+
case STATUS_SETTING_DISABLED:
67+
printPgmString(PSTR("Grbl setting disabled")); break;
68+
case STATUS_HARD_LIMIT:
69+
printPgmString(PSTR("Limit triggered <Check and Reset>")); break;
70+
}
71+
// All other non-critical error codes are less than zero. These are defined to be any
72+
// error that is not susceptible to the alarm mode. Typically settings responses.
73+
} else {
74+
switch(status_code) {
75+
case STATUS_SETTING_INVALID:
76+
printPgmString(PSTR("Invalid setting statement")); break;
77+
case STATUS_SETTING_STEPS_NEG:
78+
printPgmString(PSTR("Steps/mm must be > 0.0")); break;
79+
case STATUS_SETTING_STEP_PULSE_MIN:
80+
printPgmString(PSTR("Step pulse must be >= 3 microseconds")); break;
81+
}
6582
}
83+
printPgmString(PSTR("\r\n"));
84+
}
85+
}
86+
87+
88+
// Prints Grbl warning messages. This serves as a centralized method to provide additional
89+
// user feedback for things that do not pass through the protocol_execute_line() function.
90+
// This includes things like initialization checks or setup warnings when features are
91+
// enabled. This function maybe called from anywhere in Grbl at the point of concern.
92+
void protocol_warning_message(int8_t warning_code)
93+
{
94+
// TODO: Install silence warning messages option in settings
95+
printPgmString(PSTR("warning: "));
96+
switch(warning_code) {
97+
case WARNING_HOMING_ENABLE:
98+
printPgmString(PSTR("Install all axes limit switches before use")); break;
99+
case WARNING_SETTING_READ_FAIL:
100+
printPgmString(PSTR("Failed to read EEPROM settings. Using defaults")); break;
66101
}
102+
printPgmString(PSTR("\r\n"));
67103
}
68104

69105

@@ -99,10 +135,11 @@ void protocol_status_report()
99135
if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) { print_position[i] *= INCH_PER_MM; }
100136
printFloat(print_position[i]);
101137
if (i < 2) { printPgmString(PSTR(",")); }
138+
else { printPgmString(PSTR("]")); }
102139
}
103140

104141
// Report work position
105-
printPgmString(PSTR("],WPos:["));
142+
printPgmString(PSTR(",WPos:["));
106143
for (i=0; i<= 2; i++) {
107144
if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) {
108145
print_position[i] -= (sys.coord_system[sys.coord_select][i]+sys.coord_offset[i])*INCH_PER_MM;
@@ -111,9 +148,10 @@ void protocol_status_report()
111148
}
112149
printFloat(print_position[i]);
113150
if (i < 2) { printPgmString(PSTR(",")); }
151+
else { printPgmString(PSTR("]")); }
114152
}
115153

116-
printPgmString(PSTR("]\r\n"));
154+
printPgmString(PSTR("\r\n"));
117155
}
118156

119157

@@ -133,7 +171,7 @@ void protocol_init()
133171
// point where the execution time from the last check point may be more than a fraction of a second.
134172
// This is a way to execute runtime commands asynchronously (aka multitasking) with grbl's g-code
135173
// parsing and planning functions. This function also serves as an interface for the interrupts to
136-
// set the system runtime flags, where only the main program to handles them, removing the need to
174+
// set the system runtime flags, where only the main program handles them, removing the need to
137175
// define more computationally-expensive volatile variables.
138176
// NOTE: The sys.execute variable flags are set by the serial read subprogram, except where noted.
139177
void protocol_execute_runtime()
@@ -185,7 +223,7 @@ void protocol_execute_runtime()
185223

186224

187225
// Executes one line of input according to protocol
188-
uint8_t protocol_execute_line(char *line)
226+
int8_t protocol_execute_line(char *line)
189227
{
190228
if(line[0] == '$') {
191229

protocol.h

+16-5
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,28 @@
2121
#ifndef protocol_h
2222
#define protocol_h
2323

24+
25+
#define LINE_BUFFER_SIZE 50
26+
27+
// Define Grbl status codes.
2428
#define STATUS_OK 0
29+
// Critical error codes. Greater than zero.
2530
#define STATUS_BAD_NUMBER_FORMAT 1
2631
#define STATUS_EXPECTED_COMMAND_LETTER 2
2732
#define STATUS_UNSUPPORTED_STATEMENT 3
2833
#define STATUS_FLOATING_POINT_ERROR 4
2934
#define STATUS_MODAL_GROUP_VIOLATION 5
30-
#define STATUS_INVALID_COMMAND 6
35+
#define STATUS_INVALID_STATEMENT 6
3136
#define STATUS_SETTING_DISABLED 7
3237
#define STATUS_HARD_LIMIT 8
38+
// Non-critical error codes. Less than zero.
39+
#define STATUS_SETTING_INVALID -1
40+
#define STATUS_SETTING_STEPS_NEG -2
41+
#define STATUS_SETTING_STEP_PULSE_MIN -3
3342

34-
#define LINE_BUFFER_SIZE 50
43+
// Define Grbl warning message codes
44+
#define WARNING_HOMING_ENABLE 1
45+
#define WARNING_SETTING_READ_FAIL 2
3546

3647
// Initialize the serial protocol
3748
void protocol_init();
@@ -41,12 +52,12 @@ void protocol_init();
4152
void protocol_process();
4253

4354
// Executes one line of input according to protocol
44-
uint8_t protocol_execute_line(char *line);
55+
int8_t protocol_execute_line(char *line);
4556

4657
// Checks and executes a runtime command at various stop points in main program
4758
void protocol_execute_runtime();
4859

49-
// Prints g-code parser status message.
50-
void protocol_status_message(int8_t status_code);
60+
// Prints any warning messages.
61+
void protocol_warning_message(int8_t warning_code);
5162

5263
#endif

serial.c

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ ISR(USART_RX_vect)
169169
sys.execute |= EXEC_ALARM; // Set alarm to allow subsystem disable for certain settings.
170170

171171
// TODO: When Grbl system status is installed, set position lost state if the cycle is active.
172+
// if (sys.cycle_start) { POSITION LOST }
172173

173174
// Immediately force stepper and spindle subsystem idle at an interrupt level.
174175
if (!(sys.execute & EXEC_RESET)) { // Force stop only first time.

0 commit comments

Comments
 (0)