26 CONTROL_DDR &= ~(CONTROL_MASK);
27 #ifdef DISABLE_CONTROL_PIN_PULL_UP
28 CONTROL_PORT &= ~(CONTROL_MASK);
30 CONTROL_PORT |= CONTROL_MASK;
32 CONTROL_PCMSK |= CONTROL_MASK;
33 PCICR |= (1 << CONTROL_INT);
41 uint8_t control_state = 0;
42 uint8_t pin = (CONTROL_PIN & CONTROL_MASK);
43 #ifdef INVERT_CONTROL_PIN_MASK
44 pin ^= INVERT_CONTROL_PIN_MASK;
52 return(control_state);
108 uint8_t char_counter = 1;
109 uint8_t helper_var = 0;
110 float parameter, value;
111 switch( line[char_counter] ) {
120 case '$':
case 'G':
case 'C':
case 'X':
169 #ifdef HOMING_SINGLE_AXIS_COMMANDS
170 }
else if (line[3] == 0) {
190 if ( line[++char_counter] == 0 ) {
193 #ifdef ENABLE_BUILD_INFO_WRITE_COMMAND
196 helper_var = char_counter;
198 line[char_counter-helper_var] = line[char_counter];
199 }
while (line[char_counter++] != 0);
205 if ((line[2] !=
'S') || (line[3] !=
'T') || (line[4] !=
'=') || (line[6] != 0)) {
return(
STATUS_INVALID_STATEMENT); }
207 #ifdef ENABLE_RESTORE_EEPROM_DEFAULT_SETTINGS
210 #ifdef ENABLE_RESTORE_EEPROM_CLEAR_PARAMETERS
213 #ifdef ENABLE_RESTORE_EEPROM_WIPE_ALL
222 if ( line[++char_counter] == 0 ) {
241 helper_var = char_counter;
243 line[char_counter-helper_var] = line[char_counter];
244 }
while (line[char_counter++] != 0);
248 if (helper_var) {
return(helper_var); }
250 helper_var = trunc(parameter);
267 #ifdef FORCE_BUFFER_SYNC_DURING_WCO_CHANGE
298 for (idx=0; idx<
N_AXIS; idx++) {
306 int32_t system_convert_corexy_to_x_axis_steps(int32_t *steps)
308 return( (steps[A_MOTOR] + steps[B_MOTOR])/2 );
310 int32_t system_convert_corexy_to_y_axis_steps(int32_t *steps)
312 return( (steps[A_MOTOR] - steps[B_MOTOR])/2 );
320 for (idx=0; idx<
N_AXIS; idx++) {
321 #ifdef HOMING_FORCE_SET_ORIGIN
void mc_homing_cycle(uint8_t cycle_mask)
Perform homing cycle to locate and set machine zero. Only '$H' executes this command.
#define N_AXIS
Axis array index values. Must start with 0 and be continuous.
uint8_t system_check_safety_door_ajar()
Returns if safety door is ajar(T) or closed(F), based on pin state.
#define N_STARTUP_LINE
Enables single axis homing commands. $HX, $HY, and $HZ for X, Y, and Z-axis homing. The full homing.
void report_grbl_help()
Grbl help message.
void report_grbl_settings()
Grbl global settings print out.
#define STATE_HOLD
Active feed hold.
void system_convert_array_steps_to_mpos(float *position, int32_t *steps)
Updates a machine 'position' array based on the 'step' array sent.
uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr)
Extracts a floating point value from a string. The following code is based loosely on...
uint8_t gc_execute_line(char *line)
Executes one line of 0-terminated G-Code. The line is assumed to contain only uppercase.
void report_status_message(uint8_t status_code)
Handles the primary confirmation protocol response for streaming interfaces and human-feedback.
#define bit_true(x, mask)
ISR(CONTROL_INT_vect)
Pin change interrupt for pin-out commands, i.e. cycle start, feed hold, and reset. Sets.
uint8_t system_execute_line(char *line)
Directs and executes one line of formatted input from protocol_process. While mostly.
#define CONTROL_PIN_INDEX_FEED_HOLD
void system_flag_wco_change()
#define STATUS_CHECK_DOOR
#define STATUS_BAD_NUMBER_FORMAT
void system_set_exec_state_flag(uint8_t mask)
Special handlers for setting and clearing Grbl's real-time execution flags.
void protocol_buffer_synchronize()
Block until all buffered steps are executed or in a cycle state. Works with feed hold.
void report_ngc_parameters()
Prints Grbl NGC parameters (coordinate offsets, probing)
void system_clear_exec_accessory_overrides()
void settings_store_startup_line(uint8_t n, char *line)
Method to store startup lines into EEPROM.
void report_feedback_message(uint8_t message_code)
Prints feedback messages. This serves as a centralized method to provide additional.
uint8_t system_control_get_state()
Returns control pin state as a uint8 bitfield. Each bit indicates the input pin state, where.
volatile uint8_t sys_rt_exec_alarm
Global realtime executor bitflag variable for setting various alarms.
uint8_t state
Tracks the current system state of Grbl.
void system_set_exec_motion_override_flag(uint8_t mask)
#define MESSAGE_RESTORE_DEFAULTS
#define STATUS_LINE_LENGTH_EXCEEDED
#define STATUS_SETTING_DISABLED
#define EXEC_SAFETY_DOOR
bitmask 00100000
#define BITFLAG_HOMING_ENABLE
void settings_store_build_info(char *line)
Method to store build info into EEPROM.
#define X_AXIS
Axis indexing value.
uint8_t report_wco_counter
Tracks when to add work coordinate offset data to status reports.
#define HOMING_CYCLE_ALL
Must be zero.
#define bit(n)
Bit field and masking macros.
uint8_t abort
System abort flag. Forces exit back to main loop for reset.
#define STATUS_INVALID_STATEMENT
uint8_t settings_read_startup_line(uint8_t n, char *line)
Reads startup line from EEPROM. Updated pointed line string data.
void system_clear_exec_alarm()
volatile uint8_t sys_rt_exec_motion_override
Global realtime executor bitflag variable for motion-based overrides.
void report_startup_line(uint8_t n, char *line)
Prints specified startup line.
#define STATE_CYCLE
Cycle is running or motions are being executed.
#define CONTROL_PIN_INDEX_CYCLE_START
void report_build_info(char *line)
Prints build info line.
uint8_t flags
Contains default boolean settings.
#define STATE_CHECK_MODE
G-code check mode. Locks out planner and motion only.
void report_gcode_modes()
Print current gcode parser mode state.
#define MESSAGE_ALARM_UNLOCK
#define STATE_ALARM
In alarm state. Locks out all g-code processes. Allows settings access.
#define CONTROL_PIN_INDEX_RESET
#define EXEC_CYCLE_START
bitmask 00000010
system_t sys
Declare system global variable structure.
float system_convert_axis_steps_to_mpos(int32_t *steps, uint8_t idx)
Returns machine position of axis 'idx'. Must be sent a 'step' array.
#define SETTINGS_RESTORE_PARAMETERS
void st_go_idle()
Stepper shutdown.
float steps_per_mm[N_AXIS]
void system_clear_exec_state_flag(uint8_t mask)
#define bit_isfalse(x, mask)
uint8_t system_check_travel_limits(float *target)
CoreXY calculation only. Returns x or y-axis "steps" based on CoreXY motor steps. ...
#define CONTROL_PIN_INDEX_SAFETY_DOOR
#define EXEC_SLEEP
bitmask 10000000
volatile uint8_t sys_rt_exec_state
Global realtime executor bitflag variable for state management. See EXEC bitmasks.
#define EXEC_FEED_HOLD
bitmask 00001000
void system_set_exec_accessory_override_flag(uint8_t mask)
void report_execute_startup_message(char *line, uint8_t status_code)
#define SETTINGS_RESTORE_DEFAULTS
Define settings restore bitflags.
#define STATE_JOG
Jogging mode.
#define STATE_HOMING
Performing homing cycle.
uint8_t settings_read_build_info(char *line)
Reads startup line from EEPROM. Updated pointed line string data.
void system_set_exec_alarm(uint8_t code)
void system_init()
Initialize the serial protocol.
#define STATUS_SETTING_READ_FAIL
void mc_reset()
Method to ready the system to reset by setting the realtime reset command and killing any...
volatile uint8_t sys_rt_exec_accessory_override
Global realtime executor bitflag variable for spindle/coolant overrides.
uint8_t settings_store_global_setting(uint8_t parameter, float value)
A helper method to set settings from command line.
void system_execute_startup(char *line)
Executes user startup script, if stored.
#define STATUS_OK
Define Grbl status codes. Valid values (0-255)
#define STATUS_IDLE_ERROR
void settings_restore(uint8_t restore_flag)
Method to restore EEPROM-saved Grbl global settings back to defaults.
void system_clear_exec_motion_overrides()
#define STATE_IDLE
Define system state bit map. The state variable primarily tracks the individual functions.
#define bit_istrue(x, mask)