diff --git a/libraries/RC_Channel/RC_Channel.cpp b/libraries/RC_Channel/RC_Channel.cpp index c297224e14..ce94b57e96 100644 --- a/libraries/RC_Channel/RC_Channel.cpp +++ b/libraries/RC_Channel/RC_Channel.cpp @@ -475,22 +475,25 @@ void RC_Channel::init_aux_function(const aux_func_t ch_option, const aux_switch_ } } -void RC_Channel::read_aux() +/* + read an aux channel. Return true if a switch has changed + */ +bool RC_Channel::read_aux() { const aux_func_t _option = (aux_func_t)option.get(); if (_option == AUX_FUNC::DO_NOTHING) { // may wish to add special cases for other "AUXSW" things // here e.g. RCMAP_ROLL etc once they become options - return; + return false; } aux_switch_pos_t new_position; if (!read_3pos_switch(new_position)) { - return; + return false; } const aux_switch_pos_t old_position = old_switch_position(); if (new_position == old_position) { debounce.count = 0; - return; + return false; } if (debounce.new_position != new_position) { debounce.new_position = new_position; @@ -499,12 +502,13 @@ void RC_Channel::read_aux() // a value of 2 means we need 3 values in a row with the same // value to activate if (debounce.count++ < 2) { - return; + return false; } // debounced; undertake the action: do_aux_function(_option, new_position); set_old_switch_position(new_position); + return true; } diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h index d23d596c1f..9f60ec7ebf 100644 --- a/libraries/RC_Channel/RC_Channel.h +++ b/libraries/RC_Channel/RC_Channel.h @@ -97,7 +97,7 @@ public: // auxillary switch support: void init_aux(); - void read_aux(); + bool read_aux(); // Aux Switch enumeration enum class AUX_FUNC { diff --git a/libraries/RC_Channel/RC_Channels.cpp b/libraries/RC_Channel/RC_Channels.cpp index 4e1656a704..2bbc210977 100644 --- a/libraries/RC_Channel/RC_Channels.cpp +++ b/libraries/RC_Channel/RC_Channels.cpp @@ -25,6 +25,7 @@ extern const AP_HAL::HAL& hal; #include +#include #include "RC_Channel.h" @@ -136,13 +137,18 @@ void RC_Channels::read_aux_all() // exit immediately when no RC input return; } + bool need_log = false; for (uint8_t i=0; iread_aux(); + need_log |= c->read_aux(); + } + if (need_log) { + // guarantee that we log when a switch changes + AP::logger().Write_RCIN(); } }