Library to wrapper most of the functions on the MPL3115A2 pressure and temperature sensor.

Dependents:   WeatherBalloon4180 WeatherBalloon4180 mbed_rifletool Smart_Watch_4180_Final_Design ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Pressure.h Source File

Pressure.h

00001 /*
00002     MPL3115A2 Barometric Pressure and Tempurature Sensor Library
00003     By: Michael Lange
00004     Date: March 31, 2014
00005     License: This code is public domain.
00006  
00007     This class encapsulates a pressure reading from the sensor.
00008  
00009  */
00010  
00011  
00012 #ifndef PRESSURE_H
00013 #define PRESSURE_H
00014 
00015 #include "mbed.h"
00016 
00017 //! Pressure provides a wrapper around barometric data coming from the sensor. The class handles
00018 //! working with compressed data from the sensor and provides convenient functions for retreiving
00019 //! the data in various units (with room to add more if needed).
00020 class Pressure
00021 {
00022 public:
00023 
00024     //! The size of the compressed data buffer from the sensor. Used in an I2C read.
00025     static const int size = 3;
00026 
00027     //! The units we support converting the sensor data to.
00028     enum unitsType { PASCALS, PSI, INHG, MMHG };
00029 
00030     Pressure();
00031     Pressure(float a, unitsType units = PASCALS);
00032     Pressure(const char* compressed);
00033     Pressure(const char msb, const char csb, const char lsb);
00034 
00035     //! Allows using the object directly in an I2C read operation.
00036     operator char*(void) { return _compressed; }
00037     //! Same as calling pressure with PASCALS as the parameter.
00038     operator float(void) { return _pressure; }
00039 
00040     float pressure(unitsType units = PASCALS);
00041     //! Call to decompress the sensor data after an I2C read.
00042     void setPressure();
00043     void setPressure(const char* compressed);
00044     void setPressure(const char msb, const char csb, const char lsb);
00045     void setPressure(float a, unitsType units = PASCALS);
00046 
00047     //! Returns the pressure as a string in the units specified, defaulting to PASCAL if none specified.
00048     const char* print(unitsType units = PASCALS);
00049     
00050 private:
00051     float _pressure;
00052     char  _compressed[3];
00053     char  _printBuffer[9];
00054 };
00055 
00056 #endif // PRESSURE_H