AP_Param: added set_default_by_name()

This commit is contained in:
Andrew Tridgell 2016-04-01 16:39:51 +11:00
parent dd6c4d6225
commit 86416e8f05
2 changed files with 36 additions and 0 deletions

View File

@ -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;
}

View File

@ -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.
///
///