Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MMA8451Q8b by
Revision 13:b58b302c53f6, committed 2017-03-15
- Comitter:
- tisbrat
- Date:
- Wed Mar 15 16:48:06 2017 +0000
- Parent:
- 12:12b18fdb72f7
- Commit message:
- MMA8451Q8g
Changed in this revision
MMA8451Q8g.cpp | Show annotated file Show diff for this revision Revisions of this file |
MMA8451Q8g.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 12b18fdb72f7 -r b58b302c53f6 MMA8451Q8g.cpp --- a/MMA8451Q8g.cpp Mon Feb 22 16:54:40 2016 +0000 +++ b/MMA8451Q8g.cpp Wed Mar 15 16:48:06 2017 +0000 @@ -17,7 +17,7 @@ */ // Modify to change full scale gravity range 141207 sc - +#include "mbed.h" #include "MMA8451Q8g.h" #define REG_WHO_AM_I 0x0D @@ -41,6 +41,9 @@ #define ADDRESS_INDEX 0 #define DATA_INDEX 1 +Serial coolt(USBTX, USBRX); + + float gScaling[3] = {4095.0,2048.0,1024.0}; //scaling for acceleration of gravity values MMA8451Q::MMA8451Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) { @@ -56,6 +59,7 @@ readRegs(REG_WHO_AM_I, &who_am_i, 1); return who_am_i; } + void MMA8451Q::setStandbyMode(){ #define ACTIVEMASK 0x01 uint8_t registerData[1]; @@ -71,12 +75,16 @@ uint8_t data[NUM_DATA] = {REG_CTRL_REG_1, 0x00}; readRegs(REG_CTRL_REG_1, registerData, 1); + //coolt.printf("REG_CTRL_1: 0x%2x\r\n", REG_CTRL_REG_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}; + coolt.printf("REG_CTRL_1: 0x%2x\r\n", REG_CTRL_REG_1); gChosen = gSelect; setStandbyMode(); data[ADDRESS_INDEX ] = XYZ_DATA_CFG; @@ -97,6 +105,15 @@ setActiveMode(); // make active } +/*void MMA8451Q::setPulseThreshold ( int axisSelect, int threshold);{ +} + +void MMA8451Q::setPulseTimeLimit (int timeLimit);{ +} + +void MMA8451Q:: setPulseLatency(int latencyTime); { +}*/ + // Make a genric register updater for those commands that need to put the // accelerometer in standby mode void MMA8451Q::setRegisterInStandby(uint8_t regAddress,uint8_t regData) {
diff -r 12b18fdb72f7 -r b58b302c53f6 MMA8451Q8g.h --- a/MMA8451Q8g.h Mon Feb 22 16:54:40 2016 +0000 +++ b/MMA8451Q8g.h Wed Mar 15 16:48:06 2017 +0000 @@ -69,7 +69,6 @@ * @returns WHO_AM_I value */ uint8_t getWhoAmI(); - /** * Get X axis acceleration * @@ -98,6 +97,7 @@ * * @param res array where acceleration data will be stored */ + void getAccAllAxis(float * res); int16_t getAccAxis(uint8_t addr); @@ -115,6 +115,10 @@ Set pulse config register **/ void setPulseConfiguration(uint8_t latch,uint8_t axisSet); + void setPulseThreshold ( int axisSelect, int threshold); + void setPulseTimeLimit (int timeLimit); + void setPulseLatency(int latencyTime); + /** Generic register set mode for those needing to be put in standby to update