Skip to content

Commit

Permalink
Copter: Do not switch into a disabled flight mode
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas authored and OXINARF committed Mar 19, 2018
1 parent 489551c commit 8e143aa
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions ArduCopter/switches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand All @@ -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) {

Expand Down Expand Up @@ -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();
}
#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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 8e143aa

Please sign in to comment.