diff --git a/libraries/AP_Common/AP_Var.cpp b/libraries/AP_Common/AP_Var.cpp index aab6b949ec..c45155998e 100644 --- a/libraries/AP_Common/AP_Var.cpp +++ b/libraries/AP_Common/AP_Var.cpp @@ -159,6 +159,22 @@ AP_Var::find(const char *name) return NULL; } +// Find a variable by key. +// +AP_Var * +AP_Var::find(Key key) +{ + AP_Var *vp; + + for (vp = first(); vp; vp = vp->next()) { + + if (key == vp->key()) { + return vp; + } + } + return NULL; +} + // Save the variable to EEPROM, if supported // diff --git a/libraries/AP_Common/AP_Var.h b/libraries/AP_Common/AP_Var.h index 7b545208e3..cdf2688533 100644 --- a/libraries/AP_Common/AP_Var.h +++ b/libraries/AP_Common/AP_Var.h @@ -214,6 +214,14 @@ public: /// static AP_Var *find(const char *name); + /// Find a variable by key. + /// + /// @param key The key being looked up. + /// @return A pointer to the variable, or NULL if + /// it does not exist. + /// + static AP_Var *find(Key key); + /// Save the current value of the variable to EEPROM. /// /// This interface works for any subclass that implements