Modification to FXOS8700Q for use in Data Logger project
Dependencies: FXOS8700Q MotionSensor
Dependents: GPS_6Axis_DataLogger_SD_UDP
Fork of FXOS8700Q by
Diff: FXOS8700Q.h
- Revision:
- 1:8b53edef272f
- Parent:
- 0:2562215f5bc0
- Child:
- 2:ab84f99086e5
- Child:
- 3:eb1271ef90bc
--- a/FXOS8700Q.h Mon Apr 07 00:58:50 2014 +0000 +++ b/FXOS8700Q.h Sun Apr 13 21:22:58 2014 +0000 @@ -3,62 +3,87 @@ #include "mbed.h" // FXOS8700CQ I2C address -#define FXOS8700CQ_SLAVE_ADDR 0x3C // with pins SA0=0, SA1=0 - +#define FXOS8700CQ_SLAVE_ADDR0 (0x1E<<1) // with pins SA0=0, SA1=0 +#define FXOS8700CQ_SLAVE_ADDR1 (0x1D<<1) // with pins SA0=1, SA1=0 +#define FXOS8700CQ_SLAVE_ADDR2 (0x1C<<1) // with pins SA0=0, SA1=1 +#define FXOS8700CQ_SLAVE_ADDR3 (0x1F<<1) // with pins SA0=1, SA1=1 // FXOS8700CQ internal register addresses -#define FXOS8700CQ_STATUS 0x00 -#define FXOS8700CQ_WHOAMI 0x0D -#define FXOS8700CQ_XYZ_DATA_CFG 0x0E -#define FXOS8700CQ_CTRL_REG1 0x2A -#define FXOS8700CQ_M_CTRL_REG1 0x5B -#define FXOS8700CQ_M_CTRL_REG2 0x5C -#define FXOS8700CQ_WHOAMI_VAL 0xC7 +#define FXOS8700Q_STATUS 0x00 +#define FXOS8700Q_OUT_X_MSB 0x01 +#define FXOS8700Q_OUT_Y_MSB 0x03 +#define FXOS8700Q_OUT_Z_MSB 0x05 +#define FXOS8700Q_M_OUT_X_MSB 0x33 +#define FXOS8700Q_M_OUT_Y_MSB 0x35 +#define FXOS8700Q_M_OUT_Z_MSB 0x37 +#define FXOS8700Q_WHOAMI 0x0D +#define FXOS8700Q_XYZ_DATA_CFG 0x0E +#define FXOS8700Q_CTRL_REG1 0x2A +#define FXOS8700Q_M_CTRL_REG1 0x5B +#define FXOS8700Q_M_CTRL_REG2 0x5C +#define FXOS8700Q_WHOAMI_VAL 0xC7 class FXOS8700Q { public: - /** - * MPL3115A2 constructor - * - * @param sda SDA pin - * @param sdl SCL pin - * @param addr addr of the I2C peripheral - */ - FXOS8700Q(PinName sda, PinName scl); - - /** - * Get the value of the WHO_AM_I register - * - * @returns DEVICE_ID value == ?? - */ - //uint8_t getDeviceID(); - - /** - * Return the STATUS register value - * - * @returns STATUS register value - */ - //unsigned char getStatus( void); - - /** - * Get the Accelerometer & Magnetometer values - * Accelerometer data is in G's - * MAgnetometer Data is in microteslas - * - * @returns altimeter value as float - */ - void ReadXYZ(float * a, float * m); - + /** + * FXOS8700Q constructor + * + * @param sda SDA pin + * @param sdl SCL pin + * @param addr addr of the I2C peripheral + */ + + FXOS8700Q(PinName sda, PinName scl, int addr); + + /** + * FXOS8700Q destructor + */ + ~FXOS8700Q(); + + /** + * Get the value of the WHO_AM_I register + * + * @returns WHO_AM_I value + */ + uint8_t getWhoAmI(); + + /** + * Get X axis acceleration + * + * @returns X axis acceleration + */ + float getAccX(); -private: + /** + * Get Y axis acceleration + * + * @returns Y axis acceleration + */ + float getAccY(); + + /** + * Get Z axis acceleration + * + * @returns Z axis acceleration + */ + float getAccZ(); - I2C _i2c; - /** Set the device in active mode - */ - void begin( void); - - void RegRead( char reg, char * d, int len); + /** + * Get XYZ axis acceleration + * + * @param res array where acceleration data will be stored + */ + void getAccAllAxis(float * res); + void AccXYZraw(int16_t * d); + void MagXYZraw(int16_t * d); + void readRegs(int addr, uint8_t * data, int len); + +private: + I2C m_i2c; + int m_addr; + void writeRegs(uint8_t * data, int len); + int16_t getAccAxis(uint8_t addr); };