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.
Fork of MPL3115A2 by
Revision 10:82ac06669316, committed 2013-09-24
- Comitter:
- clemente
- Date:
- Tue Sep 24 20:22:25 2013 +0000
- Parent:
- 9:75a5960adf5c
- Commit message:
- Added a function to return delta values. Corrected but in case of negative numbers.
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 |
diff -r 75a5960adf5c -r 82ac06669316 MPL3115A2.cpp --- a/MPL3115A2.cpp Sun Sep 22 11:17:28 2013 +0000 +++ b/MPL3115A2.cpp Tue Sep 24 20:22:25 2013 +0000 @@ -21,6 +21,10 @@ #define REG_PRES_MAX_MSB 0x21 #define REG_ALTI_MAX_MSB 0x21 #define REG_TEMP_MAX_MSB 0x24 +#define REG_PRES_DELTA_MSB 0x07 +#define REG_ALTI_DELTA_MSB 0x07 +#define REG_TEMP_DELTA_MSB 0x0a + #define UINT14_MAX 16383 @@ -325,6 +329,25 @@ return 0; } +unsigned int MPL3115A2::getAllData( float *f, float *d) +{ + if ( isDataAvailable() & PTDR_STATUS) { + if ( MPL3115A2_mode == ALTIMETER_MODE) { + f[0] = getAltimeter(); + d[0] = getAltimeter( REG_ALTI_DELTA_MSB); + } else { + f[0] = getPressure(); + d[0] = getPressure( REG_PRES_DELTA_MSB); + } + + f[1] = getTemperature(); + d[1] = getTemperature( REG_TEMP_DELTA_MSB); + // + return 1; + } else + return 0; +} + void MPL3115A2::getAllMaximumData( float *f) { if ( MPL3115A2_mode == ALTIMETER_MODE) { @@ -359,6 +382,7 @@ { unsigned char dt[3]; unsigned short altm; + short tmp; float faltm; /* @@ -370,8 +394,9 @@ altm = (dt[0]<<8) | dt[1]; // if ( dt[0] > 0x7F) { - altm = ~altm + 1; - faltm = (float)altm * -1.0f; + // negative number + tmp = ~altm + 1; + faltm = (float)tmp * -1.0f; } else { faltm = (float)altm * 1.0f; } @@ -392,6 +417,7 @@ { unsigned char dt[3]; unsigned int prs; + int tmp; float fprs; /* @@ -400,15 +426,25 @@ * dt[2] = Bits 0-3 of 20-bit real-time Pressure sample (b7-b4) */ readRegs( reg, &dt[0], 3); - prs = (dt[0]<<10) | (dt[1]<<2) | (dt[2]>>6); + prs = ((dt[0]<<10) | (dt[1]<<2) | (dt[2]>>6)); // - fprs = (float)prs * 1.0f; - + if ( dt[0] > 0x7f) { + // negative number + if ( dt[0] & 0x80) + prs |= 0xFFFC0000; // set at 1 the bits to complete the word len + else + prs |= 0xFFFE0000; + tmp = ~prs + 1; // make the complemets. At this point all the bits are inverted. + fprs = (float)tmp * -1.0f; // set the signe.. + } else { + fprs = (float)prs * 1.0f; + } + + if ( dt[2] & 0x10) // I did some experiment to set the fractional parte. + fprs += 0.25f; // ** Warning: the DS is wrong! ** if ( dt[2] & 0x20) - fprs += 0.25f; - if ( dt[2] & 0x10) fprs += 0.5f; - + return fprs; }
diff -r 75a5960adf5c -r 82ac06669316 MPL3115A2.h --- a/MPL3115A2.h Sun Sep 22 11:17:28 2013 +0000 +++ b/MPL3115A2.h Tue Sep 24 20:22:25 2013 +0000 @@ -146,6 +146,14 @@ unsigned int getAllData( float *f); /** + * Get the altimeter or pressure and temperature values and the delta values + * + * @param array of float f[2], array of float d[2] + * @returns 0 no data available, 1 for data available + */ + unsigned int getAllData( float *f, float *d); + + /** * Get the altimeter or pressure and temperature captured maximum value * * @param array of float f[2]