From bdcffe29665d643a83bb697fdf8a1e1ee7394631 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 8 Nov 2022 13:09:15 +1100 Subject: [PATCH] AP_Param: allow for removing parameters from lua scripts when a parameter is removed it leaves a gap in the index numbers. We need to cope with that gap when we add the parameters in the script to allow params to be re-ordered or removed --- libraries/AP_Param/AP_Param.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/AP_Param/AP_Param.cpp b/libraries/AP_Param/AP_Param.cpp index d2fd2e3b71..2af43cce63 100644 --- a/libraries/AP_Param/AP_Param.cpp +++ b/libraries/AP_Param/AP_Param.cpp @@ -3021,6 +3021,18 @@ bool AP_Param::add_param(uint8_t _key, uint8_t param_num, const char *pname, flo return false; } + // fill in idx of any gaps, leaving them hidden, this allows + // scripts to remove parameters + for (uint8_t j=1; j(info.group_info)[j]; + if (g.idx == 0xff) { + g.idx = j; + g.flags = AP_PARAM_FLAG_HIDDEN; + g.offset = j*sizeof(float); + g.type = AP_PARAM_FLOAT; + } + } + auto &ginfo = const_cast(info.group_info)[param_num]; if (ginfo.name == _empty_string) {