From 319cfa766b82136f6d52a0b5ef47dfebe5a93e68 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 18 Nov 2016 14:13:32 +1100 Subject: [PATCH] RC_Channel: add method to get current radio out for a function --- libraries/RC_Channel/RC_Channel_aux.cpp | 18 ++++++++++++++++++ libraries/RC_Channel/RC_Channel_aux.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/libraries/RC_Channel/RC_Channel_aux.cpp b/libraries/RC_Channel/RC_Channel_aux.cpp index dd4a398e7a..2db7adaa1e 100644 --- a/libraries/RC_Channel/RC_Channel_aux.cpp +++ b/libraries/RC_Channel/RC_Channel_aux.cpp @@ -208,6 +208,24 @@ RC_Channel_aux::set_radio(RC_Channel_aux::Aux_servo_function_t function, int16_t } } +/* + get radio_out for *first* channel matching the given function type. + Returns true if a value was found. + */ +bool RC_Channel_aux::get_radio(RC_Channel_aux::Aux_servo_function_t function, int16_t &value) +{ + if (!function_assigned(function)) { + return false; + } + for (uint8_t i = 0; i < RC_AUX_MAX_CHANNELS; i++) { + if (_aux_channels[i] && _aux_channels[i]->function.get() == function) { + value = _aux_channels[i]->get_radio_out(); + return true; + } + } + return false; +} + /* set radio_out for all channels matching the given function type, allow radio_trim to center servo */ diff --git a/libraries/RC_Channel/RC_Channel_aux.h b/libraries/RC_Channel/RC_Channel_aux.h index 7776257924..50465d8f8c 100644 --- a/libraries/RC_Channel/RC_Channel_aux.h +++ b/libraries/RC_Channel/RC_Channel_aux.h @@ -107,6 +107,9 @@ public: // set radio_out for a function channel static void set_radio(Aux_servo_function_t function, int16_t value); + // get radio_out for *first* channel matching the given function type. + static bool get_radio(RC_Channel_aux::Aux_servo_function_t function, int16_t &value); + // set radio_out for all channels matching the given function type, allow radio_trim to center servo static void set_radio_trimmed(Aux_servo_function_t function, int16_t value);