test

Dependents:   FM_integration_copy

Fork of MPL3115A2 by Michael Lange

Committer:
pyonta2017
Date:
Wed Sep 06 15:12:42 2017 +0000
Revision:
4:a9ee44b59212
Parent:
3:7c7c1ea6fc33
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sophtware 0:beb43bc3d6d4 1 /*
sophtware 0:beb43bc3d6d4 2 MPL3115A2 Barometric Pressure and Tempurature Sensor Library
sophtware 0:beb43bc3d6d4 3 By: Michael Lange
sophtware 0:beb43bc3d6d4 4 Date: March 31, 2014
sophtware 0:beb43bc3d6d4 5 License: This code is public domain.
sophtware 0:beb43bc3d6d4 6
sophtware 0:beb43bc3d6d4 7 This class encapsulates a pressure reading from the sensor.
sophtware 0:beb43bc3d6d4 8
sophtware 0:beb43bc3d6d4 9 */
sophtware 0:beb43bc3d6d4 10
sophtware 0:beb43bc3d6d4 11
sophtware 0:beb43bc3d6d4 12 #ifndef PRESSURE_H
sophtware 0:beb43bc3d6d4 13 #define PRESSURE_H
sophtware 0:beb43bc3d6d4 14
sophtware 0:beb43bc3d6d4 15 #include "mbed.h"
sophtware 0:beb43bc3d6d4 16
sophtware 3:7c7c1ea6fc33 17 //! Pressure provides a wrapper around barometric data coming from the sensor. The class handles
sophtware 3:7c7c1ea6fc33 18 //! working with compressed data from the sensor and provides convenient functions for retreiving
sophtware 3:7c7c1ea6fc33 19 //! the data in various units (with room to add more if needed).
sophtware 0:beb43bc3d6d4 20 class Pressure
sophtware 0:beb43bc3d6d4 21 {
sophtware 0:beb43bc3d6d4 22 public:
sophtware 0:beb43bc3d6d4 23
sophtware 3:7c7c1ea6fc33 24 //! The size of the compressed data buffer from the sensor. Used in an I2C read.
sophtware 0:beb43bc3d6d4 25 static const int size = 3;
sophtware 3:7c7c1ea6fc33 26
sophtware 3:7c7c1ea6fc33 27 //! The units we support converting the sensor data to.
sophtware 0:beb43bc3d6d4 28 enum unitsType { PASCALS, PSI, INHG, MMHG };
sophtware 0:beb43bc3d6d4 29
sophtware 0:beb43bc3d6d4 30 Pressure();
sophtware 0:beb43bc3d6d4 31 Pressure(float a, unitsType units = PASCALS);
sophtware 0:beb43bc3d6d4 32 Pressure(const char* compressed);
sophtware 0:beb43bc3d6d4 33 Pressure(const char msb, const char csb, const char lsb);
sophtware 0:beb43bc3d6d4 34
sophtware 3:7c7c1ea6fc33 35 //! Allows using the object directly in an I2C read operation.
sophtware 0:beb43bc3d6d4 36 operator char*(void) { return _compressed; }
sophtware 3:7c7c1ea6fc33 37 //! Same as calling pressure with PASCALS as the parameter.
sophtware 0:beb43bc3d6d4 38 operator float(void) { return _pressure; }
sophtware 0:beb43bc3d6d4 39
sophtware 0:beb43bc3d6d4 40 float pressure(unitsType units = PASCALS);
sophtware 3:7c7c1ea6fc33 41 //! Call to decompress the sensor data after an I2C read.
sophtware 0:beb43bc3d6d4 42 void setPressure();
sophtware 0:beb43bc3d6d4 43 void setPressure(const char* compressed);
sophtware 0:beb43bc3d6d4 44 void setPressure(const char msb, const char csb, const char lsb);
sophtware 0:beb43bc3d6d4 45 void setPressure(float a, unitsType units = PASCALS);
sophtware 0:beb43bc3d6d4 46
sophtware 3:7c7c1ea6fc33 47 //! Returns the pressure as a string in the units specified, defaulting to PASCAL if none specified.
sophtware 0:beb43bc3d6d4 48 const char* print(unitsType units = PASCALS);
sophtware 0:beb43bc3d6d4 49
sophtware 0:beb43bc3d6d4 50 private:
sophtware 0:beb43bc3d6d4 51 float _pressure;
sophtware 0:beb43bc3d6d4 52 char _compressed[3];
sophtware 0:beb43bc3d6d4 53 char _printBuffer[9];
sophtware 0:beb43bc3d6d4 54 };
sophtware 0:beb43bc3d6d4 55
sophtware 0:beb43bc3d6d4 56 #endif // PRESSURE_H