I2C Temprature Sensor Progemm MPL3115A2
Dependents: I2C_Temprature_raspiboard
Fork of MPL3115A2 by
Altitude.h@0:beb43bc3d6d4, 2014-04-01 (annotated)
- Committer:
- sophtware
- Date:
- Tue Apr 01 21:35:23 2014 +0000
- Revision:
- 0:beb43bc3d6d4
- Child:
- 2:2ebc9c0d4a54
Initial Checkin
Who changed what in which revision?
User | Revision | Line number | New 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 an altitude 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 ALTITUDE_H |
sophtware | 0:beb43bc3d6d4 | 13 | #define ALTITUDE_H |
sophtware | 0:beb43bc3d6d4 | 14 | |
sophtware | 0:beb43bc3d6d4 | 15 | #include "mbed.h" |
sophtware | 0:beb43bc3d6d4 | 16 | |
sophtware | 0:beb43bc3d6d4 | 17 | // Casting truncates, therefore negative numbers become positive. |
sophtware | 0:beb43bc3d6d4 | 18 | // This will only cast properly in the range -128 to 127. |
sophtware | 0:beb43bc3d6d4 | 19 | #define float_to_char(x) (((x)<0)?(-(char)(x)):((char)(x))) |
sophtware | 0:beb43bc3d6d4 | 20 | |
sophtware | 0:beb43bc3d6d4 | 21 | class Altitude |
sophtware | 0:beb43bc3d6d4 | 22 | { |
sophtware | 0:beb43bc3d6d4 | 23 | public: |
sophtware | 0:beb43bc3d6d4 | 24 | |
sophtware | 0:beb43bc3d6d4 | 25 | static const int size = 3; |
sophtware | 0:beb43bc3d6d4 | 26 | enum unitsType { METERS, FEET }; |
sophtware | 0:beb43bc3d6d4 | 27 | |
sophtware | 0:beb43bc3d6d4 | 28 | Altitude(); |
sophtware | 0:beb43bc3d6d4 | 29 | Altitude(float a, unitsType units = FEET); |
sophtware | 0:beb43bc3d6d4 | 30 | Altitude(const char* compressed); |
sophtware | 0:beb43bc3d6d4 | 31 | Altitude(const char msb, const char csb, const char lsb); |
sophtware | 0:beb43bc3d6d4 | 32 | |
sophtware | 0:beb43bc3d6d4 | 33 | operator char*(void) { return _compressed; } |
sophtware | 0:beb43bc3d6d4 | 34 | operator float(void) { return _altitude; } |
sophtware | 0:beb43bc3d6d4 | 35 | |
sophtware | 0:beb43bc3d6d4 | 36 | float altitude(unitsType units = FEET); |
sophtware | 0:beb43bc3d6d4 | 37 | void setAltitude(); |
sophtware | 0:beb43bc3d6d4 | 38 | void setAltitude(const char* compressed); |
sophtware | 0:beb43bc3d6d4 | 39 | void setAltitude(const char msb, const char csb, const char lsb); |
sophtware | 0:beb43bc3d6d4 | 40 | void setAltitude(float a, unitsType units = FEET); |
sophtware | 0:beb43bc3d6d4 | 41 | |
sophtware | 0:beb43bc3d6d4 | 42 | const char* print(unitsType units = FEET); |
sophtware | 0:beb43bc3d6d4 | 43 | |
sophtware | 0:beb43bc3d6d4 | 44 | static float MetersToFeet(float meters) { return meters * 3.28084; } |
sophtware | 0:beb43bc3d6d4 | 45 | static float FeetToMeters(float feet) { return feet / 3.28084; } |
sophtware | 0:beb43bc3d6d4 | 46 | |
sophtware | 0:beb43bc3d6d4 | 47 | private: |
sophtware | 0:beb43bc3d6d4 | 48 | float _altitude; |
sophtware | 0:beb43bc3d6d4 | 49 | char _compressed[3]; |
sophtware | 0:beb43bc3d6d4 | 50 | char _printBuffer[9]; |
sophtware | 0:beb43bc3d6d4 | 51 | }; |
sophtware | 0:beb43bc3d6d4 | 52 | |
sophtware | 0:beb43bc3d6d4 | 53 | #endif // ALTITUDE_H |