AP_Param: add set_defaults_from_table

This commit is contained in:
Randy Mackay 2018-11-29 09:54:15 +09:00
parent 997d07b694
commit 98cd300885
2 changed files with 29 additions and 1 deletions

View File

@ -2197,6 +2197,22 @@ bool AP_Param::set_default_by_name(const char *name, float value)
return false; return false;
} }
/*
set parameter defaults from a defaults_struct table
sends GCS message and panics (in SITL only) if parameter is not found
*/
void AP_Param::set_defaults_from_table(const struct defaults_table_struct *table, uint8_t count)
{
for (uint8_t i=0; i<count; i++) {
if (!AP_Param::set_default_by_name(table[i].name, table[i].value)) {
gcs().send_text(MAV_SEVERITY_INFO, "set param default failure for %s", table[i].name);
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
AP_HAL::panic("set param default failure for %s", table[i].name);
#endif
}
}
}
/* /*
set a value by name set a value by name
*/ */

View File

@ -174,6 +174,12 @@ public:
const char *new_name; const char *new_name;
}; };
// param default table element
struct defaults_table_struct {
const char *name; // parameter name
float value; // parameter value
};
// called once at startup to setup the _var_info[] table. This // called once at startup to setup the _var_info[] table. This
// will also check the EEPROM header and re-initialise it if the // will also check the EEPROM header and re-initialise it if the
// wrong version is found // wrong version is found
@ -257,6 +263,12 @@ public:
/// @return true if the variable is found /// @return true if the variable is found
static bool set_default_by_name(const char *name, float value); static bool set_default_by_name(const char *name, float value);
/// set parameter defaults from a defaults_table_struct
///
/// @param table pointer to array of defaults_table_struct structures
/// @param count number of elements in table array
static void set_defaults_from_table(const struct defaults_table_struct *table, uint8_t count);
/// set a value by name /// set a value by name
/// ///
/// @param name The full name of the variable to be found. /// @param name The full name of the variable to be found.