mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-28 19:48:31 -04:00
AP_Param: added set_default_by_name()
This commit is contained in:
parent
dd6c4d6225
commit
86416e8f05
@ -1834,3 +1834,32 @@ uint16_t AP_Param::count_parameters(void)
|
||||
return _parameter_count;
|
||||
}
|
||||
|
||||
/*
|
||||
set a default value by name
|
||||
*/
|
||||
bool AP_Param::set_default_by_name(const char *name, float value)
|
||||
{
|
||||
enum ap_var_type vtype;
|
||||
AP_Param *vp = find(name, &vtype);
|
||||
if (vp == nullptr) {
|
||||
return false;
|
||||
}
|
||||
switch (vtype) {
|
||||
case AP_PARAM_INT8:
|
||||
((AP_Int8 *)vp)->set_default(value);
|
||||
return true;
|
||||
case AP_PARAM_INT16:
|
||||
((AP_Int16 *)vp)->set_default(value);
|
||||
return true;
|
||||
case AP_PARAM_INT32:
|
||||
((AP_Int32 *)vp)->set_default(value);
|
||||
return true;
|
||||
case AP_PARAM_FLOAT:
|
||||
((AP_Float *)vp)->set_default(value);
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// not a supported type
|
||||
return false;
|
||||
}
|
||||
|
@ -203,6 +203,13 @@ public:
|
||||
///
|
||||
static AP_Param * find(const char *name, enum ap_var_type *ptype);
|
||||
|
||||
/// set a default value by name
|
||||
///
|
||||
/// @param name The full name of the variable to be found.
|
||||
/// @param value The default value
|
||||
/// @return true if the variable is found
|
||||
static bool set_default_by_name(const char *name, float value);
|
||||
|
||||
/// Find a variable by index.
|
||||
///
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user