From eb452478ac4d8828c97d2bb3e1a30da90ee6ed28 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 8 Jan 2020 14:42:25 +1100 Subject: [PATCH] Copter: override do_aux_function_armdisarm method to set armed_with_switch As well as removing the code duplication, this only sets the flag if arming was actually successful. armed-with-switch is used when setting various state, and it isn't entirely clear that we only use it when armed. This would seem to be a safer option. --- ArduCopter/RC_Channel.cpp | 27 ++++++++++----------------- ArduCopter/RC_Channel.h | 1 + 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ArduCopter/RC_Channel.cpp b/ArduCopter/RC_Channel.cpp index 0e27aa882a..cd62e30533 100644 --- a/ArduCopter/RC_Channel.cpp +++ b/ArduCopter/RC_Channel.cpp @@ -142,6 +142,16 @@ void RC_Channel_Copter::do_aux_function_change_mode(const Mode::Number mode, } } +void RC_Channel_Copter::do_aux_function_armdisarm(const aux_switch_pos_t ch_flag) +{ + RC_Channel::do_aux_function_armdisarm(ch_flag); + if (copter.arming.is_armed()) { + // remember that we are using an arming switch, for use by + // set_throttle_zero_flag + copter.ap.armed_with_switch = true; + } +} + // do_aux_function - implement the function invoked by auxiliary switches void RC_Channel_Copter::do_aux_function(const aux_func_t ch_option, const aux_switch_pos_t ch_flag) { @@ -380,23 +390,6 @@ void RC_Channel_Copter::do_aux_function(const aux_func_t ch_option, const aux_sw #endif break; - case AUX_FUNC::ARMDISARM: - // arm or disarm the vehicle - switch (ch_flag) { - case HIGH: - copter.arming.arm(AP_Arming::Method::AUXSWITCH); - // remember that we are using an arming switch, for use by set_throttle_zero_flag - copter.ap.armed_with_switch = true; - break; - case MIDDLE: - // nothing - break; - case LOW: - copter.arming.disarm(); - break; - } - break; - case AUX_FUNC::SMART_RTL: #if MODE_SMARTRTL_ENABLED == ENABLED do_aux_function_change_mode(Mode::Number::SMART_RTL, ch_flag); diff --git a/ArduCopter/RC_Channel.h b/ArduCopter/RC_Channel.h index 16b7392485..7395d4c597 100644 --- a/ArduCopter/RC_Channel.h +++ b/ArduCopter/RC_Channel.h @@ -15,6 +15,7 @@ protected: private: + void do_aux_function_armdisarm(const aux_switch_pos_t ch_flag) override; void do_aux_function_change_mode(const Mode::Number mode, const aux_switch_pos_t ch_flag);