From acaea365cd7ed75c5d38a71eccf27bb8b80c312c Mon Sep 17 00:00:00 2001 From: Terje Io Date: Sun, 17 Sep 2023 09:51:58 +0200 Subject: [PATCH] Added setting $486 that allows locking G59.1 - G59.3 coordinate system offsets against accidental changes. --- changelog.md | 18 +++++++++++++++++- errors.c | 3 +++ errors.h | 1 + gcode.c | 7 +++++++ grbl.h | 2 +- settings.c | 18 ++++++++++++++++++ settings.h | 17 ++++++++--------- 7 files changed, 55 insertions(+), 11 deletions(-) diff --git a/changelog.md b/changelog.md index d8a581f..aa4fae0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,21 @@ ## grblHAL changelog +Build 20230917 + +Core: + +* Added setting `$486` that allows locking `G59.1` - `G59.3` coordinate system offsets against accidental changes. Use `$$=386` to list bitmask values. + +Drivers: + +* iMXRT1062: fix for plasma plugin [issue #2](https://github.com/grblHAL/Plugin_plasma/issues/2#issuecomment-1722313452): MCP3221 ADC driver code not allowing plugin code to claim the input. + +Plugins: + +* Plasma: made code more robust related to driver configuration changes. Still work in progress! + +--- + Build 20230913 Core: @@ -18,7 +34,7 @@ Drivers: * RP2040: workaround for [issue #74](https://github.com/grblHAL/RP2040/issues/74), odd TMC driver addressing. -* Remaining drivers updated for [improved handling of limit inputs](#20230903): +* Remaining drivers updated for [improved handling of limit inputs](#20230903). Build 20230907 diff --git a/errors.c b/errors.c index 4ea3223..e7ad3cb 100644 --- a/errors.c +++ b/errors.c @@ -83,6 +83,9 @@ PROGMEM static const status_detail_t status_detail[] = { { Status_SettingDisabled, "Setting is not available, possibly due to limited driver support." }, { Status_GcodeInvalidRetractPosition, "Retract position is less than drill depth." }, { Status_IllegalHomingConfiguration, "Attempt to home two auto squared axes at the same time." }, +#if COMPATIBILITY_LEVEL <= 1 + { Status_GCodeCoordSystemLocked, "Coordinate system is locked." }, +#endif #if NGC_EXPRESSIONS_ENABLE { Status_ExpressionUknownOp, "Unknown operation found in expression." }, { Status_ExpressionDivideByZero, "Divide by zero in expression attempted." }, diff --git a/errors.h b/errors.h index efe098b..f6afde9 100644 --- a/errors.h +++ b/errors.h @@ -85,6 +85,7 @@ typedef enum { Status_SettingDisabled = 53, Status_GcodeInvalidRetractPosition = 54, Status_IllegalHomingConfiguration = 55, + Status_GCodeCoordSystemLocked = 56, // Some error codes as defined in bdring's ESP32 port Status_SDMountError = 60, diff --git a/gcode.c b/gcode.c index 76a70f7..f9e6947 100644 --- a/gcode.c +++ b/gcode.c @@ -2111,6 +2111,13 @@ status_code_t gc_execute_block (char *block) if (!settings_read_coord_data(gc_block.values.coord_data.id, &gc_block.values.coord_data.xyz)) FAIL(Status_SettingReadFail); // [non-volatile storage read fail] +#if COMPATIBILITY_LEVEL <= 1 + if(settings.parking.flags.offset_lock && gc_block.values.coord_data.id >= CoordinateSystem_G59_1 && gc_block.values.coord_data.id <= CoordinateSystem_G59_3) { + if(bit_istrue(settings.parking.flags.offset_lock, bit(gc_block.values.coord_data.id - CoordinateSystem_G59_1))) + FAIL(Status_GCodeCoordSystemLocked); + } +#endif + // Pre-calculate the coordinate data changes. idx = N_AXIS; do { // Axes indices are consistent, so loop may be used. diff --git a/grbl.h b/grbl.h index 4fe71ef..0c282f0 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20230913 +#define GRBL_BUILD 20230917 #define GRBL_URL "https://github.com/grblHAL" diff --git a/settings.c b/settings.c index 762570a..c0cbf63 100644 --- a/settings.c +++ b/settings.c @@ -386,6 +386,7 @@ static status_code_t set_ganged_dir_invert (setting_id_t id, uint_fast16_t int_v static status_code_t set_stepper_deenergize_mask (setting_id_t id, uint_fast16_t int_value); static status_code_t set_report_interval (setting_id_t setting, uint_fast16_t int_value); static status_code_t set_estop_unlock (setting_id_t id, uint_fast16_t int_value); +static status_code_t set_offset_lock (setting_id_t id, uint_fast16_t int_value); #ifndef NO_SAFETY_DOOR_SUPPORT static status_code_t set_parking_enable (setting_id_t id, uint_fast16_t int_value); static status_code_t set_restore_overrides (setting_id_t id, uint_fast16_t int_value); @@ -598,6 +599,9 @@ PROGMEM static const setting_detail_t setting_detail[] = { #if NGC_EXPRESSIONS_ENABLE { Setting_NGCDebugOut, Group_General, "Output NGC debug messages", NULL, Format_Bool, NULL, NULL, NULL, Setting_IsExtendedFn, set_ngc_debug_out, get_int, NULL }, #endif +#if COMPATIBILITY_LEVEL <= 1 + { Setting_OffsetLock, Group_General, "Lock coordinate systems", NULL, Format_Bitfield, "G59.1,G59.2,G59.3", NULL, NULL, Setting_IsExtendedFn, set_offset_lock, get_int, NULL }, +#endif }; #ifndef NO_SETTINGS_DESCRIPTIONS @@ -764,6 +768,9 @@ PROGMEM static const setting_descr_t setting_descr[] = { { Setting_AutoReportInterval, "Interval the real time report will be sent, set to 0 to disable." }, { Setting_TimeZoneOffset, "Offset in hours from UTC." }, { Setting_UnlockAfterEStop, "If set unlock (by sending $X) is required after resetting a cleared E-Stop condition." }, +#if COMPATIBILITY_LEVEL <= 1 + { Setting_OffsetLock, "Lock coordinate systems against accidental changes." }, +#endif #if NGC_EXPRESSIONS_ENABLE { Setting_NGCDebugOut, "Example: (debug, metric mode: #<_metric>, coord system: #5220)" }, #endif @@ -1048,6 +1055,13 @@ static status_code_t set_estop_unlock (setting_id_t id, uint_fast16_t int_value) return Status_OK; } +static status_code_t set_offset_lock (setting_id_t id, uint_fast16_t int_value) +{ + settings.parking.flags.offset_lock = int_value & 0x07; + + return Status_OK; +} + static status_code_t set_hard_limits_enable (setting_id_t id, uint_fast16_t int_value) { settings.limits.flags.hard_enabled = bit_istrue(int_value, bit(0)); @@ -1625,6 +1639,10 @@ static uint32_t get_int (setting_id_t id) value = settings.flags.no_unlock_after_estop ? 0 : 1; break; + case Setting_OffsetLock: + value = settings.parking.flags.offset_lock; + break; + #if NGC_EXPRESSIONS_ENABLE case Setting_NGCDebugOut: value = settings.flags.ngc_debug_out; diff --git a/settings.h b/settings.h index 3a2b1d9..5f20a37 100644 --- a/settings.h +++ b/settings.h @@ -313,6 +313,7 @@ typedef enum { Setting_FanToSpindleLink = 483, Setting_UnlockAfterEStop = 484, Setting_EnableToolPersistence = 485, + Setting_OffsetLock = 486, Setting_Macro0 = 490, Setting_Macro1 = 491, @@ -523,7 +524,8 @@ typedef union { uint8_t enabled :1, deactivate_upon_init :1, enable_override_control :1, - unassigned :5; + unassigned :2, + offset_lock :3; }; } parking_setting_flags_t; @@ -658,14 +660,10 @@ typedef union { uint8_t value; uint8_t mask; struct { - uint8_t g55 :1, - g56 :1, - g57 :1, - g58 :1, - g59 :1, - g59_1 :1, - g59_2 :1, - g59_3 :1; + uint8_t g59_1 :1, + g59_2 :1, + g59_3 :1, + unused :5; }; } offset_lock_t; @@ -711,6 +709,7 @@ typedef struct { typedef struct { // Settings struct version uint32_t version; +// uint32_t build_date; // TODO: add in next settings version?, set to GRBL_BUILD float junction_deviation; float arc_tolerance; float g73_retract;