Commented debug printfs
Dependents: LoRaWAN-NAMote72-Application-Demo_IoTium LoRaWAN-NAMote72-BVS-confirmed-tester-0-7v1_copy LoRaWAN-NAMote72-Application-Demo-good LoRaWAN-NAMote72-Application-Demo
Fork of lib_mpl3115a2 by
Diff: mpl3115a2.cpp
- Revision:
- 1:3cd1f21925e8
- Parent:
- 0:6bba2efea51e
- Child:
- 2:0eb8b0ad292b
--- a/mpl3115a2.cpp Wed Mar 18 01:00:53 2015 +0000 +++ b/mpl3115a2.cpp Fri May 08 01:32:04 2015 +0000 @@ -2,9 +2,9 @@ #define MPL3115A_I2C_ADDRESS 0xc0 //0x60 - -MPL3115A2::MPL3115A2(I2C& r) : m_i2c(r) +MPL3115A2::MPL3115A2(I2C& r, DigitalIn& int_pin) : m_i2c(r), m_int_pin(int_pin) { + write(CTRL_REG3, 0x10); // PP_OD1: INT1 to open-drain } MPL3115A2::~MPL3115A2() @@ -36,6 +36,11 @@ SetModeActive( ); } +bool MPL3115A2::GetModeActive( ) +{ + return read(CTRL_REG1) & 1; +} + void MPL3115A2::SetModeActive( ) { uint8_t val = read(CTRL_REG1); @@ -58,7 +63,10 @@ cmd[1] = d; if (m_i2c.write(MPL3115A_I2C_ADDRESS, cmd, 2)) - printf("write-fail %02x %02x\n", cmd[0], cmd[1]); + printf("MPL write-fail %02x %02x\n", cmd[0], cmd[1]); + + if (a == CTRL_REG4) + ctrl_reg4 = d; } uint8_t MPL3115A2::read(uint8_t a) @@ -67,25 +75,16 @@ cmd[0] = a; if (m_i2c.write(MPL3115A_I2C_ADDRESS, cmd, 1, true)) - printf("write-fail %02x\n", cmd[0]); + printf("MPL write-fail %02x\n", cmd[0]); if (m_i2c.read(MPL3115A_I2C_ADDRESS, cmd, 1)) - printf("read-fail\n"); - //printf("MPL3115::try_read: %x\n", cmd[0]); + printf("MPL read-fail\n"); + + if (a == CTRL_REG4) + ctrl_reg4 = cmd[0]; + return cmd[0]; } -/*void MPL3115A2::try_read() -{ - char cmd[2]; - - cmd[0] = MPL3115_ID; - if (m_i2c.write(MPL3115A_I2C_ADDRESS, cmd, 1, true)) - printf("write-fail try_read\n"); - if (m_i2c.read(MPL3115A_I2C_ADDRESS, cmd, 1)) - printf("read-fail\n"); - printf("MPL3115::try_read: %x\n", cmd[0]); -}*/ - float MPL3115A2::ReadAltitude( void ) { uint8_t counter = 0; @@ -121,6 +120,7 @@ counter++; if( counter > 20 ) { + write( CTRL_REG4, 0x00 ); return( 0 ); //Error out after max of 512ms for a read } } @@ -134,6 +134,8 @@ decimal = ( ( float )( lsb >> 4 ) ) / 16.0; //Altitude = ( float )( ( msb << 8 ) | csb ) + decimal; Altitude = ( float )( ( int16_t )( ( msb << 8 ) | csb ) ) + decimal; + + write( CTRL_REG4, 0x00 ); return( Altitude ); } @@ -202,6 +204,7 @@ if( counter > 20 ) { + write( CTRL_REG4, 0x00 ); return( 0 ); //Error out after max of 512ms for a read } } @@ -231,7 +234,44 @@ ToggleOneShot( ); + write( CTRL_REG4, 0x00 ); + return( Temperature ); } - +void MPL3115A2::service() +{ + mpl_int_source_t int_src; + + if ((ctrl_reg4 == 0x00) || m_int_pin) // if no interrupts enabled and no interrupt occuring + return; + + int_src.octet = read(INT_SOURCE_REG); + + if (int_src.bits.SRC_TCHG) { + } + if (int_src.bits.SRC_PCHG) { + } + if (int_src.bits.SRC_TTH) { + } + if (int_src.bits.SRC_PTH) { + } + if (int_src.bits.SRC_TW) { + } + if (int_src.bits.SRC_PW) { + } + if (int_src.bits.SRC_FIFO) { + read(F_STATUS_REG); + } + if (int_src.bits.SRC_DRDY) { + read(STATUS_REG); + + read( OUT_T_MSB_REG); // Integer part of temperature + read( OUT_T_LSB_REG); // Decimal part of temperature in bits 7-4 + + read( OUT_P_MSB_REG); // High byte of integer part of altitude, + read( OUT_P_CSB_REG); // Low byte of integer part of altitude + read( OUT_P_LSB_REG); // Decimal part of altitude in bits 7-4 + } + +}