RC_Channel: add get_stick_gesture_pos() for OSD menus

This commit is contained in:
Andy Piper 2025-01-13 17:49:39 +00:00 committed by Randy Mackay
parent 9e5c6248cb
commit 16f0f5ecfd
2 changed files with 22 additions and 5 deletions

View File

@ -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)

View File

@ -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);