From 5e7a4b3ba8a032aa6880d7eb8224a37819f0286c Mon Sep 17 00:00:00 2001 From: Sonny Jeon Date: Wed, 7 Nov 2012 20:53:03 -0700 Subject: [PATCH] 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! --- config.h | 4 +-- gcode.c | 16 ++-------- gcode.h | 8 ++--- main.c | 9 +++--- protocol.c | 33 +++++++------------ report.c | 93 ++++++++++++++++++++++++++---------------------------- settings.c | 79 +++++++++++++++------------------------------- settings.h | 2 +- 8 files changed, 97 insertions(+), 147 deletions(-) diff --git a/config.h b/config.h index dca6c86..c0f9ad6 100755 --- a/config.h +++ b/config.h @@ -100,7 +100,7 @@ #define DEFAULT_FEEDRATE 250.0 #define DEFAULT_ACCELERATION (DEFAULT_FEEDRATE*60*60/10.0) // mm/min^2 #define DEFAULT_JUNCTION_DEVIATION 0.05 // mm -#define DEFAULT_STEPPING_INVERT_MASK ((1< 0.0")); break; + printPgmString(PSTR("Value < 0.0")); break; 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: - printPgmString(PSTR("Failed to read EEPROM settings. Using defaults")); break; + printPgmString(PSTR("EEPROM read fail. Using defaults")); break; case STATUS_IDLE_ERROR: - printPgmString(PSTR("Must be idle to execute")); break; + printPgmString(PSTR("Busy or locked")); break; case STATUS_ABORT_CYCLE: printPgmString(PSTR("Abort during cycle. MPos lost?")); break; case STATUS_HOMING_LOCK: @@ -117,55 +117,53 @@ void report_init_message() // Grbl help message void report_grbl_help() { - printPgmString(PSTR("$ (help)\r\n" - "$$ (print Grbl settings)\r\n" - "$# (print gcode parameters)\r\n" - "$G (print gcode parser state)\r\n" - "$N (print startup blocks)\r\n" - "$x=value (store Grbl setting)\r\n" - "$Nx=line (store startup block)\r\n" + printPgmString(PSTR("$$ (view Grbl settings)\r\n" + "$# (view # parameters)\r\n" + "$G (view parser state)\r\n" + "$N (view startup blocks)\r\n" + "$x=value (save Grbl setting)\r\n" + "$Nx=line (save startup block)\r\n" "$S0 (toggle check gcode)\r\n" - "$S1 (toggle dry run)\r\n" - "$S2 (toggle block delete)\r\n" - "$S3 (toggle single block)\r\n" - "$S4 (toggle optional stop)\r\n" - "$U (disable homing lock)\r\n" - "$H (perform homing cycle)\r\n" + "$S1 (toggle blk del)\r\n" + "$S2 (toggle single blk)\r\n" + "$S3 (toggle opt stop)\r\n" + "$X (kill homing lock)\r\n" + "$H (run homing cycle)\r\n" "~ (cycle start)\r\n" "! (feed hold)\r\n" - "? (current position)\r\n" - "^x (reset Grbl)\r\n")); + "? (position)\r\n" + "ctrl-x (reset Grbl)\r\n")); } // Grbl global settings print out. // NOTE: The numbering scheme here must correlate to storing in settings.c void report_grbl_settings() { 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(" (y axis, steps/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(" (x, step/mm)\r\n$1=")); printFloat(settings.steps_per_mm[Y_AXIS]); + printPgmString(PSTR(" (y, step/mm)\r\n$2=")); printFloat(settings.steps_per_mm[Z_AXIS]); + 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(" (default feed rate, 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(" (arc resolution, mm/segment)\r\n$7=")); printInteger(settings.invert_mask); - printPgmString(PSTR(" (step port invert mask, int:binary=")); print_uint8_base2(settings.invert_mask); - printPgmString(PSTR(")\r\n$8=")); printFloat(settings.acceleration/(60*60)); // Convert from mm/min^2 for human readability + printPgmString(PSTR(" (default feed, mm/min)\r\n$5=")); printFloat(settings.default_seek_rate); + printPgmString(PSTR(" (default seek, mm/min)\r\n$6=")); printInteger(settings.invert_mask); + printPgmString(PSTR(" (step port invert mask, int:")); print_uint8_base2(settings.invert_mask); + printPgmString(PSTR(")\r\n$7=")); printInteger(settings.stepper_idle_lock_time); + 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(" (cornering junction deviation, mm)\r\n$10=")); printInteger(bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)); - printPgmString(PSTR(" (report inches, bool)\r\n$11=")); printInteger(bit_istrue(settings.flags,BITFLAG_AUTO_START)); - printPgmString(PSTR(" (auto start enable, bool)\r\n$12=")); printInteger(bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)); - printPgmString(PSTR(" (invert stepper enable, bool)\r\n$13=")); printInteger(bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE)); - printPgmString(PSTR(" (hard limit enable, bool)\r\n$14=")); printInteger(bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)); - printPgmString(PSTR(" (homing enable, bool)\r\n$15=")); printInteger(settings.homing_dir_mask); - printPgmString(PSTR(" (homing dir invert mask, int:binary=")); print_uint8_base2(settings.homing_dir_mask); - printPgmString(PSTR(")\r\n$16=")); printFloat(settings.homing_feed_rate); - printPgmString(PSTR(" (homing feed rate, mm/min)\r\n$17=")); printFloat(settings.homing_seek_rate); - printPgmString(PSTR(" (homing seek rate, mm/min)\r\n$18=")); printInteger(settings.homing_debounce_delay); - printPgmString(PSTR(" (homing debounce delay, msec)\r\n$19=")); printFloat(settings.homing_pulloff); - printPgmString(PSTR(" (homing pull-off travel, mm)\r\n$20=")); printInteger(settings.stepper_idle_lock_time); - printPgmString(PSTR(" (stepper idle lock time, msec)\r\n$21=")); printInteger(settings.decimal_places); - printPgmString(PSTR(" (decimal places, int)\r\n$22=")); printInteger(settings.n_arc_correction); - printPgmString(PSTR(" (n arc correction, int)\r\n")); + printPgmString(PSTR(" (junction deviation, mm)\r\n$10=")); printFloat(settings.mm_per_arc_segment); + printPgmString(PSTR(" (arc, mm/segment)\r\n$11=")); printInteger(settings.n_arc_correction); + printPgmString(PSTR(" (n-arc correction, int)\r\n$12=")); printInteger(settings.decimal_places); + printPgmString(PSTR(" (n-decimals, int)\r\n$13=")); printInteger(bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)); + printPgmString(PSTR(" (report inches, bool)\r\n$14=")); printInteger(bit_istrue(settings.flags,BITFLAG_AUTO_START)); + printPgmString(PSTR(" (auto start, bool)\r\n$15=")); printInteger(bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)); + printPgmString(PSTR(" (invert step enable, bool)\r\n$16=")); printInteger(bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE)); + printPgmString(PSTR(" (hard limits, bool)\r\n$17=")); printInteger(bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)); + printPgmString(PSTR(" (homing cycle, bool)\r\n$18=")); printInteger(settings.homing_dir_mask); + printPgmString(PSTR(" (homing dir invert mask, int:")); print_uint8_base2(settings.homing_dir_mask); + printPgmString(PSTR(")\r\n$19=")); printFloat(settings.homing_feed_rate); + printPgmString(PSTR(" (homing feed, mm/min)\r\n$20=")); printFloat(settings.homing_seek_rate); + printPgmString(PSTR(" (homing seek, mm/min)\r\n$21=")); printInteger(settings.homing_debounce_delay); + printPgmString(PSTR(" (homing debounce, msec)\r\n$22=")); printFloat(settings.homing_pulloff); + printPgmString(PSTR(" (homing pull-off, mm)\r\n")); } @@ -266,10 +264,9 @@ void report_gcode_modes() // Print active switches if (gc.switches) { 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(" $S2")); } - if (bit_istrue(gc.switches,BITFLAG_SINGLE_BLOCK)) { printPgmString(PSTR(" $S3")); } - if (bit_istrue(gc.switches,BITFLAG_OPT_STOP)) { printPgmString(PSTR(" $S4")); } + if (bit_istrue(gc.switches,BITFLAG_BLOCK_DELETE)) { printPgmString(PSTR(" $S1")); } + if (bit_istrue(gc.switches,BITFLAG_SINGLE_BLOCK)) { printPgmString(PSTR(" $S2")); } + if (bit_istrue(gc.switches,BITFLAG_OPT_STOP)) { printPgmString(PSTR(" $S3")); } } printPgmString(PSTR("\r\n")); diff --git a/settings.c b/settings.c index 2e22ea6..d1d42e2 100644 --- a/settings.c +++ b/settings.c @@ -142,15 +142,7 @@ uint8_t read_global_settings() { if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_v4_t)))) { return(false); } - settings_reset(false); - } 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); + settings_reset(false); // Old settings ok. Write new settings only. } else { return(false); } @@ -170,60 +162,41 @@ uint8_t settings_store_global_setting(int parameter, float value) { settings.pulse_microseconds = round(value); break; case 4: settings.default_feed_rate = value; break; case 5: settings.default_seek_rate = value; break; - case 6: settings.mm_per_arc_segment = value; break; - case 7: settings.invert_mask = trunc(value); break; + case 6: 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 9: settings.junction_deviation = fabs(value); break; - case 10: - if (value) { - settings.flags |= BITFLAG_REPORT_INCHES; - } 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 10: settings.mm_per_arc_segment = value; break; + case 11: settings.n_arc_correction = round(value); break; + case 12: settings.decimal_places = round(value); break; case 13: - if (value) { - settings.flags |= BITFLAG_HARD_LIMIT_ENABLE; - } else { settings.flags &= ~BITFLAG_HARD_LIMIT_ENABLE; } + if (value) { settings.flags |= BITFLAG_REPORT_INCHES; } + else { settings.flags &= ~BITFLAG_REPORT_INCHES; } 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) { settings.flags |= BITFLAG_HOMING_ENABLE; sys.state = STATE_ALARM; report_feedback_message(MESSAGE_HOMING_ALARM); } else { settings.flags &= ~BITFLAG_HOMING_ENABLE; } break; - case 15: settings.homing_dir_mask = trunc(value); break; - case 16: settings.homing_feed_rate = value; break; - case 17: settings.homing_seek_rate = value; break; - case 18: settings.homing_debounce_delay = round(value); break; - case 19: - 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; + case 18: settings.homing_dir_mask = trunc(value); break; + case 19: settings.homing_feed_rate = value; break; + case 20: settings.homing_seek_rate = value; break; + case 21: settings.homing_debounce_delay = round(value); break; + case 22: settings.homing_pulloff = value; break; default: return(STATUS_INVALID_STATEMENT); } diff --git a/settings.h b/settings.h index c363605..bf3bb16 100755 --- a/settings.h +++ b/settings.h @@ -29,7 +29,7 @@ // 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 -#define SETTINGS_VERSION 56 +#define SETTINGS_VERSION 5 // Define bit flag masks for the boolean settings in settings.flag. #define BITFLAG_REPORT_INCHES bit(0)