Skip to content

Commit

Permalink
Fix for all $RST command variants resetting driver settings to defaul…
Browse files Browse the repository at this point in the history
…t when only $RST=* and $RST=& should. Ref. issue #659.

Changed behaviour of $RST=# to not reset coordinate systems locked by setting $486.
  • Loading branch information
terjeio committed Jan 10, 2025
1 parent 6cbbc63 commit c681661
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 22 deletions.
23 changes: 12 additions & 11 deletions canbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
## grblHAL changelog

<a name="20250111">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.

---

<a name="20250110">Build 20250110

Core:
Expand Down
2 changes: 1 addition & 1 deletion grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions ioports.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions kinematics/delta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 14 additions & 10 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand All @@ -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);
}
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions spindle_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c681661

Please sign in to comment.