From 00d2d5946c901af4e3141aa16098e0317e32d3d9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Feb 2014 21:30:55 +1100 Subject: [PATCH] RC_Channel: added disable_aux_channel() this will be used by copter to ensure motor channels are not enabled for aux functions --- libraries/RC_Channel/RC_Channel.h | 4 +++- libraries/RC_Channel/RC_Channel_aux.cpp | 14 ++++++++++++++ libraries/RC_Channel/RC_Channel_aux.h | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h index a45510c6ef..152c860481 100644 --- a/libraries/RC_Channel/RC_Channel.h +++ b/libraries/RC_Channel/RC_Channel.h @@ -118,9 +118,11 @@ private: int16_t _low; int16_t _high_out; int16_t _low_out; - uint8_t _ch_out; static RC_Channel *rc_ch[RC_MAX_CHANNELS]; + +protected: + uint8_t _ch_out; }; // This is ugly, but it fixes poorly architected library diff --git a/libraries/RC_Channel/RC_Channel_aux.cpp b/libraries/RC_Channel/RC_Channel_aux.cpp index 95714d6ab7..302ad48583 100644 --- a/libraries/RC_Channel/RC_Channel_aux.cpp +++ b/libraries/RC_Channel/RC_Channel_aux.cpp @@ -38,6 +38,20 @@ RC_Channel_aux::output_ch(unsigned char ch_nr) hal.rcout->write(ch_nr, radio_out); } +/* + prevent a channel from being used for auxillary functions + This is used by the copter code to ensure channels used for motors + can't be used for auxillary functions +*/ +void RC_Channel_aux::disable_aux_channel(uint8_t channel) +{ + for (uint8_t i = 0; i < RC_AUX_MAX_CHANNELS; i++) { + if (_aux_channels[i] && _aux_channels[i]->_ch_out == channel) { + _aux_channels[i] = NULL; + } + } +} + /// Update the _aux_channels array of pointers to rc_x channels /// This is to be done before rc_init so that the channels get correctly initialized. /// It also should be called periodically because the user might change the configuration and diff --git a/libraries/RC_Channel/RC_Channel_aux.h b/libraries/RC_Channel/RC_Channel_aux.h index 7a067eddde..7c0a26f760 100644 --- a/libraries/RC_Channel/RC_Channel_aux.h +++ b/libraries/RC_Channel/RC_Channel_aux.h @@ -99,6 +99,9 @@ public: // assigned and enable auxillary channels static void enable_aux_servos(void); + + // prevent a channel from being used for auxillary functions + static void disable_aux_channel(uint8_t channel); private: static uint32_t _function_mask;