mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-08 00:48:30 -04:00
RC_Channel: move to AuxFuncTrigger structure
This commit is contained in:
parent
a5741a53cb
commit
be86284f18
@ -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:
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user