mma8451q driver with a few minor modifications

Dependents:   Senet NAMote

Fork of lib_mma8451q by wayne roberts

Revision:
3:96faac0d688e
Parent:
2:4bc96749141e
Child:
4:b06535efa239
--- a/mma8451q.h	Tue Sep 01 00:27:13 2015 +0000
+++ b/mma8451q.h	Mon Mar 07 15:21:11 2016 -0500
@@ -27,6 +27,7 @@
 #define MMA8451_CTRL_REG4                  0x2d // interrupt enable
 #define MMA8451_CTRL_REG5                  0x2e // interrupt pin selection
 
+
 typedef union {
     struct {
         int16_t x;
@@ -126,6 +127,42 @@
     uint8_t octet;
 } ctrl_reg5_t;
 
+
+struct MMA_orientation
+{
+    bool up;
+    bool down;
+    bool right;
+    bool left;
+    bool front;
+    bool back;
+    bool low;
+
+    MMA_orientation()
+    {
+        reset();
+    }
+
+    inline void reset()
+    {
+        up=down=right=left=front=back=low=false;
+    }
+
+    bool operator==(const MMA_orientation &rhs)
+    {
+        return ((up == rhs.up)       && 
+                (down == rhs.down)   && 
+                (left == rhs.left)   && 
+                (front == rhs.front) && 
+                (back == rhs.back)   && 
+                (low == rhs.low));
+    }
+
+    bool operator!=(const MMA_orientation &rhs) { return !operator==(rhs); }
+
+    
+};
+
 class MMA8451Q {
     public:
         MMA8451Q(I2C& r, DigitalIn& int_pin);
@@ -141,6 +178,8 @@
         void orient_detect(void);
         uint8_t service(void); // returns 0 if no interrupt occurred
 
+        inline MMA_orientation& getOrientation() { return orientation; }
+
         bool verbose;   // print interrupt event
         mma_out_t out;
         transient_cfg_t transient_cfg;
@@ -151,5 +190,6 @@
     private:
         I2C& m_i2c;
         DigitalIn& m_int_pin;
+        MMA_orientation orientation;
 };