RC_Channel: Aux switches to respect 'reverse' option

This commit is contained in:
Sergey Bokhantsev 2020-01-04 21:04:16 +02:00 committed by Andrew Tridgell
parent f04acbd7de
commit f92d539b41
3 changed files with 14 additions and 4 deletions

View File

@ -966,10 +966,14 @@ bool RC_Channel::read_3pos_switch(RC_Channel::aux_switch_pos_t &ret) const
if (in <= 900 or in >= 2200) {
return false;
}
// switch is reversed if 'reversed' option set on channel and switches reverse is allowed by RC_OPTIONS
bool switch_reversed = reversed && rc().switch_reverse_allowed();
if (in < AUX_PWM_TRIGGER_LOW) {
ret = LOW;
ret = switch_reversed ? HIGH : LOW;
} else if (in > AUX_PWM_TRIGGER_HIGH) {
ret = HIGH;
ret = switch_reversed ? LOW : HIGH;
} else {
ret = MIDDLE;
}

View File

@ -358,6 +358,11 @@ public:
return get_singleton() != nullptr && (_options & uint32_t(Option::FPORT_PAD));
}
// should a channel reverse option affect aux switches
bool switch_reverse_allowed(void) const {
return get_singleton() != nullptr && (_options & uint32_t(Option::ALLOW_SWITCH_REV));
}
bool ignore_overrides() const {
return _options & uint32_t(Option::IGNORE_OVERRIDES);
}
@ -381,7 +386,7 @@ public:
float override_timeout_ms() const {
return _override_timeout.get() * 1e3f;
}
/*
get the RC input PWM value given a channel number. Note that
channel numbers start at 1, as this API is designed for use in
@ -401,6 +406,7 @@ protected:
LOG_DATA = (1 << 4), // log rc input bytes
ARMING_CHECK_THROTTLE = (1 << 5), // run an arming check for neutral throttle
ARMING_SKIP_CHECK_RPY = (1 << 6), // skip the an arming checks for the roll/pitch/yaw channels
ALLOW_SWITCH_REV = (1 << 7), // honor the reversed flag on switches
};
void new_override_received() {

View File

@ -86,7 +86,7 @@ const AP_Param::GroupInfo RC_Channels::var_info[] = {
// @DisplayName: RC options
// @Description: RC input options
// @User: Advanced
// @Bitmask: 0:Ignore RC Receiver, 1:Ignore MAVLink Overrides, 2:Ignore Receiver Failsafe, 3:FPort Pad, 4:Log RC input bytes, 5:Arming check throttle for 0 input, 6:Skip the arming check for neutral Roll/Pitch/Yay sticks
// @Bitmask: 0:Ignore RC Receiver, 1:Ignore MAVLink Overrides, 2:Ignore Receiver Failsafe, 3:FPort Pad, 4:Log RC input bytes, 5:Arming check throttle for 0 input, 6:Skip the arming check for neutral Roll/Pitch/Yay sticks, 7:Allow Switch reverse
AP_GROUPINFO("_OPTIONS", 33, RC_CHANNELS_SUBCLASS, _options, 0),
AP_GROUPEND