Lots of re-organization and cleaning-up. Some bug fixes.
- Added a new source and header file called system. These files contain the system commands and variables, as well as all of the system headers and standard libraries Grbl uses. Centralizing some of the code. - Re-organized the include headers throughout the source code. - ENABLE_M7 define was missing from config.h. Now there. - SPINDLE_MAX_RPM and SPINDLE_MIN_RPM now defined in config.h. No uncommenting to prevent user issues. Minimum spindle RPM now provides the lower, near 0V, scale adjustment, i.e. some spindles can go really slow so why use up our 256 voltage bins for them? - Remove some persistent variables from coolant and spindle control. They were redundant. - Removed a VARIABLE_SPINDLE define in cpu_map.h that shouldn’t have been there. - Changed the DEFAULT_ARC_TOLERANCE to 0.002mm to improve arc tracing. Before we had issues with performance, no longer. - Fixed a bug with the hard limits and the software debounce feature enabled. The invert limit pin setting wasn’t honored. - Fixed a bug with the homing direction mask. Now is like it used to be. At least for now. - Re-organized main.c to serve as only as the reset/initialization routine. Makes things a little bit clearer in terms of execution procedures. - Re-organized protocol.c as the overall master control unit for execution procedures. Not quite there yet, but starting to make a little more sense in how things are run. - Removed updating of old settings records. So many new settings have been added that it’s not worth adding the code to migrate old user settings. - Tweaked spindle_control.c a bit and made it more clear and consistent with other parts of Grbl. - Tweaked the stepper disable bit code in stepper.c. Requires less flash memory.
This commit is contained in:
84
settings.c
84
settings.c
@ -19,29 +19,15 @@
|
||||
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include "protocol.h"
|
||||
#include "report.h"
|
||||
#include "stepper.h"
|
||||
#include "nuts_bolts.h"
|
||||
#include "system.h"
|
||||
#include "settings.h"
|
||||
#include "eeprom.h"
|
||||
#include "protocol.h"
|
||||
#include "report.h"
|
||||
#include "limits.h"
|
||||
|
||||
settings_t settings;
|
||||
|
||||
// Version 4 outdated settings record
|
||||
typedef struct {
|
||||
float steps_per_mm[N_AXIS];
|
||||
uint8_t microsteps;
|
||||
uint8_t pulse_microseconds;
|
||||
float default_feed_rate;
|
||||
uint8_t invert_mask;
|
||||
float mm_per_arc_segment;
|
||||
float acceleration;
|
||||
float junction_deviation;
|
||||
} settings_v4_t;
|
||||
|
||||
|
||||
// Method to store startup lines into EEPROM
|
||||
void settings_store_startup_line(uint8_t n, char *line)
|
||||
@ -50,12 +36,14 @@ 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)
|
||||
{
|
||||
@ -63,6 +51,7 @@ void settings_write_coord_data(uint8_t coord_select, float *coord_data)
|
||||
memcpy_to_eeprom_with_checksum(addr,(char*)coord_data, sizeof(float)*N_AXIS);
|
||||
}
|
||||
|
||||
|
||||
// Method to store Grbl global settings struct and version number into EEPROM
|
||||
void write_global_settings()
|
||||
{
|
||||
@ -70,27 +59,24 @@ void write_global_settings()
|
||||
memcpy_to_eeprom_with_checksum(EEPROM_ADDR_GLOBAL, (char*)&settings, sizeof(settings_t));
|
||||
}
|
||||
|
||||
|
||||
// Method to reset Grbl global settings back to defaults.
|
||||
void settings_reset(bool reset_all) {
|
||||
// Reset all settings or only the migration settings to the new version.
|
||||
if (reset_all) {
|
||||
settings.steps_per_mm[X_AXIS] = DEFAULT_X_STEPS_PER_MM;
|
||||
settings.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM;
|
||||
settings.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM;
|
||||
settings.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS;
|
||||
settings.default_feed_rate = DEFAULT_FEEDRATE;
|
||||
settings.max_rate[X_AXIS] = DEFAULT_X_MAX_RATE;
|
||||
settings.max_rate[Y_AXIS] = DEFAULT_Y_MAX_RATE;
|
||||
settings.max_rate[Z_AXIS] = DEFAULT_Z_MAX_RATE;
|
||||
settings.acceleration[X_AXIS] = DEFAULT_X_ACCELERATION;
|
||||
settings.acceleration[Y_AXIS] = DEFAULT_Y_ACCELERATION;
|
||||
settings.acceleration[Z_AXIS] = DEFAULT_Z_ACCELERATION;
|
||||
settings.arc_tolerance = DEFAULT_ARC_TOLERANCE;
|
||||
settings.step_invert_mask = DEFAULT_STEPPING_INVERT_MASK;
|
||||
settings.dir_invert_mask = DEFAULT_DIRECTION_INVERT_MASK;
|
||||
settings.junction_deviation = DEFAULT_JUNCTION_DEVIATION;
|
||||
}
|
||||
// New settings since last version
|
||||
void settings_reset() {
|
||||
settings.steps_per_mm[X_AXIS] = DEFAULT_X_STEPS_PER_MM;
|
||||
settings.steps_per_mm[Y_AXIS] = DEFAULT_Y_STEPS_PER_MM;
|
||||
settings.steps_per_mm[Z_AXIS] = DEFAULT_Z_STEPS_PER_MM;
|
||||
settings.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS;
|
||||
settings.default_feed_rate = DEFAULT_FEEDRATE;
|
||||
settings.max_rate[X_AXIS] = DEFAULT_X_MAX_RATE;
|
||||
settings.max_rate[Y_AXIS] = DEFAULT_Y_MAX_RATE;
|
||||
settings.max_rate[Z_AXIS] = DEFAULT_Z_MAX_RATE;
|
||||
settings.acceleration[X_AXIS] = DEFAULT_X_ACCELERATION;
|
||||
settings.acceleration[Y_AXIS] = DEFAULT_Y_ACCELERATION;
|
||||
settings.acceleration[Z_AXIS] = DEFAULT_Z_ACCELERATION;
|
||||
settings.arc_tolerance = DEFAULT_ARC_TOLERANCE;
|
||||
settings.step_invert_mask = DEFAULT_STEPPING_INVERT_MASK;
|
||||
settings.dir_invert_mask = DEFAULT_DIRECTION_INVERT_MASK;
|
||||
settings.junction_deviation = DEFAULT_JUNCTION_DEVIATION;
|
||||
settings.flags = 0;
|
||||
if (DEFAULT_REPORT_INCHES) { settings.flags |= BITFLAG_REPORT_INCHES; }
|
||||
if (DEFAULT_AUTO_START) { settings.flags |= BITFLAG_AUTO_START; }
|
||||
@ -112,13 +98,14 @@ void settings_reset(bool reset_all) {
|
||||
write_global_settings();
|
||||
}
|
||||
|
||||
|
||||
// Reads startup line from EEPROM. Updated pointed line string data.
|
||||
uint8_t settings_read_startup_line(uint8_t n, char *line)
|
||||
{
|
||||
uint16_t addr = n*(LINE_BUFFER_SIZE+1)+EEPROM_ADDR_STARTUP_BLOCK;
|
||||
if (!(memcpy_from_eeprom_with_checksum((char*)line, addr, LINE_BUFFER_SIZE))) {
|
||||
// Reset line with default value
|
||||
line[0] = 0;
|
||||
line[0] = 0; // Empty line
|
||||
settings_store_startup_line(n, line);
|
||||
return(false);
|
||||
} else {
|
||||
@ -126,12 +113,13 @@ 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;
|
||||
line[0] = 0; // Empty line
|
||||
settings_store_build_info(line);
|
||||
return(false);
|
||||
} else {
|
||||
@ -139,6 +127,7 @@ uint8_t settings_read_build_info(char *line)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Read selected coordinate data from EEPROM. Updates pointed coord_data value.
|
||||
uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data)
|
||||
{
|
||||
@ -153,26 +142,18 @@ uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reads Grbl global settings struct from EEPROM.
|
||||
uint8_t read_global_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, EEPROM_ADDR_GLOBAL, sizeof(settings_t)))) {
|
||||
return(false);
|
||||
}
|
||||
} else {
|
||||
if (version <= 4) {
|
||||
// Migrate from settings version 4 to current version.
|
||||
if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_v4_t)))) {
|
||||
return(false);
|
||||
}
|
||||
settings_reset(false); // Old settings ok. Write new settings only.
|
||||
} else {
|
||||
return(false);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
@ -180,9 +161,9 @@ uint8_t read_global_settings() {
|
||||
|
||||
// A helper method to set settings from command line
|
||||
uint8_t settings_store_global_setting(int parameter, float value) {
|
||||
if (value < 0.0) { return(STATUS_SETTING_VALUE_NEG); }
|
||||
switch(parameter) {
|
||||
case 0: case 1: case 2:
|
||||
if (value <= 0.0) { return(STATUS_SETTING_VALUE_NEG); }
|
||||
settings.steps_per_mm[parameter] = value; break;
|
||||
case 3: settings.max_rate[X_AXIS] = value; break;
|
||||
case 4: settings.max_rate[Y_AXIS] = value; break;
|
||||
@ -249,11 +230,12 @@ uint8_t settings_store_global_setting(int parameter, float value) {
|
||||
return(STATUS_OK);
|
||||
}
|
||||
|
||||
|
||||
// Initialize the config subsystem
|
||||
void settings_init() {
|
||||
if(!read_global_settings()) {
|
||||
report_status_message(STATUS_SETTING_READ_FAIL);
|
||||
settings_reset(true);
|
||||
settings_reset();
|
||||
report_grbl_settings();
|
||||
}
|
||||
// Read all parameter data into a dummy variable. If error, reset to zero, otherwise do nothing.
|
||||
|
Reference in New Issue
Block a user