From 3474da6c97972019c2b4b5c49e655e6ef3b4a6da Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 21 Jul 2014 09:37:41 +1000 Subject: [PATCH] AP_Param: added a method for example programs to set parameters in objects --- libraries/AP_Param/AP_Param.cpp | 18 ++++++++++++++++++ libraries/AP_Param/AP_Param.h | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/libraries/AP_Param/AP_Param.cpp b/libraries/AP_Param/AP_Param.cpp index 9791632fa5..fa7b2eebe3 100644 --- a/libraries/AP_Param/AP_Param.cpp +++ b/libraries/AP_Param/AP_Param.cpp @@ -819,6 +819,24 @@ void AP_Param::setup_object_defaults(const void *object_pointer, const struct Gr } } +// set a value directly in an object. This should only be used by +// example code, not by mainline vehicle code +void AP_Param::set_object_value(const void *object_pointer, + const struct GroupInfo *group_info, + const char *name, float value) +{ + uintptr_t base = (uintptr_t)object_pointer; + uint8_t type; + for (uint8_t i=0; + (type=PGM_UINT8(&group_info[i].type)) != AP_PARAM_NONE; + i++) { + if (strcmp(name, group_info[i].name) == 0 && type <= AP_PARAM_FLOAT) { + void *ptr = (void *)(base + PGM_UINT16(&group_info[i].offset)); + set_value((enum ap_var_type)type, ptr, value); + } + } +} + // load default values for all scalars in a sketch. This does not // recurse into sub-objects diff --git a/libraries/AP_Param/AP_Param.h b/libraries/AP_Param/AP_Param.h index c836843ca3..4c5eadc5a5 100644 --- a/libraries/AP_Param/AP_Param.h +++ b/libraries/AP_Param/AP_Param.h @@ -199,6 +199,12 @@ public: // load default values for scalars in a group static void setup_object_defaults(const void *object_pointer, const struct GroupInfo *group_info); + // set a value directly in an object. This should only be used by + // example code, not by mainline vehicle code + static void set_object_value(const void *object_pointer, + const struct GroupInfo *group_info, + const char *name, float value); + // load default values for all scalars in the main sketch. This // does not recurse into the sub-objects static void setup_sketch_defaults(void);