From 81505e6a8111dd0fcbd4c8c0e88b5c65de5b4904 Mon Sep 17 00:00:00 2001 From: Sonny Jeon Date: Sat, 20 Jun 2015 10:27:24 -0600 Subject: [PATCH] New EEPROM restore functions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Tweaked the previous EEPROM restore implementation and added new functionality. - `$RST=$` restores the `$$` grbl settings back to firmware defaults, which are set when compiled. - `$RST=#` restores the `$#` parameters in EEPROM. At times it’s useful to clear these and start over, rather than manually writing each entry. -`$RST=*` wipe all of the data in EEPROM that Grbl uses and restores them to defaults. This includes `$$` settings, `$#` parameters, `$N` startup lines, and `$i` build info string. NOTE: This doesn’t write zeros throughout the EEPROM. It only writes where Grbl looks for data. For a complete wipe, please use the Arduino IDE’s EEPROM clear example. - Refactored the restore and wipe functions in settings.c to accommodate the new commands. --- README.md | 4 +- doc/log/commit_log_v0.9i.txt | 6 ++ grbl/grbl.h | 2 +- grbl/settings.c | 136 ++++++++++++++++------------------- grbl/settings.h | 14 ++-- grbl/system.c | 11 ++- 6 files changed, 90 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index a899d7c..b5ca02d 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Grbl includes full acceleration management with look ahead. That means the contr *** _**Master Branch:**_ -* [Grbl v0.9i Atmega328p 16mhz 115200baud with generic defaults](http://bit.ly/1EiviDk) _(2015-06-18)_ -* [Grbl v0.9i Atmega328p 16mhz 115200baud with ShapeOko2 defaults](http://bit.ly/1NYIfKl) _(2015-06-18)_ +* [Grbl v0.9i Atmega328p 16mhz 115200baud with generic defaults](http://bit.ly/1EiviDk) _(2015-06-20)_ +* [Grbl v0.9i Atmega328p 16mhz 115200baud with ShapeOko2 defaults](http://bit.ly/1NYIfKl) _(2015-06-20)_ - **IMPORTANT INFO WHEN UPGRADING TO GRBL v0.9i:** - Baudrate is now **115200** (Up from 9600). - Homing cycle updated. Located based on switch trigger, rather than release point. diff --git a/doc/log/commit_log_v0.9i.txt b/doc/log/commit_log_v0.9i.txt index 9159e62..3ace508 100644 --- a/doc/log/commit_log_v0.9i.txt +++ b/doc/log/commit_log_v0.9i.txt @@ -1,3 +1,9 @@ +---------------- +Date: 2015-06-18 +Author: Sonny Jeon +Subject: Updated README + + ---------------- Date: 2015-06-18 Author: Sonny Jeon diff --git a/grbl/grbl.h b/grbl/grbl.h index 073a571..5e730ef 100644 --- a/grbl/grbl.h +++ b/grbl/grbl.h @@ -23,7 +23,7 @@ // Grbl versioning system #define GRBL_VERSION "0.9i" -#define GRBL_VERSION_BUILD "20150618" +#define GRBL_VERSION_BUILD "20150620" // Define standard libraries used by Grbl. #include diff --git a/grbl/settings.c b/grbl/settings.c index 87535d5..f7fb6eb 100644 --- a/grbl/settings.c +++ b/grbl/settings.c @@ -56,69 +56,65 @@ void write_global_settings() // Method to restore EEPROM-saved Grbl global settings back to defaults. -void settings_restore_global_settings() { - settings.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS; - settings.stepper_idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME; - settings.step_invert_mask = DEFAULT_STEPPING_INVERT_MASK; - settings.dir_invert_mask = DEFAULT_DIRECTION_INVERT_MASK; - settings.status_report_mask = DEFAULT_STATUS_REPORT_MASK; - settings.junction_deviation = DEFAULT_JUNCTION_DEVIATION; - settings.arc_tolerance = DEFAULT_ARC_TOLERANCE; - settings.homing_dir_mask = DEFAULT_HOMING_DIR_MASK; - settings.homing_feed_rate = DEFAULT_HOMING_FEED_RATE; - settings.homing_seek_rate = DEFAULT_HOMING_SEEK_RATE; - settings.homing_debounce_delay = DEFAULT_HOMING_DEBOUNCE_DELAY; - settings.homing_pulloff = DEFAULT_HOMING_PULLOFF; +void settings_restore(uint8_t restore_flag) { + if (restore_flag & SETTINGS_RESTORE_DEFAULTS) { + settings.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS; + settings.stepper_idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME; + settings.step_invert_mask = DEFAULT_STEPPING_INVERT_MASK; + settings.dir_invert_mask = DEFAULT_DIRECTION_INVERT_MASK; + settings.status_report_mask = DEFAULT_STATUS_REPORT_MASK; + settings.junction_deviation = DEFAULT_JUNCTION_DEVIATION; + settings.arc_tolerance = DEFAULT_ARC_TOLERANCE; + settings.homing_dir_mask = DEFAULT_HOMING_DIR_MASK; + settings.homing_feed_rate = DEFAULT_HOMING_FEED_RATE; + settings.homing_seek_rate = DEFAULT_HOMING_SEEK_RATE; + settings.homing_debounce_delay = DEFAULT_HOMING_DEBOUNCE_DELAY; + settings.homing_pulloff = DEFAULT_HOMING_PULLOFF; - settings.flags = 0; - if (DEFAULT_REPORT_INCHES) { settings.flags |= BITFLAG_REPORT_INCHES; } - if (DEFAULT_INVERT_ST_ENABLE) { settings.flags |= BITFLAG_INVERT_ST_ENABLE; } - if (DEFAULT_INVERT_LIMIT_PINS) { settings.flags |= BITFLAG_INVERT_LIMIT_PINS; } - if (DEFAULT_SOFT_LIMIT_ENABLE) { settings.flags |= BITFLAG_SOFT_LIMIT_ENABLE; } - if (DEFAULT_HARD_LIMIT_ENABLE) { settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; } - if (DEFAULT_HOMING_ENABLE) { settings.flags |= BITFLAG_HOMING_ENABLE; } + settings.flags = 0; + if (DEFAULT_REPORT_INCHES) { settings.flags |= BITFLAG_REPORT_INCHES; } + if (DEFAULT_INVERT_ST_ENABLE) { settings.flags |= BITFLAG_INVERT_ST_ENABLE; } + if (DEFAULT_INVERT_LIMIT_PINS) { settings.flags |= BITFLAG_INVERT_LIMIT_PINS; } + if (DEFAULT_SOFT_LIMIT_ENABLE) { settings.flags |= BITFLAG_SOFT_LIMIT_ENABLE; } + if (DEFAULT_HARD_LIMIT_ENABLE) { settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; } + if (DEFAULT_HOMING_ENABLE) { settings.flags |= BITFLAG_HOMING_ENABLE; } - settings.steps_per_mm[X_AXIS] = DEFAULT_X_STEPS_PER_MM; - settings.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM; - settings.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM; - settings.max_rate[X_AXIS] = DEFAULT_X_MAX_RATE; - settings.max_rate[Y_AXIS] = DEFAULT_Y_MAX_RATE; - settings.max_rate[Z_AXIS] = DEFAULT_Z_MAX_RATE; - settings.acceleration[X_AXIS] = DEFAULT_X_ACCELERATION; - settings.acceleration[Y_AXIS] = DEFAULT_Y_ACCELERATION; - settings.acceleration[Z_AXIS] = DEFAULT_Z_ACCELERATION; - settings.max_travel[X_AXIS] = (-DEFAULT_X_MAX_TRAVEL); - settings.max_travel[Y_AXIS] = (-DEFAULT_Y_MAX_TRAVEL); - settings.max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL); + settings.steps_per_mm[X_AXIS] = DEFAULT_X_STEPS_PER_MM; + settings.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM; + settings.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM; + settings.max_rate[X_AXIS] = DEFAULT_X_MAX_RATE; + settings.max_rate[Y_AXIS] = DEFAULT_Y_MAX_RATE; + settings.max_rate[Z_AXIS] = DEFAULT_Z_MAX_RATE; + settings.acceleration[X_AXIS] = DEFAULT_X_ACCELERATION; + settings.acceleration[Y_AXIS] = DEFAULT_Y_ACCELERATION; + settings.acceleration[Z_AXIS] = DEFAULT_Z_ACCELERATION; + settings.max_travel[X_AXIS] = (-DEFAULT_X_MAX_TRAVEL); + settings.max_travel[Y_AXIS] = (-DEFAULT_Y_MAX_TRAVEL); + settings.max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL); - write_global_settings(); + write_global_settings(); + } + + if (restore_flag & SETTINGS_RESTORE_PARAMETERS) { + uint8_t idx; + float coord_data[N_AXIS]; + memset(&coord_data, 0, sizeof(coord_data)); + for (idx=0; idx < SETTING_INDEX_NCOORD; idx++) { settings_write_coord_data(idx, coord_data); } + } + + if (restore_flag & SETTINGS_RESTORE_STARTUP_LINES) { + #if N_STARTUP_LINE > 0 + eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK, 0); + #endif + #if N_STARTUP_LINE > 1 + eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK+(LINE_BUFFER_SIZE+1), 0); + #endif + } + + if (restore_flag & SETTINGS_RESTORE_BUILD_INFO) { eeprom_put_char(EEPROM_ADDR_BUILD_INFO , 0); } } -// Helper function to clear the EEPROM space containing parameter data. -void settings_clear_parameters() { - uint8_t idx; - float coord_data[N_AXIS]; - memset(&coord_data, 0, sizeof(coord_data)); - for (idx=0; idx < SETTING_INDEX_NCOORD; idx++) { settings_write_coord_data(idx, coord_data); } -} - - -// Helper function to clear the EEPROM space containing the startup lines. -void settings_clear_startup_lines() { - #if N_STARTUP_LINE > 0 - eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK, 0); - #endif - #if N_STARTUP_LINE > 1 - eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK+(LINE_BUFFER_SIZE+1), 0); - #endif -} - - -// Helper function to clear the EEPROM space containing the user build info string. -void settings_clear_build_info() { eeprom_put_char(EEPROM_ADDR_BUILD_INFO , 0); } - - // Reads startup line from EEPROM. Updated pointed line string data. uint8_t settings_read_startup_line(uint8_t n, char *line) { @@ -282,27 +278,21 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) { void settings_init() { if(!read_global_settings()) { report_status_message(STATUS_SETTING_READ_FAIL); - - settings_restore_global_settings(); - - // Force clear startup lines and build info user data. Parameters should be ok. - // TODO: For next version, remove these clears. Only here because line buffer increased. - settings_clear_startup_lines(); - settings_clear_build_info(); - + settings_restore(SETTINGS_RESTORE_ALL); // Force restore all EEPROM data. report_grbl_settings(); } + // NOTE: Checking paramater data, startup lines, and build info string should be done here, + // but it seems fairly redundant. Each of these can be manually checked and reset or restored. // Check all parameter data into a dummy variable. If error, reset to zero, otherwise do nothing. - float coord_data[N_AXIS]; - uint8_t i; - for (i=0; i<=SETTING_INDEX_NCOORD; i++) { - if (!settings_read_coord_data(i, coord_data)) { - report_status_message(STATUS_SETTING_READ_FAIL); - } - } + // float coord_data[N_AXIS]; + // uint8_t i; + // for (i=0; i<=SETTING_INDEX_NCOORD; i++) { + // if (!settings_read_coord_data(i, coord_data)) { + // report_status_message(STATUS_SETTING_READ_FAIL); + // } + // } // NOTE: Startup lines are checked and executed by protocol_main_loop at the end of initialization. - // TODO: Build info should be checked here, but will wait until v1.0 to address this. Ok for now. } diff --git a/grbl/settings.h b/grbl/settings.h index 957c81f..3442b9e 100644 --- a/grbl/settings.h +++ b/grbl/settings.h @@ -46,6 +46,13 @@ #define BITFLAG_RT_STATUS_SERIAL_RX bit(3) #define BITFLAG_RT_STATUS_LIMIT_PINS bit(4) +// Define settings restore bitflags. +#define SETTINGS_RESTORE_ALL 0xFF // All bitflags +#define SETTINGS_RESTORE_DEFAULTS bit(0) +#define SETTINGS_RESTORE_PARAMETERS bit(1) +#define SETTINGS_RESTORE_STARTUP_LINES bit(2) +#define SETTINGS_RESTORE_BUILD_INFO bit(3) + // Define EEPROM memory address location values for Grbl settings and parameters // NOTE: The Atmega328p has 1KB EEPROM. The upper half is reserved for parameters and // the startup script. The lower half contains the global settings and space for future @@ -98,11 +105,8 @@ extern settings_t settings; // Initialize the configuration subsystem (load settings from EEPROM) void settings_init(); -// Helper functions to clear and restore EEPROM defaults -void settings_restore_global_settings(); -void settings_clear_parameters(); -void settings_clear_startup_lines(); -void settings_clear_build_info(); +// Helper function to clear and restore EEPROM defaults +void settings_restore(uint8_t restore_flag); // A helper method to set new settings from command line uint8_t settings_store_global_setting(uint8_t parameter, float value); diff --git a/grbl/system.c b/grbl/system.c index cd62f6c..1e2ab1b 100644 --- a/grbl/system.c +++ b/grbl/system.c @@ -204,9 +204,16 @@ uint8_t system_execute_line(char *line) case 'R' : // Restore defaults [IDLE/ALARM] if (line[++char_counter] != 'S') { return(STATUS_INVALID_STATEMENT); } if (line[++char_counter] != 'T') { return(STATUS_INVALID_STATEMENT); } - if (line[++char_counter] != 0) { return(STATUS_INVALID_STATEMENT); } + if (line[++char_counter] != '=') { return(STATUS_INVALID_STATEMENT); } + if (line[char_counter+2] != 0) { return(STATUS_INVALID_STATEMENT); } + switch (line[++char_counter]) { + case '$': settings_restore(SETTINGS_RESTORE_DEFAULTS); break; + case '#': settings_restore(SETTINGS_RESTORE_PARAMETERS); break; + case '*': settings_restore(SETTINGS_RESTORE_ALL); break; + default: return(STATUS_INVALID_STATEMENT); + } report_feedback_message(MESSAGE_RESTORE_DEFAULTS); - settings_restore_global_settings(); + mc_reset(); // Force reset to ensure settings are initialized correctly. break; case 'N' : // Startup lines. [IDLE/ALARM] if ( line[++char_counter] == 0 ) { // Print startup lines