From a87862dd3ad1208e5482b83607a34729f4314e79 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 | 22 ++++++++++++++++++++++ libraries/RC_Channel/RC_Channel.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/libraries/RC_Channel/RC_Channel.cpp b/libraries/RC_Channel/RC_Channel.cpp index cd3183cc42..fa8631ac97 100644 --- a/libraries/RC_Channel/RC_Channel.cpp +++ b/libraries/RC_Channel/RC_Channel.cpp @@ -1952,6 +1952,28 @@ RC_Channel::AuxSwitchPos RC_Channel::get_aux_switch_pos() const return position; } +// 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 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) { for (uint8_t i=0; i