From d55a0c3a71f14b5c78ba2f2517af0dca44f928b7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Feb 2012 10:16:55 +1100 Subject: [PATCH] added AP_Param::show_all() this moves the logic into common code --- ArduCopter/setup.pde | 28 +------------------------- ArduPlane/setup.pde | 29 +-------------------------- Tools/VARTest/VARTest.pde | 3 +++ libraries/AP_Common/AP_Param.cpp | 34 ++++++++++++++++++++++++++++++++ libraries/AP_Common/AP_Param.h | 3 +++ 5 files changed, 42 insertions(+), 55 deletions(-) diff --git a/ArduCopter/setup.pde b/ArduCopter/setup.pde index 37f2a9c3dd..4afbcc6f40 100644 --- a/ArduCopter/setup.pde +++ b/ArduCopter/setup.pde @@ -102,34 +102,8 @@ setup_show(uint8_t argc, const Menu::arg *argv) report_gyro(); #endif - uint16_t token; - AP_Param *ap; - enum ap_var_type type; + AP_Param::show_all(); - for (ap=AP_Param::first(&token, &type); - ap; - ap=AP_Param::next_scalar(&token, &type)) { - char s[AP_MAX_NAME_SIZE+1]; - ap->copy_name(s, sizeof(s)); - s[AP_MAX_NAME_SIZE] = 0; - - switch (type) { - case AP_PARAM_INT8: - Serial.printf_P("%s: %d\n", s, (int)((AP_Int8 *)ap)->get()); - break; - case AP_PARAM_INT16: - Serial.printf_P("%s: %d\n", s, (int)((AP_Int16 *)ap)->get()); - break; - case AP_PARAM_INT32: - Serial.printf_P("%s: %ld\n", s, (long)((AP_Int32 *)ap)->get()); - break; - case AP_PARAM_FLOAT: - Serial.printf_P("%s: %f\n", s, ((AP_Float *)ap)->get()); - break; - default: - break; - } - } return(0); } diff --git a/ArduPlane/setup.pde b/ArduPlane/setup.pde index 631eba9f19..6bd7099916 100644 --- a/ArduPlane/setup.pde +++ b/ArduPlane/setup.pde @@ -66,34 +66,7 @@ setup_show(uint8_t argc, const Menu::arg *argv) Serial.printf_P(PSTR("Raw Values\n")); print_divider(); - uint16_t token; - AP_Param *ap; - enum ap_var_type type; - - for (ap=AP_Param::first(&token, &type); - ap; - ap=AP_Param::next_scalar(&token, &type)) { - char s[AP_MAX_NAME_SIZE+1]; - ap->copy_name(s, sizeof(s)); - s[AP_MAX_NAME_SIZE] = 0; - - switch (type) { - case AP_PARAM_INT8: - Serial.printf_P("%s: %d\n", s, (int)((AP_Int8 *)ap)->get()); - break; - case AP_PARAM_INT16: - Serial.printf_P("%s: %d\n", s, (int)((AP_Int16 *)ap)->get()); - break; - case AP_PARAM_INT32: - Serial.printf_P("%s: %ld\n", s, (long)((AP_Int32 *)ap)->get()); - break; - case AP_PARAM_FLOAT: - Serial.printf_P("%s: %f\n", s, ((AP_Float *)ap)->get()); - break; - default: - break; - } - } + AP_Param::show_all(); return(0); } diff --git a/Tools/VARTest/VARTest.pde b/Tools/VARTest/VARTest.pde index dee90b714a..6c5232e62e 100644 --- a/Tools/VARTest/VARTest.pde +++ b/Tools/VARTest/VARTest.pde @@ -102,6 +102,9 @@ void setup() { ap=AP_Param::next(&token, &type)) { test_variable(ap, type); } + + AP_Param::show_all(); + Serial.println_P(PSTR("All done.")); } diff --git a/libraries/AP_Common/AP_Param.cpp b/libraries/AP_Common/AP_Param.cpp index ab7c09f31f..cad13b6d8e 100644 --- a/libraries/AP_Common/AP_Param.cpp +++ b/libraries/AP_Common/AP_Param.cpp @@ -684,3 +684,37 @@ float AP_Param::cast_to_float(enum ap_var_type type) return NAN; } } + + +// print the value of all variables +void AP_Param::show_all(void) +{ + uint16_t token; + AP_Param *ap; + enum ap_var_type type; + + for (ap=AP_Param::first(&token, &type); + ap; + ap=AP_Param::next_scalar(&token, &type)) { + char s[AP_MAX_NAME_SIZE+1]; + ap->copy_name(s, sizeof(s)); + s[AP_MAX_NAME_SIZE] = 0; + + switch (type) { + case AP_PARAM_INT8: + Serial.printf_P(PSTR("%s: %d\n"), s, (int)((AP_Int8 *)ap)->get()); + break; + case AP_PARAM_INT16: + Serial.printf_P(PSTR("%s: %d\n"), s, (int)((AP_Int16 *)ap)->get()); + break; + case AP_PARAM_INT32: + Serial.printf_P(PSTR("%s: %ld\n"), s, (long)((AP_Int32 *)ap)->get()); + break; + case AP_PARAM_FLOAT: + Serial.printf_P(PSTR("%s: %f\n"), s, ((AP_Float *)ap)->get()); + break; + default: + break; + } + } +} diff --git a/libraries/AP_Common/AP_Param.h b/libraries/AP_Common/AP_Param.h index 663628bbac..5d2de07d97 100644 --- a/libraries/AP_Common/AP_Param.h +++ b/libraries/AP_Common/AP_Param.h @@ -128,6 +128,9 @@ public: /// static void erase_all(void); + /// print the value of all variables + static void show_all(void); + /// Returns the first variable /// /// @return The first variable in _var_info, or NULL if