New EEPROM restore functions.
- 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.
This commit is contained in:
parent
e6db564511
commit
81505e6a81
@ -27,8 +27,8 @@ Grbl includes full acceleration management with look ahead. That means the contr
|
|||||||
***
|
***
|
||||||
|
|
||||||
_**Master Branch:**_
|
_**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 generic defaults](http://bit.ly/1EiviDk) _(2015-06-20)_
|
||||||
* [Grbl v0.9i Atmega328p 16mhz 115200baud with ShapeOko2 defaults](http://bit.ly/1NYIfKl) _(2015-06-18)_
|
* [Grbl v0.9i Atmega328p 16mhz 115200baud with ShapeOko2 defaults](http://bit.ly/1NYIfKl) _(2015-06-20)_
|
||||||
- **IMPORTANT INFO WHEN UPGRADING TO GRBL v0.9i:**
|
- **IMPORTANT INFO WHEN UPGRADING TO GRBL v0.9i:**
|
||||||
- Baudrate is now **115200** (Up from 9600).
|
- Baudrate is now **115200** (Up from 9600).
|
||||||
- Homing cycle updated. Located based on switch trigger, rather than release point.
|
- Homing cycle updated. Located based on switch trigger, rather than release point.
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
----------------
|
||||||
|
Date: 2015-06-18
|
||||||
|
Author: Sonny Jeon
|
||||||
|
Subject: Updated README
|
||||||
|
|
||||||
|
|
||||||
----------------
|
----------------
|
||||||
Date: 2015-06-18
|
Date: 2015-06-18
|
||||||
Author: Sonny Jeon
|
Author: Sonny Jeon
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
// Grbl versioning system
|
// Grbl versioning system
|
||||||
#define GRBL_VERSION "0.9i"
|
#define GRBL_VERSION "0.9i"
|
||||||
#define GRBL_VERSION_BUILD "20150618"
|
#define GRBL_VERSION_BUILD "20150620"
|
||||||
|
|
||||||
// Define standard libraries used by Grbl.
|
// Define standard libraries used by Grbl.
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
@ -56,7 +56,8 @@ void write_global_settings()
|
|||||||
|
|
||||||
|
|
||||||
// Method to restore EEPROM-saved Grbl global settings back to defaults.
|
// Method to restore EEPROM-saved Grbl global settings back to defaults.
|
||||||
void settings_restore_global_settings() {
|
void settings_restore(uint8_t restore_flag) {
|
||||||
|
if (restore_flag & SETTINGS_RESTORE_DEFAULTS) {
|
||||||
settings.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS;
|
settings.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS;
|
||||||
settings.stepper_idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME;
|
settings.stepper_idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME;
|
||||||
settings.step_invert_mask = DEFAULT_STEPPING_INVERT_MASK;
|
settings.step_invert_mask = DEFAULT_STEPPING_INVERT_MASK;
|
||||||
@ -94,18 +95,14 @@ void settings_restore_global_settings() {
|
|||||||
write_global_settings();
|
write_global_settings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (restore_flag & SETTINGS_RESTORE_PARAMETERS) {
|
||||||
// Helper function to clear the EEPROM space containing parameter data.
|
|
||||||
void settings_clear_parameters() {
|
|
||||||
uint8_t idx;
|
uint8_t idx;
|
||||||
float coord_data[N_AXIS];
|
float coord_data[N_AXIS];
|
||||||
memset(&coord_data, 0, sizeof(coord_data));
|
memset(&coord_data, 0, sizeof(coord_data));
|
||||||
for (idx=0; idx < SETTING_INDEX_NCOORD; idx++) { settings_write_coord_data(idx, coord_data); }
|
for (idx=0; idx < SETTING_INDEX_NCOORD; idx++) { settings_write_coord_data(idx, coord_data); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (restore_flag & SETTINGS_RESTORE_STARTUP_LINES) {
|
||||||
// Helper function to clear the EEPROM space containing the startup lines.
|
|
||||||
void settings_clear_startup_lines() {
|
|
||||||
#if N_STARTUP_LINE > 0
|
#if N_STARTUP_LINE > 0
|
||||||
eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK, 0);
|
eeprom_put_char(EEPROM_ADDR_STARTUP_BLOCK, 0);
|
||||||
#endif
|
#endif
|
||||||
@ -114,9 +111,8 @@ void settings_clear_startup_lines() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (restore_flag & SETTINGS_RESTORE_BUILD_INFO) { eeprom_put_char(EEPROM_ADDR_BUILD_INFO , 0); }
|
||||||
// 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.
|
// Reads startup line from EEPROM. Updated pointed line string data.
|
||||||
@ -282,27 +278,21 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) {
|
|||||||
void settings_init() {
|
void settings_init() {
|
||||||
if(!read_global_settings()) {
|
if(!read_global_settings()) {
|
||||||
report_status_message(STATUS_SETTING_READ_FAIL);
|
report_status_message(STATUS_SETTING_READ_FAIL);
|
||||||
|
settings_restore(SETTINGS_RESTORE_ALL); // Force restore all EEPROM data.
|
||||||
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();
|
|
||||||
|
|
||||||
report_grbl_settings();
|
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.
|
// Check all parameter data into a dummy variable. If error, reset to zero, otherwise do nothing.
|
||||||
float coord_data[N_AXIS];
|
// float coord_data[N_AXIS];
|
||||||
uint8_t i;
|
// uint8_t i;
|
||||||
for (i=0; i<=SETTING_INDEX_NCOORD; i++) {
|
// for (i=0; i<=SETTING_INDEX_NCOORD; i++) {
|
||||||
if (!settings_read_coord_data(i, coord_data)) {
|
// if (!settings_read_coord_data(i, coord_data)) {
|
||||||
report_status_message(STATUS_SETTING_READ_FAIL);
|
// report_status_message(STATUS_SETTING_READ_FAIL);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// NOTE: Startup lines are checked and executed by protocol_main_loop at the end of initialization.
|
// 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.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +46,13 @@
|
|||||||
#define BITFLAG_RT_STATUS_SERIAL_RX bit(3)
|
#define BITFLAG_RT_STATUS_SERIAL_RX bit(3)
|
||||||
#define BITFLAG_RT_STATUS_LIMIT_PINS bit(4)
|
#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
|
// 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
|
// 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
|
// 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)
|
// Initialize the configuration subsystem (load settings from EEPROM)
|
||||||
void settings_init();
|
void settings_init();
|
||||||
|
|
||||||
// Helper functions to clear and restore EEPROM defaults
|
// Helper function to clear and restore EEPROM defaults
|
||||||
void settings_restore_global_settings();
|
void settings_restore(uint8_t restore_flag);
|
||||||
void settings_clear_parameters();
|
|
||||||
void settings_clear_startup_lines();
|
|
||||||
void settings_clear_build_info();
|
|
||||||
|
|
||||||
// A helper method to set new settings from command line
|
// A helper method to set new settings from command line
|
||||||
uint8_t settings_store_global_setting(uint8_t parameter, float value);
|
uint8_t settings_store_global_setting(uint8_t parameter, float value);
|
||||||
|
@ -204,9 +204,16 @@ uint8_t system_execute_line(char *line)
|
|||||||
case 'R' : // Restore defaults [IDLE/ALARM]
|
case 'R' : // Restore defaults [IDLE/ALARM]
|
||||||
if (line[++char_counter] != 'S') { return(STATUS_INVALID_STATEMENT); }
|
if (line[++char_counter] != 'S') { return(STATUS_INVALID_STATEMENT); }
|
||||||
if (line[++char_counter] != 'T') { 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);
|
report_feedback_message(MESSAGE_RESTORE_DEFAULTS);
|
||||||
settings_restore_global_settings();
|
mc_reset(); // Force reset to ensure settings are initialized correctly.
|
||||||
break;
|
break;
|
||||||
case 'N' : // Startup lines. [IDLE/ALARM]
|
case 'N' : // Startup lines. [IDLE/ALARM]
|
||||||
if ( line[++char_counter] == 0 ) { // Print startup lines
|
if ( line[++char_counter] == 0 ) { // Print startup lines
|
||||||
|
Loading…
Reference in New Issue
Block a user