From 750f60ce7490843481c248462e31fa9e7c12bd9f Mon Sep 17 00:00:00 2001 From: Terje Io Date: Mon, 1 May 2023 12:01:57 +0200 Subject: [PATCH] Fixed typos and added grbl.on_gcode_comment event. --- README.md | 2 +- changelog.md | 14 ++++++++++++++ config.h | 16 ++++++++-------- core_handlers.h | 1 + gcode.c | 29 +++++++++++++++++------------ grbl.h | 2 +- motion_control.c | 2 +- ngc_expr.c | 2 +- settings.c | 17 ++++++++--------- sleep.c | 2 +- state_machine.c | 2 +- stepper.c | 5 +++-- stream.c | 2 +- 13 files changed, 58 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 96811de..241e2d0 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ It has been written to complement grblHAL and has features such as proper keyboa --- -Latest build date is 20230427 see the [changelog](changelog.md) for details. +Latest build date is 20230501 see the [changelog](changelog.md) for details. __NOTE:__ A settings reset will be performed on an update of builds earlier than 20230125. Backup and restore of settings is recommended. __IMPORTANT!__ A new setting has been introduced for ganged axes motors in build 20211121. I have only bench tested this for a couple of drivers, correct function should be verified after updating by those who have more than three motors configured. diff --git a/changelog.md b/changelog.md index 07514d6..6830867 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,19 @@ ## grblHAL changelog +20230501 + +Core: + +* Fixed typos. + +* Added `grbl.on_gcode_comment` event - can be subscribed to by plugin code to trap comments and act upon them. Intended for implementation of non-standard functionality outside the scope of gcode and $-commands. + +Drivers: + +* ESP32: fix for spindle PWM not turning off on stop or soft reset. + +--- + Build 20230429 Core: diff --git a/config.h b/config.h index 0cc796a..1e3fef3 100644 --- a/config.h +++ b/config.h @@ -1833,28 +1833,28 @@ __NOTE:__ Must be a positive values. */ ///@{ #if !defined DEFAULT_X_CURRENT || defined __DOXYGEN__ -#define DEFAULT_X_CURRENT 0.0 // amps +#define DEFAULT_X_CURRENT 0.0 // mA #endif #if !defined DEFAULT_Y_CURRENT || defined __DOXYGEN__ -#define DEFAULT_Y_CURRENT 0.0 // amps +#define DEFAULT_Y_CURRENT 0.0 // mA #endif #if !defined DEFAULT_Z_CURRENT || defined __DOXYGEN__ -#define DEFAULT_Z_CURRENT 0.0 // amps +#define DEFAULT_Z_CURRENT 0.0 // mA #endif #if (defined A_AXIS && !defined DEFAULT_A_CURRENT) || defined __DOXYGEN__ -#define DEFAULT_A_CURRENT 0.0 // amps +#define DEFAULT_A_CURRENT 0.0 // mA #endif #if (defined B_AXIS && !defined DEFAULT_B_CURRENT) || defined __DOXYGEN__ -#define DEFAULT_B_CURRENT 0.0 // amps +#define DEFAULT_B_CURRENT 0.0 // mA #endif #if (defined C_AXIS && !defined DEFAULT_C_CURRENT) || defined __DOXYGEN__ -#define DEFAULT_C_CURRENT 0.0 // amps +#define DEFAULT_C_CURRENT 0.0 // mA #endif #if (defined U_AXIS && !defined DEFAULT_U_CURRENT) || defined __DOXYGEN__ -#define DEFAULT_U_CURRENT 0.0 // amps +#define DEFAULT_U_CURRENT 0.0 // mA #endif #if (defined V_AXIS && !defined DEFAULT_V_CURRENT) || defined __DOXYGEN__ -#define DEFAULT_V_CURRENT 0.0 // amps +#define DEFAULT_V_CURRENT 0.0 // mA #endif ///@} diff --git a/core_handlers.h b/core_handlers.h index 8a91895..2fecf54 100644 --- a/core_handlers.h +++ b/core_handlers.h @@ -146,6 +146,7 @@ typedef struct { on_probe_start_ptr on_probe_start; on_probe_completed_ptr on_probe_completed; on_gcode_message_ptr on_gcode_message; //!< Called on output of message parsed from gcode. NOTE: string pointed to is freed after this call. + on_gcode_message_ptr on_gcode_comment; //!< Called when a plain gcode comment has been parsed. on_tool_selected_ptr on_tool_selected; //!< Called prior to executing M6 or after executing M61. on_toolchange_ack_ptr on_toolchange_ack; //!< Called from interrupt context. on_jog_cancel_ptr on_jog_cancel; //!< Called from interrupt context. diff --git a/gcode.c b/gcode.c index df6851f..1942eab 100644 --- a/gcode.c +++ b/gcode.c @@ -409,11 +409,12 @@ static status_code_t init_sync_motion (plan_line_data_t *pl_data, float pitch) // Output and free previously allocated message static void output_message (char *message) { - report_message(message, Message_Plain); - if(grbl.on_gcode_message) grbl.on_gcode_message(message); + if(*message) + report_message(message, Message_Plain); + free(message); } @@ -457,18 +458,22 @@ char *gc_normalize_block (char *block, char **message) break; case ')': - if(comment && !hal.driver_cap.no_gcode_message_handling) { - size_t len = s1 - comment - 4; - if(message && *message == NULL && !strncmp(comment, "(MSG,", 5) && (*message = malloc(len))) { - *s1 = '\0'; - comment += 5; - // trim leading spaces - while(*comment == ' ') { - comment++; - len--; + if(comment) { + *s1 = '\0'; + if(!hal.driver_cap.no_gcode_message_handling) { + size_t len = s1 - comment - 4; + if(message && *message == NULL && !strncmp(comment, "(MSG,", 5) && (*message = malloc(len))) { + comment += 5; + // trim leading spaces + while(*comment == ' ') { + comment++; + len--; + } + memcpy(*message, comment, len); } - memcpy(*message, comment, len); } + if(*comment && *message == NULL && grbl.on_gcode_comment) + grbl.on_gcode_comment(comment); } comment = NULL; break; diff --git a/grbl.h b/grbl.h index efb6fef..c021125 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20230429 +#define GRBL_BUILD 20230501 #define GRBL_URL "https://github.com/grblHAL" diff --git a/motion_control.c b/motion_control.c index 3837bf6..380a9ff 100644 --- a/motion_control.c +++ b/motion_control.c @@ -234,7 +234,7 @@ void mc_arc (float *target, plan_line_data_t *pl_data, float *position, float *o do { idx--; if(!(idx == plane.axis_0 || idx == plane.axis_1)) - linear_per_turn[idx] = (target[idx] - position[idx]) / arc_travel * 2.0f * M_PI;; + linear_per_turn[idx] = (target[idx] - position[idx]) / arc_travel * 2.0f * M_PI; } while(idx); #else float linear_per_turn = (target[plane.axis_linear] - position[plane.axis_linear]) / arc_travel * 2.0f * M_PI; diff --git a/ngc_expr.c b/ngc_expr.c index 8150a32..aa2879f 100644 --- a/ngc_expr.c +++ b/ngc_expr.c @@ -451,7 +451,7 @@ static status_code_t read_operation (char *line, uint_fast8_t *pos, ngc_binary_o (*pos)++; } else - status = Status_ExpressionUknownOp;; // Unknown operation name starting with L + status = Status_ExpressionUknownOp; // Unknown operation name starting with L break; // case '\0': diff --git a/settings.c b/settings.c index 4035817..40e9666 100644 --- a/settings.c +++ b/settings.c @@ -54,6 +54,13 @@ PROGMEM const settings_t defaults = { .version = SETTINGS_VERSION, +#if DEFAULT_LASER_MODE + .mode = Mode_Laser, +#elif DEFAULT_LATHE_MODE + .mode = Mode_Lathe, +#else + .mode = Mode_Standard, +#endif .junction_deviation = DEFAULT_JUNCTION_DEVIATION, .arc_tolerance = DEFAULT_ARC_TOLERANCE, .g73_retract = DEFAULT_G73_RETRACT, @@ -69,15 +76,7 @@ PROGMEM const settings_t defaults = { #else .flags.g92_is_volatile = 0, #endif -#if DEFAULT_LASER_MODE - .mode = Mode_Laser, - .flags.disable_laser_during_hold = DDEFAULT_DISABLE_LASER_DURING_HOLD -#else - .flags.disable_laser_during_hold = 0, - #if DEFAULT_LATHE_MODE - .mode = Mode_Lathe, - #endif -#endif + .flags.disable_laser_during_hold = DEFAULT_DISABLE_LASER_DURING_HOLD, .flags.restore_after_feed_hold = DEFAULT_RESTORE_AFTER_FEED_HOLD, .flags.force_initialization_alarm = DEFAULT_FORCE_INITIALIZATION_ALARM, .flags.restore_overrides = DEFAULT_RESET_OVERRIDES, diff --git a/sleep.c b/sleep.c index aa7ddd7..0de9b6d 100644 --- a/sleep.c +++ b/sleep.c @@ -23,7 +23,7 @@ #include "hal.h" #include "state_machine.h" -volatile bool slumber; +static volatile bool slumber; static void fall_asleep() { diff --git a/state_machine.c b/state_machine.c index 2cd41a5..3ea8b02 100644 --- a/state_machine.c +++ b/state_machine.c @@ -366,7 +366,7 @@ void state_suspend_manager (void) } else if (sys.step_control.update_spindle_rpm && restore_condition.spindle[0].hal->get_state().on) { // Handles spindle state during hold. NOTE: Spindle speed overrides may be altered during hold state. - state_spindle_set_state(&restore_condition.spindle[restore_condition.spindle_num]);; + state_spindle_set_state(&restore_condition.spindle[restore_condition.spindle_num]); sys.step_control.update_spindle_rpm = Off; } } diff --git a/stepper.c b/stepper.c index a3eff5b..1212190 100644 --- a/stepper.c +++ b/stepper.c @@ -183,11 +183,12 @@ static void output_message (sys_state_t state) { if(message) { - report_message(message, Message_Plain); - if(grbl.on_gcode_message) grbl.on_gcode_message(message); + if(*message) + report_message(message, Message_Plain); + free(message); message = NULL; } diff --git a/stream.c b/stream.c index c7caaf0..f9e517b 100644 --- a/stream.c +++ b/stream.c @@ -463,7 +463,7 @@ bool stream_mpg_enable (bool on) hal.stream.reset_read_buffer(); sys.mpg_mode = on; - system_add_rt_report(Report_MPGMode);; + system_add_rt_report(Report_MPGMode); // Force a realtime status report, all reports when MPG mode active protocol_enqueue_realtime_command(on ? CMD_STATUS_REPORT_ALL : CMD_STATUS_REPORT);