pressure
Fork of MPL3115A2 by
Diff: MPL3115A2.cpp
- Revision:
- 6:03c24251e500
- Parent:
- 5:9edec5ee8bf4
- Child:
- 7:59e9ba115d0a
diff -r 9edec5ee8bf4 -r 03c24251e500 MPL3115A2.cpp --- a/MPL3115A2.cpp Thu Aug 22 12:03:19 2013 +0000 +++ b/MPL3115A2.cpp Thu Aug 22 14:52:16 2013 +0000 @@ -15,6 +15,11 @@ #define UINT14_MAX 16383 +// Status flag for data ready. +#define PTDR_STATUS 0x03 // Pressure Altitude and Temperature ready +#define PDR_STATUS 0x02 // Pressure and Altitude data ready +#define TDR_STATUS 0x01 // Temperature data ready + /** Interrupt schema * * :: The Altitude Trigger use the IRQ1. @@ -274,12 +279,8 @@ unsigned char status; readRegs( REG_STATUS, &status, 1); - - if ( status & 0x08) { - return 1; - } else { - return 0; - } + + return ((status>>1)); } @@ -291,15 +292,20 @@ return status; } -void MPL3115A2::getAllData( float *f) +unsigned int MPL3115A2::getAllData( float *f) { - if ( MPL3115A2_mode == ALTIMETER_MODE) { - f[0] = getAltimeter(); - } else { - f[0] = getPressure(); - } - - f[1] = getTemperature(); + if ( isDataAvailable() & PTDR_STATUS) { + if ( MPL3115A2_mode == ALTIMETER_MODE) { + f[0] = getAltimeter(); + } else { + f[0] = getPressure(); + } + + f[1] = getTemperature(); + // + return 1; + } else + return 0; } float MPL3115A2::getAltimeter( void) @@ -379,15 +385,20 @@ unsigned int MPL3115A2::getAllDataRaw( unsigned char *dt) { - if ( MPL3115A2_mode == ALTIMETER_MODE) { - getAltimeterRaw( &dt[0]); // 3 bytes + // Check for Press/Alti and Temp value ready + if ( isDataAvailable() & PTDR_STATUS) { + if ( MPL3115A2_mode == ALTIMETER_MODE) { + getAltimeterRaw( &dt[0]); // 3 bytes + } else { + getPressureRaw( &dt[0]); // 3 bytes + } + + getTemperatureRaw( &dt[3]); // 2 bytes + + return 1; } else { - getPressureRaw( &dt[0]); // 3 bytes + return 0; } - - getTemperatureRaw( &dt[3]); // 2 bytes - - return 1; } unsigned int MPL3115A2::getAltimeterRaw( unsigned char *dt) @@ -398,9 +409,13 @@ * dt[1] = Bits 4-11 of 20-bit real-time Pressure sample. (b7-b0) * dt[2] = Bits 0-3 of 20-bit real-time Pressure sample (b7-b4) */ - readRegs( REG_ALTIMETER_MSB, &dt[0], 3); - - return 1; + + // Check for Press/Alti value ready + if ( isDataAvailable() & PDR_STATUS) { + readRegs( REG_ALTIMETER_MSB, &dt[0], 3); + return 1; + } else + return 0; } unsigned int MPL3115A2::getPressureRaw( unsigned char *dt) @@ -411,9 +426,14 @@ * dt[1] = Bits 4-11 of 20-bit real-time Pressure sample. (b7-b0) * dt[2] = Bits 0-3 of 20-bit real-time Pressure sample (b7-b4) */ - readRegs( REG_PRESSURE_MSB, &dt[0], 3); - - return 1; + + // Check for Press/Alti value ready + if ( isDataAvailable() & PDR_STATUS) { + readRegs( REG_PRESSURE_MSB, &dt[0], 3); + return 1; + } else + return 0; + } unsigned int MPL3115A2::getTemperatureRaw( unsigned char *dt) @@ -423,9 +443,13 @@ * dt[0] = Bits 4-11 of 16-bit real-time temperature sample. (b7-b0) * dt[1] = Bits 0-3 of 16-bit real-time temperature sample. (b7-b4) */ - readRegs( REG_TEMP_MSB, &dt[0], 2); - - return 1; + + // Check for Temp value ready + if ( isDataAvailable() & TDR_STATUS) { + readRegs( REG_TEMP_MSB, &dt[0], 2); + return 1; + } else + return 0; } void MPL3115A2::readRegs(int addr, uint8_t * data, int len) {