test

Dependents:   Wallet_v1

Files at this revision

API Documentation at this revision

Comitter:
kelapuresarthak
Date:
Tue Jul 30 08:59:29 2019 +0000
Parent:
4:c4d879a39775
Commit message:
test

Changed in this revision

MMA8451Q.cpp Show annotated file Show diff for this revision Revisions of this file
MMA8451Q.h Show annotated file Show diff for this revision Revisions of this file
diff -r c4d879a39775 -r 4549fb37670a MMA8451Q.cpp
--- a/MMA8451Q.cpp	Fri Oct 12 11:35:07 2012 +0000
+++ b/MMA8451Q.cpp	Tue Jul 30 08:59:29 2019 +0000
@@ -23,12 +23,17 @@
 #define REG_OUT_X_MSB     0x01
 #define REG_OUT_Y_MSB     0x03
 #define REG_OUT_Z_MSB     0x05
+#define REG_PL_STATUS     0x10
+#define REG_PL_CFG        0x11
 
 #define UINT14_MAX        16383
 
 MMA8451Q::MMA8451Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
+    
+    uint8_t controlData[2] = {REG_PL_CFG, 0x40};
+    writeRegs(controlData,2);
     // activate the peripheral
-    uint8_t data[2] = {REG_CTRL_REG_1, 0x01};
+    uint8_t data[2] = {REG_CTRL_REG_1, 0x01 | 0x04};
     writeRegs(data, 2);
 }
 
@@ -40,6 +45,13 @@
     return who_am_i;
 }
 
+uint8_t MMA8451Q::getOrientation(void) {
+  uint8_t res[1];
+  uint8_t addr = REG_PL_STATUS;
+  readRegs(addr, res, 1);
+  uint8_t ans = (res[0] & 0x07);
+  return ans;
+}
 float MMA8451Q::getAccX() {
     return (float(getAccAxis(REG_OUT_X_MSB))/4096.0);
 }
@@ -79,3 +91,4 @@
 void MMA8451Q::writeRegs(uint8_t * data, int len) {
     m_i2c.write(m_addr, (char *)data, len);
 }
+
diff -r c4d879a39775 -r 4549fb37670a MMA8451Q.h
--- a/MMA8451Q.h	Fri Oct 12 11:35:07 2012 +0000
+++ b/MMA8451Q.h	Tue Jul 30 08:59:29 2019 +0000
@@ -98,6 +98,8 @@
    */
   void getAccAllAxis(float * res);
 
+  uint8_t getOrientation(void) ;
+  
 private:
   I2C m_i2c;
   int m_addr;