RC_Channel: guarantee logging of RCIN on switch changes
This commit is contained in:
parent
3fa419e132
commit
19ace7cace
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -97,7 +97,7 @@ public:
|
||||
|
||||
// auxillary switch support:
|
||||
void init_aux();
|
||||
void read_aux();
|
||||
bool read_aux();
|
||||
|
||||
// Aux Switch enumeration
|
||||
enum class AUX_FUNC {
|
||||
|
@ -25,6 +25,7 @@
|
||||
extern const AP_HAL::HAL& hal;
|
||||
|
||||
#include <AP_Math/AP_Math.h>
|
||||
#include <AP_Logger/AP_Logger.h>
|
||||
|
||||
#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; i<NUM_RC_CHANNELS; i++) {
|
||||
RC_Channel *c = channel(i);
|
||||
if (c == nullptr) {
|
||||
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…
Reference in New Issue
Block a user