From 16f0f5ecfdcd777d9db869f945ad731cf1ee6d4b Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Mon, 13 Jan 2025 17:49:39 +0000 Subject: [PATCH] RC_Channel: add get_stick_gesture_pos() for OSD menus --- libraries/RC_Channel/RC_Channel.cpp | 24 +++++++++++++++++++----- libraries/RC_Channel/RC_Channel.h | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libraries/RC_Channel/RC_Channel.cpp b/libraries/RC_Channel/RC_Channel.cpp index 1f6440ec00..789f64cd06 100644 --- a/libraries/RC_Channel/RC_Channel.cpp +++ b/libraries/RC_Channel/RC_Channel.cpp @@ -1922,12 +1922,26 @@ RC_Channel::AuxSwitchPos RC_Channel::get_aux_switch_pos() const return position; } -// return switch position value as LOW, MIDDLE, HIGH -// if reading the switch fails then it returns LOW -RC_Channel::AuxSwitchPos RC_Channels::get_channel_pos(const uint8_t rcmapchan) const +// return stick gesture pos as LOW, MIDDLE, HIGH +// this function uses different threshold values to RC_Chanel::get_aux_switch_pos() +// to avoid glitching on the stick travel and also always honours channel reversal +RC_Channel::AuxSwitchPos RC_Channel::get_stick_gesture_pos() const { - const RC_Channel* chan = rc().channel(rcmapchan-1); - return chan != nullptr ? chan->get_aux_switch_pos() : RC_Channel::AuxSwitchPos::LOW; + const uint16_t in = get_radio_in(); + if (in <= 900 || in >= 2200) { + return RC_Channel::AuxSwitchPos::LOW; + } + + // switch is reversed if 'reversed' option set on channel and switches reverse is allowed by RC_OPTIONS + bool switch_reversed = get_reverse(); + + if (in < RC_Channel::AUX_PWM_TRIGGER_LOW) { + return switch_reversed ? RC_Channel::AuxSwitchPos::HIGH : RC_Channel::AuxSwitchPos::LOW; + } + if (in > RC_Channel::AUX_PWM_TRIGGER_HIGH) { + return switch_reversed ? RC_Channel::AuxSwitchPos::LOW : RC_Channel::AuxSwitchPos::HIGH; + } + return RC_Channel::AuxSwitchPos::MIDDLE; } RC_Channel *RC_Channels::find_channel_for_option(const RC_Channel::AUX_FUNC option) diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h index 120fec83fc..33c0677293 100644 --- a/libraries/RC_Channel/RC_Channel.h +++ b/libraries/RC_Channel/RC_Channel.h @@ -317,6 +317,9 @@ public: AuxSwitchPos get_aux_switch_pos() const; + // aux position for stick gestures used by RunCam menus etc + AuxSwitchPos get_stick_gesture_pos() const; + // wrapper function around do_aux_function which allows us to log bool run_aux_function(AUX_FUNC ch_option, AuxSwitchPos pos, AuxFuncTriggerSource source);