From fc0f1c52cae736bce646fb8b8c7a1fdf1e72a0e0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 11 Feb 2012 22:54:21 +1100 Subject: [PATCH] modify RC_Channel for AP_Param --- libraries/RC_Channel/RC_Channel.cpp | 19 +++++++++++++++++-- libraries/RC_Channel/RC_Channel.h | 23 ++++++----------------- libraries/RC_Channel/RC_Channel_aux.cpp | 12 ++++++++++++ libraries/RC_Channel/RC_Channel_aux.h | 11 ++++++----- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/libraries/RC_Channel/RC_Channel.cpp b/libraries/RC_Channel/RC_Channel.cpp index d1ebfbad1a..4445f4d3bc 100644 --- a/libraries/RC_Channel/RC_Channel.cpp +++ b/libraries/RC_Channel/RC_Channel.cpp @@ -24,6 +24,15 @@ APM_RC_Class *RC_Channel::_apm_rc; +const AP_Param::GroupInfo RC_Channel::var_info[] PROGMEM = { + { AP_PARAM_INT16, "MIN", VAROFFSET(RC_Channel, radio_min) }, + { AP_PARAM_INT16, "TRIM", VAROFFSET(RC_Channel, radio_trim) }, + { AP_PARAM_INT16, "MAX", VAROFFSET(RC_Channel, radio_max) }, + { AP_PARAM_INT8, "REV", VAROFFSET(RC_Channel, _reverse) }, + { AP_PARAM_INT16, "DZ", VAROFFSET(RC_Channel, _dead_zone) }, + { AP_PARAM_NONE, "" } +}; + // setup the control preferences void RC_Channel::set_range(int low, int high) @@ -163,13 +172,19 @@ RC_Channel::calc_pwm(void) void RC_Channel::load_eeprom(void) { - _group.load(); + radio_min.load(); + radio_trim.load(); + radio_max.load(); + _reverse.load(); } void RC_Channel::save_eeprom(void) { - _group.save(); + radio_min.save(); + radio_trim.save(); + radio_max.save(); + _reverse.save(); } // ------------------------------------------ diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h index 8d473cbf79..24e281a978 100644 --- a/libraries/RC_Channel/RC_Channel.h +++ b/libraries/RC_Channel/RC_Channel.h @@ -12,26 +12,13 @@ /// @class RC_Channel /// @brief Object managing one RC channel class RC_Channel{ - protected: - AP_Var_group _group; // must be before all vars to keep ctor init order correct - public: /// Constructor /// /// @param key EEPROM storage key for the channel trim parameters. /// @param name Optional name for the group. /// - RC_Channel(AP_Var::Key key, const prog_char_t *name) : - _group(key, name), - radio_min (&_group, 0, 1100, name ? PSTR("MIN") : 0), // suppress name if group has no name - radio_trim(&_group, 1, 1500, name ? PSTR("TRIM") : 0), - radio_max (&_group, 2, 1900, name ? PSTR("MAX") : 0), - _high(1), - _filter(false), - _reverse (&_group, 3, 1, name ? PSTR("REV") : 0), - _dead_zone (&_group, 4, 0, name ? PSTR("DZ") : 0), - //_dead_zone(0), - scale_output(1.0) + RC_Channel() {} // setup min and max radio values in CLI @@ -97,11 +84,13 @@ class RC_Channel{ static void set_apm_rc(APM_RC_Class * apm_rc); static APM_RC_Class *_apm_rc; + static const struct AP_Param::GroupInfo var_info[]; + + AP_Int8 _reverse; + AP_Int16 _dead_zone; + private: bool _filter; - AP_Int8 _reverse; - - AP_Int16 _dead_zone; //int16_t _dead_zone; // used to keep noise down and create a dead zone. uint8_t _type; int16_t _high; diff --git a/libraries/RC_Channel/RC_Channel_aux.cpp b/libraries/RC_Channel/RC_Channel_aux.cpp index fc2b2c9e39..8071272cdf 100644 --- a/libraries/RC_Channel/RC_Channel_aux.cpp +++ b/libraries/RC_Channel/RC_Channel_aux.cpp @@ -3,6 +3,18 @@ #include #include "RC_Channel_aux.h" +const AP_Param::GroupInfo RC_Channel_aux::var_info[] PROGMEM = { + { AP_PARAM_INT16, "MIN", VAROFFSET(RC_Channel_aux, radio_min) }, + { AP_PARAM_INT16, "TRIM", VAROFFSET(RC_Channel_aux, radio_trim) }, + { AP_PARAM_INT16, "MAX", VAROFFSET(RC_Channel_aux, radio_max) }, + { AP_PARAM_INT8, "REV", VAROFFSET(RC_Channel_aux, _reverse) }, + { AP_PARAM_INT16, "DZ", VAROFFSET(RC_Channel_aux, _dead_zone) }, + { AP_PARAM_INT8, "FUNCTION", VAROFFSET(RC_Channel_aux, function) }, + { AP_PARAM_INT8, "ANGLE_MIN", VAROFFSET(RC_Channel_aux, angle_min) }, + { AP_PARAM_INT8, "ANGLE_MAX", VAROFFSET(RC_Channel_aux, angle_max) }, + { AP_PARAM_NONE, "" } +}; + RC_Channel_aux* g_rc_function[RC_Channel_aux::k_nr_aux_servo_functions]; // the aux. servo ch. assigned to each function int16_t diff --git a/libraries/RC_Channel/RC_Channel_aux.h b/libraries/RC_Channel/RC_Channel_aux.h index f34db6aada..4db81485ef 100644 --- a/libraries/RC_Channel/RC_Channel_aux.h +++ b/libraries/RC_Channel/RC_Channel_aux.h @@ -22,11 +22,11 @@ public: /// @param key EEPROM storage key for the channel trim parameters. /// @param name Optional name for the group. /// - RC_Channel_aux(AP_Var::Key key, const prog_char_t *name) : - RC_Channel(key, name), - function (&_group, 4, k_none, name ? PSTR("FUNCTION") : 0), // suppress name if group has no name - angle_min (&_group, 5, -4500, name ? PSTR("ANGLE_MIN") : 0), // assume -45 degrees min deflection - angle_max (&_group, 6, 4500, name ? PSTR("ANGLE_MAX") : 0) // assume 45 degrees max deflection + RC_Channel_aux() : + RC_Channel(), + function (0), + angle_min (-4500), // assume -45 degrees min deflection + angle_max (4500) // assume 45 degrees max deflection {} typedef enum @@ -52,6 +52,7 @@ public: void output_ch(unsigned char ch_nr); // map a function to a servo channel and output it + static const struct AP_Param::GroupInfo var_info[]; }; void update_aux_servo_function(RC_Channel_aux* rc_5, RC_Channel_aux* rc_6, RC_Channel_aux* rc_7, RC_Channel_aux* rc_8);