From be86284f1813c35f9b80a85e913a9e2ad53083fc Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Fri, 13 Dec 2024 21:15:46 +0000 Subject: [PATCH] RC_Channel: move to AuxFuncTrigger structure --- libraries/RC_Channel/RC_Channel.cpp | 23 +++++++++++++++++------ libraries/RC_Channel/RC_Channel.h | 27 +++++++++++++++++---------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/libraries/RC_Channel/RC_Channel.cpp b/libraries/RC_Channel/RC_Channel.cpp index bae3499173..4feb512739 100644 --- a/libraries/RC_Channel/RC_Channel.cpp +++ b/libraries/RC_Channel/RC_Channel.cpp @@ -779,7 +779,7 @@ void RC_Channel::init_aux_function(const AUX_FUNC ch_option, const AuxSwitchPos #endif #if AP_AHRS_ENABLED case AUX_FUNC::AHRS_TYPE: - run_aux_function(ch_option, ch_flag, AuxFuncTriggerSource::INIT); + run_aux_function(ch_option, ch_flag, AuxFuncTrigger::Source::INIT); break; #endif default: @@ -977,7 +977,7 @@ bool RC_Channel::read_aux() #endif // debounced; undertake the action: - run_aux_function(_option, new_position, AuxFuncTriggerSource::RC); + run_aux_function(_option, new_position, AuxFuncTrigger::Source::RC, get_radio_in()); return true; } @@ -1402,12 +1402,20 @@ void RC_Channel::do_aux_function_retract_mount(const AuxSwitchPos ch_flag, const } #endif // HAL_MOUNT_ENABLED -bool RC_Channel::run_aux_function(AUX_FUNC ch_option, AuxSwitchPos pos, AuxFuncTriggerSource source) +bool RC_Channel::run_aux_function(AUX_FUNC ch_option, AuxSwitchPos pos, AuxFuncTrigger::Source source, int16_t pwm) { #if AP_SCRIPTING_ENABLED rc().set_aux_cached(ch_option, pos); #endif - const bool ret = do_aux_function(ch_option, pos); + + const AuxFuncTrigger trigger { + func: ch_option, + pos: pos, + source: source, + pwm: pwm, + }; + + const bool ret = do_aux_function(trigger); #if HAL_LOGGING_ENABLED // @LoggerMessage: AUXF @@ -1418,7 +1426,7 @@ bool RC_Channel::run_aux_function(AUX_FUNC ch_option, AuxSwitchPos pos, AuxFuncT // @Field: pos: switch position when function triggered // @FieldValueEnum: pos: RC_Channel::AuxSwitchPos // @Field: source: source of auxiliary function invocation - // @FieldValueEnum: source: RC_Channel::AuxFuncTriggerSource + // @FieldValueEnum: source: RC_Channel::AuxFuncTrigger::Source // @Field: result: true if function was successful AP::logger().Write( "AUXF", @@ -1437,8 +1445,11 @@ bool RC_Channel::run_aux_function(AUX_FUNC ch_option, AuxSwitchPos pos, AuxFuncT return ret; } -bool RC_Channel::do_aux_function(const AUX_FUNC ch_option, const AuxSwitchPos ch_flag) +bool RC_Channel::do_aux_function(const AuxFuncTrigger &trigger) { + const AUX_FUNC &ch_option = trigger.func; + const AuxSwitchPos &ch_flag = trigger.pos; + switch (ch_option) { #if AP_FENCE_ENABLED case AUX_FUNC::FENCE: diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h index 378ca95e13..670810add8 100644 --- a/libraries/RC_Channel/RC_Channel.h +++ b/libraries/RC_Channel/RC_Channel.h @@ -314,19 +314,26 @@ public: HIGH // indicates auxiliary switch is in the high position (pwm >1800) }; - enum class AuxFuncTriggerSource : uint8_t { - INIT, - RC, - BUTTON, - MAVLINK, - MISSION, - SCRIPTING, + // Trigger structure containing the function, position and pwm (if applicable) + struct AuxFuncTrigger { + AUX_FUNC func; + AuxSwitchPos pos; + enum class Source : uint8_t { + INIT, + RC, + BUTTON, + MAVLINK, + MISSION, + SCRIPTING, + } source; + // Trigger PWM, only valid for RC source + int16_t pwm; }; AuxSwitchPos get_aux_switch_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); + bool run_aux_function(AUX_FUNC ch_option, AuxSwitchPos pos, AuxFuncTrigger::Source source, int16_t pwm = 0); #if AP_RC_CHANNEL_AUX_FUNCTION_STRINGS_ENABLED const char *string_for_aux_function(AUX_FUNC function) const; @@ -357,7 +364,7 @@ protected: virtual void init_aux_function(AUX_FUNC ch_option, AuxSwitchPos); // virtual function to be overridden my subclasses - virtual bool do_aux_function(AUX_FUNC ch_option, AuxSwitchPos); + virtual bool do_aux_function(const AuxFuncTrigger &trigger); void do_aux_function_armdisarm(const AuxSwitchPos ch_flag); void do_aux_function_avoid_adsb(const AuxSwitchPos ch_flag); @@ -597,7 +604,7 @@ public: // method for other parts of the system (e.g. Button and mavlink) // to trigger auxiliary functions - bool run_aux_function(RC_Channel::AUX_FUNC ch_option, RC_Channel::AuxSwitchPos pos, RC_Channel::AuxFuncTriggerSource source) { + bool run_aux_function(RC_Channel::AUX_FUNC ch_option, RC_Channel::AuxSwitchPos pos, RC_Channel::AuxFuncTrigger::Source source) { return rc_channel(0)->run_aux_function(ch_option, pos, source); }