From 9b292ffe3cbdb2bd73856b0148b9d3957be7aeb8 Mon Sep 17 00:00:00 2001 From: Simen Svale Skogsrud Date: Mon, 31 Jan 2011 23:04:08 +0100 Subject: [PATCH] added support for silently upgrading from old settings record w/o accelleration parameters --- config.c | 47 +++++++++++++++++++++++++++++++++++------------ config.h | 19 +------------------ 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/config.c b/config.c index 4db278e..7a26cfd 100644 --- a/config.c +++ b/config.c @@ -28,6 +28,17 @@ settings_t settings; +// Version 1 outdated settings record +typedef struct { + double steps_per_mm[3]; + uint8_t microsteps; + uint8_t pulse_microseconds; + double default_feed_rate; + double default_seek_rate; + uint8_t invert_mask; + double mm_per_arc_segment; +} settings_v1_t; + void reset_settings() { settings.steps_per_mm[0] = X_STEPS_PER_MM; settings.steps_per_mm[1] = Y_STEPS_PER_MM; @@ -37,7 +48,7 @@ void reset_settings() { settings.default_seek_rate = RAPID_FEEDRATE; settings.acceleration = DEFAULT_ACCELERATION; settings.mm_per_arc_segment = MM_PER_ARC_SEGMENT; - settings.invert_mask = STEPPING_INVERT_MASK; + settings.invert_mask = DEFAULT_STEPPING_INVERT_MASK; settings.max_jerk = DEFAULT_MAX_JERK; } @@ -57,22 +68,33 @@ void dump_settings() { printPgmString(PSTR("\r\n'$x=value' to set parameter or just '$' to dump current settings\r\n")); } -int read_settings() { - // Check version-byte of eeprom - uint8_t version = eeprom_get_char(0); - if (version != SETTINGS_VERSION) { return(FALSE); } - // Read settings-record and check checksum - if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_t)))) { - return(FALSE); - } - return(TRUE); -} - void write_settings() { eeprom_put_char(0, SETTINGS_VERSION); memcpy_to_eeprom_with_checksum(1, (char*)&settings, sizeof(settings_t)); } +int read_settings() { + // Check version-byte of eeprom + uint8_t version = eeprom_get_char(0); + + if (version == SETTINGS_VERSION) { + // Read settings-record and check checksum + if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_t)))) { + return(FALSE); + } + } else if (version == 1) { + // Migrate from old settings version + if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_v1_t)))) { + return(FALSE); + } + settings.acceleration = DEFAULT_ACCELERATION; + settings.max_jerk = DEFAULT_MAX_JERK; + } else { + return(FALSE); + } + return(TRUE); +} + // A helper method to set settings from command line void store_setting(int parameter, double value) { switch(parameter) { @@ -93,6 +115,7 @@ void store_setting(int parameter, double value) { printPgmString(PSTR("Stored new setting\r\n")); } +// Initialize the config subsystem void config_init() { if(read_settings()) { printPgmString(PSTR("'$' to dump current settings\r\n")); diff --git a/config.h b/config.h index 333cfd8..a1acb49 100644 --- a/config.h +++ b/config.h @@ -85,37 +85,20 @@ void dump_settings(); // A helper method to set new settings from command line void store_setting(int parameter, double value); - // Default settings (used when resetting eeprom-settings) #define MICROSTEPS 8 #define X_STEPS_PER_MM (94.488188976378*MICROSTEPS) #define Y_STEPS_PER_MM (94.488188976378*MICROSTEPS) #define Z_STEPS_PER_MM (94.488188976378*MICROSTEPS) #define STEP_PULSE_MICROSECONDS 30 - #define MM_PER_ARC_SEGMENT 0.1 - #define RAPID_FEEDRATE 480.0 // in millimeters per minute #define DEFAULT_FEEDRATE 480.0 #define DEFAULT_ACCELERATION (DEFAULT_FEEDRATE/100.0) #define DEFAULT_MAX_JERK 50.0 - -// Use this line for default operation (step-pulses high) -#define STEPPING_INVERT_MASK 0 -// Uncomment this line for inverted stepping (step-pulses low, rest high) -// #define STEPPING_INVERT_MASK (STEP_MASK) -// Uncomment this line to invert all step- and direction bits -// #define STEPPING_INVERT_MASK (STEPPING_MASK) -// Or bake your own like this adding any step-bits or directions you want to invert: -// #define STEPPING_INVERT_MASK (STEP_MASK | (1<