From ed17f644597ba03664a26b23c67f2529e0fceaf1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 17 Dec 2011 06:28:25 +1100 Subject: [PATCH] geofence: added FENCE_TRIGGERED_PIN this allows for a digital pin to be set high when the geofence triggers. This pin can be connected to an external failsafe device --- ArduPlane/config.h | 6 ++++++ ArduPlane/geofence.pde | 8 ++++++++ ArduPlane/system.pde | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/ArduPlane/config.h b/ArduPlane/config.h index c0045b88bf..fd308b2ef1 100644 --- a/ArduPlane/config.h +++ b/ArduPlane/config.h @@ -809,3 +809,9 @@ #ifndef FENCE_ENABLE_PWM # define FENCE_ENABLE_PWM 1750 #endif + +// a digital pin to set high when the geo-fence triggers. Defaults +// to -1, which means don't activate a pin +#ifndef FENCE_TRIGGERED_PIN +# define FENCE_TRIGGERED_PIN -1 +#endif diff --git a/ArduPlane/geofence.pde b/ArduPlane/geofence.pde index c623ce05d9..bc72a4fa89 100644 --- a/ArduPlane/geofence.pde +++ b/ArduPlane/geofence.pde @@ -209,6 +209,9 @@ static void geofence_check(bool altitude_check_only) // we have moved back inside the fence geofence_state->fence_triggered = false; gcs_send_text_P(SEVERITY_LOW,PSTR("geo-fence OK")); +#if FENCE_TRIGGERED_PIN > 0 + digitalWrite(FENCE_TRIGGERED_PIN, LOW); +#endif } // we're inside, all is good with the world return; @@ -227,6 +230,11 @@ static void geofence_check(bool altitude_check_only) geofence_state->breach_count++; geofence_state->breach_time = millis(); geofence_state->breach_type = breach_type; + +#if FENCE_TRIGGERED_PIN > 0 + digitalWrite(FENCE_TRIGGERED_PIN, HIGH); +#endif + gcs_send_text_P(SEVERITY_LOW,PSTR("geo-fence triggered")); // see what action the user wants diff --git a/ArduPlane/system.pde b/ArduPlane/system.pde index e11f895074..249952a68b 100644 --- a/ArduPlane/system.pde +++ b/ArduPlane/system.pde @@ -224,6 +224,13 @@ static void init_ardupilot() #if CONFIG_RELAY == ENABLED DDRL |= B00000100; // Set Port L, pin 2 to output for the relay #endif + +#if FENCE_TRIGGERED_PIN > 0 + pinMode(FENCE_TRIGGERED_PIN, OUTPUT); + digitalWrite(FENCE_TRIGGERED_PIN, LOW); +#endif + + // If the switch is in 'menu' mode, run the main menu. // // Since we can't be sure that the setup or test mode won't leave