From c681661516f3a803af88183e14fb0330918286dd Mon Sep 17 00:00:00 2001 From: Terje Io Date: Fri, 10 Jan 2025 21:10:47 +0100 Subject: [PATCH] Fix for all $RST command variants resetting driver settings to default when only $RST=* and $RST=& should. Ref. issue #659. Changed behaviour of $RST=# to not reset coordinate systems locked by setting $486. --- canbus.c | 23 ++++++++++++----------- changelog.md | 18 ++++++++++++++++++ grbl.h | 2 +- ioports.c | 1 + kinematics/delta.c | 1 + settings.c | 24 ++++++++++++++---------- settings.h | 1 + spindle_control.c | 1 + 8 files changed, 49 insertions(+), 22 deletions(-) diff --git a/canbus.c b/canbus.c index 29bf792..b693608 100644 --- a/canbus.c +++ b/canbus.c @@ -5,7 +5,7 @@ Part of grblHAL Copyright (c) 2022 Jon Escombe - Copyright (c) 2024 Terje Io + Copyright (c) 2024-2025 Terje Io grblHAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -160,16 +160,6 @@ static void canbus_settings_load (void) canbus_start(baud[canbus_get_baud(Setting_CANbus_BaudRate)]); } -static setting_details_t setting_details = { - .groups = canbus_groups, - .n_groups = sizeof(canbus_groups) / sizeof(setting_group_detail_t), - .settings = canbus_setting_detail, - .n_settings = sizeof(canbus_setting_detail) / sizeof(setting_detail_t), - .save = settings_write_global, - .load = canbus_settings_load, - .restore = canbus_settings_restore -}; - // Public API bool canbus_enabled (void) @@ -198,6 +188,17 @@ bool canbus_add_filter (uint32_t id, uint32_t mask, bool ext_id, can_rx_ptr call void canbus_init (void) { + static setting_details_t setting_details = { + .is_core = true, + .groups = canbus_groups, + .n_groups = sizeof(canbus_groups) / sizeof(setting_group_detail_t), + .settings = canbus_setting_detail, + .n_settings = sizeof(canbus_setting_detail) / sizeof(setting_detail_t), + .save = settings_write_global, + .load = canbus_settings_load, + .restore = canbus_settings_restore + }; + static bool init_ok = false; if(!init_ok) { diff --git a/changelog.md b/changelog.md index 400af13..bc41123 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,23 @@ ## grblHAL changelog +Build 20250111 + +Core: + +* Fix for all `$RST` command variants resetting driver settings to default when only `$RST=*` and `$RST=&` should. Ref. issue [#659](https://github.com/grblHAL/core/issues/659). + +* Changed behaviour of `$RST=#` \(reset parameters such as coordinate systems and tool table\) to not reset coordinate systems locked by setting `$486`. + +Drivers: + +* STM32F7xx: fixed typos and removed leftover code in UNO board map. Ref. issue [#21](https://github.com/grblHAL/STM32F7xx/issues/21). + +Plugins: + +* Misc, eventout: fix for not initializing setting defaults when plugin first enabled. + +--- + Build 20250110 Core: diff --git a/grbl.h b/grbl.h index 3b78118..37db197 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20250110 +#define GRBL_BUILD 20250111 #define GRBL_URL "https://github.com/grblHAL" diff --git a/ioports.c b/ioports.c index 8db8e26..7b9da42 100644 --- a/ioports.c +++ b/ioports.c @@ -836,6 +836,7 @@ void ioport_setting_changed (setting_id_t id) void ioports_add_settings (driver_settings_load_ptr settings_loaded, setting_changed_ptr setting_changed) { static setting_details_t setting_details = { + .is_core = true, .groups = ioport_groups, .n_groups = sizeof(ioport_groups) / sizeof(setting_group_detail_t), .settings = ioport_settings, diff --git a/kinematics/delta.c b/kinematics/delta.c index 7bbbad1..a59ebbb 100644 --- a/kinematics/delta.c +++ b/kinematics/delta.c @@ -883,6 +883,7 @@ static const char *delta_setting_get_description (setting_id_t id) void delta_robot_init (void) { static setting_details_t setting_details = { + .is_core = true, .groups = kinematics_groups, .n_groups = sizeof(kinematics_groups) / sizeof(setting_group_detail_t), .settings = kinematics_settings, diff --git a/settings.c b/settings.c index 325a20d..bbebcfc 100644 --- a/settings.c +++ b/settings.c @@ -2278,6 +2278,7 @@ PROGMEM static const setting_descr_t setting_descr[] = { #endif static setting_details_t setting_details = { + .is_core = true, .groups = setting_group_detail, .n_groups = sizeof(setting_group_detail) / sizeof(setting_group_detail_t), .settings = setting_detail, @@ -2520,12 +2521,13 @@ void settings_restore (settings_restore_t restore) settings_write_global(); } - if (restore.parameters) { + if(restore.parameters) { float coord_data[N_AXIS]; - memset(coord_data, 0, sizeof(coord_data)); - for (idx = 0; idx <= N_WorkCoordinateSystems; idx++) - settings_write_coord_data((coord_system_id_t)idx, &coord_data); + for(idx = 0; idx <= N_WorkCoordinateSystems; idx++) { + if(idx < CoordinateSystem_G59_1 || idx > CoordinateSystem_G59_3 || bit_isfalse(settings.offset_lock.mask, bit(idx - CoordinateSystem_G59_1))) + settings_write_coord_data((coord_system_id_t)idx, &coord_data); + } settings_write_coord_data(CoordinateSystem_G92, &coord_data); // Clear G92 offsets @@ -2534,12 +2536,12 @@ void settings_restore (settings_restore_t restore) #endif } - if (restore.startup_lines) { + if(restore.startup_lines) { for (idx = 0; idx < N_STARTUP_LINE; idx++) settings_write_startup_line(idx, empty_line); } - if (restore.build_info) { + if(restore.build_info) { settings_write_build_info(empty_line); settings_write_build_info(BUILD_INFO); } @@ -2550,10 +2552,12 @@ void settings_restore (settings_restore_t restore) setting_details_t *details = setting_details.next; if(details) do { - if(details->restore) - details->restore(); - if(details->on_changed) - details->on_changed(&settings, restore.defaults ? (settings_changed_flags_t){-1} : (settings_changed_flags_t){0}); + if(details->is_core ? restore.defaults : restore.driver_parameters) { + if(details->restore) + details->restore(); + if(details->on_changed) + details->on_changed(&settings, details->is_core ? (settings_changed_flags_t){-1} : (settings_changed_flags_t){0}); + } } while((details = details->next)); nvs_buffer_sync_physical(); diff --git a/settings.h b/settings.h index 409bdb8..83f5cf9 100644 --- a/settings.h +++ b/settings.h @@ -1024,6 +1024,7 @@ typedef void (*driver_settings_restore_ptr)(void); typedef bool (*driver_settings_iterator_ptr)(const setting_detail_t *setting, setting_output_ptr callback, void *data); typedef struct setting_details { + const bool is_core; const uint8_t n_groups; const setting_group_detail_t *groups; const uint16_t n_settings; diff --git a/spindle_control.c b/spindle_control.c index d734ea0..61fc299 100644 --- a/spindle_control.c +++ b/spindle_control.c @@ -1121,6 +1121,7 @@ spindle1_pwm_settings_t *spindle1_settings_add (bool claim_ports) void spindle1_settings_register (spindle_cap_t cap, spindle1_settings_changed_ptr on_changed) { static setting_details_t spindle1_setting_details = { + .is_core = true, .settings = spindle1_settings, .n_settings = sizeof(spindle1_settings) / sizeof(setting_detail_t), #ifndef NO_SETTINGS_DESCRIPTIONS