More tweaks. Removed dry run. Trimmed all messages to save flash space.

- Removed the dry run switch. It was getting overly complicated for
what it needed to do. In practice, single block mode and feed rate
overrides (coming in next release) does a much better job with dry runs
than 'dry run'.

- Trimmed all of Grbl's messages from help, status, feedback to
settings. Saved 0.6KB+ of flash space that could be used for v0.9
features.

- Removed some settings inits when set. Will depend on user to power
cycle to get some of these to reload.

- Fixed a bug with settings version not re-writing old settings, when
it should. Thanks Alden!
This commit is contained in:
Sonny Jeon 2012-11-07 20:53:03 -07:00
parent e2e794af45
commit 5e7a4b3ba8
8 changed files with 97 additions and 147 deletions

View File

@ -100,7 +100,7 @@
#define DEFAULT_FEEDRATE 250.0 #define DEFAULT_FEEDRATE 250.0
#define DEFAULT_ACCELERATION (DEFAULT_FEEDRATE*60*60/10.0) // mm/min^2 #define DEFAULT_ACCELERATION (DEFAULT_FEEDRATE*60*60/10.0) // mm/min^2
#define DEFAULT_JUNCTION_DEVIATION 0.05 // mm #define DEFAULT_JUNCTION_DEVIATION 0.05 // mm
#define DEFAULT_STEPPING_INVERT_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) #define DEFAULT_STEPPING_INVERT_MASK ((1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT))
#define DEFAULT_REPORT_INCHES 0 // false #define DEFAULT_REPORT_INCHES 0 // false
#define DEFAULT_AUTO_START 1 // true #define DEFAULT_AUTO_START 1 // true
#define DEFAULT_INVERT_ST_ENABLE 0 // false #define DEFAULT_INVERT_ST_ENABLE 0 // false
@ -108,7 +108,7 @@
#define DEFAULT_HOMING_ENABLE 0 // false #define DEFAULT_HOMING_ENABLE 0 // false
#define DEFAULT_HOMING_DIR_MASK 0 // move positive dir #define DEFAULT_HOMING_DIR_MASK 0 // move positive dir
#define DEFAULT_HOMING_RAPID_FEEDRATE 250.0 // mm/min #define DEFAULT_HOMING_RAPID_FEEDRATE 250.0 // mm/min
#define DEFAULT_HOMING_FEEDRATE 50 // mm/min #define DEFAULT_HOMING_FEEDRATE 25 // mm/min
#define DEFAULT_HOMING_DEBOUNCE_DELAY 100 // msec (0-65k) #define DEFAULT_HOMING_DEBOUNCE_DELAY 100 // msec (0-65k)
#define DEFAULT_HOMING_PULLOFF 1 // mm #define DEFAULT_HOMING_PULLOFF 1 // mm
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-255) #define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-255)

16
gcode.c
View File

@ -248,17 +248,9 @@ uint8_t gc_execute_line(char *line)
NOTE: Independent non-motion/settings parameters are set out of this order for code efficiency NOTE: Independent non-motion/settings parameters are set out of this order for code efficiency
and simplicity purposes, but this should not affect proper g-code execution. */ and simplicity purposes, but this should not affect proper g-code execution. */
// ([F]: Set feed and seek rates. Used to enforce user feed rate for dry runs.) // ([F]: Set feed and seek rates.)
// TODO: Dry runs move at whatever feed rate the user specifies. Need to update this to allow
// this feature. Users can also change the rates realtime like a feedrate override. Until that
// is installed, it will have to wait, but users could control it by using the default feed rate.
// TODO: Seek rates can change depending on the direction and maximum speeds of each axes. When // TODO: Seek rates can change depending on the direction and maximum speeds of each axes. When
// max axis speed is installed, the calculation can be performed here, or maybe in the planner. // max axis speed is installed, the calculation can be performed here, or maybe in the planner.
if (bit_istrue(gc.switches,BITFLAG_DRY_RUN)) {
// NOTE: Since dry run resets after disabled, the defaults rates should come back.
gc.feed_rate = settings.default_feed_rate;
gc.seek_rate = settings.default_feed_rate;
}
// ([M6]: Tool change should be executed here.) // ([M6]: Tool change should be executed here.)
@ -283,10 +275,8 @@ uint8_t gc_execute_line(char *line)
if (p < 0) { // Time cannot be negative. if (p < 0) { // Time cannot be negative.
FAIL(STATUS_INVALID_STATEMENT); FAIL(STATUS_INVALID_STATEMENT);
} else { } else {
// Ignore dwell in dry run and check gcode modes // Ignore dwell in check gcode modes
if (!(gc.switches & (BITFLAG_DRY_RUN | BITFLAG_CHECK_GCODE))) { if (!(gc.switches & BITFLAG_CHECK_GCODE)) { mc_dwell(p); }
mc_dwell(p);
}
} }
break; break;
case NON_MODAL_SET_COORDINATE_DATA: case NON_MODAL_SET_COORDINATE_DATA:

