modified from jppang's MMA8451Q for MMA8491Q on sensor evaluation board with the FRDM-KL25Z

Dependencies:   mbed

Fork of MMA8491Q by JP PANG

Revision:
2:b79d19bdfe10
Parent:
1:2d4b7fadb1e6
Child:
3:3f5c717835c3
--- a/MMA8491Q.h	Mon Oct 14 15:00:36 2013 +0000
+++ b/MMA8491Q.h	Fri Nov 29 23:07:17 2013 +0000
@@ -55,10 +55,14 @@
   * @param sda SDA pin
   * @param sdl SCL pin
   * @param addr addr of the I2C peripheral
+  * @param en EN pin
+  * @param Xout digital output pin
+  * @param Yout digital output pin
+  * @param Zout digital output pin
   */
-  MMA8491Q(PinName sda, PinName scl, int addr);
+  MMA8491Q(PinName sda, PinName scl, int addr, PinName en);
   
- // MMA8491Q(PinName sda, PinName scl, int addr, PinName Xout, PinName Yout, PinName Zout);
+  MMA8491Q(PinName sda, PinName scl, int addr, PinName en, PinName Xout, PinName Yout, PinName Zout);
 
   /**
   * MMA8491Q destructor
@@ -66,13 +70,6 @@
   ~MMA8491Q();
 
   /**
-   * Get the value of the WHO_AM_I register
-   *
-   * @returns WHO_AM_I value
-   */
-  uint8_t getWhoAmI();
-
-  /**
    * Get X axis acceleration
    *
    * @returns X axis acceleration
@@ -97,61 +94,21 @@
    * Get XYZ axis acceleration
    *
    * @param res array where acceleration data will be stored
+   * @returns true if sensor was ready and data was read
    */
-  void getAccAllAxis(float * res);
+  uint8_t getAccAllAxis(float * res);
   
-  /** JK
-  * Setup Double Tap detection
- 
- 
-Example:
-
-#include "mbed.h"
-#include "MMA8491Q.h"
-
-#define MMA8451_I2C_ADDRESS (0x1d<<1)
-#define ON  0
-#define OFF !ON
-
-//Setup the interrupts for the MMA8491Q
-InterruptIn accInt1(PTA14);
-InterruptIn accInt2(PTA15);//not used in this prog but this is the other int from the accelorometer
-
-uint8_t togstat=0;//Led status
-DigitalOut bled(LED_BLUE);
-
-
-void tapTrue(void){//ISR
-    if(togstat == 0){
-        togstat = 1;
-        bled=ON;
-    } else {
-        togstat = 0;
-        bled=OFF;
-    }
-        
-}
-
-
-int main(void) {
-
-    MMA8491Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);//accelorometer instance
-  
-    acc.setDoubleTap();//Setup the MMA8491Q to look for a double Tap
-    accInt1.rise(&tapTrue);//call tapTrue when an interrupt is generated on PTA14
-    
-    while (true) {
-    //Interrupt driven so nothing in main loop
-    }
-}
-
-
-  */
-  void setDoubleTap(void);
 
 private:
   I2C m_i2c;
-  int m_addr;
+  int m_addr;          //MMA8491Q address
+  DigitalOut m_en;     //MMA8491Q ENABLE pin
+  PinName m_xout;
+  PinName m_yout;
+  PinName m_zout; 
+  uint8_t isDataAvailable( uint8_t mask);
+  float intAccToFloat(uint8_t * data);
+  void toggleEN(void);
   void readRegs(int addr, uint8_t * data, int len);
   void writeRegs(uint8_t * data, int len);
   int16_t getAccAxis(uint8_t addr);