BMP180 Pressure/Temperature Sensor library

Dependents:   GliderFuncTest1 DropTest

Fork of BMP180 by Spiridion Mbed

Revision:
3:ae101ea7bd90
Parent:
2:1dad52218be5
diff -r 1dad52218be5 -r ae101ea7bd90 BMP180.cpp
--- a/BMP180.cpp	Sun Apr 09 05:05:11 2017 +0000
+++ b/BMP180.cpp	Mon Apr 24 21:34:02 2017 +0000
@@ -11,7 +11,7 @@
   Released under the MIT License (see http://mbed.org/license/mit)
 
   Documentation regarding the BMP180 can be found here:
-  
+  http://mbed.org/media/uploads/spiridion/bst-bmp180-ds000-09.pdf
 */
 
 #include "BMP180.h"
@@ -105,18 +105,20 @@
         *pPressure = m_pressure;
     if (pTemperature)
         *pTemperature = m_temperature;
-    if (pAltitude)
-        *pAltitude = getAltitude(pPressure);
-
-    return 1;
+        
+    *pAltitude = getAltitude(pPressure);
+    return 1;   
 }
 
-float BMP180::getAltitude(float* p) {
-    //return 44330.0 * (1.0 - pow((*p / m_altitude), (float)0.1903)); 
-    float altitude = (*p / m_altitude);
+float BMP180::getAltitude(float* p)
+{   /*
+    // formula for conversion directly from documentation
+    float altitude = (*p / SENSORS_PRESSURE_SEALEVELHPA);
     altitude = pow(altitude, (float)(1 / 5.255));
     altitude = 44330 * (1 - altitude);
     return altitude;
+    */
+    return 44330.0 * (1.0 - pow((float)(*p / SENSORS_PRESSURE_SEALEVELHPA), (float)0.1903));
 }
 
 int BMP180::ReadRawTemperature(long* pUt)
@@ -227,10 +229,11 @@
     x1 = (x1 * 3038) >> 16;
     x2 = (-7357 * p) >> 16;
     p = p + ((x1 + x2 + 3791) >> 4);
-
+    
     // convert to hPa and, if altitude has been initialized, to sea level pressure  
     if (m_altitude == 0.F)
         return p / 100.F;
     else
         return  p / (100.F * pow((1.F - m_altitude / 44330.0L), 5.255L)); 
+    
 }
\ No newline at end of file