Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RC_Channel: Aux switches to respect 'reverse' option #13172

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libraries/RC_Channel/RC_Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,10 +977,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;
}
Expand Down
8 changes: 7 additions & 1 deletion libraries/RC_Channel/RC_Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ class RC_Channels {
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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can remove the get_singleton() check on all these functions, it looks like it was leftover from when we needed singleton to get at _options

}

bool ignore_overrides() const {
return _options & uint32_t(Option::IGNORE_OVERRIDES);
}
Expand All @@ -381,7 +386,7 @@ class RC_Channels {
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
Expand All @@ -401,6 +406,7 @@ class RC_Channels {
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() {
Expand Down
2 changes: 1 addition & 1 deletion libraries/RC_Channel/RC_Channels_VarInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down