pressure
Fork of MPL3115A2 by
Diff: MPL3115A2.cpp
- Revision:
- 5:9edec5ee8bf4
- Parent:
- 4:fdf14a259af8
- Child:
- 6:03c24251e500
diff -r fdf14a259af8 -r 9edec5ee8bf4 MPL3115A2.cpp --- a/MPL3115A2.cpp Thu May 30 07:27:24 2013 +0000 +++ b/MPL3115A2.cpp Thu Aug 22 12:03:19 2013 +0000 @@ -309,9 +309,9 @@ float faltm; /* - * dt[0] = Bits 12-19 of 20-bit real-time Pressure sample. (b7-b0) - * 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) + * dt[0] = Bits 12-19 of 20-bit real-time Altitude sample. (b7-b0) + * dt[1] = Bits 4-11 of 20-bit real-time Altitude sample. (b7-b0) + * dt[2] = Bits 0-3 of 20-bit real-time Altitude sample (b7-b4) */ readRegs( REG_ALTIMETER_MSB, &dt[0], 3); altm = (dt[0]<<8) | dt[1]; @@ -377,6 +377,57 @@ } +unsigned int MPL3115A2::getAllDataRaw( unsigned char *dt) +{ + if ( MPL3115A2_mode == ALTIMETER_MODE) { + getAltimeterRaw( &dt[0]); // 3 bytes + } else { + getPressureRaw( &dt[0]); // 3 bytes + } + + getTemperatureRaw( &dt[3]); // 2 bytes + + return 1; +} + +unsigned int MPL3115A2::getAltimeterRaw( unsigned char *dt) +{ + + /* + * dt[0] = Bits 12-19 of 20-bit real-time Pressure sample. (b7-b0) + * 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; +} + +unsigned int MPL3115A2::getPressureRaw( unsigned char *dt) +{ + + /* + * dt[0] = Bits 12-19 of 20-bit real-time Pressure sample. (b7-b0) + * 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; +} + +unsigned int MPL3115A2::getTemperatureRaw( unsigned char *dt) +{ + + /* + * 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; +} + void MPL3115A2::readRegs(int addr, uint8_t * data, int len) { char t[1] = {addr}; m_i2c.write(m_addr, t, 1, true);