Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MPL3115A2 by
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
Generated on Thu Jul 14 2022 01:23:11 by
1.7.2