View File

@ -64,10 +64,10 @@
// Define bit flag masks for gc.switches. (8 flag limit) // Define bit flag masks for gc.switches. (8 flag limit)
#define BITFLAG_CHECK_GCODE bit(0) #define BITFLAG_CHECK_GCODE bit(0)
#define BITFLAG_DRY_RUN bit(1) #define BITFLAG_BLOCK_DELETE bit(1)
#define BITFLAG_BLOCK_DELETE bit(2) #define BITFLAG_SINGLE_BLOCK bit(2)
#define BITFLAG_SINGLE_BLOCK bit(3) #define BITFLAG_OPT_STOP bit(3)
#define BITFLAG_OPT_STOP bit(4) // #define bit(4)
// #define bit(5) // #define bit(5)
// #define bit(6) // #define bit(6)
// #define bit(7) // #define bit(7)

9
main.c
View File

@ -46,6 +46,7 @@ int main(void)
{ {
// Initialize system // Initialize system
serial_init(BAUD_RATE); // Setup serial baud rate and interrupts serial_init(BAUD_RATE); // Setup serial baud rate and interrupts
settings_init(); // Load grbl settings from EEPROM
st_init(); // Setup stepper pins and interrupt timers st_init(); // Setup stepper pins and interrupt timers
sei(); // Enable interrupts sei(); // Enable interrupts
@ -62,7 +63,6 @@ int main(void)
// Reset system. // Reset system.
serial_reset_read_buffer(); // Clear serial read buffer serial_reset_read_buffer(); // Clear serial read buffer
settings_init(); // Load grbl settings from EEPROM
plan_init(); // Clear block buffer and planner variables plan_init(); // Clear block buffer and planner variables
gc_init(); // Set g-code parser to default state gc_init(); // Set g-code parser to default state
protocol_init(); // Clear incoming line data and execute startup lines protocol_init(); // Clear incoming line data and execute startup lines
@ -83,10 +83,9 @@ int main(void)
sys.abort = false; sys.abort = false;
sys.execute = 0; sys.execute = 0;
if (sys.state == STATE_ALARM && bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { if (sys.state == STATE_ALARM && bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) {
// If a critical event has occurred, set the position lost system state. For example, a // Position has either been lost from a critical event or a power cycle reboot. If
// hard limit event can cause the stepper to lose steps and position due to an immediate // homing is enabled, force user to home to get machine position. Otherwise, let the
// stop, not with a controlled deceleration. Or, if an abort was issued while a cycle // user manage position on their own.
// was active, the immediate stop can also cause lost steps.
report_feedback_message(MESSAGE_HOMING_ALARM); report_feedback_message(MESSAGE_HOMING_ALARM);
} else { } else {
sys.state = STATE_IDLE; sys.state = STATE_IDLE;

View File

@ -76,11 +76,9 @@ ISR(PINOUT_INT_vect)
if (bit_isfalse(PINOUT_PIN,bit(PIN_RESET))) { if (bit_isfalse(PINOUT_PIN,bit(PIN_RESET))) {
mc_alarm(); mc_alarm();
sys.execute |= EXEC_RESET; // Set as true sys.execute |= EXEC_RESET; // Set as true
} } else if (bit_isfalse(PINOUT_PIN,bit(PIN_FEED_HOLD))) {
if (bit_isfalse(PINOUT_PIN,bit(PIN_FEED_HOLD))) {
sys.execute |= EXEC_FEED_HOLD; sys.execute |= EXEC_FEED_HOLD;
} } else if (bit_isfalse(PINOUT_PIN,bit(PIN_CYCLE_START))) {
if (bit_isfalse(PINOUT_PIN,bit(PIN_CYCLE_START))) {
sys.execute |= EXEC_CYCLE_START; sys.execute |= EXEC_CYCLE_START;
} }
} }
@ -216,31 +214,24 @@ uint8_t protocol_execute_line(char *line)
// Set helper_var as switch bitmask or clearing flag // Set helper_var as switch bitmask or clearing flag
switch (line[++char_counter]) { switch (line[++char_counter]) {
case '0' : helper_var = BITFLAG_CHECK_GCODE; break; case '0' : helper_var = BITFLAG_CHECK_GCODE; break;
case '1' : helper_var = BITFLAG_DRY_RUN; break; case '1' : helper_var = BITFLAG_BLOCK_DELETE; break;
case '2' : helper_var = BITFLAG_BLOCK_DELETE; break; case '2' : helper_var = BITFLAG_SINGLE_BLOCK; break;
case '3' : helper_var = BITFLAG_SINGLE_BLOCK; break; case '3' : helper_var = BITFLAG_OPT_STOP; break;
case '4' : helper_var = BITFLAG_OPT_STOP; break;
default : return(STATUS_INVALID_STATEMENT); default : return(STATUS_INVALID_STATEMENT);
} }
if ( line[++char_counter] != 0 ) { return(STATUS_UNSUPPORTED_STATEMENT); } if ( line[++char_counter] != 0 ) { return(STATUS_UNSUPPORTED_STATEMENT); }
if ( helper_var & (BITFLAG_CHECK_GCODE | BITFLAG_DRY_RUN) ) { if ( helper_var & BITFLAG_CHECK_GCODE ) {
if ( bit_istrue(gc.switches,helper_var) ) { // Perform reset when toggling off. Check g-code mode should only work if Grbl
// Perform reset and check for cycle when toggling off. If disabled while in cycle, // is idle and ready, regardless of homing locks. This is mainly to keep things
// immediately stop everything and notify user that stopping mid-cycle and likely // simple and consistent.
// lost position. In check g-code mode, there is never a cycle. if ( bit_istrue(gc.switches,helper_var) ) { sys.execute |= EXEC_RESET; }
if (sys.state == STATE_CYCLE) { mc_alarm(); } else if (sys.state) { return(STATUS_IDLE_ERROR); }
sys.execute |= EXEC_RESET; // Soft-reset Grbl.
} else {
// Check if Grbl is idle and ready or if the other mode is enabled.
if (sys.state) { return(STATUS_IDLE_ERROR); }
if ((gc.switches & (BITFLAG_CHECK_GCODE | BITFLAG_DRY_RUN)) & ~(helper_var)) { return(STATUS_INVALID_STATEMENT); }
}
} }
gc.switches ^= helper_var; gc.switches ^= helper_var;
if (bit_istrue(gc.switches,helper_var)) { report_feedback_message(MESSAGE_ENABLED); } if (bit_istrue(gc.switches,helper_var)) { report_feedback_message(MESSAGE_ENABLED); }
else { report_feedback_message(MESSAGE_DISABLED); } else { report_feedback_message(MESSAGE_DISABLED); }
break; break;
case 'U' : // Disable homing lock case 'X' : // Disable homing lock
if ( line[++char_counter] != 0 ) { return(STATUS_UNSUPPORTED_STATEMENT); } if ( line[++char_counter] != 0 ) { return(STATUS_UNSUPPORTED_STATEMENT); }
if (sys.state == STATE_ALARM) { if (sys.state == STATE_ALARM) {
report_feedback_message(MESSAGE_HOMING_UNLOCK); report_feedback_message(MESSAGE_HOMING_UNLOCK);

View File

@ -57,23 +57,23 @@ void report_status_message(uint8_t status_code)
case STATUS_UNSUPPORTED_STATEMENT: case STATUS_UNSUPPORTED_STATEMENT:
printPgmString(PSTR("Unsupported statement")); break; printPgmString(PSTR("Unsupported statement")); break;
case STATUS_FLOATING_POINT_ERROR: case STATUS_FLOATING_POINT_ERROR:
printPgmString(PSTR("Floating point error")); break; printPgmString(PSTR("Float error")); break;
case STATUS_MODAL_GROUP_VIOLATION: case STATUS_MODAL_GROUP_VIOLATION:
printPgmString(PSTR("Modal group violation")); break; printPgmString(PSTR("Modal group violation")); break;
case STATUS_INVALID_STATEMENT: case STATUS_INVALID_STATEMENT:
printPgmString(PSTR("Invalid statement")); break; printPgmString(PSTR("Invalid statement")); break;
case STATUS_HARD_LIMIT: case STATUS_HARD_LIMIT:
printPgmString(PSTR("Limit triggered. MPos lost?")); break; printPgmString(PSTR("Hard limit. MPos lost?")); break;
case STATUS_SETTING_DISABLED: case STATUS_SETTING_DISABLED:
printPgmString(PSTR("Setting disabled")); break; printPgmString(PSTR("Setting disabled")); break;
case STATUS_SETTING_VALUE_NEG: case STATUS_SETTING_VALUE_NEG:
printPgmString(PSTR("Set value must be > 0.0")); break; printPgmString(PSTR("Value < 0.0")); break;
case STATUS_SETTING_STEP_PULSE_MIN: case STATUS_SETTING_STEP_PULSE_MIN:
printPgmString(PSTR("Step pulse must be >= 3 microseconds")); break; printPgmString(PSTR("Value < 3 usec")); break;
case STATUS_SETTING_READ_FAIL: case STATUS_SETTING_READ_FAIL:
printPgmString(PSTR("Failed to read EEPROM settings. Using defaults")); break; printPgmString(PSTR("EEPROM read fail. Using defaults")); break;
case STATUS_IDLE_ERROR: case STATUS_IDLE_ERROR:
printPgmString(PSTR("Must be idle to execute")); break; printPgmString(PSTR("Busy or locked")); break;
case STATUS_ABORT_CYCLE: case STATUS_ABORT_CYCLE:
printPgmString(PSTR("Abort during cycle. MPos lost?")); break; printPgmString(PSTR("Abort during cycle. MPos lost?")); break;
case STATUS_HOMING_LOCK: case STATUS_HOMING_LOCK:
@ -117,55 +117,53 @@ void report_init_message()
// Grbl help message // Grbl help message
void report_grbl_help() { void report_grbl_help() {
printPgmString(PSTR("$ (help)\r\n" printPgmString(PSTR("$$ (view Grbl settings)\r\n"
"$$ (print Grbl settings)\r\n" "$# (view # parameters)\r\n"
"$# (print gcode parameters)\r\n" "$G (view parser state)\r\n"
"$G (print gcode parser state)\r\n" "$N (view startup blocks)\r\n"
"$N (print startup blocks)\r\n" "$x=value (save Grbl setting)\r\n"
"$x=value (store Grbl setting)\r\n" "$Nx=line (save startup block)\r\n"
"$Nx=line (store startup block)\r\n"
"$S0 (toggle check gcode)\r\n" "$S0 (toggle check gcode)\r\n"
"$S1 (toggle dry run)\r\n" "$S1 (toggle blk del)\r\n"
"$S2 (toggle block delete)\r\n" "$S2 (toggle single blk)\r\n"
"$S3 (toggle single block)\r\n" "$S3 (toggle opt stop)\r\n"
"$S4 (toggle optional stop)\r\n" "$X (kill homing lock)\r\n"
"$U (disable homing lock)\r\n" "$H (run homing cycle)\r\n"
"$H (perform homing cycle)\r\n"
"~ (cycle start)\r\n" "~ (cycle start)\r\n"
"! (feed hold)\r\n" "! (feed hold)\r\n"
"? (current position)\r\n" "? (position)\r\n"
"^x (reset Grbl)\r\n")); "ctrl-x (reset Grbl)\r\n"));
} }
// Grbl global settings print out. // Grbl global settings print out.
// NOTE: The numbering scheme here must correlate to storing in settings.c // NOTE: The numbering scheme here must correlate to storing in settings.c
void report_grbl_settings() { void report_grbl_settings() {
printPgmString(PSTR("$0=")); printFloat(settings.steps_per_mm[X_AXIS]); printPgmString(PSTR("$0=")); printFloat(settings.steps_per_mm[X_AXIS]);
printPgmString(PSTR(" (x axis, steps/mm)\r\n$1=")); printFloat(settings.steps_per_mm[Y_AXIS]); printPgmString(PSTR(" (x, step/mm)\r\n$1=")); printFloat(settings.steps_per_mm[Y_AXIS]);
printPgmString(PSTR(" (y axis, steps/mm)\r\n$2=")); printFloat(settings.steps_per_mm[Z_AXIS]); printPgmString(PSTR(" (y, step/mm)\r\n$2=")); printFloat(settings.steps_per_mm[Z_AXIS]);
printPgmString(PSTR(" (z axis, steps/mm)\r\n$3=")); printInteger(settings.pulse_microseconds); printPgmString(PSTR(" (z, step/mm)\r\n$3=")); printInteger(settings.pulse_microseconds);
printPgmString(PSTR(" (step pulse, usec)\r\n$4=")); printFloat(settings.default_feed_rate); printPgmString(PSTR(" (step pulse, usec)\r\n$4=")); printFloat(settings.default_feed_rate);
printPgmString(PSTR(" (default feed rate, mm/min)\r\n$5=")); printFloat(settings.default_seek_rate); printPgmString(PSTR(" (default feed, mm/min)\r\n$5=")); printFloat(settings.default_seek_rate);
printPgmString(PSTR(" (default seek rate, mm/min)\r\n$6=")); printFloat(settings.mm_per_arc_segment); printPgmString(PSTR(" (default seek, mm/min)\r\n$6=")); printInteger(settings.invert_mask);
printPgmString(PSTR(" (arc resolution, mm/segment)\r\n$7=")); printInteger(settings.invert_mask); printPgmString(PSTR(" (step port invert mask, int:")); print_uint8_base2(settings.invert_mask);
printPgmString(PSTR(" (step port invert mask, int:binary=")); print_uint8_base2(settings.invert_mask); printPgmString(PSTR(")\r\n$7=")); printInteger(settings.stepper_idle_lock_time);
printPgmString(PSTR(")\r\n$8=")); printFloat(settings.acceleration/(60*60)); // Convert from mm/min^2 for human readability printPgmString(PSTR(" (step idle delay, msec)\r\n$8=")); printFloat(settings.acceleration/(60*60)); // Convert from mm/min^2 for human readability
printPgmString(PSTR(" (acceleration, mm/sec^2)\r\n$9=")); printFloat(settings.junction_deviation); printPgmString(PSTR(" (acceleration, mm/sec^2)\r\n$9=")); printFloat(settings.junction_deviation);
printPgmString(PSTR(" (cornering junction deviation, mm)\r\n$10=")); printInteger(bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)); printPgmString(PSTR(" (junction deviation, mm)\r\n$10=")); printFloat(settings.mm_per_arc_segment);
printPgmString(PSTR(" (report inches, bool)\r\n$11=")); printInteger(bit_istrue(settings.flags,BITFLAG_AUTO_START)); printPgmString(PSTR(" (arc, mm/segment)\r\n$11=")); printInteger(settings.n_arc_correction);
printPgmString(PSTR(" (auto start enable, bool)\r\n$12=")); printInteger(bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)); printPgmString(PSTR(" (n-arc correction, int)\r\n$12=")); printInteger(settings.decimal_places);
printPgmString(PSTR(" (invert stepper enable, bool)\r\n$13=")); printInteger(bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE)); printPgmString(PSTR(" (n-decimals, int)\r\n$13=")); printInteger(bit_istrue(settings.flags,BITFLAG_REPORT_INCHES));
printPgmString(PSTR(" (hard limit enable, bool)\r\n$14=")); printInteger(bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)); printPgmString(PSTR(" (report inches, bool)\r\n$14=")); printInteger(bit_istrue(settings.flags,BITFLAG_AUTO_START));
printPgmString(PSTR(" (homing enable, bool)\r\n$15=")); printInteger(settings.homing_dir_mask); printPgmString(PSTR(" (auto start, bool)\r\n$15=")); printInteger(bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE));
printPgmString(PSTR(" (homing dir invert mask, int:binary=")); print_uint8_base2(settings.homing_dir_mask); printPgmString(PSTR(" (invert step enable, bool)\r\n$16=")); printInteger(bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE));
printPgmString(PSTR(")\r\n$16=")); printFloat(settings.homing_feed_rate); printPgmString(PSTR(" (hard limits, bool)\r\n$17=")); printInteger(bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE));
printPgmString(PSTR(" (homing feed rate, mm/min)\r\n$17=")); printFloat(settings.homing_seek_rate); printPgmString(PSTR(" (homing cycle, bool)\r\n$18=")); printInteger(settings.homing_dir_mask);
printPgmString(PSTR(" (homing seek rate, mm/min)\r\n$18=")); printInteger(settings.homing_debounce_delay); printPgmString(PSTR(" (homing dir invert mask, int:")); print_uint8_base2(settings.homing_dir_mask);
printPgmString(PSTR(" (homing debounce delay, msec)\r\n$19=")); printFloat(settings.homing_pulloff); printPgmString(PSTR(")\r\n$19=")); printFloat(settings.homing_feed_rate);
printPgmString(PSTR(" (homing pull-off travel, mm)\r\n$20=")); printInteger(settings.stepper_idle_lock_time); printPgmString(PSTR(" (homing feed, mm/min)\r\n$20=")); printFloat(settings.homing_seek_rate);
printPgmString(PSTR(" (stepper idle lock time, msec)\r\n$21=")); printInteger(settings.decimal_places); printPgmString(PSTR(" (homing seek, mm/min)\r\n$21=")); printInteger(settings.homing_debounce_delay);
printPgmString(PSTR(" (decimal places, int)\r\n$22=")); printInteger(settings.n_arc_correction); printPgmString(PSTR(" (homing debounce, msec)\r\n$22=")); printFloat(settings.homing_pulloff);
printPgmString(PSTR(" (n arc correction, int)\r\n")); printPgmString(PSTR(" (homing pull-off, mm)\r\n"));
} }
@ -266,10 +264,9 @@ void report_gcode_modes()
// Print active switches // Print active switches
if (gc.switches) { if (gc.switches) {
if (bit_istrue(gc.switches,BITFLAG_CHECK_GCODE)) { printPgmString(PSTR(" $S0")); } if (bit_istrue(gc.switches,BITFLAG_CHECK_GCODE)) { printPgmString(PSTR(" $S0")); }
if (bit_istrue(gc.switches,BITFLAG_DRY_RUN)) { printPgmString(PSTR(" $S1")); } if (bit_istrue(gc.switches,BITFLAG_BLOCK_DELETE)) { printPgmString(PSTR(" $S1")); }
if (bit_istrue(gc.switches,BITFLAG_BLOCK_DELETE)) { printPgmString(PSTR(" $S2")); } if (bit_istrue(gc.switches,BITFLAG_SINGLE_BLOCK)) { printPgmString(PSTR(" $S2")); }
if (bit_istrue(gc.switches,BITFLAG_SINGLE_BLOCK)) { printPgmString(PSTR(" $S3")); } if (bit_istrue(gc.switches,BITFLAG_OPT_STOP)) { printPgmString(PSTR(" $S3")); }
if (bit_istrue(gc.switches,BITFLAG_OPT_STOP)) { printPgmString(PSTR(" $S4")); }
} }
printPgmString(PSTR("\r\n")); printPgmString(PSTR("\r\n"));

