diff --git a/libraries/AP_Scripting/AP_Scripting_helpers.cpp b/libraries/AP_Scripting/AP_Scripting_helpers.cpp index b22be853b8..5727285a8c 100644 --- a/libraries/AP_Scripting/AP_Scripting_helpers.cpp +++ b/libraries/AP_Scripting/AP_Scripting_helpers.cpp @@ -38,7 +38,7 @@ bool Parameter::set(float value) return false; } -// get a value by name +// get value bool Parameter::get(float &value) { if (vp == nullptr) { @@ -67,7 +67,7 @@ bool Parameter::get(float &value) return true; } -// set and save a value by name +// set and save value bool Parameter::set_and_save(float value) { if (vp == nullptr) { @@ -93,3 +93,37 @@ bool Parameter::set_and_save(float value) return false; } +// Check if param had been configured +bool Parameter::configured() +{ + if (vp == nullptr) { + return false; + } + return vp->configured(); +} + +// set default value +bool Parameter::set_default(float value) +{ + 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; +} diff --git a/libraries/AP_Scripting/AP_Scripting_helpers.h b/libraries/AP_Scripting/AP_Scripting_helpers.h index 2a74199b73..89427d6b36 100644 --- a/libraries/AP_Scripting/AP_Scripting_helpers.h +++ b/libraries/AP_Scripting/AP_Scripting_helpers.h @@ -14,6 +14,8 @@ public: bool set(float value); bool set_and_save(float value); bool get(float &value); + bool configured(); + bool set_default(float value); private: enum ap_var_type vtype;