From 4f242aedec3e3f31a46ab2e6a0f13c854facb777 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 17 Dec 2013 14:13:32 +1100 Subject: [PATCH] Plane: fixed a bug where mode would not revert on geo-fence disable the mode would not revert if the switch was in position 0 --- ArduPlane/ArduPlane.pde | 10 ++++++---- ArduPlane/control_modes.pde | 2 +- ArduPlane/geofence.pde | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ArduPlane/ArduPlane.pde b/ArduPlane/ArduPlane.pde index 8add040fbd..09b4b52d9f 100644 --- a/ArduPlane/ArduPlane.pde +++ b/ArduPlane/ArduPlane.pde @@ -350,12 +350,14 @@ static bool usb_connected; //////////////////////////////////////////////////////////////////////////////// // This is the state of the flight control system // There are multiple states defined such as MANUAL, FBW-A, AUTO -enum FlightMode control_mode = INITIALISING; +static enum FlightMode control_mode = INITIALISING; + // Used to maintain the state of the previous control switch position -// This is set to -1 when we need to re-read the switch -uint8_t oldSwitchPosition; +// This is set to 254 when we need to re-read the switch +static uint8_t oldSwitchPosition = 254; + // This is used to enable the inverted flight feature -bool inverted_flight = false; +static bool inverted_flight = false; static struct { // These are trim values used for elevon control diff --git a/ArduPlane/control_modes.pde b/ArduPlane/control_modes.pde index 9930b89f40..5f5c9f010d 100644 --- a/ArduPlane/control_modes.pde +++ b/ArduPlane/control_modes.pde @@ -70,7 +70,7 @@ static uint8_t readSwitch(void){ static void reset_control_switch() { - oldSwitchPosition = 0; + oldSwitchPosition = 254; read_control_switch(); } diff --git a/ArduPlane/geofence.pde b/ArduPlane/geofence.pde index 2cb2588e54..5cd4b247c5 100644 --- a/ArduPlane/geofence.pde +++ b/ArduPlane/geofence.pde @@ -87,6 +87,7 @@ static void geofence_load(void) // not much we can do here except disable it goto failed; } + geofence_state->old_switch_position = 254; } if (g.fence_total <= 0) { @@ -188,7 +189,7 @@ static void geofence_check(bool altitude_check_only) geofence_state->old_switch_position == oldSwitchPosition && guided_WP.lat == geofence_state->boundary[0].x && guided_WP.lng == geofence_state->boundary[0].y) { - geofence_state->old_switch_position = 0; + geofence_state->old_switch_position = 254; reset_control_switch(); } return;