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

Altitude.cpp

00001 #include "Altitude.h"
00002 #include "mbed.h"
00003 
00004 Altitude::Altitude()
00005 {
00006     _altitude = 0.0;
00007 
00008     _compressed[0] = 0;
00009     _compressed[1] = 0;
00010     _compressed[2] = 0;
00011 }
00012 
00013 Altitude::Altitude(float a, unitsType units)
00014 {
00015     setAltitude(a, units);
00016 }
00017     
00018 Altitude::Altitude(const char* compressed)
00019 {
00020     setAltitude(compressed);
00021 }
00022 
00023 Altitude::Altitude(const char msb, const char csb, const char lsb)
00024 {
00025     setAltitude(msb, csb, lsb);
00026 }
00027 
00028 void Altitude::setAltitude()
00029 {
00030     setAltitude(_compressed[0], _compressed[1], _compressed[2]);
00031 }
00032 
00033 void Altitude::setAltitude(float a, unitsType units)
00034 {
00035     // TODO:
00036 }
00037     
00038 void Altitude::setAltitude(const char* compressed)
00039 {
00040     setAltitude(compressed[0], compressed[1], compressed[2]);
00041 }
00042 
00043 void Altitude::setAltitude(const char msb, const char csb, const char lsb)
00044 {
00045     float tempcsb = (lsb>>4) / 16.0;
00046     _altitude = (float)((msb << 8) | csb) + tempcsb;
00047 }
00048 
00049 float Altitude::altitude(unitsType units)
00050 {
00051     switch (units)
00052     {
00053         case FEET:
00054             return MetersToFeet(_altitude);
00055     }
00056     
00057     return _altitude;
00058 }
00059 
00060 const char* Altitude::print(unitsType units)
00061 {
00062     sprintf(_printBuffer, "%.0f", altitude(units));
00063     return _printBuffer;
00064 }