From e35af1abc17fd2508048c8e21d793b1e735cae28 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Thu, 26 Jun 2025 07:25:58 +0200 Subject: [PATCH] Added setting flag to $675 (Macro ATC options) for enabling error on M6 if tc.macro is not found in the filing system. Changed $I NEWOPT "ATC" element to ATC=1 when ATC is online and ATC=0 when offline. For macro based ATC code this is set to ATC=0 if tc.macro is not found and the new $675 flag is set. --- README.md | 2 +- changelog.md | 18 +++++++++++++++++- gcode.c | 13 ++++++++----- grbl.h | 2 +- grbllib.c | 9 +++++++++ hal.h | 17 ++++++++++++++--- report.c | 5 +++-- settings.h | 3 ++- tool_change.c | 2 +- 9 files changed, 56 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c3177ec..2f5ebd9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## grblHAL ## -Latest build date is 20250625, see the [changelog](changelog.md) for details. +Latest build date is 20250626, see the [changelog](changelog.md) for details. > [!NOTE] > A settings reset will be performed on an update of builds prior to 20241208. Backup and restore of settings is recommended. diff --git a/changelog.md b/changelog.md index dd9dade..69d3da4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,26 @@ ## grblHAL changelog +Build 20250626 + +Core: + +* Added flag to `$675` \(Macro ATC options\) for enabling error on `M6` if _tc.macro_ is not found in the filing system. + +* Changed `$I` `NEWOPT` "ATC" element to `ATC=1` when ATC is online and `ATC=0` when offline. +For macro based ATC code this is set to `ATC=0` if _tc.macro_ is not found and the new `$675` flag is set. + +Plugins: + +* Spindle, all VFDs: added exception trigger level for async Modbus messages \(status requests\), defaults to 10. +This means that ten consecutive messages has to fail before alarm 14 is raised. Ref. issue [#762](https://github.com/grblHAL/core/issues/762#issuecomment-3006372138) + +--- + Build 20250625 Core: -* Added option flag to $22 \(Homing cycle\) to run startup scripts only on homing completed. +* Added option flag to `$22` \(Homing cycle\) to run startup scripts only on homing completed. * Added API call `modbus_isbusy()` for checking if Modbus transaction is ongoing. diff --git a/gcode.c b/gcode.c index d7c87a7..d0e5462 100644 --- a/gcode.c +++ b/gcode.c @@ -1343,11 +1343,14 @@ status_code_t gc_execute_block (char *block) break; case 6: - if(hal.driver_cap.atc || settings.tool_change.mode != ToolChange_Ignore) { - if(hal.stream.suspend_read || hal.tool.change) - word_bit.modal_group.M6 = On; - else - FAIL(Status_GcodeUnsupportedCommand); // [Unsupported M command] + { + atc_status_t atc = hal.tool.atc_get_state(); + if(atc != ATC_None || settings.tool_change.mode != ToolChange_Ignore) { + if(atc == ATC_None ? !!hal.stream.suspend_read : (atc == ATC_Online && hal.tool.change)) + word_bit.modal_group.M6 = On; + else + FAIL(Status_GcodeUnsupportedCommand); // [Unsupported M command] + } } break; diff --git a/grbl.h b/grbl.h index efebb34..1c5490a 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20250625 +#define GRBL_BUILD 20250626 #define GRBL_URL "https://github.com/grblHAL" diff --git a/grbllib.c b/grbllib.c index c298878..9d7d30b 100644 --- a/grbllib.c +++ b/grbllib.c @@ -216,6 +216,11 @@ static void settings_changed (settings_t *settings, settings_changed_flags_t cha grbl.on_settings_changed(settings, changed); } +static atc_status_t atc_get_state (void) +{ + return hal.driver_cap.atc ? ATC_Online : ATC_None; +} + // main entry point int grbl_enter (void) @@ -257,6 +262,7 @@ int grbl_enter (void) hal.control.interrupt_callback = control_interrupt_handler; hal.stepper.interrupt_callback = stepper_driver_interrupt_handler; hal.stream_blocking_callback = stream_tx_blocking; + hal.tool.atc_get_state = atc_get_state; hal.signals_pullup_disable_cap.value = (uint16_t)-1; sys.cold_start = true; @@ -361,6 +367,9 @@ int grbl_enter (void) } else driver.spindle = spindle_select(spindle_add_null()); + if(!hal.driver_cap.sd_card) + settings.macro_atc_flags.error_on_no_macro = Off; + if(driver.ok != 0xFF) { sys.alarm = Alarm_SelftestFailed; task_run_on_startup(report_driver_error, NULL); diff --git a/hal.h b/hal.h index d3336d8..9714330 100644 --- a/hal.h +++ b/hal.h @@ -405,6 +405,12 @@ typedef struct { * Tool selection and change * *******************************/ +typedef enum { + ATC_None = 0, + ATC_Offline, + ATC_Online +} atc_status_t; + /*! \brief Pointer to function for selecting a tool. \param tool pointer to tool_data_t struct. \param next \a true if tool is selected for next the next tool change (M6), \a false to as set current tool. @@ -416,6 +422,11 @@ typedef void (*tool_select_ptr)(tool_data_t *tool, bool next); */ typedef status_code_t (*tool_change_ptr)(parser_state_t *gc_state); +/*! \brief Pointer to function for checking ATC status. +\returns \a true if online. +*/ +typedef atc_status_t (*atc_get_state_ptr)(void); + /*! \brief Handlers for tool changes. If the driver (or a plugin) does not set these handlers the core will set them to its own @@ -423,11 +434,11 @@ handlers for manual or semi-automatic tool change if the current input stream su the tool change protocol. */ typedef struct { - tool_select_ptr select; //!< Optional handler for selecting a tool. - tool_change_ptr change; //!< Optional handler for executing a tool change (M6). + tool_select_ptr select; //!< Optional handler for selecting a tool. + tool_change_ptr change; //!< Optional handler for executing a tool change (M6). + atc_get_state_ptr atc_get_state; //!< Optional handler for checking ATC status. } tool_ptrs_t; - /******************* * Encoder input * *******************/ diff --git a/report.c b/report.c index 1418129..c9a19c5 100644 --- a/report.c +++ b/report.c @@ -941,6 +941,7 @@ void report_build_info (char *line, bool extended) uint_fast8_t idx; nvs_io_t *nvs = nvs_buffer_get_physical(); + atc_status_t atc = hal.tool.atc_get_state(); strcat(strcpy(buf, "[AXS:"), uitoa(N_AXIS)); @@ -1001,8 +1002,8 @@ void report_build_info (char *line, bool extended) strcat(buf, "EXPR,"); #endif - if(hal.tool.change) - strcat(buf, hal.driver_cap.atc ? "ATC," : "TC,"); // Tool change supported (M6) + if(atc != ATC_None || (settings.tool_change.mode != ToolChange_Ignore && !!hal.stream.suspend_read)) + strcat(buf, atc == ATC_None ? "TC," : (atc == ATC_Online ? "ATC=1," : "ATC=0,")); // Tool change supported (M6) if(hal.driver_cap.spindle_sync) strcat(buf, "SS,"); diff --git a/settings.h b/settings.h index e008b2e..ef4f8ca 100644 --- a/settings.h +++ b/settings.h @@ -845,8 +845,9 @@ typedef union { uint8_t value; struct { uint8_t execute_m6t0 :1, + error_on_no_macro :1, random_toolchanger :1, - unassigned :6; + unassigned :5; }; } macro_atc_flags_t; diff --git a/tool_change.c b/tool_change.c index d61803d..18c90ea 100644 --- a/tool_change.c +++ b/tool_change.c @@ -559,7 +559,7 @@ void tc_init (void) { static bool on_homing_subscribed = false; - if(hal.driver_cap.atc) // Do not override driver tool change implementation! + if(hal.tool.atc_get_state() != ATC_None) // Do not override tool change implementation! return; if(!hal.stream.suspend_read) // Tool change requires support for suspending input stream.