test

Fork of MPL3115A2 by Michael Lange

Committer:
pyonta2017
Date:
Tue Sep 05 14:54:16 2017 +0000
Revision:
4:249d5270511d
Parent:
3:7c7c1ea6fc33
test

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 temperature 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 TEMPERATURE_H
sophtware 0:beb43bc3d6d4 13 #define TEMPERATURE_H
sophtware 0:beb43bc3d6d4 14
sophtware 0:beb43bc3d6d4 15 #include "mbed.h"
sophtware 0:beb43bc3d6d4 16
sophtware 3:7c7c1ea6fc33 17 //! Temperature provides a wrapper around temperature 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 Temperature
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 = 2;
sophtware 3:7c7c1ea6fc33 26
sophtware 3:7c7c1ea6fc33 27 //! The units we support converting the sensor data to.
sophtware 0:beb43bc3d6d4 28 enum unitsType { CELSIUS, FAHRENHEIT, KELVIN };
sophtware 0:beb43bc3d6d4 29
sophtware 0:beb43bc3d6d4 30 Temperature();
pyonta2017 4:249d5270511d 31 Temperature(float a, unitsType units = CELSIUS);
sophtware 0:beb43bc3d6d4 32 Temperature(const char* compressed);
sophtware 0:beb43bc3d6d4 33 Temperature(const char msb, 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 temperature with FAHRENHEIT as the parameter.
sophtware 0:beb43bc3d6d4 38 operator float(void) { return _temperature; }
sophtware 0:beb43bc3d6d4 39
pyonta2017 4:249d5270511d 40 float temperature(unitsType units = CELSIUS);
sophtware 3:7c7c1ea6fc33 41 //! Call to decompress the sensor data after an I2C read.
sophtware 0:beb43bc3d6d4 42 void setTemperature();
sophtware 0:beb43bc3d6d4 43 void setTemperature(const char* compressed);
sophtware 0:beb43bc3d6d4 44 void setTemperature(const char msb, const char lsb);
pyonta2017 4:249d5270511d 45 void setTemperature(float a, unitsType units = CELSIUS);
sophtware 0:beb43bc3d6d4 46
sophtware 3:7c7c1ea6fc33 47 //! Returns the temperature as a string in the units specified, defaulting to FAHRENHEIT if none specified.
pyonta2017 4:249d5270511d 48 const char* print(unitsType units = CELSIUS);
sophtware 0:beb43bc3d6d4 49
sophtware 0:beb43bc3d6d4 50 private:
sophtware 0:beb43bc3d6d4 51 float _temperature;
sophtware 0:beb43bc3d6d4 52 char _compressed[2];
sophtware 0:beb43bc3d6d4 53 char _printBuffer[9];
sophtware 0:beb43bc3d6d4 54 };
sophtware 0:beb43bc3d6d4 55
sophtware 0:beb43bc3d6d4 56 #endif // TEMPERATURE_H