From 8e143aa637f21fcd2fb2a53c8644fc3bf88484f8 Mon Sep 17 00:00:00 2001 From: "Dr.-Ing. Amilcar do Carmo Lucas" Date: Mon, 19 Mar 2018 15:02:14 +0100 Subject: [PATCH] Copter: Do not switch into a disabled flight mode --- ArduCopter/switches.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/ArduCopter/switches.cpp b/ArduCopter/switches.cpp index 93834553d1..6f8e8c3f41 100644 --- a/ArduCopter/switches.cpp +++ b/ArduCopter/switches.cpp @@ -232,6 +232,7 @@ void Copter::do_aux_switch_function(int8_t ch_function, uint8_t ch_flag) break; case AUXSW_RTL: +#if MODE_RTL_ENABLED == ENABLED if (ch_flag == AUX_SWITCH_HIGH) { // engage RTL (if not possible we remain in current flight mode) set_mode(RTL, MODE_REASON_TX_COMMAND); @@ -241,6 +242,7 @@ void Copter::do_aux_switch_function(int8_t ch_function, uint8_t ch_flag) reset_control_switch(); } } +#endif break; case AUXSW_SAVE_TRIM: @@ -249,8 +251,8 @@ void Copter::do_aux_switch_function(int8_t ch_function, uint8_t ch_flag) } break; -#if MODE_AUTO_ENABLED == ENABLED case AUXSW_SAVE_WP: +#if MODE_AUTO_ENABLED == ENABLED // save waypoint when switch is brought high if (ch_flag == AUX_SWITCH_HIGH) { @@ -302,14 +304,29 @@ void Copter::do_aux_switch_function(int8_t ch_function, uint8_t ch_flag) Log_Write_Event(DATA_SAVEWP_ADD_WP); } } +#endif break; case AUXSW_MISSION_RESET: +#if MODE_AUTO_ENABLED == ENABLED if (ch_flag == AUX_SWITCH_HIGH) { mission.reset(); } - break; #endif + break; + + case AUXSW_AUTO: +#if MODE_AUTO_ENABLED == ENABLED + if (ch_flag == AUX_SWITCH_HIGH) { + set_mode(AUTO, MODE_REASON_TX_COMMAND); + } else { + // return to flight mode switch's flight mode if we are currently in AUTO + if (control_mode == AUTO) { + reset_control_switch(); + } + } +#endif + break; case AUXSW_CAMERA_TRIGGER: #if CAMERA == ENABLED @@ -385,17 +402,6 @@ void Copter::do_aux_switch_function(int8_t ch_function, uint8_t ch_flag) #endif break; - case AUXSW_AUTO: - if (ch_flag == AUX_SWITCH_HIGH) { - set_mode(AUTO, MODE_REASON_TX_COMMAND); - } else { - // return to flight mode switch's flight mode if we are currently in AUTO - if (control_mode == AUTO) { - reset_control_switch(); - } - } - break; - case AUXSW_AUTOTUNE: #if AUTOTUNE_ENABLED == ENABLED // turn on auto tuner @@ -534,6 +540,7 @@ void Copter::do_aux_switch_function(int8_t ch_function, uint8_t ch_flag) break; case AUXSW_BRAKE: +#if MODE_BRAKE_ENABLED == ENABLED // brake flight mode if (ch_flag == AUX_SWITCH_HIGH) { set_mode(BRAKE, MODE_REASON_TX_COMMAND); @@ -543,6 +550,7 @@ void Copter::do_aux_switch_function(int8_t ch_function, uint8_t ch_flag) reset_control_switch(); } } +#endif break; case AUXSW_THROW: @@ -612,6 +620,7 @@ void Copter::do_aux_switch_function(int8_t ch_function, uint8_t ch_flag) break; case AUXSW_SMART_RTL: +#if MODE_SMARTRTL_ENABLED == ENABLED if (ch_flag == AUX_SWITCH_HIGH) { // engage SmartRTL (if not possible we remain in current flight mode) set_mode(SMART_RTL, MODE_REASON_TX_COMMAND); @@ -621,8 +630,9 @@ void Copter::do_aux_switch_function(int8_t ch_function, uint8_t ch_flag) reset_control_switch(); } } +#endif break; - + case AUXSW_INVERTED: #if FRAME_CONFIG == HELI_FRAME switch (ch_flag) {