Spring 2017 PS-154L Variation with Cosmic Radiation with Shielding Material.
Fork of MPL3115A2 by
Diff: Altitude.cpp
- Revision:
- 0:beb43bc3d6d4
diff -r 000000000000 -r beb43bc3d6d4 Altitude.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Altitude.cpp Tue Apr 01 21:35:23 2014 +0000 @@ -0,0 +1,64 @@ +#include "Altitude.h" +#include "mbed.h" + +Altitude::Altitude() +{ + _altitude = 0.0; + + _compressed[0] = 0; + _compressed[1] = 0; + _compressed[2] = 0; +} + +Altitude::Altitude(float a, unitsType units) +{ + setAltitude(a, units); +} + +Altitude::Altitude(const char* compressed) +{ + setAltitude(compressed); +} + +Altitude::Altitude(const char msb, const char csb, const char lsb) +{ + setAltitude(msb, csb, lsb); +} + +void Altitude::setAltitude() +{ + setAltitude(_compressed[0], _compressed[1], _compressed[2]); +} + +void Altitude::setAltitude(float a, unitsType units) +{ + // TODO: +} + +void Altitude::setAltitude(const char* compressed) +{ + setAltitude(compressed[0], compressed[1], compressed[2]); +} + +void Altitude::setAltitude(const char msb, const char csb, const char lsb) +{ + float tempcsb = (lsb>>4) / 16.0; + _altitude = (float)((msb << 8) | csb) + tempcsb; +} + +float Altitude::altitude(unitsType units) +{ + switch (units) + { + case FEET: + return MetersToFeet(_altitude); + } + + return _altitude; +} + +const char* Altitude::print(unitsType units) +{ + sprintf(_printBuffer, "%.0f", altitude(units)); + return _printBuffer; +}