From 3c3382ff7557a8dff61505b0020f50fdb77d1190 Mon Sep 17 00:00:00 2001 From: Sonny Jeon Date: Sun, 5 Jan 2014 10:27:34 -0700 Subject: [PATCH] New build info feature. (per @Analogreality request) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - New build info feature. Hidden command ā€˜$Iā€™ will print the build info for your Grbl firmware. Users may also write an identifying message within it via ā€˜$I=ā€˜ with up to 32 characters. (no more, or else it will break). - Adjusted the max number of startup lines to 3. Majority of people will only need one. - Fixed a compile error with spindle_control.c. A rogue #endif was causing problems. --- config.h | 4 ++-- protocol.c | 16 ++++++++++++++++ report.c | 12 +++++++++++- report.h | 3 +++ settings.c | 19 +++++++++++++++++++ settings.h | 5 +++++ spindle_control.c | 2 -- 7 files changed, 56 insertions(+), 5 deletions(-) diff --git a/config.h b/config.h index 4cb4de5..78d0ecf 100644 --- a/config.h +++ b/config.h @@ -74,10 +74,10 @@ #define N_HOMING_LOCATE_CYCLE 2 // Integer (1-128) // Number of blocks Grbl executes upon startup. These blocks are stored in EEPROM, where the size -// and addresses are defined in settings.h. With the current settings, up to 5 startup blocks may +// and addresses are defined in settings.h. With the current settings, up to 3 startup blocks may // be stored and executed in order. These startup blocks would typically be used to set the g-code // parser state depending on user preferences. -#define N_STARTUP_LINE 2 // Integer (1-5) +#define N_STARTUP_LINE 2 // Integer (1-3) // --------------------------------------------------------------------------------------- // ADVANCED CONFIGURATION OPTIONS: diff --git a/protocol.c b/protocol.c index 29d81e6..0cc0319 100644 --- a/protocol.c +++ b/protocol.c @@ -254,6 +254,22 @@ uint8_t protocol_execute_line(char *line) if (!sys.abort) { protocol_execute_startup(); } // Execute startup scripts after successful homing. } else { return(STATUS_SETTING_DISABLED); } break; + case 'I' : // Print or store build info. + if ( line[++char_counter] == 0 ) { + if (!(settings_read_build_info(line))) { + report_status_message(STATUS_SETTING_READ_FAIL); + } else { + report_build_info(line); + } + } else { // Store startup line + if(line[char_counter++] != '=') { return(STATUS_UNSUPPORTED_STATEMENT); } + helper_var = char_counter; // Set helper variable as counter to start of user info line. + do { + line[char_counter-helper_var] = line[char_counter]; + } while (line[char_counter++] != 0); + settings_store_build_info(line); + } + break; case 'N' : // Startup lines. if ( line[++char_counter] == 0 ) { // Print startup lines for (helper_var=0; helper_var < N_STARTUP_LINE; helper_var++) { diff --git a/report.c b/report.c index 7e32ef1..1796c8c 100644 --- a/report.c +++ b/report.c @@ -125,7 +125,7 @@ void report_feedback_message(uint8_t message_code) // Welcome message void report_init_message() { - printPgmString(PSTR("\r\nGrbl " GRBL_VERSION " ("GRBL_VERSION_BUILD ") ['$' for help]\r\n")); + printPgmString(PSTR("\r\nGrbl " GRBL_VERSION " ['$' for help]\r\n")); } // Grbl help message @@ -292,6 +292,16 @@ void report_startup_line(uint8_t n, char *line) printPgmString(PSTR("\r\n")); } + +// Prints build info line +void report_build_info(char *line) +{ + printPgmString(PSTR("[" GRBL_VERSION "." GRBL_VERSION_BUILD ":")); + printString(line); + printPgmString(PSTR("]\r\n")); +} + + // Prints real-time data. This function grabs a real-time snapshot of the stepper subprogram // and the actual location of the CNC machine. Users may change the following function to their // specific needs, but the desired real-time data report must be as short as possible. This is diff --git a/report.h b/report.h index 53c97dc..92984df 100644 --- a/report.h +++ b/report.h @@ -78,4 +78,7 @@ void report_gcode_modes(); // Prints startup line void report_startup_line(uint8_t n, char *line); +// Prints build info and user info +void report_build_info(char *line); + #endif diff --git a/settings.c b/settings.c index ae36abf..a312ee4 100644 --- a/settings.c +++ b/settings.c @@ -50,6 +50,12 @@ void settings_store_startup_line(uint8_t n, char *line) memcpy_to_eeprom_with_checksum(addr,(char*)line, LINE_BUFFER_SIZE); } +// Method to store build info into EEPROM +void settings_store_build_info(char *line) +{ + memcpy_to_eeprom_with_checksum(EEPROM_ADDR_BUILD_INFO,(char*)line, LINE_BUFFER_SIZE); +} + // Method to store coord data parameters into EEPROM void settings_write_coord_data(uint8_t coord_select, float *coord_data) { @@ -120,6 +126,19 @@ uint8_t settings_read_startup_line(uint8_t n, char *line) } } +// Reads startup line from EEPROM. Updated pointed line string data. +uint8_t settings_read_build_info(char *line) +{ + if (!(memcpy_from_eeprom_with_checksum((char*)line, EEPROM_ADDR_BUILD_INFO, LINE_BUFFER_SIZE))) { + // Reset line with default value + line[0] = 0; + settings_store_build_info(line); + return(false); + } else { + return(true); + } +} + // Read selected coordinate data from EEPROM. Updates pointed coord_data value. uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data) { diff --git a/settings.h b/settings.h index 40c5cca..05840bb 100644 --- a/settings.h +++ b/settings.h @@ -48,6 +48,7 @@ #define EEPROM_ADDR_GLOBAL 1 #define EEPROM_ADDR_PARAMETERS 512 #define EEPROM_ADDR_STARTUP_BLOCK 768 +#define EEPROM_ADDR_BUILD_INFO 992 // Define EEPROM address indexing for coordinate parameters #define N_COORDINATE_SYSTEM 6 // Number of supported work coordinate systems (from index 1) @@ -93,6 +94,10 @@ void settings_store_startup_line(uint8_t n, char *line); // Reads an EEPROM startup line to the protocol line variable uint8_t settings_read_startup_line(uint8_t n, char *line); +void settings_store_build_info(char *line); + +uint8_t settings_read_build_info(char *line); + // Writes selected coordinate data to EEPROM void settings_write_coord_data(uint8_t coord_select, float *coord_data); diff --git a/spindle_control.c b/spindle_control.c index 9dcc870..70e819e 100644 --- a/spindle_control.c +++ b/spindle_control.c @@ -92,5 +92,3 @@ void spindle_run(int8_t direction, uint16_t rpm) current_rpm = rpm; } } - -#endif