MPL sensor
Fork of MPL3115A2 by
MPL3115A2.h@0:cfecfabc5e23, 2013-05-23 (annotated)
- Committer:
- clemente
- Date:
- Thu May 23 06:42:15 2013 +0000
- Revision:
- 0:cfecfabc5e23
- Child:
- 1:30a04f651efe
First version. Under development.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
clemente | 0:cfecfabc5e23 | 1 | #ifndef MPL3115A2_H |
clemente | 0:cfecfabc5e23 | 2 | #define MPL3115A2_H |
clemente | 0:cfecfabc5e23 | 3 | |
clemente | 0:cfecfabc5e23 | 4 | #include "mbed.h" |
clemente | 0:cfecfabc5e23 | 5 | |
clemente | 0:cfecfabc5e23 | 6 | /* Oversampling */ |
clemente | 0:cfecfabc5e23 | 7 | #define OVERSAMPLE_RATIO_1 0 |
clemente | 0:cfecfabc5e23 | 8 | #define OVERSAMPLE_RATIO_2 1 |
clemente | 0:cfecfabc5e23 | 9 | #define OVERSAMPLE_RATIO_4 2 |
clemente | 0:cfecfabc5e23 | 10 | #define OVERSAMPLE_RATIO_8 3 |
clemente | 0:cfecfabc5e23 | 11 | #define OVERSAMPLE_RATIO_16 4 |
clemente | 0:cfecfabc5e23 | 12 | #define OVERSAMPLE_RATIO_32 5 |
clemente | 0:cfecfabc5e23 | 13 | #define OVERSAMPLE_RATIO_64 6 |
clemente | 0:cfecfabc5e23 | 14 | #define OVERSAMPLE_RATIO_128 7 |
clemente | 0:cfecfabc5e23 | 15 | |
clemente | 0:cfecfabc5e23 | 16 | /* Mode */ |
clemente | 0:cfecfabc5e23 | 17 | #define ALTIMETER_MODE 1 |
clemente | 0:cfecfabc5e23 | 18 | #define BAROMETRIC_MODE 2 |
clemente | 0:cfecfabc5e23 | 19 | |
clemente | 0:cfecfabc5e23 | 20 | /** |
clemente | 0:cfecfabc5e23 | 21 | * MPL3115A2 Altimeter example |
clemente | 0:cfecfabc5e23 | 22 | * |
clemente | 0:cfecfabc5e23 | 23 | * @code |
clemente | 0:cfecfabc5e23 | 24 | * #include "mbed.h" |
clemente | 0:cfecfabc5e23 | 25 | * #include "MPL3115A2.h" |
clemente | 0:cfecfabc5e23 | 26 | * |
clemente | 0:cfecfabc5e23 | 27 | * #define MPL3115A2_I2C_ADDRESS (0x60<<1) |
clemente | 0:cfecfabc5e23 | 28 | * MPL3115A2 altimeter(PTE0, PTE1, MPL3115A2_I2C_ADDRESS); |
clemente | 0:cfecfabc5e23 | 29 | * Serial pc(USBTX, USBRX); |
clemente | 0:cfecfabc5e23 | 30 | * |
clemente | 0:cfecfabc5e23 | 31 | * int main(void) { |
clemente | 0:cfecfabc5e23 | 32 | * |
clemente | 0:cfecfabc5e23 | 33 | * pc.baud( 230400); |
clemente | 0:cfecfabc5e23 | 34 | * pc.printf("MPL3115A2 Altimeter mode. [%d]\r\n", wigo_sensor1.getDeviceID()); |
clemente | 0:cfecfabc5e23 | 35 | * |
clemente | 0:cfecfabc5e23 | 36 | * wigo_sensor1.Oversample_Ratio( OVERSAMPLE_RATIO_32); |
clemente | 0:cfecfabc5e23 | 37 | * |
clemente | 0:cfecfabc5e23 | 38 | * while(1) { |
clemente | 0:cfecfabc5e23 | 39 | * // |
clemente | 0:cfecfabc5e23 | 40 | * if ( wigo_sensor1.isDataAvailable()) { |
clemente | 0:cfecfabc5e23 | 41 | * wigo_sensor1.getAllData( &sensor_data[0]); |
clemente | 0:cfecfabc5e23 | 42 | * pc.printf("\Altitude: %f\tTemperature: %f\r\n", sensor_data[0], sensor_data[1]); |
clemente | 0:cfecfabc5e23 | 43 | * } |
clemente | 0:cfecfabc5e23 | 44 | * // |
clemente | 0:cfecfabc5e23 | 45 | * wait( 0.001); |
clemente | 0:cfecfabc5e23 | 46 | * } |
clemente | 0:cfecfabc5e23 | 47 | * |
clemente | 0:cfecfabc5e23 | 48 | * } |
clemente | 0:cfecfabc5e23 | 49 | * @endcode |
clemente | 0:cfecfabc5e23 | 50 | */ |
clemente | 0:cfecfabc5e23 | 51 | class MPL3115A2 |
clemente | 0:cfecfabc5e23 | 52 | { |
clemente | 0:cfecfabc5e23 | 53 | public: |
clemente | 0:cfecfabc5e23 | 54 | /** |
clemente | 0:cfecfabc5e23 | 55 | * MPL3115A2 constructor |
clemente | 0:cfecfabc5e23 | 56 | * |
clemente | 0:cfecfabc5e23 | 57 | * @param sda SDA pin |
clemente | 0:cfecfabc5e23 | 58 | * @param sdl SCL pin |
clemente | 0:cfecfabc5e23 | 59 | * @param addr addr of the I2C peripheral |
clemente | 0:cfecfabc5e23 | 60 | */ |
clemente | 0:cfecfabc5e23 | 61 | MPL3115A2(PinName sda, PinName scl, int addr); |
clemente | 0:cfecfabc5e23 | 62 | |
clemente | 0:cfecfabc5e23 | 63 | /** |
clemente | 0:cfecfabc5e23 | 64 | * Get the value of the WHO_AM_I register |
clemente | 0:cfecfabc5e23 | 65 | * |
clemente | 0:cfecfabc5e23 | 66 | * @returns DEVICE_ID value == 0xC4 |
clemente | 0:cfecfabc5e23 | 67 | */ |
clemente | 0:cfecfabc5e23 | 68 | uint8_t getDeviceID(); |
clemente | 0:cfecfabc5e23 | 69 | |
clemente | 0:cfecfabc5e23 | 70 | /** |
clemente | 0:cfecfabc5e23 | 71 | * Return the STATUS register value |
clemente | 0:cfecfabc5e23 | 72 | * |
clemente | 0:cfecfabc5e23 | 73 | * @returns STATUS register value |
clemente | 0:cfecfabc5e23 | 74 | */ |
clemente | 0:cfecfabc5e23 | 75 | unsigned char getStatus( void); |
clemente | 0:cfecfabc5e23 | 76 | |
clemente | 0:cfecfabc5e23 | 77 | /** |
clemente | 0:cfecfabc5e23 | 78 | * Get the altimeter value |
clemente | 0:cfecfabc5e23 | 79 | * |
clemente | 0:cfecfabc5e23 | 80 | * @returns altimeter value as float |
clemente | 0:cfecfabc5e23 | 81 | */ |
clemente | 0:cfecfabc5e23 | 82 | float getAltimeter( void); |
clemente | 0:cfecfabc5e23 | 83 | |
clemente | 0:cfecfabc5e23 | 84 | /** |
clemente | 0:cfecfabc5e23 | 85 | * Get the pressure value |
clemente | 0:cfecfabc5e23 | 86 | * |
clemente | 0:cfecfabc5e23 | 87 | * @returns pressure value as float |
clemente | 0:cfecfabc5e23 | 88 | */ |
clemente | 0:cfecfabc5e23 | 89 | float getPressure( void); |
clemente | 0:cfecfabc5e23 | 90 | |
clemente | 0:cfecfabc5e23 | 91 | /** |
clemente | 0:cfecfabc5e23 | 92 | * Get the temperature value |
clemente | 0:cfecfabc5e23 | 93 | * |
clemente | 0:cfecfabc5e23 | 94 | * @returns temperature value as float |
clemente | 0:cfecfabc5e23 | 95 | */ |
clemente | 0:cfecfabc5e23 | 96 | float getTemperature( void); |
clemente | 0:cfecfabc5e23 | 97 | |
clemente | 0:cfecfabc5e23 | 98 | /** |
clemente | 0:cfecfabc5e23 | 99 | * Set the Altimeter Mode |
clemente | 0:cfecfabc5e23 | 100 | * |
clemente | 0:cfecfabc5e23 | 101 | * @returns none |
clemente | 0:cfecfabc5e23 | 102 | */ |
clemente | 0:cfecfabc5e23 | 103 | void Altimeter_Mode( void); |
clemente | 0:cfecfabc5e23 | 104 | |
clemente | 0:cfecfabc5e23 | 105 | /** |
clemente | 0:cfecfabc5e23 | 106 | * Set the Barometric Mode |
clemente | 0:cfecfabc5e23 | 107 | * |
clemente | 0:cfecfabc5e23 | 108 | * @returns none |
clemente | 0:cfecfabc5e23 | 109 | */ |
clemente | 0:cfecfabc5e23 | 110 | void Barometric_Mode( void); |
clemente | 0:cfecfabc5e23 | 111 | |
clemente | 0:cfecfabc5e23 | 112 | /** |
clemente | 0:cfecfabc5e23 | 113 | * Get the altimeter, pressure and temperature values |
clemente | 0:cfecfabc5e23 | 114 | * |
clemente | 0:cfecfabc5e23 | 115 | * @param array of float f[3] |
clemente | 0:cfecfabc5e23 | 116 | * @returns none |
clemente | 0:cfecfabc5e23 | 117 | */ |
clemente | 0:cfecfabc5e23 | 118 | void getAllData( float *f); |
clemente | 0:cfecfabc5e23 | 119 | |
clemente | 0:cfecfabc5e23 | 120 | /** Return is there are date available |
clemente | 0:cfecfabc5e23 | 121 | * |
clemente | 0:cfecfabc5e23 | 122 | * @return 1 for data available, 0 for no data available |
clemente | 0:cfecfabc5e23 | 123 | */ |
clemente | 0:cfecfabc5e23 | 124 | unsigned int isDataAvailable( void); |
clemente | 0:cfecfabc5e23 | 125 | |
clemente | 0:cfecfabc5e23 | 126 | /** Set the oversampling rate value |
clemente | 0:cfecfabc5e23 | 127 | * |
clemente | 0:cfecfabc5e23 | 128 | * @param oversampling values. See MPL3115A2.h |
clemente | 0:cfecfabc5e23 | 129 | * @return none |
clemente | 0:cfecfabc5e23 | 130 | */ |
clemente | 0:cfecfabc5e23 | 131 | void Oversample_Ratio( unsigned int ratio); |
clemente | 0:cfecfabc5e23 | 132 | |
clemente | 0:cfecfabc5e23 | 133 | private: |
clemente | 0:cfecfabc5e23 | 134 | I2C m_i2c; |
clemente | 0:cfecfabc5e23 | 135 | int m_addr; |
clemente | 0:cfecfabc5e23 | 136 | unsigned char MPL3115A2_mode; |
clemente | 0:cfecfabc5e23 | 137 | unsigned char MPL3115A2_oversampling; |
clemente | 0:cfecfabc5e23 | 138 | |
clemente | 0:cfecfabc5e23 | 139 | /** Set the device in active mode |
clemente | 0:cfecfabc5e23 | 140 | */ |
clemente | 0:cfecfabc5e23 | 141 | void Active( void); |
clemente | 0:cfecfabc5e23 | 142 | |
clemente | 0:cfecfabc5e23 | 143 | /** Set the device in standby mode |
clemente | 0:cfecfabc5e23 | 144 | */ |
clemente | 0:cfecfabc5e23 | 145 | void Standby( void); |
clemente | 0:cfecfabc5e23 | 146 | |
clemente | 0:cfecfabc5e23 | 147 | void readRegs(int addr, uint8_t * data, int len); |
clemente | 0:cfecfabc5e23 | 148 | void writeRegs(uint8_t * data, int len); |
clemente | 0:cfecfabc5e23 | 149 | |
clemente | 0:cfecfabc5e23 | 150 | }; |
clemente | 0:cfecfabc5e23 | 151 | |
clemente | 0:cfecfabc5e23 | 152 | #endif |