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 Peter Barker
parent 2c3eec070f
commit a87862dd3a
2 changed files with 25 additions and 0 deletions

View File

@ -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<NUM_RC_CHANNELS; i++) {

View File

@ -332,6 +332,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, AuxFuncTrigger::Source source, uint16_t source_index);