Added code to manage Orientation, FreeFall and Motion Detection. Data is also available via IRQ.

Dependents:   Test_FRDM_MMA8451Q AccelTest FRDM-KL46-Template KL25Z_Demo ... more

Fork of MMA8451Q by Emilio Monti

Revision:
8:7e6013f11b10
Parent:
7:ba0016258d5d
Child:
9:2aa9b1668d14
--- a/MMA8451Q.h	Tue May 28 10:33:50 2013 +0000
+++ b/MMA8451Q.h	Tue May 28 17:18:30 2013 +0000
@@ -81,6 +81,11 @@
 #define PL_HYS_17       0x05    // Set Hysteresis to ±17°
 #define PL_HYS_21       0x06    // Set Hysteresis to ±21°
 #define PL_HYS_24       0x07    // Set Hysteresis to ±24°
+// Landscape/Portrait orientation
+#define cLAPO_PU        0       // Portrait Up: Equipment standing vertically in the normal orientation
+#define cLAPO_PD        1       // Portrait Down: Equipment standing vertically in the inverted orientation
+#define cLAPO_LR        2       // Landscape Right: Equipment is in landscape mode to the right
+#define cLAPO_LL        3       // Landscape Left: Equipment is in landscape mode to the left.
 
 class MMA8451Q
 {
@@ -134,10 +139,66 @@
     */
     void getAccAllAxis(float * res);
 
-    void FreFallDetection( void(*fptr)(void));
+    /**
+    * Configure the Accelerometere for free fall detection
+    *
+    * @param pointer to the user function to execute after IRQ assertion
+    * @return none
+    */
+    void FreeFallDetection( void(*fptr)(void));
+
+    /**
+    * Configure the Accelerometere for motion detection
+    *
+    * @param pointer to the user function to execute after IRQ assertion
+    * @return none
+    */
     void MotionDetection( void(*fptr)(void));
+    
+    /**
+    * Configure the Accelerometere for orientation detection
+    *
+    * @param pointer to the user function to execute after IRQ assertion
+    * @param Z lockout value, Z Backfront, Port/Landscape Thsld, Port/Landscape Hysteresis
+    * @return none
+    */
     void OrientationDetect( void(*fptr)(void), unsigned int Z_LockOut, unsigned int Z_BkFr, unsigned int PL_Thsld, unsigned int PL_Hyst);
     void OrientationDetect( void(*fptr)(void));
+       
+    /**
+    * Get the orientation state. 
+    *
+    *    0x10: PL_STATUS Register (Read Only)
+    *    Bit 7   Bit 6   Bit 5   Bit 4   Bit 3   Bit 2   Bit 1   Bit 0
+    *    NEWLP   LO      —       —       —       LAPO[1] LAPO[0] BAFRO
+    *
+    *    NEWLP
+    *        Landscape/Portrait status change flag. Default value: 0.
+    *        0: No change, 1: BAFRO and/or LAPO and/or Z-Tilt lockout value has changed
+    *    LO
+    *        Z-Tilt Angle Lockout. Default value: 0.
+    *        0: Lockout condition has not been detected.
+    *        1: Z-Tilt lockout trip angle has been exceeded. Lockout has been detected.
+    *    LAPO[1:0](*)
+    *        Landscape/Portrait orientation. Default value: 00
+    *        00: Portrait Up: Equipment standing vertically in the normal orientation
+    *        01: Portrait Down: Equipment standing vertically in the inverted orientation
+    *        10: Landscape Right: Equipment is in landscape mode to the right
+    *        11: Landscape Left: Equipment is in landscape mode to the left.
+    *        (*) The default power up state is BAFRO = 0, LAPO = 0, and LO = 0.        
+    *    BAFRO
+    *        Back or Front orientation. Default value: 0
+    *        0: Front: Equipment is in the front facing orientation.
+    *        1: Back: Equipment is in the back facing orientation.
+    */
+    unsigned char GetOrientationState( void);
+
+    /**
+    * Soft Reset
+    * @param none
+    * @return none
+    */
+    void Reset( void);
     
 private:
     I2C m_i2c;
@@ -150,6 +211,9 @@
     void Fall_IRQ( void);
     void Motion_IRQ( void);
     void Orientation_IRQ( void);
+    //
+    unsigned char OrientationState;
+    unsigned char OrientationStateUpdated;
 };
 
 #endif