Working on readReg
Fork of MPL3115A2 by
Revision 3:641510862795, committed 2018-02-27
- 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 |
diff -r c705222de18d -r 641510862795 MPL3115.cpp --- 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) {
diff -r c705222de18d -r 641510862795 MPL3115.h --- 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;