SB

Fork of MMA8451Q by Johan Kritzinger

Files at this revision

API Documentation at this revision

Comitter:
bmdlh
Date:
Sat Feb 08 22:20:08 2014 +0000
Parent:
5:2d14600116fc
Commit message:
ni men bu zhi dao

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 2d14600116fc -r f834bd401ef2 MMA8451Q.cpp
--- a/MMA8451Q.cpp	Sun Mar 10 04:34:03 2013 +0000
+++ b/MMA8451Q.cpp	Sat Feb 08 22:20:08 2014 +0000
@@ -39,7 +39,7 @@
 
 #define UINT14_MAX        16383
 
-MMA8451Q::MMA8451Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
+MMA8451Q::MMA8451Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr),dr(MMA8415Q_SAMPLE400) {
     // activate the peripheral
     uint8_t data[2] = {REG_CTRL_REG_1, 0x01};
     writeRegs(data, 2);
@@ -90,7 +90,7 @@
 
     uint8_t CTRL_REG1_Data;
 //    int adds;
-   uint8_t data[2] = {REG_CTRL_REG_1, 0x08};
+   uint8_t data[2] = {REG_CTRL_REG_1, dr};           //Sample Rate
     
     //400 Hz, Standby Mode
     writeRegs(data,2);
@@ -153,3 +153,33 @@
 void MMA8451Q::writeRegs(uint8_t * data, int len) {
     m_i2c.write(m_addr, (char *)data, len);
 }
+
+void MMA8451Q::Setdr(float dateRate)
+{
+    if (dateRate==800)
+        dr=MMA8415Q_SAMPLE800;
+    else if(dateRate==400)
+        dr=MMA8415Q_SAMPLE400;
+    else if(dateRate==200)
+        dr=MMA8415Q_SAMPLE200;
+    else if(dateRate==100)
+        dr=MMA8415Q_SAMPLE100;
+    else if(dateRate==50)
+        dr=MMA8415Q_SAMPLE50;
+    else if(dateRate==12.5)
+        dr=MMA8415Q_SAMPLE12_5;
+    else if(dateRate==6.25)
+        dr=MMA8415Q_SAMPLE6_25;
+    else if(dateRate==1.56)
+        dr=MMA8415Q_SAMPLE1_56;
+}
+
+void MMA8451Q::Overwrite_dr(float dateRate)
+{
+   Setdr(dateRate);
+//   uint8_t data[2] = {REG_CTRL_REG_1, dr};           //Sample Rate
+    
+    //400 Hz, Standby Mode
+//    writeRegs(data,2);
+    setDoubleTap();
+}
\ No newline at end of file
diff -r 2d14600116fc -r f834bd401ef2 MMA8451Q.h
--- a/MMA8451Q.h	Sun Mar 10 04:34:03 2013 +0000
+++ b/MMA8451Q.h	Sat Feb 08 22:20:08 2014 +0000
@@ -18,6 +18,14 @@
 
 #ifndef MMA8451Q_H
 #define MMA8451Q_H
+#define MMA8415Q_SAMPLE800 0x00
+#define MMA8415Q_SAMPLE400 0x08
+#define MMA8415Q_SAMPLE200 0x10
+#define MMA8415Q_SAMPLE100 0x18
+#define MMA8415Q_SAMPLE50 0x20
+#define MMA8415Q_SAMPLE12_5 0x28
+#define MMA8415Q_SAMPLE6_25 0x30
+#define MMA8415Q_SAMPLE1_56 0x38
 
 #include "mbed.h"
 
@@ -146,13 +154,15 @@
 
   */
   void setDoubleTap(void);
-
+    void Overwrite_dr(float dateRate);
+    void Setdr(float dateRate);
 private:
   I2C m_i2c;
   int m_addr;
   void readRegs(int addr, uint8_t * data, int len);
   void writeRegs(uint8_t * data, int len);
   int16_t getAccAxis(uint8_t addr);
+  char dr;
 
 };