mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-30 09:39:49 +02:00
* Fixed various small bugs * Fixed potential cast bug * Fixed double reporting of errors Co-authored-by: Stefan de Bruijn <stefan@nubilosoft.com> Co-authored-by: Stefan de Bruijn <atlaste@users.noreply.github.com> Co-authored-by: Stefan de Bruijn <stefan@nubilosoft.com>
This commit is contained in:
@@ -23,9 +23,10 @@
|
||||
void memcpy_to_eeprom_with_checksum(unsigned int destination, const char* source, unsigned int size) {
|
||||
unsigned char checksum = 0;
|
||||
for (; size > 0; size--) {
|
||||
checksum = (checksum << 1) || (checksum >> 7);
|
||||
checksum += *source;
|
||||
EEPROM.write(destination++, *(source++));
|
||||
unsigned char data = static_cast<unsigned char>(*source++);
|
||||
checksum = (checksum << 1) | (checksum >> 7);
|
||||
checksum += data;
|
||||
EEPROM.write(destination++, data);
|
||||
}
|
||||
EEPROM.write(destination, checksum);
|
||||
EEPROM.commit();
|
||||
@@ -35,7 +36,7 @@ int memcpy_from_eeprom_with_checksum(char* destination, unsigned int source, uns
|
||||
unsigned char data, checksum = 0;
|
||||
for (; size > 0; size--) {
|
||||
data = EEPROM.read(source++);
|
||||
checksum = (checksum << 1) || (checksum >> 7);
|
||||
checksum = (checksum << 1) | (checksum >> 7);
|
||||
checksum += data;
|
||||
*(destination++) = data;
|
||||
}
|
||||
|
@@ -37,6 +37,23 @@ parser_block_t gc_block;
|
||||
#define FAIL(status) return (status);
|
||||
|
||||
void gc_init() {
|
||||
// First thing we do here is iterate through the coord systems and read them all, so that
|
||||
// we get all our coord system errors here, and not while we're busy:
|
||||
float coord_system[MAX_N_AXIS];
|
||||
|
||||
// g54 - g59 is 6 coordinate systems, plus 2 for G28 and G30 reference positions
|
||||
bool reported_error = false;
|
||||
const int MAX_COORD_SYSTEMS = 8;
|
||||
for (uint8_t i = 0; i < MAX_COORD_SYSTEMS; ++i) {
|
||||
if (!(settings_read_coord_data(i, coord_system))) {
|
||||
if (!reported_error) {
|
||||
reported_error = true;
|
||||
report_status_message(Error::SettingReadFail, CLIENT_SERIAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset parser state:
|
||||
memset(&gc_state, 0, sizeof(parser_state_t));
|
||||
// Load default G54 coordinate system.
|
||||
if (!(settings_read_coord_data(gc_state.modal.coord_select, gc_state.coord_system))) {
|
||||
|
@@ -365,7 +365,8 @@ namespace Motors {
|
||||
tx_message[++msg_index] = 4; // low order data length
|
||||
tx_message[++msg_index] = 0; // high order data length
|
||||
|
||||
for (uint8_t axis = X_AXIS; axis < N_AXIS; axis++) {
|
||||
auto n_axis = number_axis->get();
|
||||
for (uint8_t axis = X_AXIS; axis < n_axis; axis++) {
|
||||
for (uint8_t gang_index = 0; gang_index < 2; gang_index++) {
|
||||
current_id = ids[axis][gang_index];
|
||||
if (current_id != 0) {
|
||||
|
@@ -167,6 +167,7 @@ void grbl_notifyf(const char* title, const char* format, ...) {
|
||||
}
|
||||
|
||||
// formats axis values into a string and returns that string in rpt
|
||||
// NOTE: rpt should have at least size: 20 * MAX_N_AXIS
|
||||
static void report_util_axis_values(float* axis_value, char* rpt) {
|
||||
uint8_t idx;
|
||||
char axisVal[20];
|
||||
@@ -178,9 +179,9 @@ static void report_util_axis_values(float* axis_value, char* rpt) {
|
||||
auto n_axis = number_axis->get();
|
||||
for (idx = 0; idx < n_axis; idx++) {
|
||||
if (report_inches->get()) {
|
||||
sprintf(axisVal, "%4.4f", axis_value[idx] * unit_conv); // Report inches to 4 decimals
|
||||
snprintf(axisVal, 19, "%4.4f", axis_value[idx] * unit_conv); // Report inches to 4 decimals
|
||||
} else {
|
||||
sprintf(axisVal, "%4.3f", axis_value[idx] * unit_conv); // Report mm to 3 decimals
|
||||
snprintf(axisVal, 19, "%4.3f", axis_value[idx] * unit_conv); // Report mm to 3 decimals
|
||||
}
|
||||
strcat(rpt, axisVal);
|
||||
if (idx < (number_axis->get() - 1)) {
|
||||
@@ -283,8 +284,8 @@ void report_grbl_help(uint8_t client) {
|
||||
void report_probe_parameters(uint8_t client) {
|
||||
// Report in terms of machine position.
|
||||
float print_position[MAX_N_AXIS];
|
||||
char probe_rpt[100]; // the probe report we are building here
|
||||
char temp[60];
|
||||
char probe_rpt[(MAX_N_AXIS * 20 + 13 + 6 + 1)]; // the probe report we are building here
|
||||
char temp[MAX_N_AXIS * 20];
|
||||
strcpy(probe_rpt, "[PRB:"); // initialize the string with the first characters
|
||||
// get the machine position and put them into a string and append to the probe report
|
||||
system_convert_array_steps_to_mpos(print_position, sys_probe_position);
|
||||
@@ -300,8 +301,8 @@ void report_probe_parameters(uint8_t client) {
|
||||
void report_ngc_parameters(uint8_t client) {
|
||||
float coord_data[MAX_N_AXIS];
|
||||
uint8_t coord_select;
|
||||
char temp[60];
|
||||
char ngc_rpt[500];
|
||||
char temp[MAX_N_AXIS * 20];
|
||||
char ngc_rpt[((8 + (MAX_N_AXIS * 20)) * SETTING_INDEX_NCOORD + 4 + MAX_N_AXIS * 20 + 8 + 2 * 20)];
|
||||
ngc_rpt[0] = '\0';
|
||||
for (coord_select = 0; coord_select <= SETTING_INDEX_NCOORD; coord_select++) {
|
||||
if (!(settings_read_coord_data(coord_select, coord_data))) {
|
||||
@@ -332,9 +333,9 @@ void report_ngc_parameters(uint8_t client) {
|
||||
strcat(ngc_rpt, "]\r\n");
|
||||
strcat(ngc_rpt, "[TLO:"); // Print tool length offset value
|
||||
if (report_inches->get()) {
|
||||
sprintf(temp, "%4.3f]\r\n", gc_state.tool_length_offset * INCH_PER_MM);
|
||||
snprintf(temp, 20, "%4.3f]\r\n", gc_state.tool_length_offset * INCH_PER_MM);
|
||||
} else {
|
||||
sprintf(temp, "%4.3f]\r\n", gc_state.tool_length_offset);
|
||||
snprintf(temp, 20, "%4.3f]\r\n", gc_state.tool_length_offset);
|
||||
}
|
||||
strcat(ngc_rpt, temp);
|
||||
grbl_send(client, ngc_rpt);
|
||||
@@ -598,7 +599,7 @@ void report_realtime_status(uint8_t client) {
|
||||
memcpy(current_position, sys_position, sizeof(sys_position));
|
||||
float print_position[MAX_N_AXIS];
|
||||
char status[200];
|
||||
char temp[80];
|
||||
char temp[MAX_N_AXIS * 20];
|
||||
system_convert_array_steps_to_mpos(print_position, current_position);
|
||||
// Report current machine state and sub-states
|
||||
strcpy(status, "<");
|
||||
@@ -670,7 +671,7 @@ void report_realtime_status(uint8_t client) {
|
||||
if (bit_istrue(status_mask->get(), BITFLAG_RT_STATUS_POSITION_TYPE)) {
|
||||
strcat(status, "|MPos:");
|
||||
} else {
|
||||
#ifdef USE_FWD_KINEMATICS
|
||||
#ifdef USE_FWD_KINEMATICS
|
||||
forward_kinematics(print_position);
|
||||
#endif
|
||||
strcat(status, "|WPos:");
|
||||
@@ -855,7 +856,7 @@ void report_realtime_status(uint8_t client) {
|
||||
|
||||
void report_realtime_steps() {
|
||||
uint8_t idx;
|
||||
auto n_axis = number_axis->get();
|
||||
auto n_axis = number_axis->get();
|
||||
for (idx = 0; idx < n_axis; idx++) {
|
||||
grbl_sendf(CLIENT_ALL, "%ld\n", sys_position[idx]); // OK to send to all ... debug stuff
|
||||
}
|
||||
|
Reference in New Issue
Block a user