diff --git a/grbl/.vscode/settings.json b/grbl/.vscode/settings.json new file mode 100644 index 0000000..2143081 --- /dev/null +++ b/grbl/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "typeinfo": "c" + } +} \ No newline at end of file diff --git a/grbl/coolant_control.c b/grbl/coolant_control.c index 1eebfc0..034e7b1 100644 --- a/grbl/coolant_control.c +++ b/grbl/coolant_control.c @@ -23,35 +23,37 @@ void coolant_init() { - COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); // Configure as output pin - #ifdef ENABLE_M7 - COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT); - #endif - coolant_stop(); +printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__); +// COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); // Configure as output pin +// #ifdef ENABLE_M7 +// COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT); +// #endif +// coolant_stop(); } // Returns current coolant output state. Overrides may alter it from programmed state. uint8_t coolant_get_state() { - uint8_t cl_state = COOLANT_STATE_DISABLE; - #ifdef INVERT_COOLANT_FLOOD_PIN - if (bit_isfalse(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) { - #else - if (bit_istrue(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) { - #endif - cl_state |= COOLANT_STATE_FLOOD; - } - #ifdef ENABLE_M7 - #ifdef INVERT_COOLANT_MIST_PIN - if (bit_isfalse(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) { - #else - if (bit_istrue(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) { - #endif - cl_state |= COOLANT_STATE_MIST; - } - #endif - return(cl_state); + printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__); +// uint8_t cl_state = COOLANT_STATE_DISABLE; +// #ifdef INVERT_COOLANT_FLOOD_PIN +// if (bit_isfalse(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) { +// #else +// if (bit_istrue(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) { +// #endif +// cl_state |= COOLANT_STATE_FLOOD; +// } +// #ifdef ENABLE_M7 +// #ifdef INVERT_COOLANT_MIST_PIN +// if (bit_isfalse(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) { +// #else +// if (bit_istrue(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) { +// #endif +// cl_state |= COOLANT_STATE_MIST; +// } +// #endif +// return(cl_state); } @@ -59,18 +61,20 @@ uint8_t coolant_get_state() // an interrupt-level. No report flag set, but only called by routines that don't need it. void coolant_stop() { - #ifdef INVERT_COOLANT_FLOOD_PIN - COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); - #else - COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); - #endif - #ifdef ENABLE_M7 - #ifdef INVERT_COOLANT_MIST_PIN - COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); - #else - COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); - #endif - #endif + printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__); + +// #ifdef INVERT_COOLANT_FLOOD_PIN +// COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); +// #else +// COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); +// #endif +// #ifdef ENABLE_M7 +// #ifdef INVERT_COOLANT_MIST_PIN +// COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); +// #else +// COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); +// #endif +// #endif } @@ -80,39 +84,41 @@ void coolant_stop() // parser program end, and g-code parser coolant_sync(). void coolant_set_state(uint8_t mode) { - if (sys.abort) { return; } // Block during abort. - - if (mode & COOLANT_FLOOD_ENABLE) { - #ifdef INVERT_COOLANT_FLOOD_PIN - COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); - #else - COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); - #endif - } else { - #ifdef INVERT_COOLANT_FLOOD_PIN - COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); - #else - COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); - #endif - } - - #ifdef ENABLE_M7 - if (mode & COOLANT_MIST_ENABLE) { - #ifdef INVERT_COOLANT_MIST_PIN - COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); - #else - COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); - #endif - } else { - #ifdef INVERT_COOLANT_MIST_PIN - COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); - #else - COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); - #endif - } - #endif - - sys.report_ovr_counter = 0; // Set to report change immediately + printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__); + +// if (sys.abort) { return; } // Block during abort. +// +// if (mode & COOLANT_FLOOD_ENABLE) { +// #ifdef INVERT_COOLANT_FLOOD_PIN +// COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); +// #else +// COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); +// #endif +// } else { +// #ifdef INVERT_COOLANT_FLOOD_PIN +// COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); +// #else +// COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); +// #endif +// } +// +// #ifdef ENABLE_M7 +// if (mode & COOLANT_MIST_ENABLE) { +// #ifdef INVERT_COOLANT_MIST_PIN +// COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); +// #else +// COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); +// #endif +// } else { +// #ifdef INVERT_COOLANT_MIST_PIN +// COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); +// #else +// COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); +// #endif +// } +// #endif +// +// sys.report_ovr_counter = 0; // Set to report change immediately } @@ -120,7 +126,8 @@ void coolant_set_state(uint8_t mode) // if an abort or check-mode is active. void coolant_sync(uint8_t mode) { - if (sys.state == STATE_CHECK_MODE) { return; } - protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program. - coolant_set_state(mode); + printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__); + //if (sys.state == STATE_CHECK_MODE) { return; } + //protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program. + //coolant_set_state(mode); } diff --git a/grbl/eeprom.c b/grbl/eeprom.c index 02caf20..e6da28d 100644 --- a/grbl/eeprom.c +++ b/grbl/eeprom.c @@ -21,21 +21,82 @@ * $Revision: 1.6 $ * $Date: Friday, February 11, 2005 07:16:44 UTC $ ****************************************************************************/ -#include -#include +//#include +//#include + + +// ecmc added +#include +#include +#define EEPROM_DUMMY_FILE ./ecmc_grbl_eeprom.txt +#define EEPROM_MEM_SIZE 512 +char buffer[EEPROM_MEM_SIZE]; + /* These EEPROM bits have different names on different devices. */ -#ifndef EEPE - #define EEPE EEWE //!< EEPROM program/write enable. - #define EEMPE EEMWE //!< EEPROM master program/write enable. -#endif +//#ifndef EEPE +// #define EEPE EEWE //!< EEPROM program/write enable. +// #define EEMPE EEMWE //!< EEPROM master program/write enable. +//#endif /* These two are unfortunately not defined in the device include files. */ -#define EEPM1 5 //!< EEPROM Programming Mode Bit 1. -#define EEPM0 4 //!< EEPROM Programming Mode Bit 0. +//#define EEPM1 5 //!< EEPROM Programming Mode Bit 1. +//#define EEPM0 4 //!< EEPROM Programming Mode Bit 0. /* Define to reduce code size. */ -#define EEPROM_IGNORE_SELFPROG //!< Remove SPM flag polling. +//#define EEPROM_IGNORE_SELFPROG //!< Remove SPM flag polling. + + +// Init file +void ecmc_init_file() { + printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); + memset(&buffer[0],0,EEPROM_MEM_SIZE); + ecmc_mem_to_file(); +} + +// Read file to buffer[] +unsigned char ecmc_file_to_mem() +{ + printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); + + FILE* fh = fopen(EEPROM_DUMMY_FILE, "rd"); + + if (fh == NULL) + { + printf("something went wrong and file could not be opened"); + return 1; + } + unsigned char c = 0; + for (int i = 0, i < EEPROM_MEM_SIZE ; i++) { + // Get the characters + buffer[i] = fgetc(fh); + } + + fclose(fh); + return 0; +} + +// Write buffer[] to file +unsigned char void ecmc_mem_to_file() +{ + printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); + + FILE* fh = fopen(EEPROM_DUMMY_FILE, "w"); + + if (fh == NULL) + { + printf("something went wrong and file could not be opened"); + return 1; + } + for (int i = 0, i < EEPROM_MEM_SIZE ; i++) { + // Get the characters + fputc (buffer[i], fh); + } + + fclose(fh); + return 0; +} + /*! \brief Read byte from EEPROM. * @@ -48,10 +109,15 @@ */ unsigned char eeprom_get_char( unsigned int addr ) { - do {} while( EECR & (1< 0; size--) { checksum = (checksum << 1) || (checksum >> 7); @@ -138,6 +211,7 @@ void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsi } int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size) { + printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); unsigned char data, checksum = 0; for(; size > 0; size--) { data = eeprom_get_char(source++); diff --git a/grbl/eeprom.h b/grbl/eeprom.h index c9718a2..6760262 100644 --- a/grbl/eeprom.h +++ b/grbl/eeprom.h @@ -21,6 +21,9 @@ #ifndef eeprom_h #define eeprom_h +//Added for ecmc +void ecmc_init_file(); + unsigned char eeprom_get_char(unsigned int addr); void eeprom_put_char(unsigned int addr, unsigned char new_value); void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size); diff --git a/grbl/grbl.h b/grbl/grbl.h index dd8e781..3f75e4f 100644 --- a/grbl/grbl.h +++ b/grbl/grbl.h @@ -26,11 +26,11 @@ #define GRBL_VERSION_BUILD "20190830" // Define standard libraries used by Grbl. -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include #include #include #include diff --git a/grbl/limits.c b/grbl/limits.c index 1348c14..931f430 100644 --- a/grbl/limits.c +++ b/grbl/limits.c @@ -20,7 +20,7 @@ */ #include "grbl.h" - +#include "ecmcMotion.h" // Homing axis search distance multiplier. Computed by this value times the cycle travel. #ifndef HOMING_AXIS_SEARCH_SCALAR @@ -40,34 +40,37 @@ void limits_init() { - LIMIT_DDR &= ~(LIMIT_MASK); // Set as input pins + printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__); - #ifdef DISABLE_LIMIT_PIN_PULL_UP - LIMIT_PORT &= ~(LIMIT_MASK); // Normal low operation. Requires external pull-down. - #else - LIMIT_PORT |= (LIMIT_MASK); // Enable internal pull-up resistors. Normal high operation. - #endif - - if (bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE)) { - LIMIT_PCMSK |= LIMIT_MASK; // Enable specific pins of the Pin Change Interrupt - PCICR |= (1 << LIMIT_INT); // Enable Pin Change Interrupt - } else { - limits_disable(); - } - - #ifdef ENABLE_SOFTWARE_DEBOUNCE - MCUSR &= ~(1<condition = (PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE); - #ifdef USE_LINE_NUMBERS - pl_data->line_number = HOMING_CYCLE_LINE_NUMBER; - #endif - - // Initialize variables used for homing computations. - uint8_t n_cycle = (2*N_HOMING_LOCATE_CYCLE+1); - uint8_t step_pin[N_AXIS]; - #ifdef ENABLE_DUAL_AXIS - uint8_t step_pin_dual; - uint8_t dual_axis_async_check; - int32_t dual_trigger_position; - #if (DUAL_AXIS_SELECT == X_AXIS) - float fail_distance = (-DUAL_AXIS_HOMING_FAIL_AXIS_LENGTH_PERCENT/100.0)*settings.max_travel[Y_AXIS]; - #else - float fail_distance = (-DUAL_AXIS_HOMING_FAIL_AXIS_LENGTH_PERCENT/100.0)*settings.max_travel[X_AXIS]; - #endif - fail_distance = min(fail_distance, DUAL_AXIS_HOMING_FAIL_DISTANCE_MAX); - fail_distance = max(fail_distance, DUAL_AXIS_HOMING_FAIL_DISTANCE_MIN); - int32_t dual_fail_distance = trunc(fail_distance*settings.steps_per_mm[DUAL_AXIS_SELECT]); - // int32_t dual_fail_distance = trunc((DUAL_AXIS_HOMING_TRIGGER_FAIL_DISTANCE)*settings.steps_per_mm[DUAL_AXIS_SELECT]); - #endif - float target[N_AXIS]; - float max_travel = 0.0; - uint8_t idx; - for (idx=0; idxfeed_rate = homing_rate; // Set current homing rate. - plan_buffer_line(target, pl_data); // Bypass mc_line(). Directly plan homing motion. - - sys.step_control = STEP_CONTROL_EXECUTE_SYS_MOTION; // Set to execute homing motion and clear existing flags. - st_prep_buffer(); // Prep and fill segment buffer from newly planned block. - st_wake_up(); // Initiate motion - do { - if (approach) { - // Check limit state. Lock out cycle axes when they change. - limit_state = limits_get_state(); - for (idx=0; idx dual_fail_distance) { - system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_DUAL_APPROACH); - mc_reset(); - protocol_execute_realtime(); - return; - } - } - } else { - dual_axis_async_check |= DUAL_AXIS_CHECK_ENABLE; - dual_trigger_position = sys_position[DUAL_AXIS_SELECT]; - } - } - #endif - } - - st_prep_buffer(); // Check and prep segment buffer. NOTE: Should take no longer than 200us. - - // Exit routines: No time to run protocol_execute_realtime() in this loop. - if (sys_rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_RESET | EXEC_CYCLE_STOP)) { - uint8_t rt_exec = sys_rt_exec_state; - // Homing failure condition: Reset issued during cycle. - if (rt_exec & EXEC_RESET) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET); } - // Homing failure condition: Safety door was opened. - if (rt_exec & EXEC_SAFETY_DOOR) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_DOOR); } - // Homing failure condition: Limit switch still engaged after pull-off motion - if (!approach && (limits_get_state() & cycle_mask)) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_PULLOFF); } - // Homing failure condition: Limit switch not found during approach. - if (approach && (rt_exec & EXEC_CYCLE_STOP)) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_APPROACH); } - if (sys_rt_exec_alarm) { - mc_reset(); // Stop motors, if they are running. - protocol_execute_realtime(); - return; - } else { - // Pull-off motion complete. Disable CYCLE_STOP from executing. - system_clear_exec_state_flag(EXEC_CYCLE_STOP); - break; - } - } - - #ifdef ENABLE_DUAL_AXIS - } while ((STEP_MASK & axislock) || (sys.homing_axis_lock_dual)); - #else - } while (STEP_MASK & axislock); - #endif - - st_reset(); // Immediately force kill steppers and reset step segment buffer. - delay_ms(settings.homing_debounce_delay); // Delay to allow transient dynamics to dissipate. - - // Reverse direction and reset homing rate for locate cycle(s). - approach = !approach; - - // After first cycle, homing enters locating phase. Shorten search to pull-off distance. - if (approach) { - max_travel = settings.homing_pulloff*HOMING_AXIS_LOCATE_SCALAR; - homing_rate = settings.homing_feed_rate; - } else { - max_travel = settings.homing_pulloff; - homing_rate = settings.homing_seek_rate; - } - - } while (n_cycle-- > 0); - - // The active cycle axes should now be homed and machine limits have been located. By - // default, Grbl defines machine space as all negative, as do most CNCs. Since limit switches - // can be on either side of an axes, check and set axes machine zero appropriately. Also, - // set up pull-off maneuver from axes limit switches that have been homed. This provides - // some initial clearance off the switches and should also help prevent them from falsely - // triggering when hard limits are enabled or when more than one axes shares a limit pin. - int32_t set_axis_position; - // Set machine positions for homed limit switches. Don't update non-homed axes. - for (idx=0; idxcondition = (PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE); +// #ifdef USE_LINE_NUMBERS +// pl_data->line_number = HOMING_CYCLE_LINE_NUMBER; +// #endif +// +// // Initialize variables used for homing computations. +// uint8_t n_cycle = (2*N_HOMING_LOCATE_CYCLE+1); +// uint8_t step_pin[N_AXIS]; +// #ifdef ENABLE_DUAL_AXIS +// uint8_t step_pin_dual; +// uint8_t dual_axis_async_check; +// int32_t dual_trigger_position; +// #if (DUAL_AXIS_SELECT == X_AXIS) +// float fail_distance = (-DUAL_AXIS_HOMING_FAIL_AXIS_LENGTH_PERCENT/100.0)*settings.max_travel[Y_AXIS]; +// #else +// float fail_distance = (-DUAL_AXIS_HOMING_FAIL_AXIS_LENGTH_PERCENT/100.0)*settings.max_travel[X_AXIS]; +// #endif +// fail_distance = min(fail_distance, DUAL_AXIS_HOMING_FAIL_DISTANCE_MAX); +// fail_distance = max(fail_distance, DUAL_AXIS_HOMING_FAIL_DISTANCE_MIN); +// int32_t dual_fail_distance = trunc(fail_distance*settings.steps_per_mm[DUAL_AXIS_SELECT]); +// // int32_t dual_fail_distance = trunc((DUAL_AXIS_HOMING_TRIGGER_FAIL_DISTANCE)*settings.steps_per_mm[DUAL_AXIS_SELECT]); +// #endif +// float target[N_AXIS]; +// float max_travel = 0.0; +// uint8_t idx; +// for (idx=0; idxfeed_rate = homing_rate; // Set current homing rate. +// plan_buffer_line(target, pl_data); // Bypass mc_line(). Directly plan homing motion. +// +// sys.step_control = STEP_CONTROL_EXECUTE_SYS_MOTION; // Set to execute homing motion and clear existing flags. +// st_prep_buffer(); // Prep and fill segment buffer from newly planned block. +// st_wake_up(); // Initiate motion +// do { +// if (approach) { +// // Check limit state. Lock out cycle axes when they change. +// limit_state = limits_get_state(); +// for (idx=0; idx dual_fail_distance) { +// system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_DUAL_APPROACH); +// mc_reset(); +// protocol_execute_realtime(); +// return; +// } +// } +// } else { +// dual_axis_async_check |= DUAL_AXIS_CHECK_ENABLE; +// dual_trigger_position = sys_position[DUAL_AXIS_SELECT]; +// } +// } +// #endif +// } +// +// st_prep_buffer(); // Check and prep segment buffer. NOTE: Should take no longer than 200us. +// +// // Exit routines: No time to run protocol_execute_realtime() in this loop. +// if (sys_rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_RESET | EXEC_CYCLE_STOP)) { +// uint8_t rt_exec = sys_rt_exec_state; +// // Homing failure condition: Reset issued during cycle. +// if (rt_exec & EXEC_RESET) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET); } +// // Homing failure condition: Safety door was opened. +// if (rt_exec & EXEC_SAFETY_DOOR) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_DOOR); } +// // Homing failure condition: Limit switch still engaged after pull-off motion +// if (!approach && (limits_get_state() & cycle_mask)) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_PULLOFF); } +// // Homing failure condition: Limit switch not found during approach. +// if (approach && (rt_exec & EXEC_CYCLE_STOP)) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_APPROACH); } +// if (sys_rt_exec_alarm) { +// mc_reset(); // Stop motors, if they are running. +// protocol_execute_realtime(); +// return; +// } else { +// // Pull-off motion complete. Disable CYCLE_STOP from executing. +// system_clear_exec_state_flag(EXEC_CYCLE_STOP); +// break; +// } +// } +// +// #ifdef ENABLE_DUAL_AXIS +// } while ((STEP_MASK & axislock) || (sys.homing_axis_lock_dual)); +// #else +// } while (STEP_MASK & axislock); +// #endif +// +// st_reset(); // Immediately force kill steppers and reset step segment buffer. +// delay_ms(settings.homing_debounce_delay); // Delay to allow transient dynamics to dissipate. +// +// // Reverse direction and reset homing rate for locate cycle(s). +// approach = !approach; +// +// // After first cycle, homing enters locating phase. Shorten search to pull-off distance. +// if (approach) { +// max_travel = settings.homing_pulloff*HOMING_AXIS_LOCATE_SCALAR; +// homing_rate = settings.homing_feed_rate; +// } else { +// max_travel = settings.homing_pulloff; +// homing_rate = settings.homing_seek_rate; +// } +// +// } while (n_cycle-- > 0); +// +// // The active cycle axes should now be homed and machine limits have been located. By +// // default, Grbl defines machine space as all negative, as do most CNCs. Since limit switches +// // can be on either side of an axes, check and set axes machine zero appropriately. Also, +// // set up pull-off maneuver from axes limit switches that have been homed. This provides +// // some initial clearance off the switches and should also help prevent them from falsely +// // triggering when hard limits are enabled or when more than one axes shares a limit pin. +// int32_t set_axis_position; +// // Set machine positions for homed limit switches. Don't update non-homed axes. +// for (idx=0; idx +CLOCK_MONOTONIC + // Extracts a floating point value from a string. The following code is based loosely on // the avr-libc strtod() function by Michael Stumpf and Dmitry Xmelkov and many freely @@ -111,18 +115,21 @@ uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr) // Non-blocking delay function used for general operation and suspend features. void delay_sec(float seconds, uint8_t mode) { - uint16_t i = ceil(1000/DWELL_TIME_STEP*seconds); - while (i-- > 0) { - if (sys.abort) { return; } - if (mode == DELAY_MODE_DWELL) { - protocol_execute_realtime(); - } else { // DELAY_MODE_SYS_SUSPEND - // Execute rt_system() only to avoid nesting suspend loops. - protocol_exec_rt_system(); - if (sys.suspend & SUSPEND_RESTART_RETRACT) { return; } // Bail, if safety door reopens. - } - _delay_ms(DWELL_TIME_STEP); // Delay DWELL_TIME_STEP increment - } + + clock_nanosleep(CLOCK_MONOTONIC,0,1E9); + + //uint16_t i = ceil(1000/DWELL_TIME_STEP*seconds); + //while (i-- > 0) { + // if (sys.abort) { return; } + // if (mode == DELAY_MODE_DWELL) { + // protocol_execute_realtime(); + // } else { // DELAY_MODE_SYS_SUSPEND + // // Execute rt_system() only to avoid nesting suspend loops. + // protocol_exec_rt_system(); + // if (sys.suspend & SUSPEND_RESTART_RETRACT) { return; } // Bail, if safety door reopens. + // } + // _delay_ms(DWELL_TIME_STEP); // Delay DWELL_TIME_STEP increment + //} } @@ -130,7 +137,8 @@ void delay_sec(float seconds, uint8_t mode) // which only accepts constants in future compiler releases. void delay_ms(uint16_t ms) { - while ( ms-- ) { _delay_ms(1); } + clock_nanosleep(CLOCK_MONOTONIC,0,1E6); + //while ( ms-- ) { _delay_ms(1); } } @@ -139,21 +147,23 @@ void delay_ms(uint16_t ms) // efficiently with larger delays, as the counter adds parasitic time in each iteration. void delay_us(uint32_t us) { - while (us) { - if (us < 10) { - _delay_us(1); - us--; - } else if (us < 100) { - _delay_us(10); - us -= 10; - } else if (us < 1000) { - _delay_us(100); - us -= 100; - } else { - _delay_ms(1); - us -= 1000; - } - } + clock_nanosleep(CLOCK_MONOTONIC,0,1E3); + + //while (us) { + // if (us < 10) { + // _delay_us(1); + // us--; + // } else if (us < 100) { + // _delay_us(10); + // us -= 10; + // } else if (us < 1000) { + // _delay_us(100); + // us -= 100; + // } else { + // _delay_ms(1); + // us -= 1000; + // } + //} } diff --git a/grbl/print.c b/grbl/print.c index 771e399..61e28aa 100644 --- a/grbl/print.c +++ b/grbl/print.c @@ -24,17 +24,20 @@ void printString(const char *s) { - while (*s) - serial_write(*s++); + printf("%s:%s:%d:%s\n",__FILE__,__FUNCTION__,__LINE__,s); + + //while (*s) + // serial_write(*s++); } // Print a string stored in PGM-memory void printPgmString(const char *s) { - char c; - while ((c = pgm_read_byte_near(s++))) - serial_write(c); + printf("%s:%s:%d: Not supported\n",__FILE__,__FUNCTION__,__LINE__,s); +// char c; +// while ((c = pgm_read_byte_near(s++))) +// serial_write(c); } @@ -63,24 +66,30 @@ void printPgmString(const char *s) // Prints an uint8 variable in base 10. void print_uint8_base10(uint8_t n) { - uint8_t digit_a = 0; - uint8_t digit_b = 0; - if (n >= 100) { // 100-255 - digit_a = '0' + n % 10; - n /= 10; - } - if (n >= 10) { // 10-99 - digit_b = '0' + n % 10; - n /= 10; - } - serial_write('0' + n); - if (digit_b) { serial_write(digit_b); } - if (digit_a) { serial_write(digit_a); } + printf("%s:%s:%d:%d\n",__FILE__,__FUNCTION__,__LINE__,n); + + //uint8_t digit_a = 0; + //uint8_t digit_b = 0; + //if (n >= 100) { // 100-255 + // digit_a = '0' + n % 10; + // n /= 10; + //} + //if (n >= 10) { // 10-99 + // digit_b = '0' + n % 10; + // n /= 10; + //} + //serial_write('0' + n); + //if (digit_b) { serial_write(digit_b); } + //if (digit_a) { serial_write(digit_a); } } // Prints an uint8 variable in base 2 with desired number of desired digits. void print_uint8_base2_ndigit(uint8_t n, uint8_t digits) { + + + printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__,n); + unsigned char buf[digits]; uint8_t i = 0; @@ -89,39 +98,46 @@ void print_uint8_base2_ndigit(uint8_t n, uint8_t digits) { n /= 2; } - for (; i > 0; i--) - serial_write('0' + buf[i - 1]); + for (; i > 0; i--) { + //serial_write('0' + buf[i - 1]); + printf("%c", '0' + buf[i - 1]); + } + printf("\n"); } void print_uint32_base10(uint32_t n) { - if (n == 0) { - serial_write('0'); - return; - } + printf("%s:%s:%d:%d\n",__FILE__,__FUNCTION__,__LINE__,n); - unsigned char buf[10]; - uint8_t i = 0; - - while (n > 0) { - buf[i++] = n % 10; - n /= 10; - } - - for (; i > 0; i--) - serial_write('0' + buf[i-1]); +// if (n == 0) { +// serial_write('0'); +// return; +// } +// +// unsigned char buf[10]; +// uint8_t i = 0; +// +// while (n > 0) { +// buf[i++] = n % 10; +// n /= 10; +// } +// +// for (; i > 0; i--) +// serial_write('0' + buf[i-1]); } void printInteger(long n) { - if (n < 0) { - serial_write('-'); - print_uint32_base10(-n); - } else { - print_uint32_base10(n); - } + printf("%s:%s:%d:%d\n",__FILE__,__FUNCTION__,__LINE__,n); + + //if (n < 0) { + // serial_write('-'); + // print_uint32_base10(-n); + //} else { + // print_uint32_base10(n); + //} } @@ -132,39 +148,41 @@ void printInteger(long n) // techniques are actually just slightly slower. Found this out the hard way. void printFloat(float n, uint8_t decimal_places) { - if (n < 0) { - serial_write('-'); - n = -n; - } + printf("%s:%s:%d:%f\n",__FILE__,__FUNCTION__,__LINE__,n); - uint8_t decimals = decimal_places; - while (decimals >= 2) { // Quickly convert values expected to be E0 to E-4. - n *= 100; - decimals -= 2; - } - if (decimals) { n *= 10; } - n += 0.5; // Add rounding factor. Ensures carryover through entire value. - - // Generate digits backwards and store in string. - unsigned char buf[13]; - uint8_t i = 0; - uint32_t a = (long)n; - while(a > 0) { - buf[i++] = (a % 10) + '0'; // Get digit - a /= 10; - } - while (i < decimal_places) { - buf[i++] = '0'; // Fill in zeros to decimal point for (n < 1) - } - if (i == decimal_places) { // Fill in leading zero, if needed. - buf[i++] = '0'; - } - - // Print the generated string. - for (; i > 0; i--) { - if (i == decimal_places) { serial_write('.'); } // Insert decimal point in right place. - serial_write(buf[i-1]); - } +// if (n < 0) { +// serial_write('-'); +// n = -n; +// } +// +// uint8_t decimals = decimal_places; +// while (decimals >= 2) { // Quickly convert values expected to be E0 to E-4. +// n *= 100; +// decimals -= 2; +// } +// if (decimals) { n *= 10; } +// n += 0.5; // Add rounding factor. Ensures carryover through entire value. +// +// // Generate digits backwards and store in string. +// unsigned char buf[13]; +// uint8_t i = 0; +// uint32_t a = (long)n; +// while(a > 0) { +// buf[i++] = (a % 10) + '0'; // Get digit +// a /= 10; +// } +// while (i < decimal_places) { +// buf[i++] = '0'; // Fill in zeros to decimal point for (n < 1) +// } +// if (i == decimal_places) { // Fill in leading zero, if needed. +// buf[i++] = '0'; +// } +// +// // Print the generated string. +// for (; i > 0; i--) { +// if (i == decimal_places) { serial_write('.'); } // Insert decimal point in right place. +// //serial_write(buf[i-1]); +// } } diff --git a/grbl/probe.c b/grbl/probe.c index 60c9073..7da453e 100644 --- a/grbl/probe.c +++ b/grbl/probe.c @@ -28,13 +28,15 @@ uint8_t probe_invert_mask; // Probe pin initialization routine. void probe_init() { - PROBE_DDR &= ~(PROBE_MASK); // Configure as input pins - #ifdef DISABLE_PROBE_PIN_PULL_UP - PROBE_PORT &= ~(PROBE_MASK); // Normal low operation. Requires external pull-down. - #else - PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation. - #endif - probe_configure_invert_mask(false); // Initialize invert mask. + printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__); + +// PROBE_DDR &= ~(PROBE_MASK); // Configure as input pins +// #ifdef DISABLE_PROBE_PIN_PULL_UP +// PROBE_PORT &= ~(PROBE_MASK); // Normal low operation. Requires external pull-down. +// #else +// PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation. +// #endif +// probe_configure_invert_mask(false); // Initialize invert mask. } @@ -43,14 +45,21 @@ void probe_init() // and the probing cycle modes for toward-workpiece/away-from-workpiece. void probe_configure_invert_mask(uint8_t is_probe_away) { - probe_invert_mask = 0; // Initialize as zero. - if (bit_isfalse(settings.flags,BITFLAG_INVERT_PROBE_PIN)) { probe_invert_mask ^= PROBE_MASK; } - if (is_probe_away) { probe_invert_mask ^= PROBE_MASK; } + printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__); + + //probe_invert_mask = 0; // Initialize as zero. + //if (bit_isfalse(settings.flags,BITFLAG_INVERT_PROBE_PIN)) { probe_invert_mask ^= PROBE_MASK; } + //if (is_probe_away) { probe_invert_mask ^= PROBE_MASK; } } // Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor. -uint8_t probe_get_state() { return((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask); } +uint8_t probe_get_state() +{ + printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__); + return 0; + //return((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask); +} // Monitors probe pin state and records the system position when detected. Called by the @@ -58,6 +67,7 @@ uint8_t probe_get_state() { return((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask) // NOTE: This function must be extremely efficient as to not bog down the stepper ISR. void probe_state_monitor() { + printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__); if (probe_get_state()) { sys_probe_state = PROBE_OFF; memcpy(sys_probe_position, sys_position, sizeof(sys_position)); diff --git a/grbl/system.c b/grbl/system.c index 55e6c40..f8d8334 100644 --- a/grbl/system.c +++ b/grbl/system.c @@ -120,6 +120,9 @@ void system_execute_startup(char *line) // the lines that are processed afterward, not necessarily real-time during a cycle, // since there are motions already stored in the buffer. However, this 'lag' should not // be an issue, since these commands are not typically used during a cycle. + + +// Anders: MAIN entry point for configuration and G-CODE!!!!! uint8_t system_execute_line(char *line) { uint8_t char_counter = 1;