From a46c60f4dedb3bc46846cce114e3bc0c315d270c Mon Sep 17 00:00:00 2001
From: Michael du Breuil <wicked.shell.scripts@gmail.com>
Date: Sun, 4 Mar 2018 17:13:48 -0700
Subject: [PATCH] AP_Airspeed: Create a singleton

---
 libraries/AP_Airspeed/AP_Airspeed.cpp | 9 +++++++++
 libraries/AP_Airspeed/AP_Airspeed.h   | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/libraries/AP_Airspeed/AP_Airspeed.cpp b/libraries/AP_Airspeed/AP_Airspeed.cpp
index ffa8f162ae..f8ba19153a 100644
--- a/libraries/AP_Airspeed/AP_Airspeed.cpp
+++ b/libraries/AP_Airspeed/AP_Airspeed.cpp
@@ -201,6 +201,11 @@ AP_Airspeed::AP_Airspeed()
         state[i].EAS2TAS = 1;
     }
     AP_Param::setup_object_defaults(this, var_info);
+
+    if (_singleton != nullptr) {
+        AP_HAL::panic("AP_Airspeed must be singleton");
+    }
+    _singleton = this;
 }
 
 
@@ -449,3 +454,7 @@ bool AP_Airspeed::all_healthy(void) const
     }
     return true;
 }
+
+// singleton instance
+AP_Airspeed *AP_Airspeed::_singleton;
+
diff --git a/libraries/AP_Airspeed/AP_Airspeed.h b/libraries/AP_Airspeed/AP_Airspeed.h
index 65df10d31e..02fbdf588f 100644
--- a/libraries/AP_Airspeed/AP_Airspeed.h
+++ b/libraries/AP_Airspeed/AP_Airspeed.h
@@ -164,8 +164,11 @@ public:
 
     // get current primary sensor
     uint8_t get_primary(void) const { return primary; }
+
+    static AP_Airspeed *get_singleton() { return _singleton; }
     
 private:
+    static AP_Airspeed *_singleton;
 
     AP_Int8 primary_sensor;