Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: sensor AerCloud_MutliTech_Socket_Modem_Example Freescale_Multi-Sensor_Shield 2lemetry_Sensor_Example ... more
Fork of MPL3115A2 by
Revision 6:03c24251e500, committed 2013-08-22
- Comitter:
- clemente
- Date:
- Thu Aug 22 14:52:16 2013 +0000
- Parent:
- 5:9edec5ee8bf4
- Child:
- 7:59e9ba115d0a
- Commit message:
- Added check for data available.
Changed in this revision
| MPL3115A2.cpp | Show annotated file Show diff for this revision Revisions of this file |
| MPL3115A2.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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) {
--- a/MPL3115A2.h Thu Aug 22 12:03:19 2013 +0000
+++ b/MPL3115A2.h Thu Aug 22 14:52:16 2013 +0000
@@ -89,7 +89,7 @@
* Get the altimeter value in raw mode
*
* @param dt pointer to unsigned char array
- * @returns status as 1
+ * @returns 1 if data are available, 0 if not.
*/
unsigned int getAltimeterRaw( unsigned char *dt);
@@ -104,7 +104,7 @@
* Get the pressure value in raw mode
*
* @param dt pointer to unsigned char array
- * @returns status as 1
+ * @returns 1 if data are available, 0 if not.
*/
unsigned int getPressureRaw( unsigned char *dt);
@@ -119,7 +119,7 @@
* Get the temperature value in raw mode
*
* @param dt pointer to unsigned char array
- * @returns status as 1
+ * @returns 1 if data are available, 0 if not.
*/
unsigned int getTemperatureRaw( unsigned char *dt);
@@ -141,22 +141,23 @@
* Get the altimeter or pressure and temperature values
*
* @param array of float f[2]
- * @returns none
+ * @returns 0 no data available, 1 for data available
*/
- void getAllData( float *f);
+ unsigned int getAllData( float *f);
/**
* Get the altimeter or pressure, and temperature values in raw mode
*
* @param array of unsigned char[5]
- * @returns staus as 1
+ * @returns 1 if data are available, 0 if not.
*/
unsigned int getAllDataRaw( unsigned char *dt);
/**
* Return if there are date available
*
- * @return 1 for data available, 0 for no data available
+ * @return 0 for no data available, bit0 set for Temp data available, bit1 set for Press/Alti data available
+ * bit2 set for both Temp and Press/Alti data available
*/
unsigned int isDataAvailable( void);
