Working on readReg

Fork of MPL3115A2 by NXP

Files at this revision

API Documentation at this revision

Comitter:
csinders
Date:
Tue Feb 27 15:56:28 2018 +0000
Parent:
2:c705222de18d
Commit message:
Have a start for readReg. Need to figure out the bitshifting for it.

Changed in this revision

MPL3115.cpp Show annotated file Show diff for this revision Revisions of this file
MPL3115.h Show annotated file Show diff for this revision Revisions of this file
--- a/MPL3115.cpp	Wed Apr 26 00:10:29 2017 +0000
+++ b/MPL3115.cpp	Tue Feb 27 15:56:28 2018 +0000
@@ -50,7 +50,33 @@
       
  }
  
+ int MPL3115::readReg(int address) { 
+    int length = 8;
+    char d[1];
+    char readData[length];
+    
+    d[0] = MPL3115_STATUS;
+    MPL3115_i2c.write(MPL3115_I2C_ADDRESS,d,1,true);
+    MPL3115_i2c.read(MPL3115_I2C_ADDRESS,readData,length);
+    for (int i = 0; i < length; i++) { 
+        if (readData[i]) { 
+            printf("The readData of %d is 1\r\n",i);
+        } else {
+            printf("The readData of %d is 0\r\n",i);
+        }
+    }
+    
+    //printf("The readData is : %s\r\n", readData);
+    int returnValue = 0;
+    for (int i = 0; i < length; i++) {
+        returnValue << readData[i];
+    }
+    
+    return returnValue;
+
+}
  
+  
  
  void MPL3115::acquire_MPL3115_data_Altitude_in_m(float * alt_data)
  {
--- a/MPL3115.h	Wed Apr 26 00:10:29 2017 +0000
+++ b/MPL3115.h	Tue Feb 27 15:56:28 2018 +0000
@@ -50,6 +50,8 @@
         
     void acquire_MPL3115_data_Altitude_in_m(float * du);
     
+    int readReg(int address);
+    
     private:
     I2C MPL3115_i2c;