Browse Source

RC_Channel: guarantee logging of RCIN on switch changes

master
Andrew Tridgell 6 years ago
parent
commit
19ace7cace
  1. 14
      libraries/RC_Channel/RC_Channel.cpp
  2. 2
      libraries/RC_Channel/RC_Channel.h
  3. 8
      libraries/RC_Channel/RC_Channels.cpp

14
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(); const aux_func_t _option = (aux_func_t)option.get();
if (_option == AUX_FUNC::DO_NOTHING) { if (_option == AUX_FUNC::DO_NOTHING) {
// may wish to add special cases for other "AUXSW" things // may wish to add special cases for other "AUXSW" things
// here e.g. RCMAP_ROLL etc once they become options // here e.g. RCMAP_ROLL etc once they become options
return; return false;
} }
aux_switch_pos_t new_position; aux_switch_pos_t new_position;
if (!read_3pos_switch(new_position)) { if (!read_3pos_switch(new_position)) {
return; return false;
} }
const aux_switch_pos_t old_position = old_switch_position(); const aux_switch_pos_t old_position = old_switch_position();
if (new_position == old_position) { if (new_position == old_position) {
debounce.count = 0; debounce.count = 0;
return; return false;
} }
if (debounce.new_position != new_position) { if (debounce.new_position != new_position) {
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 // a value of 2 means we need 3 values in a row with the same
// value to activate // value to activate
if (debounce.count++ < 2) { if (debounce.count++ < 2) {
return; return false;
} }
// debounced; undertake the action: // debounced; undertake the action:
do_aux_function(_option, new_position); do_aux_function(_option, new_position);
set_old_switch_position(new_position); set_old_switch_position(new_position);
return true;
} }

2
libraries/RC_Channel/RC_Channel.h

@ -97,7 +97,7 @@ public:
// auxillary switch support: // auxillary switch support:
void init_aux(); void init_aux();
void read_aux(); bool read_aux();
// Aux Switch enumeration // Aux Switch enumeration
enum class AUX_FUNC { enum class AUX_FUNC {

8
libraries/RC_Channel/RC_Channels.cpp

@ -25,6 +25,7 @@
extern const AP_HAL::HAL& hal; extern const AP_HAL::HAL& hal;
#include <AP_Math/AP_Math.h> #include <AP_Math/AP_Math.h>
#include <AP_Logger/AP_Logger.h>
#include "RC_Channel.h" #include "RC_Channel.h"
@ -136,13 +137,18 @@ void RC_Channels::read_aux_all()
// exit immediately when no RC input // exit immediately when no RC input
return; return;
} }
bool need_log = false;
for (uint8_t i=0; i<NUM_RC_CHANNELS; i++) { for (uint8_t i=0; i<NUM_RC_CHANNELS; i++) {
RC_Channel *c = channel(i); RC_Channel *c = channel(i);
if (c == nullptr) { if (c == nullptr) {
continue; continue;
} }
c->read_aux(); need_log |= c->read_aux();
}
if (need_log) {
// guarantee that we log when a switch changes
AP::logger().Write_RCIN();
} }
} }

Loading…
Cancel
Save