View File

@ -142,15 +142,7 @@ uint8_t read_global_settings() {
if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_v4_t)))) { if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_v4_t)))) {
return(false); return(false);
} }
settings_reset(false); settings_reset(false); // Old settings ok. Write new settings only.
} else if (version >= 50) {
// 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
// should be re-written to the default value, if the developmental version number changed.
// Grab settings regardless of error.
memcpy_from_eeprom_with_checksum((char*)&settings, EEPROM_ADDR_GLOBAL, sizeof(settings_t));
settings_reset(false);
} else { } else {
return(false); return(false);
} }
@ -170,60 +162,41 @@ uint8_t settings_store_global_setting(int parameter, float value) {
settings.pulse_microseconds = round(value); break; settings.pulse_microseconds = round(value); break;
case 4: settings.default_feed_rate = value; break; case 4: settings.default_feed_rate = value; break;
case 5: settings.default_seek_rate = value; break; case 5: settings.default_seek_rate = value; break;
case 6: settings.mm_per_arc_segment = value; break; case 6: settings.invert_mask = trunc(value); break;
case 7: settings.invert_mask = trunc(value); break; case 7: settings.stepper_idle_lock_time = round(value); break;
case 8: settings.acceleration = value*60*60; break; // Convert to mm/min^2 for grbl internal use. case 8: settings.acceleration = value*60*60; break; // Convert to mm/min^2 for grbl internal use.
case 9: settings.junction_deviation = fabs(value); break; case 9: settings.junction_deviation = fabs(value); break;
case 10: case 10: settings.mm_per_arc_segment = value; break;
if (value) { case 11: settings.n_arc_correction = round(value); break;
settings.flags |= BITFLAG_REPORT_INCHES; case 12: settings.decimal_places = round(value); break;
} else { settings.flags &= ~BITFLAG_REPORT_INCHES; }
break;
case 11:
// Immediately apply auto_start to sys struct.
if (value) {
settings.flags |= BITFLAG_AUTO_START;
sys.auto_start = true;
} else {
settings.flags &= ~BITFLAG_AUTO_START;
sys.auto_start = false;
}
break;
case 12:
if (value) {
settings.flags |= BITFLAG_INVERT_ST_ENABLE;
} else { settings.flags &= ~BITFLAG_INVERT_ST_ENABLE; }
break;
case 13: case 13:
if (value) { if (value) { settings.flags |= BITFLAG_REPORT_INCHES; }
settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; else { settings.flags &= ~BITFLAG_REPORT_INCHES; }
} else { settings.flags &= ~BITFLAG_HARD_LIMIT_ENABLE; }
break; break;
case 14: case 14: // Reboot to ensure change
if (value) { settings.flags |= BITFLAG_AUTO_START; }
else { settings.flags &= ~BITFLAG_AUTO_START; }
break;
case 15: // Reboot to ensure change
if (value) { settings.flags |= BITFLAG_INVERT_ST_ENABLE; }
else { settings.flags &= ~BITFLAG_INVERT_ST_ENABLE; }
break;
case 16: // Reboot to ensure change
if (value) { settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; }
else { settings.flags &= ~BITFLAG_HARD_LIMIT_ENABLE; }
break;
case 17:
if (value) { if (value) {
settings.flags |= BITFLAG_HOMING_ENABLE; settings.flags |= BITFLAG_HOMING_ENABLE;
sys.state = STATE_ALARM; sys.state = STATE_ALARM;
report_feedback_message(MESSAGE_HOMING_ALARM); report_feedback_message(MESSAGE_HOMING_ALARM);
} else { settings.flags &= ~BITFLAG_HOMING_ENABLE; } } else { settings.flags &= ~BITFLAG_HOMING_ENABLE; }
break; break;
case 15: settings.homing_dir_mask = trunc(value); break; case 18: settings.homing_dir_mask = trunc(value); break;
case 16: settings.homing_feed_rate = value; break; case 19: settings.homing_feed_rate = value; break;
case 17: settings.homing_seek_rate = value; break; case 20: settings.homing_seek_rate = value; break;
case 18: settings.homing_debounce_delay = round(value); break; case 21: settings.homing_debounce_delay = round(value); break;
case 19: case 22: settings.homing_pulloff = value; break;
if (value <= 0.0) { return(STATUS_SETTING_VALUE_NEG); }
settings.homing_pulloff = value; break;
case 20:
settings.stepper_idle_lock_time = round(value);
// Immediately toggle stepper enable/disable functions to ensure change from always
// enable or disable. Will not start or stop a cycle.
if (!sys.state) { // Only if idle.
st_wake_up();
st_go_idle();
}
break;
case 21: settings.decimal_places = round(value); break;
case 22: settings.n_arc_correction = round(value); break;
default: default:
return(STATUS_INVALID_STATEMENT); return(STATUS_INVALID_STATEMENT);
} }

View File

@ -29,7 +29,7 @@
// 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 56 #define SETTINGS_VERSION 5
// Define bit flag masks for the boolean settings in settings.flag. // Define bit flag masks for the boolean settings in settings.flag.
#define BITFLAG_REPORT_INCHES bit(0) #define BITFLAG_REPORT_INCHES bit(0)