@@ -36,34 +36,70 @@ static char line[LINE_BUFFER_SIZE]; // Line to be executed. Zero-terminated.
36
36
static uint8_t char_counter ; // Last character counter in line variable.
37
37
static uint8_t iscomment ; // Comment/block delete flag for processor to ignore comment characters.
38
38
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.
39
41
void protocol_status_message (int8_t status_code )
40
42
{
41
- if (status_code == 0 ) {
43
+ // TODO: Compile time option to only return numeric codes for GUIs.
44
+ if (status_code == 0 ) { // STATUS_OK
42
45
printPgmString (PSTR ("ok\r\n" ));
43
46
} else {
44
47
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
+ }
65
82
}
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 ;
66
101
}
102
+ printPgmString (PSTR ("\r\n" ));
67
103
}
68
104
69
105
@@ -99,10 +135,11 @@ void protocol_status_report()
99
135
if (bit_istrue (settings .flags ,BITFLAG_REPORT_INCHES )) { print_position [i ] *= INCH_PER_MM ; }
100
136
printFloat (print_position [i ]);
101
137
if (i < 2 ) { printPgmString (PSTR ("," )); }
138
+ else { printPgmString (PSTR ("]" )); }
102
139
}
103
140
104
141
// Report work position
105
- printPgmString (PSTR ("] ,WPos:[" ));
142
+ printPgmString (PSTR (",WPos:[" ));
106
143
for (i = 0 ; i <= 2 ; i ++ ) {
107
144
if (bit_istrue (settings .flags ,BITFLAG_REPORT_INCHES )) {
108
145
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()
111
148
}
112
149
printFloat (print_position [i ]);
113
150
if (i < 2 ) { printPgmString (PSTR ("," )); }
151
+ else { printPgmString (PSTR ("]" )); }
114
152
}
115
153
116
- printPgmString (PSTR ("] \r\n" ));
154
+ printPgmString (PSTR ("\r\n" ));
117
155
}
118
156
119
157
@@ -133,7 +171,7 @@ void protocol_init()
133
171
// point where the execution time from the last check point may be more than a fraction of a second.
134
172
// This is a way to execute runtime commands asynchronously (aka multitasking) with grbl's g-code
135
173
// 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
137
175
// define more computationally-expensive volatile variables.
138
176
// NOTE: The sys.execute variable flags are set by the serial read subprogram, except where noted.
139
177
void protocol_execute_runtime ()
@@ -185,7 +223,7 @@ void protocol_execute_runtime()
185
223
186
224
187
225
// Executes one line of input according to protocol
188
- uint8_t protocol_execute_line (char * line )
226
+ int8_t protocol_execute_line (char * line )
189
227
{
190
228
if (line [0 ] == '$' ) {
191
229
0 commit comments