mirror of https://github.com/ArduPilot/ardupilot
AP_Param: add set_defaults_from_table
This commit is contained in:
parent
997d07b694
commit
98cd300885
|
@ -2197,6 +2197,22 @@ bool AP_Param::set_default_by_name(const char *name, float value)
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -174,6 +174,12 @@ public:
|
|||
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
|
||||
// will also check the EEPROM header and re-initialise it if the
|
||||
// wrong version is found
|
||||
|
@ -256,7 +262,13 @@ public:
|
|||
/// @param value The default value
|
||||
/// @return true if the variable is found
|
||||
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
|
||||
///
|
||||
/// @param name The full name of the variable to be found.
|
||||
|
|
Loading…
Reference in New Issue