Homing direction pin bits fixed. Lite refactoring of settings.

This commit is contained in:
Sonny Jeon 2012-10-10 18:01:43 -06:00
parent 4c6f5bec48
commit 32963289fe
3 changed files with 33 additions and 38 deletions

View File

@ -80,9 +80,8 @@ static void homing_cycle(bool x_axis, bool y_axis, bool z_axis, int8_t pos_dir,
uint32_t dt_min = lround(1000000*60/(ds*homing_rate)); // Cruising (usec/step) uint32_t dt_min = lround(1000000*60/(ds*homing_rate)); // Cruising (usec/step)
uint32_t dt = 1000000*60/MINIMUM_STEPS_PER_MINUTE; // Initial (usec/step) uint32_t dt = 1000000*60/MINIMUM_STEPS_PER_MINUTE; // Initial (usec/step)
// Determine default out_bits set. Direction fixed and step pin inverted // Set default out_bits.
uint8_t out_bits0 = DIRECTION_MASK; uint8_t out_bits0 = settings.invert_mask;
out_bits0 ^= settings.invert_mask; // Apply the global step and direction invert mask
if (!pos_dir) { out_bits0 ^= DIRECTION_MASK; } // Invert bits, if negative dir. if (!pos_dir) { out_bits0 ^= DIRECTION_MASK; } // Invert bits, if negative dir.
// Initialize stepping variables // Initialize stepping variables

View File

@ -75,19 +75,32 @@ typedef struct {
#define DEFAULT_HOMING_DEBOUNCE_DELAY 100 // msec (0-65k) #define DEFAULT_HOMING_DEBOUNCE_DELAY 100 // msec (0-65k)
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-255) #define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-255)
// #define DEFAULT_AUTO_START 1 // true // #define DEFAULT_AUTO_START 1 // true
// #define DEFAULT_INCHES_MODE 1 // true
// #define DEFAULT_BLOCK_DELETE 0 // false // #define DEFAULT_BLOCK_DELETE 0 // false
void settings_reset() { void settings_reset(bool reset_all) {
settings.steps_per_mm[X_AXIS] = DEFAULT_X_STEPS_PER_MM; // Reset all settings or only the migration settings to the new version.
settings.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM; if (reset_all) {
settings.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM; settings.steps_per_mm[X_AXIS] = DEFAULT_X_STEPS_PER_MM;
settings.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS; settings.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM;
settings.default_feed_rate = DEFAULT_FEEDRATE; settings.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM;
settings.default_seek_rate = DEFAULT_RAPID_FEEDRATE; settings.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS;
settings.acceleration = DEFAULT_ACCELERATION; settings.default_feed_rate = DEFAULT_FEEDRATE;
settings.mm_per_arc_segment = DEFAULT_MM_PER_ARC_SEGMENT; settings.default_seek_rate = DEFAULT_RAPID_FEEDRATE;
settings.invert_mask = DEFAULT_STEPPING_INVERT_MASK; settings.acceleration = DEFAULT_ACCELERATION;
settings.junction_deviation = DEFAULT_JUNCTION_DEVIATION; settings.mm_per_arc_segment = DEFAULT_MM_PER_ARC_SEGMENT;
settings.invert_mask = DEFAULT_STEPPING_INVERT_MASK;
settings.junction_deviation = DEFAULT_JUNCTION_DEVIATION;
}
// New settings since last version
settings.flags = 0;
// if (DEFAULT_AUTO_START) { settings.flags |= FLAG_BIT_AUTO_START; }
// if (DEFAULT_INCHES_MODE) { settings.flags |= FLAG_BIT_INCHES_MODE; }
if (DEFAULT_HOMING_ENABLE) { settings.flags |= FLAG_BIT_HOMING_ENABLE; }
settings.homing_feed_rate = DEFAULT_HOMING_FEEDRATE;
settings.homing_seek_rate = DEFAULT_HOMING_RAPID_FEEDRATE;
settings.homing_debounce_delay = DEFAULT_HOMING_DEBOUNCE_DELAY;
settings.stepper_idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME;
} }
void settings_dump() { void settings_dump() {
@ -107,7 +120,7 @@ void settings_dump() {
printPgmString(PSTR(" (mm/min homing feed rate)\r\n$12 = ")); printFloat(settings.homing_seek_rate); printPgmString(PSTR(" (mm/min homing feed rate)\r\n$12 = ")); printFloat(settings.homing_seek_rate);
printPgmString(PSTR(" (mm/min homing seek rate)\r\n$13 = ")); printInteger(settings.homing_debounce_delay); printPgmString(PSTR(" (mm/min homing seek rate)\r\n$13 = ")); printInteger(settings.homing_debounce_delay);
printPgmString(PSTR(" (milliseconds homing debounce delay)\r\n$14 = ")); printInteger(settings.stepper_idle_lock_time); printPgmString(PSTR(" (milliseconds homing debounce delay)\r\n$14 = ")); printInteger(settings.stepper_idle_lock_time);
printPgmString(PSTR(" (milliseconds stepper idle lock time)\r\n")); printPgmString(PSTR(" (milliseconds stepper idle lock time)"));
printPgmString(PSTR("\r\n'$x=value' to set parameter or just '$' to dump current settings\r\n")); printPgmString(PSTR("\r\n'$x=value' to set parameter or just '$' to dump current settings\r\n"));
} }
@ -173,17 +186,8 @@ int read_settings() {
if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_v2_v4_t)))) { if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_v2_v4_t)))) {
return(false); return(false);
} }
settings_reset(false);
settings.flags = 0;
// if (DEFAULT_AUTO_START) { settings.flags |= FLAG_BIT_AUTO_START; }
if (DEFAULT_HOMING_ENABLE) { settings.flags |= FLAG_BIT_HOMING_ENABLE; }
settings.homing_feed_rate = DEFAULT_HOMING_FEEDRATE;
settings.homing_seek_rate = DEFAULT_HOMING_RAPID_FEEDRATE;
settings.homing_debounce_delay = DEFAULT_HOMING_DEBOUNCE_DELAY;
settings.stepper_idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME;
write_settings(); write_settings();
} else if (version >= 50) { } else if (version >= 50) {
// Developmental settings. Version numbers greater than or equal to 50 are temporary. // Developmental settings. Version numbers greater than or equal to 50 are temporary.
// Currently, this will update the user settings to v4 and the remainder of the settings // Currently, this will update the user settings to v4 and the remainder of the settings
@ -191,17 +195,8 @@ int read_settings() {
// Grab settings regardless of error. // Grab settings regardless of error.
memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_t)); memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_t));
settings_reset(false);
settings.flags = 0;
// if (DEFAULT_AUTO_START) { settings.flags |= FLAG_BIT_AUTO_START; }
if (DEFAULT_HOMING_ENABLE) { settings.flags |= FLAG_BIT_HOMING_ENABLE; }
settings.homing_feed_rate = DEFAULT_HOMING_FEEDRATE;
settings.homing_seek_rate = DEFAULT_HOMING_RAPID_FEEDRATE;
settings.homing_debounce_delay = DEFAULT_HOMING_DEBOUNCE_DELAY;
settings.stepper_idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME;
write_settings(); write_settings();
} else { } else {
return(false); return(false);
} }
@ -252,7 +247,7 @@ void settings_store_setting(int parameter, float value) {
void settings_init() { void settings_init() {
if(!read_settings()) { if(!read_settings()) {
printPgmString(PSTR("Warning: Failed to read EEPROM settings. Using defaults.\r\n")); printPgmString(PSTR("Warning: Failed to read EEPROM settings. Using defaults.\r\n"));
settings_reset(); settings_reset(true);
write_settings(); write_settings();
settings_dump(); settings_dump();
} }

View File

@ -29,11 +29,12 @@
// Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl
// when firmware is upgraded. Always stored in byte 0 of eeprom // when firmware is upgraded. Always stored in byte 0 of eeprom
#define SETTINGS_VERSION 50 #define SETTINGS_VERSION 51
// Define bit flag masks in settings.flag. // Define bit flag masks in settings.flag.
#define FLAG_BIT_HOMING_ENABLE bit(0) #define FLAG_BIT_HOMING_ENABLE bit(0)
//#define FLAG_BIT_AUTO_START bit(1) //#define FLAG_BIT_AUTO_START bit(1)
//#define FLAG_BIT_INCHES_MODE bit(2)
// Current global settings (persisted in EEPROM from byte 1 onwards) // Current global settings (persisted in EEPROM from byte 1 onwards)
typedef struct { typedef struct {