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.cpp Source File

Temperature.cpp

00001 #include "Temperature.h"
00002 #include "mbed.h"
00003 
00004 Temperature::Temperature()
00005 {
00006     _temperature = 0.0;
00007 
00008     _compressed[0] = 0;
00009     _compressed[1] = 0;
00010 }
00011 
00012 Temperature::Temperature(float t, unitsType units)
00013 {
00014     setTemperature(t, units);
00015 }
00016     
00017 Temperature::Temperature(const char* compressed)
00018 {
00019     setTemperature(compressed);
00020 }
00021 
00022 Temperature::Temperature(const char msb, const char lsb)
00023 {
00024     setTemperature(msb, lsb);
00025 }
00026 
00027 void Temperature::setTemperature()
00028 {
00029     setTemperature(_compressed[0], _compressed[1]);
00030 }
00031 
00032 void Temperature::setTemperature(float t, unitsType units)
00033 {
00034     // TODO:
00035 }
00036     
00037 void Temperature::setTemperature(const char* compressed)
00038 {
00039     setTemperature(compressed[0], compressed[1]);
00040 }
00041 
00042 void Temperature::setTemperature(const char msb, const char lsb)
00043 {
00044     float templsb = (lsb>>4) / 16.0; //temp, fraction of a degree
00045     _temperature = (float)(msb + templsb);
00046 }
00047 
00048 float Temperature::temperature(unitsType units)
00049 {
00050     switch (units)
00051     {
00052         case FAHRENHEIT:
00053             return (_temperature * 9.0)/ 5.0 + 32.0;
00054         
00055         case KELVIN:
00056             return _temperature + 273.15;
00057     }
00058     
00059     return _temperature;
00060 }
00061 
00062 const char* Temperature::print(unitsType units)
00063 {
00064     sprintf(_printBuffer, "%.1f", temperature(units));
00065     return _printBuffer;
00066 }