From 8bfab6d2f2e9a4a1d9a942d092ce3b3afba5b095 Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Mon, 16 Sep 2019 13:24:41 -0700 Subject: [PATCH] Plane: Geofence, speed up the no fence checks if disabled This just checks if we are going to early out on the fence because it's disabled. This also saves us 60 bytes of flash space. This technically is a behaviour change as it was possible to load the fence before while disabled if there was an RC channel mapped to it. This defers that until the fence will have an action. The advantage of this though is that it speeds up the check that's done per loop in a quadplane for stick mixing --- ArduPlane/geofence.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ArduPlane/geofence.cpp b/ArduPlane/geofence.cpp index 0fc5f26d50..9f1f5a319e 100644 --- a/ArduPlane/geofence.cpp +++ b/ArduPlane/geofence.cpp @@ -207,14 +207,20 @@ bool Plane::geofence_set_enabled(bool enable) */ bool Plane::geofence_enabled(void) { + if (g.fence_action == FENCE_ACTION_NONE) { + if (geofence_state != nullptr) { + geofence_state->fence_triggered = false; + } + return false; + } + geofence_update_pwm_enabled_state(); if (geofence_state == nullptr) { return false; } - if (g.fence_action == FENCE_ACTION_NONE || - !geofence_present() || + if (!geofence_present() || (g.fence_action != FENCE_ACTION_REPORT && !geofence_state->is_enabled)) { // geo-fencing is disabled // re-arm for when the channel trigger is switched on