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 wayne roberts

Files at this revision

API Documentation at this revision

Comitter:
dudmuck
Date:
Fri May 08 01:32:04 2015 +0000
Parent:
0:6bba2efea51e
Child:
2:0eb8b0ad292b
Commit message:
set INT pin to open-drain

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	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              
+    }
+            
+}
--- a/mpl3115a2.h	Wed Mar 18 01:00:53 2015 +0000
+++ b/mpl3115a2.h	Fri May 08 01:32:04 2015 +0000
@@ -63,15 +63,29 @@
 #define OFF_T_REG             0x2C // Temperature data offset 
 #define OFF_H_REG             0x2D // Altitude data offset
 
+typedef union { 
+    struct {    // at 0x
+        uint8_t SRC_TCHG    : 1;    // 0
+        uint8_t SRC_PCHG    : 1;    // 1
+        uint8_t SRC_TTH     : 1;    // 2
+        uint8_t SRC_PTH     : 1;    // 3
+        uint8_t SRC_TW      : 1;    // 4
+        uint8_t SRC_PW      : 1;    // 5
+        uint8_t SRC_FIFO    : 1;    // 6
+        uint8_t SRC_DRDY    : 1;    // 7
+    } bits;
+    uint8_t octet;
+} mpl_int_source_t;
+
 class MPL3115A2 {
     public:
-        MPL3115A2(I2C& r);
+        MPL3115A2(I2C& r, DigitalIn& int_pin);
         ~MPL3115A2();
-        //void try_read(void);
         void write(uint8_t reg_addr, uint8_t reg_value);
         void init(void);
         uint8_t read(uint8_t a);
         void SetModeActive(void);
+        bool GetModeActive(void);
         void SetModeStandby(void);
         float ReadAltitude( void );
         float ReadTemperature( void );
@@ -79,9 +93,12 @@
         void ToggleOneShot( void );
         float Altitude;
         float Temperature;
+        void service(void);
 
     private:
         I2C& m_i2c;
+        DigitalIn& m_int_pin;
+        uint8_t ctrl_reg4;
 };