Jim Carver / MMA8451Q

Dependencies:   MotionSensor

Dependents:   KL46_eCompass KL46_eCompass_TiltCompensed_Acel-Mag Ragnarok_2ejes compass_acc ... more

Fork of MMA8451Q by Emilio Monti

Files at this revision

API Documentation at this revision

Comitter:
JimCarver
Date:
Mon Apr 07 21:03:37 2014 +0000
Parent:
4:c4d879a39775
Child:
6:d3f7851ff32e
Commit message:
Added function to retrieve raw data from sensor

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
--- a/MMA8451Q.cpp	Fri Oct 12 11:35:07 2012 +0000
+++ b/MMA8451Q.cpp	Mon Apr 07 21:03:37 2014 +0000
@@ -32,6 +32,7 @@
     writeRegs(data, 2);
 }
 
+
 MMA8451Q::~MMA8451Q() { }
 
 uint8_t MMA8451Q::getWhoAmI() {
@@ -52,12 +53,32 @@
     return (float(getAccAxis(REG_OUT_Z_MSB))/4096.0);
 }
 
+
 void MMA8451Q::getAccAllAxis(float * res) {
     res[0] = getAccX();
     res[1] = getAccY();
     res[2] = getAccZ();
 }
 
+void MMA8451Q::getAccXYZraw(int16_t * d) {
+    int16_t acc;
+    uint8_t res[6];
+    readRegs(REG_OUT_X_MSB, res, 6);
+
+    acc = (res[0] << 6) | (res[1] >> 2);
+    if (acc > UINT14_MAX/2)
+        acc -= UINT14_MAX;
+    d[0] = acc;
+    acc = (res[2] << 6) | (res[3] >> 2);
+    if (acc > UINT14_MAX/2)
+        acc -= UINT14_MAX;
+    d[1] = acc;
+    acc = (res[4] << 6) | (res[5] >> 2);
+    if (acc > UINT14_MAX/2)
+        acc -= UINT14_MAX;
+    d[2] = acc;
+}
+
 int16_t MMA8451Q::getAccAxis(uint8_t addr) {
     int16_t acc;
     uint8_t res[2];
--- a/MMA8451Q.h	Fri Oct 12 11:35:07 2012 +0000
+++ b/MMA8451Q.h	Mon Apr 07 21:03:37 2014 +0000
@@ -97,7 +97,7 @@
    * @param res array where acceleration data will be stored
    */
   void getAccAllAxis(float * res);
-
+  void getAccXYZraw(int16_t * d);
 private:
   I2C m_i2c;
   int m_addr;