diff --git a/libraries/AP_Param/AP_Param.cpp b/libraries/AP_Param/AP_Param.cpp index ad6f7dfab6..01e809b4be 100644 --- a/libraries/AP_Param/AP_Param.cpp +++ b/libraries/AP_Param/AP_Param.cpp @@ -1074,7 +1074,7 @@ void AP_Param::save_sync(bool force_save) if (phdr.type == AP_PARAM_INT8 && ginfo != nullptr && (ginfo->flags & AP_PARAM_FLAG_ENABLE)) { // clear cached parameter count - _parameter_count = 0; + invalidate_count(); } char name[AP_MAX_NAME_SIZE+1]; @@ -1476,7 +1476,7 @@ void AP_Param::load_object_from_eeprom(const void *object_pointer, const struct uint16_t key; // reset cached param counter as we may be loading a dynamic var_info - _parameter_count = 0; + invalidate_count(); if (!find_key_by_pointer(object_pointer, key)) { hal.console->printf("ERROR: Unable to find param pointer\n"); @@ -2340,6 +2340,14 @@ uint16_t AP_Param::count_parameters(void) return ret; } +/* + invalidate parameter count cache + */ +void AP_Param::invalidate_count(void) +{ + _parameter_count = 0; +} + /* set a default value by name */ diff --git a/libraries/AP_Param/AP_Param.h b/libraries/AP_Param/AP_Param.h index 3724868153..f4822a8488 100644 --- a/libraries/AP_Param/AP_Param.h +++ b/libraries/AP_Param/AP_Param.h @@ -478,6 +478,9 @@ public: // count of parameters in tree static uint16_t count_parameters(void); + // invalidate parameter count + static void invalidate_count(void); + static void set_hide_disabled_groups(bool value) { _hide_disabled_groups = value; } // set frame type flags. Used to unhide frame specific parameters @@ -735,6 +738,14 @@ public: _value = v; } + // set a parameter that is an ENABLE param + void set_enable(const T &v) { + if (v != _value) { + invalidate_count(); + } + _value = v; + } + /// Sets if the parameter is unconfigured /// void set_default(const T &v) {