For experimentation NMHU Ambient computing

Dependents:   KL46z_single_tap_empty_DE_4_1_PROJECT1B_wInterrupts KL46z_single_tap_empty_DE_4_1_PROJECT1D KL46z_single_tap_generic RAHUL_KL46z_single_tap_generic_copy ... more

Fork of MMA8451Q8a by Stanley Cohen

Revision:
12:12b18fdb72f7
Parent:
9:3229b6691c89
--- a/MMA8451Q8g.cpp	Mon Feb 09 20:05:35 2015 +0000
+++ b/MMA8451Q8g.cpp	Mon Feb 22 16:54:40 2016 +0000
@@ -56,31 +56,45 @@
     readRegs(REG_WHO_AM_I, &who_am_i, 1);
     return who_am_i;
 }
+void MMA8451Q::setStandbyMode(){
+#define ACTIVEMASK 0x01
+    uint8_t registerData[1];
+    uint8_t data[NUM_DATA] = {REG_CTRL_REG_1, 0x00};
+    
+    readRegs(REG_CTRL_REG_1, registerData, 1);
+    data[1] = registerData[0] & ~ACTIVEMASK;
+    writeRegs(data, NUM_DATA); // put in standby
+}
+void MMA8451Q::setActiveMode(){
+#define ACTIVEMASK 0x01
+    uint8_t registerData[1];
+    uint8_t data[NUM_DATA] = {REG_CTRL_REG_1, 0x00};
+    
+    readRegs(REG_CTRL_REG_1, registerData, 1);
+    data[1] = registerData[0] | ACTIVEMASK;
+    writeRegs(data, NUM_DATA); // put in standby
+}
+
 void MMA8451Q::setGLimit(int gSelect) {   
     uint8_t data[NUM_DATA] = {REG_CTRL_REG_1, 0x00};
     gChosen = gSelect;
-    writeRegs(data, NUM_DATA); // put in standby
+    setStandbyMode();
     data[ADDRESS_INDEX ] = XYZ_DATA_CFG;
     data[DATA_INDEX] = gChosen;
     writeRegs(data, 2);// change g limit
-    data[ADDRESS_INDEX ] = REG_CTRL_REG_1;
-    data[DATA_INDEX] = 0x01;
-    writeRegs(data, 2); // make active
+    setActiveMode(); // make active
 }
 // add Pusle configuration register access
 // Also add function prototype to .h file
 void MMA8451Q::setPulseConfiguration(uint8_t latch,uint8_t axisSet) {
     uint8_t configBits;   
-    uint8_t data[NUM_DATA] = {REG_CTRL_REG_1, 0x00}; // put in standby mode
+    uint8_t data[NUM_DATA] = {REG_PULSE_CFG, 0x00}; // put in standby mode
 // set up configuration bits.
     configBits = latch | axisSet;
-    writeRegs(data, NUM_DATA); // put in standby
-    data[ADDRESS_INDEX ] = REG_PULSE_CFG;
+    setStandbyMode(); // put in standby
     data[DATA_INDEX] = configBits;
     writeRegs(data, NUM_DATA);
-    data[ADDRESS_INDEX ] = REG_CTRL_REG_1; // put back in active mode
-    data[DATA_INDEX] = 0x01;
-    writeRegs(data, 2); // make active
+    setActiveMode(); // make active
 }
 
 // Make a genric register updater for those commands that need to put the 
@@ -90,13 +104,11 @@
     uint8_t data[NUM_DATA] = {REG_CTRL_REG_1, 0x00}; // put in standby mode
 // set up configuration bits.
     configBits = regData;
-    writeRegs(data, NUM_DATA); // put in standby
+    setStandbyMode(); // put in standby
     data[ADDRESS_INDEX ] = regAddress;
     data[DATA_INDEX] = configBits;
     writeRegs(data, NUM_DATA);
-    data[ADDRESS_INDEX ] = REG_CTRL_REG_1; // put back in active mode
-    data[DATA_INDEX] = 0x01;
-    writeRegs(data, 2); // make active
+    setActiveMode(); // put back in active mode
 }
 
 float MMA8451Q::getAccX() {