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 Temperature.h Source File

Temperature.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 temperature reading from the sensor.
00008  
00009  */
00010  
00011  
00012 #ifndef TEMPERATURE_H
00013 #define TEMPERATURE_H
00014 
00015 #include "mbed.h"
00016 
00017 //! Temperature provides a wrapper around temperature 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 Temperature
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 = 2;
00026 
00027     //! The units we support converting the sensor data to.
00028     enum unitsType { CELSIUS, FAHRENHEIT, KELVIN };
00029 
00030     Temperature();
00031     Temperature(float a, unitsType units = FAHRENHEIT);
00032     Temperature(const char* compressed);
00033     Temperature(const char msb, 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 temperature with FAHRENHEIT as the parameter.
00038     operator float(void) { return _temperature; }
00039 
00040     float temperature(unitsType units = FAHRENHEIT);
00041     //! Call to decompress the sensor data after an I2C read.
00042     void setTemperature();
00043     void setTemperature(const char* compressed);
00044     void setTemperature(const char msb, const char lsb);
00045     void setTemperature(float a, unitsType units = FAHRENHEIT);
00046 
00047     //! Returns the temperature as a string in the units specified, defaulting to FAHRENHEIT if none specified.
00048     const char* print(unitsType units = FAHRENHEIT);
00049     
00050 private:
00051     float _temperature;
00052     char  _compressed[2];
00053     char  _printBuffer[9];
00054 };
00055 
00056 #endif // TEMPERATURE_H