caternuson преди 5 години
родител
ревизия
e8cb7eacf2
променени са 3 файла, в които са добавени 23 реда и са изтрити 1 реда
  1. 20 0
      Adafruit_DPS310.cpp
  2. 2 0
      Adafruit_DPS310.h
  3. 1 1
      library.properties

+ 20 - 0
Adafruit_DPS310.cpp

@@ -253,6 +253,26 @@ bool Adafruit_DPS310::pressureAvailable(void) {
   return presbit.read();
 }
 
+/**************************************************************************/
+/*!
+ * @brief Calculates the approximate altitude using barometric pressure and the
+ * supplied sea level hPa as a reference.
+ * @param seaLevelhPa
+ *        The current hPa at sea level.
+ * @return The approximate altitude above sea level in meters.
+ */
+/**************************************************************************/
+float Adafruit_DPS310::readAltitude(float seaLevelhPa) {
+
+  float altitude;
+
+  _read();
+
+  altitude = 44330 * (1.0 - pow((_pressure / 100) / seaLevelhPa, 0.1903));
+
+  return altitude;
+}
+
 /**************************************************************************/
 /*!
     @brief  Set the operational mode of the sensor (continuous or one-shot)

+ 2 - 0
Adafruit_DPS310.h

@@ -120,6 +120,8 @@ public:
   bool pressureAvailable(void);
   bool temperatureAvailable(void);
 
+  float readAltitude(float seaLevelhPa = 1013.25);
+
   Adafruit_Sensor *getTemperatureSensor(void);
   Adafruit_Sensor *getPressureSensor(void);
 

+ 1 - 1
library.properties

@@ -1,5 +1,5 @@
 name=Adafruit DPS310
-version=1.0.5
+version=1.1.0
 author=Adafruit <info@adafruit.com>
 maintainer=Adafruit <info@adafruit.com>
 sentence=Library for the Adafruit DPS310 barometric pressure sensor.